通过设备名称获取设备标志
希望你能帮助我: 我试图确定该设备是否可移动,我所拥有的只是设备名称(/dev/sdc)。实际上,我需要通过该文件的完整路径来确定该文件何时位于可移动媒体或本地磁盘上。
我尝试在 当前->fs->pwd 我所能找到的只是这里的一组标志: *当前->fs->pwd.mnt->mnt_sb->s_bdev->bd_disk->flags* 其中 GENHD_FL_REMOVABLE 设置为可移动设备
但我总是得到相同的标志集(据我所知,s_bdev 总是指向相同的设备(/dev/sda))。
所以现在我通过解析mtab得到了包含我的文件的设备名称(/dev/sdc),但仍然找不到,是否删除它。
有没有可能通过设备名称获取 block_device 结构? (例如,“文件”结构可以通过调用获得 fd = 打开(“名称”) fl = fged(fd) 其中 fl 指向“文件”结构)
hope you can help me:
I'm trying to determine whether the device is removable or not, all i have is device name (/dev/sdc). Actually, I need to determine when the file on removable media or on local disk by full path of this file.
I've tryed to search in the
current->fs->pwd
and all I could find is a set of flags here:
*current->fs->pwd.mnt->mnt_sb->s_bdev->bd_disk->flags*
where GENHD_FL_REMOVABLE set for removable devices
But i always get the same flags set (as i understand, s_bdev always points to the same device (/dev/sda)).
So now i get the device name (/dev/sdc) that contains my file by parsing mtab, but still can't find out, removable it or not.
Is there possible way to get block_device structure by device name?
(for example, "file" structure may be obtained by calling
fd = open("name")
fl = fged(fd)
where fl points to "file" structure)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
class_dev_iter_init
和class_dev_iter_next
迭代块设备。使用方法请参见block/genhd.c
blk_lookup_devt
中的代码。拥有设备后,您可以使用 dev_to_disk 来获取 struct gendisk * ,您可以在其中检查可移动标志。
You can iterate over block devices using
class_dev_iter_init
andclass_dev_iter_next
. See the code inblock/genhd.c
blk_lookup_devt
for usage.Once you have the device, you can use
dev_to_disk
to get astruct gendisk *
, in which you can check the removable flag.读取 /sys/block/dev-name/removable,因为如果设备可移动,则它应包含 1,否则应包含 0。 (dev-name = 设备名称: sda, hda, fd0, ...)
Read /sys/block/dev-name/removable as it should contain 1 if the device is removable or 0 if not. (dev-name = the device's name: sda, hda, fd0, ...)