2016-02-18 13:27
浏览 910


I'm trying to use the syscall.Mount function to mount a usb pendrive and autodetect the filesystem to some folder. I fetch the device path from the kernel's netlink socket and try to mount it to /tmp/+devicename, in my instance /dev/sdd1 should be mounted to /tmp/sdd1

I have the following lines of code in a go program

if err := syscall.Mount(src, target, "auto", 0, "ro"); err != nil {
    log.Printf("Mount(\"%s\", \"%s\", \"auto\", 0, \"ro\")


main.go:47: Mount("/dev/sdd1", "/tmp/sdd1", "auto", 0, "ro")
main.go:48: no such device

I'm running the application with root privileges with "sudo", however it seems unable to mount using the syscall package. If i however in the terminal type sudo mount /dev/sdd1 /tmp/sdd1 then that works fine.

What is the issue here? Is the device path somehow different when using the system call?

Any help is appreciated. Cheers

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用syscall.Mount函数来安装USB PenDrive并将文件系统自动检测到某个文件夹。 我从内核的netlink套接字获取设备路径,并尝试将其安装到 / tmp / + devicename ,在我的实例中 / dev / sdd1 应该安装到 / tmp / sdd1

如果err:= syscall,我在go程序中有以下几行代码

 。  Mount(src,target,“ auto”,0,“ ro”);  err!= nil {
 log.Printf(“ Mount(\”%s \“,\”%s \“,\” auto \“,0,\” ro \“)


  main.go:47:  Mount(“ / dev / sdd1”,“ / tmp / sdd1”,“ auto”,0,“ ro”)

我正在以“ sudo”的root特权运行该应用程序,但是似乎无法使用syscall程序包挂载。 但是,如果我在终端中键入 sudo mount / dev / sdd1 / tmp / sdd1 ,则可以正常工作。

这里的问题是什么? 使用系统调用时设备路径是否有所不同?

我们将提供任何帮助。 干杯

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongmeng2687 2016-02-18 14:26

    You didn't specify your OS but I think the problem is the same on many implementations.

    On Linux syscall.Mount just wraps mount(2) which doesn't itself support the concept of an "auto" fstype.

    The reason the mount(8) command works with "auto" is because 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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题