Re: RFC: disk geometry via sysfs

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

 



linux-os (Dick Johnson) wrote:
Heads start at 0. Sectors start at 1. Cylinders start at 0.
A "lower head" than allowed would be 0xff so the BIOS wouldn't
know it was "lower". The BIOS doesn't look at the MBR for
normal read/write access! Only while booting does it
read the first sector of the master boot record (MBR) into
the appropriate physical place (0x7c00). Then it checks to see
if there is an 0xaa55 as the last word in the sector. If so,
it executes code starting at offset zero. Modern BIOS don't
even check the "boot flag" because it may be wrong, preventing
a boot.


I'm talking about the geometry of the disk. If the disk has 16 sectors and 8 heads, then the maximum value allowed for any valid address is 16 in the sector field and 7 in the heads field. This influences the translation to/from LBA. A sector with LBA of 1234 would have a CHS address using this geometry of 9/5/3. If the disk reports a geometry of x/8/16 but the bios is using a geometry of x/255/63, then when you pass 9/5/3 to int 13 it will fetch LBA 144902 which is clearly not going to give you what you wanted.

This is why you must use the same geometry that the bios exposes, NOT what the disk reports in its inquiry command. It is quite typical for a disk to report that it uses 8 heads and has a number of cylinders that is > 1024. The bios will typically present a view of the disk with 255 heads ( though it very well may use a smaller value ). If you generate CHS addresses when you write the MBR using 8 heads, they will be wrong when you try to pass them to the bios.

Now, during the boot sequence, the BIOS via INT 0x13 or 0x40
will be called upon to read data into memory from various
offsets on the media. If the offsets are calculated in the
same way that they were calculated when the disk was initialized
as a boot disk, then everything is okay. The calculations of
offsets do not require the same C/H/S phony variables! One

Yes, they do require the same geometry, see above.

only has to follow the correct rules. The rules are that
heads increment from 0, as do cylinders, and sectors start
at 1. Also "sectors" must be 512-byte intervals even though
the physical media may have 16 kilobyte sectors. Given
these rules, there are zillions of ways for one to arrive
at the correct offset. The interpretation will be correct
IFF the number of cylinders are extracted first, then the
number of heads (tracks), then the number of sectors, always
using the largest number that will fit into the BIOS
registers used to make that access.


The bios will not accept values that are larger than it's idea of the disk's geometry. If the bios thinks the disk only has 8 heads, you can't ask it to fetch a sector on head 17.

In the case of "large media" access, the cylinders are
set to 0xffff. This triggers additional logic that invents
a new virtual sector length to accommodate.

The following is the __entire__ boot code for an IBM/PC
compatible BIOS! Constant "DISKS" is 0x13.


<snip>

Not sure why you pasted the example bios code, maybe you could explain?


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

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux