Page 1 of 1

Get max cylinders sectors heads from a hdd file size

Posted: Sat Dec 01, 2012 12:54 am
by Matt123456
Looking at this from an x86 emulator point of view, is it possible to know the Max CHS just from the HDD image size.
I've tried assumptions like CHS = x/255/63 or x/15/63 but it does not appear to work fully.

Making a loop to guess what it might be. E.G. (In Basic)

Code: Select all

    lbaSize = (32 Meg or 112 Meg etc...) / 512
    For C = 0 To 1023
        For H = 0 To 255
            For S = 1 To 63
                If (C * H * S) = lbaSize Then Print C, H, S
            Next S
        Next H
    Next C
It shows a dozen possible answers. But is there a proper way?
I'm thinking the emulator should not need to know what filing system in on the HDD, otherwise I'll have to program in many file system type checks.

This is regarding basic interupt 13h, during the bootup/bootstrap time. I'm tring to run some various OS images I've downloaded from the web. I've got no problem with floppy images (obviously) but trouble with the HDD ones.

Re: Get max cylinders sectors heads from a hdd file size

Posted: Sat Dec 01, 2012 6:30 am
by Kevin
No, you can't know, it's ambiguous. Either you let the user specify the values (very inconvenient), or you just pick any geometry (may not match what the OS expects on preexisting images) or you start doing crazy things like looking at the partition table (imagine what happens with the virtual disk when you modify the partition table and reboot...)

qemu looks at the partition table, and failing that it picks a x/16/63 geometry.

Re: Get max cylinders sectors heads from a hdd file size

Posted: Sat Dec 01, 2012 12:02 pm
by Matt123456
'doh', thanks for the info - I can stop trying to look / workout the answer.
qemu looks at the partition table, and failing that it picks a x/16/63 geometry.
I think I will use the qemu suggestion, it seems like a good idea. Especially the default chs setting :idea:
Thank you, Matty

Re: Get max cylinders sectors heads from a hdd file size

Posted: Sat Dec 01, 2012 1:06 pm
by bewing
Technically, the point is that in any emulator or in real life you are supposed to use an int13h command to dynamically get the HD geometry from the BIOS, and you aren't supposed to ever need to hardcode it.