Page 1 of 1

fat_BS->DirectoryEntries (FAT page)

Posted: Thu Aug 28, 2014 6:38 pm
by M374LX
In the Programming Guide section of the FAT file system page of the Wiki, the formula shown to find the first data sector of an entry needs the value of fat_BS->DirectoryEntries, but the fat_BS struct, as shown earlier in the section, has no DirectoryEntries member (nor directory_entries, which would follow the coding style used). Also, the formula requires fat_BS->BytesPerSector, but the actual member found in the struct is bytes_per_sector.

What exactly does fat_BS->DirectoryEntries mean? Do I need to count the total number of directory entries in the entire disk?

Re: fat_BS->DirectoryEntries (FAT page)

Posted: Fri Aug 29, 2014 9:08 am
by zhiayang
Looking through the wiki page, it's a bit confusing. To be honest, I'd suggest looking at the wikipedia article on the subject. Indeed, also reference fatgen103.

I've personally never been to the FAT page on the OSDev wiki and managed to implement a FAT32 driver.
To get the LBA (sector number) of a cluster, I use

Code: Select all

this->FirstUsableCluster + cluster * this->SectorsPerCluster - (2 * this->SectorsPerCluster)
where

Code: Select all

this->FirstUsableCluster	= this->partition->GetStartLBA() + this->ReservedSectors + (this->NumberOfFATs * this->FATSectorSize);
This is for FAT32. So given a cluster number of a directory, use use the above formula to calculate which sector it starts at. TBH I don't know what the wiki article is trying to do, it might be FAT12/16 specific.