[英]How to read and write the raw device file of a usb flash drive as non-root
My USB flash drive gets automatically mounted at /media/ME
without requiring root
intervention. 我的USB闪存驱动器会自动安装在
/media/ME
而无需root
干预。
Now, I can read and write sectors on the drive mounted at /dev/sdX
device using open
, lseek
, read
, and write
. 现在,我可以使用
open
, lseek
, read
和write
来读取/写入安装在/dev/sdX
设备上的驱动器上的扇区。 But I can do this only as root
. 但是我只能以
root
身份执行此操作。
Question: Just as the device can get mounted without root
intervention, is it also possible to read and write from/to this device without being root
? 问:正如的设备可以安装无需
root
干预,是否也可以读取和/这个设备写而不root
?
If it's not possible, I'm willing to show a GUI password dialog for
root
.
如果不可能,我愿意为
root
显示一个GUI密码对话框。
But how do I do this from my console program?
但是如何从控制台程序执行此操作?
Yes 是
The block device /dev/sdX has standard UNIX permissions - so if it is owned by your user or a group your user is in and the permissions are set correctly then you will be able to write to it. 块设备/ dev / sdX具有标准的UNIX权限-因此,如果它属于您的用户或用户所在的组,并且权限设置正确,则可以对其进行写入。
$ ls -l /dev/sda
brw-rw---T 1 root disk 8, 0 Dec 3 18:27 /dev/sda
So only root and members of the group disk can read or write to my /dev/sda. 因此,只有root和组磁盘成员可以读取或写入我的/ dev / sda。 If I put myself in the disk group I would be able to write to the block device.
如果我将自己放入磁盘组,则可以写入块设备。
You can set-up udev to set the permission of the block devices automagically when they are plugged in. 您可以设置udev以在插入块设备时自动设置其权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.