[Solved] Calculate Disk Geometry from Disk Size

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
User avatar
trinopoty
Member
Member
Posts: 87
Joined: Wed Feb 09, 2011 2:21 am
Location: Raipur, India

[Solved] Calculate Disk Geometry from Disk Size

Post by trinopoty »

How can one calculate the disk geometry with nothing but the size of the disk in sectors.
Without even the clue if the disk is removable or fixed or floppy.
Last edited by trinopoty on Sun Nov 18, 2012 5:08 am, edited 1 time in total.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Calculate Disk Geometry from Disk Size

Post by Brendan »

Hi,
trinopoty wrote:How can one calculate the disk geometry with nothing but the size of the disk in sectors.
Without even the clue if the disk is removable or fixed or floppy.
You can't. Consider this formula:

x * y * z = total;

If you know the value of 3 variables you can determine the fourth/missing value. If you only know the value of 2 of the variables then you're stuck, and if you only know the value of one variable you're stuck twice as much.

However; you do know that x, y and z are positive integers. This rules out some of the billions of possible solutions. For example, if the total is 13 then you know that x can't be 4 because 13 /4 is not an integer.

Anything beyond that is guesswork and/or estimation.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
trinopoty
Member
Member
Posts: 87
Joined: Wed Feb 09, 2011 2:21 am
Location: Raipur, India

Re: Calculate Disk Geometry from Disk Size

Post by trinopoty »

We can narrow down the possibilities by considering that a fixed disk is at-least 5 MB. Anything lower than that is removable/floppy disk.
After that, the size can be compared to standards in case of removable/floppy media.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Calculate Disk Geometry from Disk Size

Post by Brendan »

Hi,
trinopoty wrote:We can narrow down the possibilities by considering that a fixed disk is at-least 5 MB. Anything lower than that is removable/floppy disk.
After that, the size can be compared to standards in case of removable/floppy media.
For floppies it's easy enough if you avoid the extremely old stuff (e.g. there's 2 different "320 KiB" formats - one for 5.25 inch disks and one for 3.5 inch disks) and also avoid the unusual stuff (e.g. nothing prevents a 3.5 inch disk from being formatted as a 1200 KiB disk).

For hard disks you could create a database of every hard drive ever manufactured, and that would narrow down the options a lot. Of course that won't solve most cases completely; and then there's RAID arrays to consider (e.g. a pair of 100 GiB physical drives using striping and pretending to be a 200 GiB logical drive, or a set of four 100 GiB drives pretending to be whatever it works out to for RAID5).

In any case, it's best/easiest to ask the device driver.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Calculate Disk Geometry from Disk Size

Post by Kazinsal »

Solution: don't use disk geometry if you can avoid it. Most computers with at least a 486 in them will support LBA extensions in BIOS interrupts. After that you can just use LBA directly through the disk controllers.

If you need disk geometry that badly, the BIOS should be able to tell you. Failing that, I think ATA IDENTIFY will do what you want.
User avatar
trinopoty
Member
Member
Posts: 87
Joined: Wed Feb 09, 2011 2:21 am
Location: Raipur, India

Re: Calculate Disk Geometry from Disk Size

Post by trinopoty »

Well the problem is, I am working with disk images under windows.
Disk images provide only one info, the size in sectors. I have to somehow use that info to calculate the geometry.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Calculate Disk Geometry from Disk Size

Post by Brendan »

Hi,
trinopoty wrote:Well the problem is, I am working with disk images under windows.
Disk images provide only one info, the size in sectors. I have to somehow use that info to calculate the geometry.
That creates a whole new level of headaches - calculate the geometry for what?

If you're calculating the physical disk's geometry for the file itself, then you don't have a physical disk and the only thing that might make sense is "sectors per track = total size; heads = 1, cylinders = 1".

If you're calculating what the physical disk's geometry might become in a specific emulator; then you can either look at the emulator's source code (e.g. Bochs, Qemu) or run a series of tests on that emulator (if it's closed source), and determine how the emulator itself calculates the disk's geometry from the image's size. In this case, an alternative option would be to ask the emulator (e.g. use the ATA "Identify" command to ask the emulated disk what it is).

If you're calculating the fake geometry that a (real or emulated) BIOS might use (e.g. for the old/obsolete "int 0x13" functions or for an MBR or partition table) and not calculating the disk's physical geometry at all; then the same process (look at the BIOS's source code or run a series of tests on that specific BIOS) would work. Note that the calculation that a specific BIOS uses may or may not depend on the physical disk's geometry; and that different BIOSs may do the calculation completely differently. In this case, an alternative option would be to ask the BIOS (e.g. use the old "get drive parameters" function).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
SparrowOS
Member
Member
Posts: 72
Joined: Wed Nov 14, 2012 5:22 pm
Location: Vegas
Contact:

Re: Calculate Disk Geometry from Disk Size

Post by SparrowOS »

CHS<28 LBA<48 LBA
User avatar
trinopoty
Member
Member
Posts: 87
Joined: Wed Feb 09, 2011 2:21 am
Location: Raipur, India

Re: Calculate Disk Geometry from Disk Size

Post by trinopoty »

Well then the best option is to set the CHS of MBR to invalid i.e. 0xFFFFFF, and force everything to use LBA or do their own math based on BIOS reported geometry.
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: Calculate Disk Geometry from Disk Size

Post by Yoda »

This task is unsolvable for more reasons than just a multitude of X*Y*Z=N solutions.
There are three other reasons:
1. There are two geometries - BIOS and physical geometry. Physical geometry is limited to 16 heads, while BIOS limited to 256 (and old MS-DOS implementations are limited to 255). So, which geometry we need to find?
2. BIOS gets geometry converted from physical. But there are several methods of conversion. You'll get different geometries by using different methods.
3. The equation to solve is not necessarily X*Y*Z=N. More correct is to solve X*Y*Z>=N, since drive may have actual number of sectors slightly less than product C*H*S. Last track is not full.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Calculate Disk Geometry from Disk Size

Post by bluemoon »

Furthermore, there is not necessary a unique solution; there may be multiple solutions and it's up to the BIOS or whoever got the numbers to interpret the them.
linguofreak
Member
Member
Posts: 510
Joined: Wed Mar 09, 2011 3:55 am

Re: Calculate Disk Geometry from Disk Size

Post by linguofreak »

Brendan wrote: If you're calculating the fake geometry that a (real or emulated) BIOS might use (e.g. for the old/obsolete "int 0x13" functions or for an MBR or partition table) and not calculating the disk's physical geometry at all; then the same process (look at the BIOS's source code or run a series of tests on that specific BIOS) would work. Note that the calculation that a specific BIOS uses may or may not depend on the physical disk's geometry; and that different BIOSs may do the calculation completely differently. In this case, an alternative option would be to ask the BIOS (e.g. use the old "get drive parameters" function).
This may end up with a catch-22 though: Some emulators ask the user to supply the geometry for disk images.
Post Reply