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)
You can iterate over block devices using
class_dev_iter_initandclass_dev_iter_next. See the code inblock/genhd.cblk_lookup_devtfor usage.Once you have the device, you can use
dev_to_diskto get astruct gendisk *, in which you can check the removable flag.