How to get 'device struct' from 'dev_t' in Linux kernel programming?
I am new to kernel programming and I am following the guide given in: USB Boot Authentication
I want to get the "device structure" of a USB stick. I have a "dev_t" USB device instance. Also, I want to check if the struct is a USB device or not. I can't figure out how to start ...
thank
source to share
As hiteshradia said, dev_t
is device number (major and minor). However, you can use this in conjunction with the knowledge that the block device is accessing the struct device
associated one. To do this, use struct block_device *bdget(dev_t)
from linux/fs.h
. From this you can use block_device->bd_part
to get struct hd_struct *
to the device and finally use the struct device *part_to_dev(struct hd_struct *)
defined as a macro in linux/genhd.h
.
source to share
dev_t
is just the device number which represents the section /dev/sdb1
as seen in your link. Cannot get detailed information on USB storage.
The link provided has a section
if(udev->serial != NULL)
{
if((strcmp(udev->serial, "3513001D97827E69")) == 0) /* Hard coded usb device serial here*/
{
key_dev_found = 1;
}
}
where you can get USB device data and struct usb_device *udev
source to share