[core] fix computation of FAT size for Large FAT32

* Ridgecropt's GetFATSizeSectors() computation was incorrect
  and resulted in data sectors being "wasted" (unaddressable)
* See: http://www.syslinux.org/archives/2016-February/024850.html
* Also revert the minfatsize check of Syslinux, since it no longer fails.
This commit is contained in:
Pete Batard 2016-02-26 13:26:34 +00:00
parent ade5639c00
commit b9caf8b605
3 changed files with 13 additions and 24 deletions

View file

@ -347,31 +347,20 @@ static DWORD GetVolumeID(void)
}
/*
* This is the Microsoft calculation from FATGEN
*
* DWORD RootDirSectors = 0;
* DWORD TmpVal1, TmpVal2, FATSz;
*
* TmpVal1 = DskSize - (ReservedSecCnt + RootDirSectors);
* TmpVal2 = (256 * SecPerClus) + NumFATs;
* TmpVal2 = TmpVal2 / 2;
* FATSz = (TmpVal1 + (TmpVal2 - 1)) / TmpVal2;
*
* return( FatSz );
* Proper computation of FAT size
* See: http://www.syslinux.org/archives/2016-February/024850.html
* and subsequent replies.
*/
static DWORD GetFATSizeSectors(DWORD DskSize, DWORD ReservedSecCnt, DWORD SecPerClus, DWORD NumFATs, DWORD BytesPerSect)
{
ULONGLONG Numerator, Denominator;
ULONGLONG FatElementSize = 4;
ULONGLONG ReservedClusCnt = 2;
ULONGLONG FatSz;
// This is based on
// http://hjem.get2net.dk/rune_moeller_barnkob/filesystems/fat.html
Numerator = FatElementSize * (DskSize - ReservedSecCnt);
Denominator = (SecPerClus * BytesPerSect) + (FatElementSize * NumFATs);
FatSz = Numerator / Denominator;
// round up
FatSz += 1;
Numerator = DskSize - ReservedSecCnt + ReservedClusCnt * SecPerClus;
Denominator = SecPerClus * BytesPerSect / FatElementSize + NumFATs;
FatSz = Numerator / Denominator + 1; // +1 to ensure we are rounded up
return (DWORD)FatSz;
}