From: Seewer Philippe <philippe.seewer@bfh.ch>
To: Francis Moreau <francis.moro@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Disk geometry from /sys
Date: Thu, 17 Apr 2008 16:49:02 +0200 [thread overview]
Message-ID: <4807635E.9060101@bfh.ch> (raw)
In-Reply-To: <38b2ab8a0804170709m58830adagcba46f059ed10809@mail.gmail.com>
Hi,
Francis Moreau wrote:
> Hello Seewer,
>
> On Wed, Apr 16, 2008 at 9:49 AM, Seewer Philippe <philippe.seewer@bfh.ch> wrote:
>> Correct. Though be really careful which geometry you are requesting:
>>
>> root@local:/# sfdisk -g /dev/sda
>> /dev/sda: 7296 cylinders, 255 heads, 63 sectors/track
>> root@local:/# sfdisk -G /dev/sda
>> /dev/sda: 116280 cylinders, 16 heads, 63 sectors/track
>>
>> The first one is the kernels idea of a disks geometry which is probably as
>> often correct as it's just plain wrong,
>
> Sorry but I don't understand, what do you mean ?
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 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
Philippe
next prev parent reply other threads:[~2008-04-17 14:49 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-09 20:53 Disk geometry from /sys Francis Moreau
2008-04-09 21:28 ` Lennart Sorensen
2008-04-09 21:52 ` Alan Cox
2008-04-09 22:16 ` Bernd Eckenfels
2008-04-10 14:52 ` Lennart Sorensen
2008-04-10 19:23 ` Francis Moreau
2008-04-09 21:57 ` Mark Lord
2008-04-10 19:05 ` Francis Moreau
2008-04-10 19:53 ` Mark Lord
2008-04-10 12:22 ` linux-os (Dick Johnson)
2008-04-10 19:15 ` Francis Moreau
2008-04-10 13:58 ` Bill Davidsen
2008-04-14 12:57 ` Seewer Philippe
2008-04-15 7:40 ` Francis Moreau
2008-04-16 7:49 ` Seewer Philippe
2008-04-17 14:09 ` Francis Moreau
2008-04-17 14:49 ` Seewer Philippe [this message]
2008-04-18 13:22 ` Mark Lord
2008-04-18 13:37 ` Seewer Philippe
2008-04-22 20:11 ` Francis Moreau
2008-04-23 6:44 ` Seewer Philippe
2008-04-23 6:56 ` Francis Moreau
2008-04-22 20:16 ` Francis Moreau
2008-04-22 22:44 ` Mark Lord
2008-04-23 6:53 ` Seewer Philippe
2008-04-23 7:02 ` Francis Moreau
2008-04-23 9:33 ` Seewer Philippe
2008-04-23 13:47 ` Mark Lord
2008-04-22 20:10 ` Francis Moreau
2008-04-23 6:48 ` Seewer Philippe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4807635E.9060101@bfh.ch \
--to=philippe.seewer@bfh.ch \
--cc=francis.moro@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox