Adding Partitions

add_partition is 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 of struct hd_struct is allocated 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->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, the ktype is not ktype_block, but ktype_part. This allows for distinguishing uevents (see Section 7.4) that originate from disks from uevents that originate 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;

Adding the new object with kobject_add makes 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);

Continue reading here: Adding Disks

Was this article helpful?

0 0