Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


❑ fopsis a pointer to device-specific functions that perform various low-level tasks. I discuss these
below.
❑ queueis needed to manage request queues, which I discuss below.
❑ private_datais a pointer to private driver data not modified by the generic functions of the
block layer.
❑ capacityspecifies the disk capacity in sectors.
❑ driverfs_devidentifies the hardware device to which the disk belongs. The destination is an
object of the driver model, which is discussed in Section 6.7.1.
❑ kobjis an integratedkobjectinstance for the generic kernel object model as discussed in
Chapter 1.

For each partition, there is an instance ofhd_structto describe the key data of the partition within
the device. Again, I present a slightly simplified version of the data structure to focus on the essential
features.

<genhd.h>
struct hd_struct {
sector_t start_sect;
sector_t nr_sects;
struct kobject kobj;
...
};
start_sectandnr_sectsdefine the start sector and the size of the partition on the block device, thus
describing the partition uniquely (for the sake of brevity, other elements used for statistical purposes are
omitted).kobjassociates the object with the generic object model, as usual.

Thepartsarray is filled by various routines that examine the partition structure of the hard disk when
it is registered. The kernel supports a large number of partitioning methods to support coexistence with
most other systems on many architectures. I won’t bother describing how they are implemented because
they differ only in the details of how information is read from disk and analyzed.

Althoughgendisks represent partitioned disks, they can as well represent devices
without any partitions.

It is also important to note that instances ofstruct gendiskmay not be individually allocated by drivers.
Instead, the auxiliary functionalloc_diskmust be used:

<genhd.h>
struct gendisk *alloc_disk(int minors);
Given the number of minors for the device, calling this function automatically allocates thegenhdinstance
equipped with sufficient space for pointers tohd_structs of the individual partitions.

Only memory for the pointers is added; the partition instances are only allocated when an actual partition
is detected on the device and added withadd_partition.

Additionally,alloc_diskintegrates the new disk into thedevice model data structures.

Consequently,gendisksmustnotbedestroyedbysimplyfreeing them. Usedel_gendiskinstead.
Free download pdf