Heads, tracks and sectors? any help please

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.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Heads, tracks and sectors? any help please

Post 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
1100110100010011
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Heads, tracks and sectors? any help please

Post by qw »

All you need to know may be found here: http://wiki.osdev.org/FAT.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: Heads, tracks and sectors? any help please

Post 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
1100110100010011
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Heads, tracks and sectors? any help please

Post 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.
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Prochamber
Member
Member
Posts: 100
Joined: Wed Mar 13, 2013 2:27 am

Re: Heads, tracks and sectors? any help please

Post 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)
TachyonOS - Violates causality on 95% of attempts. Runs at approximately 1.5c.
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: Heads, tracks and sectors? any help please

Post 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.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Heads, tracks and sectors? any help please

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Heads, tracks and sectors? any help please

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Heads, tracks and sectors? any help please

Post by Combuster »

Point was that CHS is still unavoidable for floppies regardless of your computer's relative age...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Prochamber
Member
Member
Posts: 100
Joined: Wed Mar 13, 2013 2:27 am

Re: Heads, tracks and sectors? any help please

Post 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?
TachyonOS - Violates causality on 95% of attempts. Runs at approximately 1.5c.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Heads, tracks and sectors? any help please

Post 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.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: Heads, tracks and sectors? any help please

Post 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
1100110100010011
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

Re: Heads, tracks and sectors? any help please

Post by FallenAvatar »

computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: Heads, tracks and sectors? any help please

Post 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
1100110100010011
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: Heads, tracks and sectors? any help please

Post 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.
Last edited by Yoda on Tue Jun 11, 2013 2:15 pm, edited 1 time in total.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
Post Reply