Convert from/to CHS-LBA

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Convert from/to CHS-LBA

Post by ~ »

I have the following formulas to convert CHS-to-LBA and LBA-to-CHS. I think they are right because they seem to work fine with floppies:

Code: Select all

CHS_to_LBA = (((Sectors_Per_Track*NumHeads)*Track)+(Sectors_Per_Track*Head)+Sector)-1;

Code: Select all

Cylinder = (int)(LBA/(Sectors_Per_Track*NumHeads));
Head     = (int)(LBA/Sectors_Per_Track)%NumHeads;
Sector   = (int)(LBA%Sectors_Per_Track)+1;
-----------------------------

Now the question is: Will those formulas work seamlessly both for any capacity floppies, and even for ATA disks that are addressed using CHS?

Or are there another many CHS-to-LBA-to-CHS conversion formulas I should need to know, that somebody knows about?
User avatar
muisei
Member
Member
Posts: 79
Joined: Sat Sep 23, 2006 2:10 pm
Location: Bulgaria
Contact:

Post by muisei »

Take a look at this tutorial
Post Reply