[fs] set default cluster sizes for Large FAT32

* Closes #1560
This commit is contained in:
Pete Batard 2020-06-12 10:54:46 +01:00
parent 3e4b03a116
commit a1d605f206
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
2 changed files with 32 additions and 8 deletions

View File

@ -27,11 +27,13 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#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

View File

@ -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"