From b9caf8b6058de12bf028f907471561a6aa50f7e9 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Fri, 26 Feb 2016 13:26:34 +0000 Subject: [PATCH] [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. --- src/format.c | 25 +++++++------------------ src/rufus.rc | 10 +++++----- src/syslinux/libfat/open.c | 2 +- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/format.c b/src/format.c index 4adbce86..56c4d9d4 100644 --- a/src/format.c +++ b/src/format.c @@ -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; } diff --git a/src/rufus.rc b/src/rufus.rc index 34895c52..8921c761 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 242, 376 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 2.8.868" +CAPTION "Rufus 2.8.869" FONT 8, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 @@ -320,8 +320,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,8,868,0 - PRODUCTVERSION 2,8,868,0 + FILEVERSION 2,8,869,0 + PRODUCTVERSION 2,8,869,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -338,13 +338,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "2.8.868" + VALUE "FileVersion", "2.8.869" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "2.8.868" + VALUE "ProductVersion", "2.8.869" END END BLOCK "VarFileInfo" diff --git a/src/syslinux/libfat/open.c b/src/syslinux/libfat/open.c index dad372b3..4f0334d7 100644 --- a/src/syslinux/libfat/open.c +++ b/src/syslinux/libfat/open.c @@ -92,7 +92,7 @@ libfat_open(int (*readfunc) (intptr_t, void *, size_t, libfat_sector_t), } else goto barf; /* Impossibly many clusters */ - minfatsize >>= LIBFAT_SECTOR_SHIFT; + minfatsize = (minfatsize + LIBFAT_SECTOR_SIZE - 1) >> LIBFAT_SECTOR_SHIFT; if (minfatsize > fatsize) goto barf; /* The FATs don't fit */