Hello,
I need to know the size of a partition by a dev_t in a module. Could please anyone tell me how I can get it?
What I tried (perhaps uninteresting for you):
To get it I tried to access the hd_struct via bdget(dev)->bd_part. But the nr_sects entry results in 0. So I read the data of the wohle disk, and I do not understand the output. Can anyone explain me what the entrys of the hd_struct mean? And how can I get the size of a Partition?
I tried the following in my module:
gd = bdget(dev)->bd_disk;
if (gd) {
part = bdget(dev)->bd_part;
printk(KERN_ALERT "rad: bdev->part: start %lu, size %lu, part-no %d\n", part->start_sect, part->nr_sects, part->partno);
printk(KERN_ALERT "rad: While importing disk (%d,%d) we had first minor %d and %d partitions.\n", disk.major, disk.minor, gd->first_minor, gd->minors);
printk(KERN_ALERT "rad: gd: major %d, name %s, cap %lu, dev-name %s\n", gd->major, gd->disk_name, gd->capacity, gd->devfs_name);
for (i=0; i < gd->minors; i++) {
part = gd->part[i];
if (part != NULL) {
printk(KERN_ALERT "rad: part index %d: start %lu, size %lu, part-no %d\n", i, part->start_sect, part->nr_sects, part->partno);
}
}
}
I get the following output:
Mar 3 18:40:07 aubinc kernel: rad: bdev->part: start 1317330, size 0, part-no 1028160 Mar 3 18:40:07 aubinc kernel: rad: While importing disk (8,2) we had first minor 0 and 16 partitions. Mar 3 18:40:07 aubinc kernel: rad: gd: major 8, name sda, cap 12582912, dev-name <NULL> Mar 3 18:40:07 aubinc kernel: rad: part index 0: start 63, size 0, part-no 1317267 Mar 3 18:40:07 aubinc kernel: rad: part index 1: start 1317330, size 0, part-no 1028160 Mar 3 18:40:07 aubinc kernel: rad: part index 2: start 2345490, size 0, part-no 2 Mar 3 18:40:07 aubinc kernel: rad: part index 4: start 2345553, size 0, part-no 10233342
This is what fdisk says:
Command (m for help): p
Disk /dev/sda: 6442 MB, 6442450944 bytes 255 heads, 63 sectors/track, 783 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sda1 1 82 658633+ 82 Linux swap/ Solaris /dev/sda2 83 146 514080 fc Unknown /dev/sda3 147 783 5116702+ f W95 Ext'd (LBA) /dev/sda5 147 783 5116671 83 Linux
Command (m for help):
And /dev/sda2 is (8,2): brw-rw---- 1 root disk 8, 2 Oct 2 10:38 /dev/sda2
I don't know whats going wrong.
thanks
Sascha Effert fermat@xxxxxxxxxxxxxxxx
-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/