看块设备驱动部分的笔记(3)
gendisk
相关数据结构:
struct gendisk {
int major; /* major number of driver */
int first_minor;
int minors; /* maximum number of minors, =1 for
* disks that can't be partitioned. */
char disk_name[32]; /* name of major driver */
struct hd_struct **part; /* [indexed by minor] */
struct block_device_operations *fops;
struct request_queue *queue;
void *private_data;
sector_t capacity;
int flags;
char devfs_name[64]; /* devfs crap */
int number; /* more of the same */
struct device *driverfs_dev;
struct kobject kobj;
struct timer_rand_state *random;
int policy;
atomic_t sync_io; /* RAID */
unsigned long stamp, stamp_idle;
int in_flight;
#ifdef CONFIG_SMP
struct disk_stats *dkstats;
#else
struct disk_stats dkstats;
#endif
};
struct hd_struct {
sector_t start_sect;
sector_t nr_sects;
struct kobject kobj;
unsigned reads, read_sectors, writes, write_sectors;
int policy, partno;
};
磁盘由gendisk对象来表示。
磁盘的分区用hd_struct对象表示。
磁盘的分区是通过设备的次设备号(minor)来区分的,例如
hda1就是个分区,hda2就是第二个分区。
gendisk的part指向分区数组的首地址,数组的下标是分区的minor索引(从1开始),即数组的个成员是指向minor为1的分区。
文章来源CU社区:看块设备驱动部分的笔记
相关文章