I want to retrieve the dev_t
structure for a whole disk, given that of a partition on the disk. This is for for a blkext
driver, like nvme
.
Something like:
dev_t part_disk;
dev_t whole_disk = get_whole_disk_dev_t(part_disk);
I would like my the interface of get_whole_disk_dev_t()
to be:
Argument: dev_t
: part_disk
Return: dev_t
: whole_disk
My proposed algorithm:
- Get path of partitioned disk from
dev_t
i.e "/dev/nvme1n1p3". I couldn't find any API to get path fromdev_t
. - Do some string manipulation to remove "p3", giving the path for whole disk
- Pass the path_name of whole disk to
blk_lookup_devt
to get thedev_t
of whole disk.
i.ewhole_disk=blk_lookup_devt(path_name,0)
Is this the right approach or is there a better approach? If the former, then how can I get path from dev_t
?
P.S: I need to implement this in a device driver (i.e in kernel context). In user space I know I can use the udev
API.