CHS or LBA translation

Programming, for all ages and all languages.
Post Reply
0x3B0
Member
Member
Posts: 26
Joined: Fri Apr 27, 2012 6:28 am

CHS or LBA translation

Post by 0x3B0 »

I only have the MBR of my Hard Disk now I need to know in what sector is the boot sector to read this but I don't know how to find with the CHS. How to find the boot sector through LBA?
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: CHS or LBA translation

Post by Yoda »

Read an article about MBR structure. http://wiki.osdev.org/MBR
There you'll find details on how to find the boot sector of active partition.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
0x3B0
Member
Member
Posts: 26
Joined: Fri Apr 27, 2012 6:28 am

Re: CHS or LBA translation

Post by 0x3B0 »

I already read this article but it dont explain how to find the boot sector of a partition with the logigal block address or with the cylinder head sector. This is my doubt. I only want to know what I do with the LBA address or with the CHS address because my hard disk have more than 1023 cylinders.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: CHS or LBA translation

Post by egos »

Try this.

if "EDD installation check" function is OK:
- use "Extended read" function (42h) with LBA value;
else:
- use "Get disk params" function (8) to get SPT and Heads params;
- translate LBA to CHS using formulas: s = LBA mod SPT + 1, t = LBA div SPT, h = t mod Heads, c = t div Heads;
- check c value (<=1023?);
- use "Legacy read" function (2) with c, h, s values.
If you have seen bad English in my words, tell me what's wrong, please.
Rudster816
Member
Member
Posts: 141
Joined: Thu Jun 17, 2010 2:36 am

Re: CHS or LBA translation

Post by Rudster816 »

CHS fields in the MBR are unreliable. Microsoft decided to dump them (rightfully so) when they switched to NTFS, and are using the fields to store something else.

IMO, you shouldn't mess around with CHS at all with HDD's. If the HDD\BIOS doesn't support, sucks for whoever has that 15+ year old machine. Any effort to support CHS will likely be wasted, and could just end up making things worse\introducing bugs. Just my .02 though.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: CHS or LBA translation

Post by bluemoon »

0x3B0 wrote:I already read this article but it dont explain how to find the boot sector of a partition with the logigal block address or with the cylinder head sector. This is my doubt. I only want to know what I do with the LBA address or with the CHS address because my hard disk have more than 1023 cylinders.
MBR does explains it all.
See the Partition Table article for the format of each partition table entry field.
Follow the link Partition_Table and it explains each field including CHS and LBA of a partiton.
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: CHS or LBA translation

Post by Yoda »

0x3B0 wrote:I do with the LBA address or with the CHS address because my hard disk have more than 1023 cylinders.
Forget about CHS access for any drive larger than 8GiB. Only LBA access will allow you address the whole drive.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
Post Reply