From a1d605f2068ddf9ce94405f0b7b087d5d426bb35 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Fri, 12 Jun 2020 10:54:46 +0100 Subject: [PATCH] [fs] set default cluster sizes for Large FAT32 * Closes #1560 --- src/format_fat32.c | 30 +++++++++++++++++++++++++++--- src/rufus.rc | 10 +++++----- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/format_fat32.c b/src/format_fat32.c index 781db4dd..054b2a39 100644 --- a/src/format_fat32.c +++ b/src/format_fat32.c @@ -27,11 +27,13 @@ #include #include #include +#include #include "rufus.h" #include "file.h" #include "drive.h" #include "format.h" +#include "missing.h" #include "resource.h" #include "msapi_utf8.h" #include "localization.h" @@ -251,6 +253,27 @@ BOOL FormatLargeFAT32(DWORD DriveIndex, uint64_t PartitionOffset, DWORD ClusterS die("This drive is too big for FAT32 - max 2TB supported", APPERR(ERROR_INVALID_VOLUME_SIZE)); } + // Set default cluster size + // https://support.microsoft.com/en-us/help/140365/default-cluster-size-for-ntfs-fat-and-exfat + if (ClusterSize == 0) { + if (piDrive.PartitionLength.QuadPart < 64 * MB) + ClusterSize = 512; + else if (piDrive.PartitionLength.QuadPart < 128 * MB) + ClusterSize = 1 * KB; + else if (piDrive.PartitionLength.QuadPart < 256 * MB) + ClusterSize = 2 * KB; + else if (piDrive.PartitionLength.QuadPart < 8 * GB) + ClusterSize = 4 * KB; + else if (piDrive.PartitionLength.QuadPart < 16 * GB) + ClusterSize = 8 * KB; + else if (piDrive.PartitionLength.QuadPart < 32 * GB) + ClusterSize = 16 * KB; + else if (piDrive.PartitionLength.QuadPart < 2 * TB) + ClusterSize = 32 * KB; + else + ClusterSize = 64 * KB; + } + // coverity[tainted_data] pFAT32BootSect = (FAT_BOOTSECTOR32*)calloc(BytesPerSect, 1); pFAT32FsInfo = (FAT_FSINFO*)calloc(BytesPerSect, 1); @@ -340,6 +363,7 @@ BOOL FormatLargeFAT32(DWORD DriveIndex, uint64_t PartitionOffset, DWORD ClusterS // RootDir - allocated to cluster2 UserAreaSize = TotalSectors - ReservedSectCount - (NumFATs * FatSize); + assert(SectorsPerCluster > 0); ClusterCount = UserAreaSize / SectorsPerCluster; // Sanity check for a cluster count of >2^28, since the upper 4 bits of the cluster values in @@ -367,16 +391,16 @@ BOOL FormatLargeFAT32(DWORD DriveIndex, uint64_t PartitionOffset, DWORD ClusterS // Now we're committed - print some info first uprintf("Size : %s %u sectors", SizeToHumanReadable(piDrive.PartitionLength.QuadPart, TRUE, FALSE), TotalSectors); - uprintf("Cluster size %d bytes, %d Bytes Per Sector", SectorsPerCluster * BytesPerSect, BytesPerSect); + uprintf("Cluster size %d bytes, %d bytes per sector", SectorsPerCluster * BytesPerSect, BytesPerSect); uprintf("Volume ID is %x:%x", VolumeId >> 16, VolumeId & 0xffff); - uprintf("%d Reserved Sectors, %d Sectors per FAT, %d FATs", ReservedSectCount, FatSize, NumFATs); + uprintf("%d Reserved sectors, %d sectors per FAT, %d FATs", ReservedSectCount, FatSize, NumFATs); uprintf("%d Total clusters", ClusterCount); // Fix up the FSInfo sector pFAT32FsInfo->dFree_Count = (UserAreaSize / SectorsPerCluster) - 1; pFAT32FsInfo->dNxt_Free = 3; // clusters 0-1 reserved, we used cluster 2 for the root dir - uprintf("%d Free Clusters", pFAT32FsInfo->dFree_Count); + uprintf("%d Free clusters", pFAT32FsInfo->dFree_Count); // Work out the Cluster count // First zero out ReservedSect + FatSize * NumFats + SectorsPerCluster diff --git a/src/rufus.rc b/src/rufus.rc index cb836b7b..10373123 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 232, 326 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 3.11.1674" +CAPTION "Rufus 3.11.1675" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -395,8 +395,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,11,1674,0 - PRODUCTVERSION 3,11,1674,0 + FILEVERSION 3,11,1675,0 + PRODUCTVERSION 3,11,1675,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -414,13 +414,13 @@ BEGIN VALUE "Comments", "https://rufus.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "3.11.1674" + VALUE "FileVersion", "3.11.1675" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "OriginalFilename", "rufus-3.11.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "3.11.1674" + VALUE "ProductVersion", "3.11.1675" END END BLOCK "VarFileInfo"