FAT Page method of finding first sector of cluster wrong?

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
User avatar
ScropTheOSAdventurer
Member
Member
Posts: 86
Joined: Sun Aug 25, 2013 5:47 pm
Location: Nebraska, USA

FAT Page method of finding first sector of cluster wrong?

Post 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.
"Procrastination is the art of keeping up with yesterday."
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

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

Post 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.
User avatar
ScropTheOSAdventurer
Member
Member
Posts: 86
Joined: Sun Aug 25, 2013 5:47 pm
Location: Nebraska, USA

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

Post 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?
"Procrastination is the art of keeping up with yesterday."
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

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

Post 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.
User avatar
ScropTheOSAdventurer
Member
Member
Posts: 86
Joined: Sun Aug 25, 2013 5:47 pm
Location: Nebraska, USA

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

Post 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.)
"Procrastination is the art of keeping up with yesterday."
Post Reply