From 2945389edcaaa357c6d508e84ae0ee6cf25ebd09 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Sun, 22 Sep 2013 03:28:56 +0100 Subject: [PATCH] [core] fix large FAT32 formatting for > 1TB disks * Closes #159 --- src/format.c | 29 ++++++++++++++++------------- src/rufus.c | 6 +----- src/rufus.h | 2 +- src/rufus.rc | 10 +++++----- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/format.c b/src/format.c index c24a225d..567e101c 100644 --- a/src/format.c +++ b/src/format.c @@ -54,6 +54,7 @@ static int task_number = 0; extern const int nb_steps[FS_MAX]; static int fs_index = 0; BOOL force_large_fat32 = FALSE; +static BOOL WritePBR(HANDLE hLogicalDrive); /* * FormatEx callback. Return FALSE to halt operations @@ -572,6 +573,13 @@ static BOOL FormatFAT32(DWORD DriveIndex) write_sectors(hLogicalVolume, BytesPerSect, SectorStart, 1, pFirstSectOfFat); } + // Must do it here, as have issues when trying to write the PBR after a remount + PrintStatus(0, TRUE, "Writing partition boot record..."); + if (!WritePBR(hLogicalVolume)) { + // Non fatal error, but the drive probably won't boot + uprintf("Could not write partition boot record - drive may not boot...\n"); + } + // Set the FAT32 volume label GetWindowTextW(hLabel, wLabel, ARRAYSIZE(wLabel)); ToValidLabel(wLabel, TRUE); @@ -778,7 +786,9 @@ static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSi // http://en.wikipedia.org/wiki/GUID_Partition_Table tells us we should clear 34 sectors at the // beginning and 33 at the end. We bump these values to MAX_SECTORS_TO_CLEAR each end to help // with reluctant access to large drive. - for (i=0; i LARGE_FAT32_SIZE) || (force_large_fat32)); PrintStatus(0, TRUE, "Requesting disk access...\n"); hPhysicalDrive = GetPhysicalHandle(DriveIndex, TRUE, TRUE); @@ -1323,8 +1327,7 @@ DWORD WINAPI FormatThread(LPVOID param) // If FAT32 is requested and we have a large drive (>32 GB) use // large FAT32 format, else use MS's FormatEx. - ret = ((fs == FS_FAT32) && ((SelectedDrive.DiskSize > LARGE_FAT32_SIZE) || (force_large_fat32)))? - FormatFAT32(DriveIndex):FormatDrive(DriveIndex); + ret = use_large_fat32?FormatFAT32(DriveIndex):FormatDrive(DriveIndex); if (!ret) { // Error will be set by FormatDrive() in FormatStatus uprintf("Format error: %s\n", StrError(FormatStatus)); @@ -1369,7 +1372,7 @@ DWORD WINAPI FormatThread(LPVOID param) FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INSTALL_FAILURE; goto out; } - } else if ((dt == DT_WINME) || (dt == DT_FREEDOS) || ((dt == DT_ISO) && (fs == FS_NTFS))) { + } else if ((((dt == DT_WINME) || (dt == DT_FREEDOS)) && (!use_large_fat32)) || ((dt == DT_ISO) && (fs == FS_NTFS))) { // We still have a lock, which we need to modify the volume boot record // => no need to reacquire the lock... hLogicalVolume = GetLogicalHandle(DriveIndex, TRUE, FALSE); @@ -1426,7 +1429,7 @@ DWORD WINAPI FormatThread(LPVOID param) goto out; } if ((bt == BT_UEFI) && (!iso_report.has_efi) && (iso_report.has_win7_efi)) { - // TODO: (v1.3.4) check ISO with EFI only + // TODO: (v1.4.0) check ISO with EFI only PrintStatus(0, TRUE, "Win7 EFI boot setup (this may take a while)..."); wim_image[0] = drive_name[0]; efi_dst[0] = drive_name[0]; diff --git a/src/rufus.c b/src/rufus.c index 44512988..e15b4a94 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -213,11 +213,7 @@ static BOOL DefineClusterSizes(void) // > 32GB FAT32 is not supported by MS and FormatEx but is achieved using fat32format // See: http://www.ridgecrop.demon.co.uk/index.htm?fat32format.htm // < 32 MB FAT32 is not allowed by FormatEx, so we don't bother - // We also found issues with > 1TB drives, so we use our own max threshold (can be disabled with Alt-S) - if ((size_check) && (1.0f*SelectedDrive.DiskSize >= 1.0f*MAX_FAT32_SIZE*TB)) - uprintf("FAT32 support is disabled for this device, as it is larger than %.1f TB\n", 1.0f*MAX_FAT32_SIZE); - - if ((SelectedDrive.DiskSize >= 32*MB) && ((!size_check) || (1.0f*SelectedDrive.DiskSize < 1.0f*MAX_FAT32_SIZE*TB))) { + if ((SelectedDrive.DiskSize >= 32*MB) && (1.0f*SelectedDrive.DiskSize < 1.0f*MAX_FAT32_SIZE*TB)) { SelectedDrive.ClusterSize[FS_FAT32].Allowed = 0x000001F8; for (i=32; i<=(32*1024); i<<=1) { // 32 MB -> 32 GB if (SelectedDrive.DiskSize < i*MB) { diff --git a/src/rufus.h b/src/rufus.h index 12bf7ee7..475d9246 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -51,7 +51,7 @@ #define PROPOSEDLABEL_TOLERANCE 0.10 #define FS_DEFAULT FS_FAT32 #define LARGE_FAT32_SIZE (32*1073741824LL) // Size at which we need to use fat32format -#define MAX_FAT32_SIZE 1.0f // Threshold above which we disable FAT32 formatting (in TB) +#define MAX_FAT32_SIZE 2.0f // Threshold above which we disable FAT32 formatting (in TB) #define WHITE RGB(255,255,255) #define SEPARATOR_GREY RGB(223,223,223) #define RUFUS_URL "http://rufus.akeo.ie" diff --git a/src/rufus.rc b/src/rufus.rc index 2a80a150..284c6e79 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -30,7 +30,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 206, 329 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW -CAPTION "Rufus v1.3.4.276" +CAPTION "Rufus v1.3.4.277" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN DEFPUSHBUTTON "Start",IDC_START,94,291,50,14 @@ -278,8 +278,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,3,4,276 - PRODUCTVERSION 1,3,4,276 + FILEVERSION 1,3,4,277 + PRODUCTVERSION 1,3,4,277 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -296,13 +296,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "1.3.4.276" + VALUE "FileVersion", "1.3.4.277" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2013 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "1.3.4.276" + VALUE "ProductVersion", "1.3.4.277" END END BLOCK "VarFileInfo"