【发布时间】:2020-10-26 18:39:53
【问题描述】:
函数Linux syscall.Mount 需要文件系统类型。
如果您尝试使用文件系统auto 运行它,像这样:
func main(){
if err := syscall.Mount("/dev/sda1", "/mnt1", "auto", 0, "w"); err != nil {
log.Printf("Mount(\"%s\", \"%s\", \"auto\", 0, \"rw\")\n","/dev/sda1","/mnt1")
log.Fatal(err)
}
}
它会以no such device 失败。已经描述了here Linux syscall.Mount 只是包装 mount(2), which doesn't itself support the concept of an "auto" fstype。
我知道如何使用 bash 找到它:
root@ubuntu:~/go/src# blkid /dev/sda1
/dev/sda1: UUID="527c895c-864e-4f4c-8fba-460754181173" TYPE="ext4" PARTUUID="db5c2e63-01"
或
root@ubuntu:~/go/src# file -sL /dev/sda1
/dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=527c895c-864e-4f4c-8fba-460754181173 (needs journal recovery) (extents) (large files) (huge files)
在这两种情况下,您都会获得 ext4 文件系统类型。
在Go中用ext4替换auto会解决问题,但是我感兴趣的是,如何使用Go获取文件系统类型,例如@ 987654337@?
有没有类似blkid或file的函数可以显示设备的文件系统类型?
【问题讨论】:
-
这能回答你的问题吗? Get BLKID of an unmounted volume in go
-
好吧,5 年前有人问过这个问题,我希望有人已经“搜索 libblkid 源并在 go 中重新实现它”,所以让我们拭目以待,看看是否有人知道更好的方法,我会的检查我是否可以根据源代码重新实现它。
-
很公平。我无法通过快速搜索找到任何内容,但如果您找到了,请使用信息更新链接的问题。
标签: linux bash go filesystems mount