看块设备驱动部分的笔记(5)

2020-06-28 00:00:00 专区 对象 磁盘 设备 指向

block_device

相关数据结构:

struct block_device {
dev_t bd_dev; /* not a kdev_t - it's a search key */
struct inode * bd_inode; /* will die */
int bd_openers;
struct semaphore bd_sem; /* open/close mutex */
struct semaphore bd_mount_sem; /* mount mutex */
struct list_head bd_inodes;
void * bd_holder;
int bd_holders;
struct block_device * bd_contains;
unsigned bd_block_size;
struct hd_struct * bd_part;
/* number of times partitions within this device have been opened. */
unsigned bd_part_count;
int bd_invalidated;
struct gendisk * bd_disk;
struct list_head bd_list;
struct backing_dev_info *bd_inode_backing_dev_info;
/*
* Private data. You must have bd_claim'ed the block_device
* to use this. NOTE: bd_claim allows an owner to claim
* the same device multiple times, the owner must take special
* care to not mess up bd_private for that case.
*/
unsigned long bd_private;
};

每一个块设备都由一个block_device对象来表示.
这里所说的块设备其实是指一个逻辑块设备.
比如一个磁盘由一个block_device对象来表示,而该磁盘又分了三个分区,这三个分区就又是三个逻辑块设备.

block_device中的bd_contains字段指向与整个磁盘相关的block_device对象.
因而,如果如果block_device表示一个磁盘分区,则其bd_contains指向整个磁盘的block_device对象.
如果block_device表示的是一个磁盘,则其bd_contains指向自己.


block_device中有几个比较重要的字段:
bd_disk 指向块设备中磁盘对应的gendisk结构.
bd_part 指向hd_struct分区描述符(如果是整个磁盘的话,bd_part为NULL)

综合前面所有的结构,整体的结构关系如下图所示:


  


文章来源CU社区:看块设备驱动部分的笔记

相关文章