golang在syscall.Mount中没有这样的设备 [英] golang no such device in syscall.Mount

查看:98
本文介绍了golang在syscall.Mount中没有这样的设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我在go程序中有以下几行代码

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\")\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特权运行该应用程序,但是似乎无法使用syscall软件包进行挂载.但是,如果我在终端中键入 sudo mount/dev/sdd1/tmp/sdd1 ,则可以正常工作.

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?

感谢您的帮助.干杯

推荐答案

您没有指定操作系统,但我认为在许多实现中问题都相同.

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

Linux syscall.Mount 仅包装 mount(2) 本身不支持自动" fstype的概念.

mount(8) 命令"auto" 一起使用的原因是因为

The reason the mount(8) command works with "auto" is because it does its own magic:

如果未指定-t选项,或者指定了自动类型,mount将尝试猜测所需的类型.安装使用blkid库,用于猜测文件系统类型;如果有的话没有打开任何看起来很熟悉的东西,mount会尝试读取文件/etc/filesystems,或者,如果该文件不存在,/proc/filesystems .

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.

这篇关于golang在syscall.Mount中没有这样的设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆