[Solved] Calculate Disk Geometry from Disk Size
[Solved] Calculate Disk Geometry from Disk Size
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.
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.
Re: Calculate Disk Geometry from Disk Size
Hi,
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
You can't. Consider this formula: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.
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.
Re: Calculate Disk Geometry from Disk Size
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.
After that, the size can be compared to standards in case of removable/floppy media.
Re: Calculate Disk Geometry from Disk Size
Hi,
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 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).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 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.
- Kazinsal
- 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
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.
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.
Re: Calculate Disk Geometry from Disk Size
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.
Disk images provide only one info, the size in sectors. I have to somehow use that info to calculate the geometry.
Re: Calculate Disk Geometry from Disk Size
Hi,
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
That creates a whole new level of headaches - calculate the geometry for what?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.
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.
Re: Calculate Disk Geometry from Disk Size
CHS<28 LBA<48 LBA
Re: Calculate Disk Geometry from Disk Size
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.
Re: Calculate Disk Geometry from Disk Size
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.
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.
Re: Calculate Disk Geometry from Disk Size
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.
-
- Member
- Posts: 510
- Joined: Wed Mar 09, 2011 3:55 am
Re: Calculate Disk Geometry from Disk Size
This may end up with a catch-22 though: Some emulators ask the user to supply the geometry for disk images.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).