First read the code and comments:
/**
* Bdget_disk-Do bdget () by gendisk and Partition Number
* @ Disk: gendisk of interest
* @ Partno: Partition Number
*
* Find partition @ partno from @ disk, do bdget () on it.
*
* Context:
* Don't care.
*
* Returns:
* Resulting block_device on success, null on failure.
*/
Struct block_device * bdget_disk (struct gendisk * disk, int partno)
{
Struct hd_struct * part;
Struct block_device * bdev = NULL;
Part = disk_get_part (disk, partno );
If (Part)
Bdev = bdget (part_devt (part ));
Disk_put_part (part );
Return bdev;
}
The bdget_disk function provides the generic disk descriptor pointer and Partition Number, and returns the block device descriptor pointer corresponding to the partition.
If the input Partition Number is 0 during the call, the system obtains the entire disk block device.
To obtain the block device descriptor of a partition, you must use the bdev file system. Inode is searched or allocated in the bdev File System Based on the partition number, and the block device descriptor is associated with inode. The function call relationship is as follows:
Sd_probe ()
| ___ Add_disk ()
|__ Register_disk ()
|__ Bdget_dev ()
|__ Bdget ()
Bdev file system Introduction Reference:
Http://blog.csdn.net/a954423389/article/details/6870967