Help with FAT12 filesystem

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
me239
Member
Member
Posts: 25
Joined: Thu Jul 29, 2010 10:36 pm
Contact:

Help with FAT12 filesystem

Post by me239 »

I've been looking at examples and diagrams all over the web and still have yet to find a simple exploratory example. I've been looking at MikeOS's bootloader and understanding some parts, but when it gets to the part about loading clusters, I'm lost. If somebody could explain to me a very simple way to read a program off a FAT12 disk, it would be a great help :)
eXeCuTeR
Member
Member
Posts: 63
Joined: Tue Dec 09, 2008 12:43 pm

Re: Help with FAT12 filesystem

Post by eXeCuTeR »

the FAT filesystem work in such way that it holds two tables (file allocation tables, aka FAT, which one of these are for backups when the first is messed) which represent where each file sits on disk.

Whenever you want to read a file of the disk, you first trace it's entry in the table (FAT), then you read the value of the entry. if it holds a value from a bad cluster/unused cluster/any other specifier of a type of cluster you basically stop reading. if it was an EOC (end of cluster), you basically just read this cluster in disc (convert it into specific sector number).
If it holds any other value, you save it's cluster number and keep on going until you reach an EOC.

There's a specific way to convert a cluster number (entry "id" in FAT) into cluster (which is basically 33 + cluster - 2)
33 is because this is where data sectors begin, and the minus 2 is because 2 entries are reserved.

All is left to do, is just use your disk driver and read these clusters.

e.g:
FAT LOOKS LIKE:
[RESERVED | RESERVED | file1(4) | file2(6) | file1(EOC) | UNUSED | file2(EOC) ]
(if you are wondering, the root dir has reserved sectors for it, sectors 19-33)
(the number in the braces is the actual value of this fat entry, i wrote `file1/2` just so you see what entry refers to what)
If you look at the table i made here, when we got file1's first logical cluster, we could get all the sectors it takes (and as you can see, it might not be continual, it can be located on different sectors) and then read from them.
roboman
Posts: 24
Joined: Fri Feb 27, 2009 9:41 am
Location: USA
Contact:

Re: Help with FAT12 filesystem

Post by roboman »

About the best example I've seen of the easy way to do it is at: http://alexfru.chat.ru/eindex.html and called bootprog.zip
It's in nasm. I've got a copy on my site that is in fasm and puts up real error messages if the file doesn't load. http://home.comcast.net/~dexos/Dos32ex/

Fat 12 is a bit of a pain, 12 bit long words on an 8/16/32/64 bit computer are just going to be a pain.
Post Reply