Page 1 of 1

FAT Offset Algorithm

Posted: Mon Dec 29, 2008 1:42 am
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.

Re: FAT Offset Algorithm

Posted: Mon Dec 29, 2008 2:49 am
by egos
Look at MS manual of FAT.
Search with keywords: White paper FAT

Re: FAT Offset Algorithm

Posted: Mon Dec 29, 2008 1:31 pm
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.