Although gendisks represent partitioned disks they can as well represent devices without any partitions

It is also important to note that instances of struct gendisk may not be individually allocated by drivers. Instead, the auxiliary function alloc_disk must be used:

struct gendisk *alloc_disk(int minors);

Given the number of minors for the device, calling this function automatically allocates the genhd instance equipped with sufficient space for pointers to hd_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 with add_partition.

Additionally, alloc_disk integrates the new disk into the device model data structures.

Consequently, gendisks must not be destroyed by simply freeing them. Use del_gendisk instead.

Continue reading here: Connecting the Pieces

Was this article helpful?

0 0