先看代码及注释:
/**
* 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;
}
bdget_disk函数给出通用磁盘描述符指针,以及分区编号,返回分区对应的块设备描述符指针。
调用时传入分区号为0,则表示获取整个磁盘块设备。
获取分区的块设备描述符需要用到bdev文件系统。根据分区号在bdev文件系统查找或分配inode,而块设备描述符与inode是相关联的。函数调用关系为:
sd_probe()
|___add_disk()
|__register_disk()
|__bdget_dev()
|__bdget()
bdev文件系统介绍参考:
http://blog.csdn.net/a954423389/article/details/6870967