Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


When a block device is opened for usingblkdev_openand exclusive use is requested as dis-
cussed in Section 6.5.4, thefileinstance associated with the device file claims the block device.
It is interesting to observe that there are currently no users ofbd_privatefield in the kernel
sources. Thebd_claimmechanism, however, is still useful even if no holder needs to associate
private data with a block device currently.
A block device is released withbd_release.

Generic Hard Disks and Partitions


Whilestruct block_devicerepresents a block device toward the device driver level, another abstrac-
tion emphasizes the connection with generic kernel data structures. From this point of view, the block
devices by themselves are not interesting. Instead, the notion of a hard disk, possibly with subpartitions,
is more useful. The partition information on a device is independent of theblock_deviceinstances that
represent the partitions. Indeed, when a disk is added to the system, the kernel reads and analyzes the
partition information on the underlying block device but does not create theblock_deviceinstances
for the individual partitions. For these reasons, the kernel uses the following data structure to provide a
representation for generic partitioned hard disks (some fields related to statistics bookkeeping have been
omitted):

<genhd.h>
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] */
int part_uevent_suppress;
struct block_device_operations *fops;
struct request_queue *queue;
void *private_data;
sector_t capacity;
int flags;
struct device *driverfs_dev;
struct kobject kobj;
...
};

❑ majorspecifies the major number of the driver;first_minorandminorsindicate the range
within which minor numbers may be located (we already know that each partition is allocated
its own minor number).
❑ disk_namegives a name to the disk. It is used to represent the disk in sysfs and in
/proc/partitions.
❑ partis an array consisting of pointers tohd_struct, whose definition is given below. There is
one entry for each disk partition.
❑ Ifpart_uevent_suppressis set to a positive value, no hotplug events are sent to userspace if
changes in the partition information of the device are detected. This is only used for the initial
partition scan that occurs before the disk is fully integrated into the system.
Free download pdf