/proc/mounts没有像/proc/self/mountinfo那样的源信息。

huangapple go评论80阅读模式
英文:

/proc/mounts does not have Source info like /proc/self/mountinfo has

问题

我正在开发一个Go应用程序,我想使用mount-utils包:https://pkg.go.dev/k8s.io/utils/mount

在这个包中,它解析的是/proc/mounts文件而不是/proc/self/mountinfo文件。

如何使用这个包来确定source的值?与/proc/self/mountinfo相比,/proc/mounts文件中缺少这个信息。

英文:

I am working on a go application where I want to use the the mount-utils package: https://pkg.go.dev/k8s.io/utils/mount

Here, this package parses /proc/mounts file instead of /proc/self/mountinfo.

How do I figure out value for source using this package? This piece of information is missing in /proc/mounts file as compared to /proc/self/mountinfo.

答案1

得分: 1

mount.ParseMountInfo 函数用于解析 /proc/<pid>/mountinfo 文件。

package main

import (
	"fmt";

	"k8s.io/utils/mount"
)

func main() {
	mounts, err := mount.ParseMountInfo("/proc/self/mountinfo")
	if err != nil {
		panic(err)
	}

	for _, m := range mounts {
		fmt.Printf("%-100s%s\n", m.MountPoint, m.Source)
	}
}

顺便提一下,k8s.io/utils/mount 包已经被移动到新的位置。请使用 k8s.io/mount-utils 替代。

英文:

mount.ParseMountInfo parses /proc/&lt;pid&gt;/mountinfo.

package main

import (
	&quot;fmt&quot;

	&quot;k8s.io/utils/mount&quot;
)

func main() {
	mounts, err := mount.ParseMountInfo(&quot;/proc/self/mountinfo&quot;)
	if err != nil {
		panic(err)
	}

	for _, m := range mounts {
		fmt.Printf(&quot;%-100s%s\n&quot;, m.MountPoint, m.Source)
	}
}

BTW, The package k8s.io/utils/mount has been moved to new location. Use k8s.io/mount-utils instead.

huangapple
  • 本文由 发表于 2023年7月12日 13:47:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76667454.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定