FAT Offset Algorithm

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
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

FAT Offset Algorithm

Post by System123 »

I am trying to load a file from my Floppy into memory. I have everything set up and it works. The only problem I am having is that I don't know how to work out the FAT sector to load when I have the number of the Cluster in the FAT.

ie: I need an algorithm that I can supply the starting cluster number of the file and it gives me the sector of the Disk with that FAT entry in. I tried an algorithm I had but it doesn't work.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: FAT Offset Algorithm

Post by egos »

Look at MS manual of FAT.
Search with keywords: White paper FAT
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: FAT Offset Algorithm

Post by Firestryke31 »

Here's my basic algorithm (if you're looking for what I think you're looking for):

EntriesPerSector = BytesPerSector / BytesPerEntry;
Sector = (ClusterIndex / EntriesPerSector) + StartOfFAT;
Entry = (ClusterIndex % EntriesPerSector);

Keep it integer math and it should work for FAT16 and FAT32.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Post Reply