Get max cylinders sectors heads from a hdd file size

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
Matt123456
Posts: 2
Joined: Sat Dec 01, 2012 12:20 am

Get max cylinders sectors heads from a hdd file size

Post 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.
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

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

Post 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.
Developer of tyndur - community OS of Lowlevel (German)
Matt123456
Posts: 2
Joined: Sat Dec 01, 2012 12:20 am

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

Post 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
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

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

Post 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.
Post Reply