Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


Adding the new object withkobject_addmakes it a member of the block subsystem, and consequently,
the sysfs entries that provide information about the partition appear in/sys/block. Finally, the generic
hard disk object must be modified to point to the new partition:

fs/partitions/check.c
kobject_init(&p->kobj);
kobject_add(&p->kobj);

disk->part[part-1] = p;
}

Adding Disks


Figure 6-12 shows the code flow diagram foradd_disk. A three-stage strategy is employed.

add_disk

blk_register_region

register_disk

blk_register_queue

Figure 6-12: Code flow diagram
foradd_disk.

First of all, callingblk_register_regionensures that the desired device number range is not yet allo-
cated. More interesting work is performed inregister_disk. After the kernel object is supplied with
aname,anewblock_deviceinstance for the device is obtained withbdget_disk(the function is a
parameter conversion front end forbdget).

Until now, nothing is known about the partitions of the device. To remedy this situation, the kernel
calls several procedures that end up inrescan_partitions(see the discussion of the exact call chain in
the next section). The function tries to identify the partitions on the block device by trial and error. The
global arraycheck_partcontains pointers to functions that are able to identify one particular partition
type. On standard computers, usually PC Bios or EFI partitions will be used, but support is also available
for more esoteric types like SGI Ultrix or Acorn Cumana partitions. Each of these functions is allowed to
have a look at the block device,^9 and if a known partition scheme is detected, thecheck_partfunction
returns this information torescan_partitions. Here,add_partitionas discussed above is called for
each detected partition.

6.5.4 Opening Block Device Files


When a user application opens the device file of a block device, the virtual filesystem invokes theopen
function of thefile_operationsstructure and arrives atblkdev_open. Figure 6-13 shows the associated
code flow diagram.

(^9) Note that this implies that reading data from the block device is already required to work when the device is registered with
disk_add!

Free download pdf