Page 1 of 2

Heads, tracks and sectors? any help please

Posted: Mon Jun 10, 2013 12:40 pm
by computertrick
Hi I am implementing FAT16 in my operating system so far all good. But I am having trouble determining what sector, head, track to load from.

I am running the operating system from HDD. Lets say the ROOT directory is at 0x1ea00 how can I divide that down to get the correct sector, track and head


Many thanks

Re: Heads, tracks and sectors? any help please

Posted: Mon Jun 10, 2013 2:55 pm
by qw
All you need to know may be found here: http://wiki.osdev.org/FAT.

Re: Heads, tracks and sectors? any help please

Posted: Mon Jun 10, 2013 4:53 pm
by computertrick
That's not what I need I have looked up plenty on FAT I just need to determine how to split an address down into sectors, heads and tracks for example lets not talk about FAT for a second imagine the number 1024 I know that to access data at offset 1024 I would do

Sector = 3
head = 1
Track = 1

I think that's right might be a bit off but that's the general idea

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 12:15 am
by BMW
Is there any reason not to use LBA? Then if you want to access data at offset 1024, just send 1024 to the ATA controller as the LBA address.

http://wiki.osdev.org/LBA

If you want to use CHS (not sure why anyone would...), there is a handy code snippet on the page specified above that can convert from LBA to CHS for you.

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 1:15 am
by Prochamber
The only real reason to use CHS on a hard drive is if you are using a really old BIOS that doesn't support LBA extensions. In fact doing so will limit you to the first 8GB of the media. Regardless, I will assume you have a good reason.

To find a CHS address you must know some information about the media, such as "sectors per track" and "number of heads". You should also know the number of cylinders so you know when the drive ends. You can find out this information about your drives using INT 0x13 AH=8.

Here's the formulas from the ATA in Real Mode page.
Temp = LBA / (Sectors per Track)
Sector = (LBA % (Sectors per Track)) + 1
Head = Temp % (Number of Heads)
Cylinder = Temp / (Number of Heads)

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 1:39 am
by Yoda
You have to design all the algorithms to use LBA.
For the drives that don't support LBA you need just to implement LBA to CHS translation (as a separate mechanism). But the logic of file system driver needs to stay in LBA.

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 1:42 am
by Combuster
Prochamber wrote:The only real reason to use CHS on a hard drive is if you are using a really old BIOS that doesn't support LBA extensions.
So a 2-year old BIOS is "really old" because it supports a floppy drive? :wink:

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 2:09 am
by Antti
Combuster wrote:So a 2-year old BIOS is "really old" because it supports a floppy drive?
A BIOS is really old it it does not support LBA on hard disk drives.

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 2:15 am
by Combuster
Point was that CHS is still unavoidable for floppies regardless of your computer's relative age...

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 4:31 am
by Prochamber
Combuster wrote:
Prochamber wrote:The only real reason to use CHS on a hard drive is if you are using a really old BIOS that doesn't support LBA extensions.
So a 2-year old BIOS is "really old" because it supports a floppy drive? :wink:
What are you babbling about?

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 4:48 am
by iansjack
Combuster wrote:Point was that CHS is still unavoidable for floppies regardless of your computer's relative age...
The question was specifically about access to a hard disk. Probably best not to wander off topic.

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 1:34 pm
by computertrick
Thanks for all your responses I did not know about LBA until now how can I access data on a disk without specifying sector, head , track. At the moment I am using int 13 to access the storage device.


Many thanks

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 1:39 pm
by FallenAvatar

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 2:02 pm
by computertrick
tjmonk15 wrote:http://bit.ly/13yYS6f

- Monk
Hi Monk, I have found these parameters

AH = 42h
DL = drive number
DS:SI -> disk address packet

for an extended read , LBA ?

the thing I don't understand about this is no value to point to the data is being specified and if the value is DS:SI then where is the value that says where to load it into memory

Many thanks

Re: Heads, tracks and sectors? any help please

Posted: Tue Jun 11, 2013 2:15 pm
by Yoda
Again, split the task to two independent parts.
The first one - implement FAT16 driver using only the linear numbers of sectors. That sector number is just the LBA sector number.
The second - implement the Int13 BIOS request (if you are using real mode) forming the LBA packet or using LBA number to CHS parameters translation.