Re: Size of a partition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thursday 03 March 2005 08:06 pm, Sascha Effert wrote:
> 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
>

By the looks of you partno, I am guessing that your kernel has large block 
device support, which means that sector_t is 64bits. If that's the case, use 
%llu instead of %lu for those fields with the type sector_t .

tavi 

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux