Chapter 6: Device Drivers
Connectingthe Pieces
The previously introduced data structures —struct block_device,struct gendisk,andstruct
hd_struct— are directly connected with each other. Figure 6-10 shows how.struct
block_devicebd_containsbd_containsbd_part
bd_diskbd_part
bd_diskbd_contains
bd_part
bd_diskstruct
gendiskstruct hd_structpartFigure 6-10: Connection between block devices, generic hard disks, and partitions.For each partition of a block device that has already been opened, there is an instance ofstruct
block_device. The objects for partitions are connectedwith the object for the complete device via
bd_contains.Allblock_deviceinstances contain a link to their generic disk data structuregen_diskvia
bd_disk. Note that while there are multipleblock_deviceinstances for a partitioned disk, onegendisk
instance is sufficient.Thegendiskinstance points to an array with pointers tohd_structs. Each represents one partition. If
ablock_devicerepresents a partition, then it contains a pointer to thehd_structin question — the
hd_structinstances are shared betweenstruct gendiskandstruct block_device.Additionally, generic hard disks are integrated into thekobjectframework as shown in Figure 6-11. The
block subsystem is represented by theksetinstanceblock_subsystem.Theksetcontains a linked list on
which the embeddedkobjectsofeachgendiskinstance are collected.listkobj.parent kobj.parentstruct hd_structstruct kset
block_subsysentry entrystruct gendiskembedded
kobjFigure 6-11: Integration of generic harddisks with the generic kernel object
framework.