Re: Disk geometry from /sys

From: Francis Moreau
Date: Tue Apr 22 2008 - 16:10:29 EST


Hi Seewer,

Sorry for being late.

On Thu, Apr 17, 2008 at 4:49 PM, Seewer Philippe <philippe.seewer@xxxxxx> wrote:
> Take the example above. A disk with 255 heads? Not impossible but
> improbable. Where's the value from?
>
> -The physical disks behind the example is an older laptop IDE disk. 'hdparm
> -I' shows 16 heads and 63 sectors, which is already an approximated value
> anyway. See Dick Johnson's post about that.
>
> -The module handling the drive is 'ata_piix', the newer Driver from the
> SATA/PATA tree, which presents all drives (*ATA) to the rest of the system
> through the scsi sublayer.
>
> -The final "getter" geometry code in the scsi sublayer (scsicam_bios_param
> in scsicam.c):
>
> /* if something went wrong, then apparently we have to return
> a geometry with more than 1024 cylinders */
> if (ret || ip[0] > 255 || ip[1] > 63) {
> if ((capacity >> 11) > 65534) {
> ip[0] = 255;
> ip[1] = 63;
> } else {
> ip[0] = 64;
> ip[1] = 32;
> }
>
> if (capacity > 65535*63*255)
> ip[2] = 65535;
> else
> ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
> }
> Read this as ip[0] is heads, ip[1] is sectors and ip[2] is cylinders. Make
> sense of course, since C/H/S values don't really matter to scsi anyway. So

Just out of curiosity, what does scsi use for addressing IO operations ?

> the default return value for the disks we use today is 255/63 for heads and
> sectors. A fixed constant which most of the time makes sense and works for
> most bios and bootloaders, but is wrong in the sense that it doesn't
> represent the actual values printed on the disks back.
>
> >
> > > versus the second one which tries to
> > > guess a disks geometry by looking at the current partition table. Which
> > > might be just as wrong since its only necessary for bios and/or
> bootloader.
> > >
> >
> > But what happens if you want to guess the geometry of a disk with no
> > partition table ? You need to trust the kernel guess but from what I
> understood
> > it's just wrong.
> >
> Assuming H/S as 255/63 and calculating C from the disks capaticy is quite
> safe. Except for a few weird use cases like using old OS's and os-installers
> that still trust the BIOS.
> Depending on the type of disks you work with 'hdparm -I' works well too.
> Otherwise there's always CONFIG_EDD ('BIOS Enhanced Disk Drive calls
> determine boot disk') which exports BIOS geometry values to sysfs for the
> current default boot disk.
>
> Hope this helps

Thanks a lot for your time.
--
Francis
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/