douyanzan9145 2016-02-18 13:27
浏览 1020
已采纳

golang在syscall.Mount中没有这样的设备

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\")
",src,target)
    log.Fatal(err)
}

Output:

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

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型