Chapter 6: Device Drivers
Table 6-2: Hardware Characteristics of a Request Queue.
Element Meaning
max_sectors Specifies the maximum number of sectors that the device can process in a
single request; the sector size of the specific device (hardsect_size)isused
as the size unit.
max_segment_size Maximum segment size (in bytes) for a single request.
max_phys_segments Specifies the maximum number of non-continuous segments for scatter-
gather requests used to transport non-contiguous data.
max_hw_segments Same asmax_phys_segmentsbut takes into account any remappings that
may be made by a (possible) I/O MMU. The constant specifies the maxi-
mum number of address/length pairs that the driver can pass to the device.
hardsect_size Specifies the physical sector size with which the device operates. This value
is almost always 512; only a few very new devices use different settings.
Adding Partitions
add_partitionis responsible for adding a new partitions into the generic hard disk data structures. I
shall discuss a slightly simplified version here. First of all, a new instance ofstruct hd_structis allo-
cated and filled with some basic information about the partition:
fs/partitions/check.c
void add_partition(struct gendisk disk, int part, sector_t start, sector_t len, int flags)
{
struct hd_struct p;
p = kzalloc(sizeof(*p), GFP_KERNEL);
...
p->start_sect = start;
p->nr_sects = len;
p->partno = part;
...
After assigning a name that shows up, for instance, in sysfs, the partition’s kernel object parent is set to be
the generic hard disk object. In contrast to complete disks, thektypeis notktype_block,butktype_part.
This allows for distinguishing uevents (see Section 7.4) that originate from disks from uevents that origi-
nate from partitions:
fs/partitions/check.c
kobject_set_name(&p->kobj, "%s%d",
kobject_name(&disk->kobj),part);
p->kobj.parent = &disk->kobj;
p->kobj.ktype = &ktype_part;
...