golang syscall.Mount 中没有这样的设备
golang no such device in syscall.Mount
我正在尝试使用 syscall.Mount 函数挂载 USB 随身碟并将文件系统自动检测到某个文件夹。我从内核的 netlink 套接字获取设备路径并尝试将其挂载到 /tmp/+devicename
,在我的实例中 /dev/sdd1
应该挂载到 /tmp/sdd1
我在go程序中有如下几行代码
if err := syscall.Mount(src, target, "auto", 0, "ro"); err != nil {
log.Printf("Mount(\"%s\", \"%s\", \"auto\", 0, \"ro\")\n",src,target)
log.Fatal(err)
}
输出:
main.go:47: Mount("/dev/sdd1", "/tmp/sdd1", "auto", 0, "ro")
main.go:48: no such device
我是 运行 具有 "sudo" root 权限的应用程序,但它似乎无法使用系统调用包进行挂载。但是,如果我在终端类型 sudo mount /dev/sdd1 /tmp/sdd1
中工作正常。
这里有什么问题?使用系统调用时设备路径是否有所不同?
感谢任何帮助。
干杯
你没有指定你的 OS 但我认为这个问题在许多实现中都是一样的。
在 Linux syscall.Mount
just wraps mount(2)
which doesn't itself support the concept of an "auto" fstype。
mount(8)
命令与"auto"
一起工作的原因是因为it does its own magic:
If no -t option is given, or if the auto type is specified,
mount will try to guess the desired type. Mount uses the
blkid library for guessing the filesystem type; if that does
not turn up anything that looks familiar, mount will try to
read the file /etc/filesystems, or, if that does not exist,
/proc/filesystems
.
我正在尝试使用 syscall.Mount 函数挂载 USB 随身碟并将文件系统自动检测到某个文件夹。我从内核的 netlink 套接字获取设备路径并尝试将其挂载到 /tmp/+devicename
,在我的实例中 /dev/sdd1
应该挂载到 /tmp/sdd1
我在go程序中有如下几行代码
if err := syscall.Mount(src, target, "auto", 0, "ro"); err != nil {
log.Printf("Mount(\"%s\", \"%s\", \"auto\", 0, \"ro\")\n",src,target)
log.Fatal(err)
}
输出:
main.go:47: Mount("/dev/sdd1", "/tmp/sdd1", "auto", 0, "ro")
main.go:48: no such device
我是 运行 具有 "sudo" root 权限的应用程序,但它似乎无法使用系统调用包进行挂载。但是,如果我在终端类型 sudo mount /dev/sdd1 /tmp/sdd1
中工作正常。
这里有什么问题?使用系统调用时设备路径是否有所不同?
感谢任何帮助。 干杯
你没有指定你的 OS 但我认为这个问题在许多实现中都是一样的。
在 Linux syscall.Mount
just wraps mount(2)
which doesn't itself support the concept of an "auto" fstype。
mount(8)
命令与"auto"
一起工作的原因是因为it does its own magic:
If no -t option is given, or if the auto type is specified, mount will try to guess the desired type. Mount uses the blkid library for guessing the filesystem type; if that does not turn up anything that looks familiar, mount will try to read the file /etc/filesystems, or, if that does not exist,
/proc/filesystems
.