Page 1 of 1

FAT Page method of finding first sector of cluster wrong?

Posted: Sun Feb 15, 2015 7:44 pm
by ScropTheOSAdventurer
Although I could edit the page, I am 99% certain I am wrong, so I am going to ask instead if I got a point. Anyways, I was reading up on FAT so I could figure out how to load a second stage bootloader from my current bootloader project. Now, the page says this is how the first sector of a cluster should be computed:
first_sector_of_cluster = (cluster - 2) * fat_boot->reserved_sector_count + first_data_sector;


However, shouldn't it be:
first_sector_of_cluster = ((cluster - 2) * fat_boot->sectors_per_cluster) + first_data_sector;


If I am wrong, please explain how it is so so I can move on to actually making a bootloader :D.

Re: FAT Page method of finding first sector of cluster wrong

Posted: Sun Feb 15, 2015 8:01 pm
by alexfru
Reserved sectors definitely aren't multiplied by cluster number. There's a constant number of them, all grouped in one location.
As usual, look up your copy of fatgen103.doc.

Re: FAT Page method of finding first sector of cluster wrong

Posted: Sun Feb 15, 2015 8:16 pm
by ScropTheOSAdventurer
Reserved sectors definitely aren't multiplied by cluster number. There's a constant number of them, all grouped in one location.
As usual, look up your copy of fatgen103.doc.
I know; it is what drew my eye to the page's method of looking up a cluster's first sector and suggested the latter method in my post.

What is fatgen103.doc anyway? (EDIT: Found the pdf.)

Also, are you saying I am right (at least partly), or are you saying I am mistaken?

Re: FAT Page method of finding first sector of cluster wrong

Posted: Sun Feb 15, 2015 8:52 pm
by alexfru
I'm saying that the official document from MS is the ultimate reference and it is correct (I've been able to implement FAT12/16/32 code based on it) and if you have any doubts, you should see what it says.

Re: FAT Page method of finding first sector of cluster wrong

Posted: Sun Feb 15, 2015 9:04 pm
by ScropTheOSAdventurer
Turns out I was right. Here is what I found after some quick text-searching:
Given any valid data cluster number N, the sector number of the first sector of that cluster (again relative to sector 0 of the FAT volume) is computed as follows:
FirstSectorofCluster = ((N – 2) * BPB_SecPerClus) + FirstDataSector;


I'll get the FAT page corrected in the next few minutes! (EDIT: Done.)