英文:
/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/<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)
}
}
BTW, The package k8s.io/utils/mount
has been moved to new location. Use k8s.io/mount-utils
instead.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论