Skip to contentSkip to conversation

Getting the number of 512-byte sectors?

DISCUSSION [email protected] 1 participant 1 message Jan 22, 2001

lore
Share & tools
lore
#0 lore raw

From: Anton Altaparmakov <[email protected]>
Subject: Getting the number of 512-byte sectors?

My question is how to get the _real_ number of sectors of a partition from within a file system. I.e. we are starting only with the knowledge of the struct super_block for the partition.

As you conjectured already, you find this info in the gendisk->part[] array, in the start_sect and nr_sects fields.

Locate the correct gendisk structure by performing a walk of gendisk_head as done in drivers/block/blkpg.c::get_gendisk(kdev_t), (Could we make this function to not be private to blkpg.c?), then get the hd_struct for the partition and obtain the values from that. In code:

struct gendisk *g = get_gendisk(my_super_block->s_dev) struct hd_struct *hd = &g->part[MINOR(my_super_block->s_dev)];

wanted "subtracted" values:
hd->start_sect
hd->nr_sects

Am I missing something?

No, I agree completely.

Note: I know I can normally get the number of sectors from the boot sector of the partition

Not necessarily. The partition table need not be of DOS type. Or, even if it is, the kernel's tables may be set up dynamically.

Quoted 1 line

Could we make this function to not be private to blkpg.c?

I think this area will change rather drastically in 2.5.*.

Andries
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/