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_device
bd_contains
bd_contains
bd_part
bd_disk
bd_part
bd_disk
bd_contains
bd_part
bd_disk
struct
gendisk
struct hd_struct
part
Figure 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.
list
kobj.parent kobj.parent
struct hd_struct
struct kset
block_subsys
entry entry
struct gendisk
embedded
kobj
Figure 6-11: Integration of generic harddisks with the generic kernel object
framework.