From 91565477ed5695d687503db3006f4a7415a70d51 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Tue, 28 Oct 2014 19:16:35 +0000 Subject: [PATCH] [core] fix formatting for drives with nonstandard sector size * Issue #385 * Also bump version to 1.4.11 --- configure | 20 ++++++++++---------- configure.ac | 2 +- src/drive.c | 11 +++++------ src/format.c | 16 ++++++++-------- src/rufus.c | 13 +++++++++++-- src/rufus.h | 1 + src/rufus.rc | 12 ++++++------ src/smart.c | 2 +- 8 files changed, 43 insertions(+), 34 deletions(-) diff --git a/configure b/configure index 91385f0a..085c6b74 100644 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.68 for rufus 1.4.10. +# Generated by GNU Autoconf 2.68 for rufus 1.4.11. # # Report bugs to . # @@ -560,8 +560,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='rufus' PACKAGE_TARNAME='rufus' -PACKAGE_VERSION='1.4.10' -PACKAGE_STRING='rufus 1.4.10' +PACKAGE_VERSION='1.4.11' +PACKAGE_STRING='rufus 1.4.11' PACKAGE_BUGREPORT='https://github.com/pbatard/rufus/issues' PACKAGE_URL='http://rufus.akeo.ie' @@ -1203,7 +1203,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures rufus 1.4.10 to adapt to many kinds of systems. +\`configure' configures rufus 1.4.11 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1269,7 +1269,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of rufus 1.4.10:";; + short | recursive ) echo "Configuration of rufus 1.4.11:";; esac cat <<\_ACEOF @@ -1357,7 +1357,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -rufus configure 1.4.10 +rufus configure 1.4.11 generated by GNU Autoconf 2.68 Copyright (C) 2010 Free Software Foundation, Inc. @@ -1412,7 +1412,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by rufus $as_me 1.4.10, which was +It was created by rufus $as_me 1.4.11, which was generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -2227,7 +2227,7 @@ fi # Define the identity of the package. PACKAGE='rufus' - VERSION='1.4.10' + VERSION='1.4.11' cat >>confdefs.h <<_ACEOF @@ -4140,7 +4140,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by rufus $as_me 1.4.10, which was +This file was extended by rufus $as_me 1.4.11, which was generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -4194,7 +4194,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -rufus config.status 1.4.10 +rufus config.status 1.4.11 configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 1f087c84..6d3411d7 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([rufus], [1.4.10], [https://github.com/pbatard/rufus/issues], [rufus], [http://rufus.akeo.ie]) +AC_INIT([rufus], [1.4.11], [https://github.com/pbatard/rufus/issues], [rufus], [http://rufus.akeo.ie]) AM_INIT_AUTOMAKE([-Wno-portability foreign no-dist no-dependencies]) AC_CONFIG_SRCDIR([src/rufus.c]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/src/drive.c b/src/drive.c index 4a8d9298..cf306636 100644 --- a/src/drive.c +++ b/src/drive.c @@ -136,7 +136,6 @@ HANDLE GetPhysicalHandle(DWORD DriveIndex, BOOL bWriteAccess, BOOL bLockDrive) * Return the first GUID volume name for the associated drive or NULL if not found * See http://msdn.microsoft.com/en-us/library/cc542456.aspx * The returned string is allocated and must be freed - * TODO: a drive may have multiple volumes - should we handle those? */ char* GetLogicalName(DWORD DriveIndex, BOOL bKeepTrailingBackslash, BOOL bSilent) { @@ -535,7 +534,7 @@ BOOL AnalyzeMBR(HANDLE hPhysicalDrive, const char* TargetName) int i; fake_fd._ptr = (char*)hPhysicalDrive; - fake_fd._bufsiz = 512; + fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector; if (!is_br(&fake_fd)) { uprintf("%s does not have an x86 %s\n", TargetName, mbr_name); @@ -570,7 +569,7 @@ BOOL AnalyzePBR(HANDLE hLogicalVolume) int i; fake_fd._ptr = (char*)hLogicalVolume; - fake_fd._bufsiz = 512; + fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector; if (!is_br(&fake_fd)) { uprintf("Volume does not have an x86 %s\n", pbr_name); @@ -900,9 +899,9 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m DriveLayoutEx.PartitionStyle = PARTITION_STYLE_GPT; DriveLayoutEx.PartitionCount = 1; - // At the very least, a GPT disk has 34 reserved blocks (512 bytes) at the beginning and 33 at the end. - DriveLayoutEx.Type.Gpt.StartingUsableOffset.QuadPart = 34*512; - DriveLayoutEx.Type.Gpt.UsableLength.QuadPart = SelectedDrive.DiskSize - (34+33)*512; + // At the very least, a GPT disk has 34 reserved sectors at the beginning and 33 at the end. + DriveLayoutEx.Type.Gpt.StartingUsableOffset.QuadPart = 34 * SelectedDrive.Geometry.BytesPerSector; + DriveLayoutEx.Type.Gpt.UsableLength.QuadPart = SelectedDrive.DiskSize - (34+33) * SelectedDrive.Geometry.BytesPerSector; DriveLayoutEx.Type.Gpt.MaxPartitionCount = MAX_GPT_PARTITIONS; DriveLayoutEx.Type.Gpt.DiskId = CreateDisk.Gpt.DiskId; DriveLayoutEx.PartitionEntry[0].PartitionStyle = PARTITION_STYLE_GPT; diff --git a/src/format.c b/src/format.c index e78261d7..1ffc5777 100644 --- a/src/format.c +++ b/src/format.c @@ -855,14 +855,14 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) // FormatEx rewrites the MBR and removes the LBA attribute of FAT16 // and FAT32 partitions - we need to correct this in the MBR - buf = (unsigned char*)malloc(512); + buf = (unsigned char*)malloc(SelectedDrive.Geometry.BytesPerSector); if (buf == NULL) { uprintf("Could not allocate memory for MBR"); FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY; goto out; } - if (!read_sectors(hPhysicalDrive, 512, 0, 1, buf)) { + if (!read_sectors(hPhysicalDrive, SelectedDrive.Geometry.BytesPerSector, 0, 1, buf)) { uprintf("Could not read MBR\n"); FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_READ_FAULT; goto out; @@ -892,14 +892,14 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) uprintf("Set bootable USB partition as 0x%02X\n", buf[0x1be]); } - if (!write_sectors(hPhysicalDrive, 512, 0, 1, buf)) { + if (!write_sectors(hPhysicalDrive, SelectedDrive.Geometry.BytesPerSector, 0, 1, buf)) { uprintf("Could not write MBR\n"); FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; goto out; } fake_fd._ptr = (char*)hPhysicalDrive; - fake_fd._bufsiz = 512; + fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector; fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem)); dt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); bt = GETBIOSTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme))); @@ -953,7 +953,7 @@ static BOOL WritePBR(HANDLE hLogicalVolume) const char* using_msg = "Using %s %s partition boot record\n"; fake_fd._ptr = (char*)hLogicalVolume; - fake_fd._bufsiz = 512; + fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector; switch (ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem))) { case FS_FAT16: @@ -997,7 +997,7 @@ static BOOL WritePBR(HANDLE hLogicalVolume) // Disk Drive ID needs to be corrected on XP if (!write_partition_physical_disk_drive_id_fat32(&fake_fd)) break; - fake_fd._cnt += 6 * 512; + fake_fd._cnt += 6 * SelectedDrive.Geometry.BytesPerSector; } return TRUE; case FS_NTFS: @@ -1335,7 +1335,7 @@ DWORD WINAPI FormatThread(void* param) uprintf("Bad blocks: Check failed.\n"); if (!IS_ERROR(FormatStatus)) FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_BADBLOCKS_FAILURE); - ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, 512, FALSE); + ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, SelectedDrive.Geometry.BytesPerSector, FALSE); fclose(log_fd); _unlink(logfile); goto out; @@ -1368,7 +1368,7 @@ DWORD WINAPI FormatThread(void* param) // Especially after destructive badblocks test, you must zero the MBR/GPT completely // before repartitioning. Else, all kind of bad things happen. - if (!ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, 512, use_large_fat32)) { + if (!ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, SelectedDrive.Geometry.BytesPerSector, use_large_fat32)) { uprintf("unable to zero MBR/GPT\n"); if (!IS_ERROR(FormatStatus)) FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; diff --git a/src/rufus.c b/src/rufus.c index a222bf14..3111e5e6 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -289,14 +289,14 @@ static BOOL DefineClusterSizes(void) // UDF (only supported for Vista and later) if (nWindowsVersion >= WINDOWS_VISTA) { - SelectedDrive.ClusterSize[FS_UDF].Allowed = 0x00000100; + SelectedDrive.ClusterSize[FS_UDF].Allowed = SINGLE_CLUSTERSIZE_DEFAULT; SelectedDrive.ClusterSize[FS_UDF].Default = 1; } // ReFS (only supported for Windows 8.1 and later and for fixed disks) if (SelectedDrive.DiskSize >= 512*MB) { if ((nWindowsVersion >= WINDOWS_8_1_OR_LATER) && (SelectedDrive.Geometry.MediaType == FixedMedia)) { - SelectedDrive.ClusterSize[FS_REFS].Allowed = 0x00000100; + SelectedDrive.ClusterSize[FS_REFS].Allowed = SINGLE_CLUSTERSIZE_DEFAULT; SelectedDrive.ClusterSize[FS_REFS].Default = 1; } } @@ -305,6 +305,15 @@ static BOOL DefineClusterSizes(void) out: // Only add the filesystems we can service for (fs=0; fs Use rightmost bit to select the new one + SelectedDrive.ClusterSize[fs].Default = + SelectedDrive.ClusterSize[fs].Allowed & (-(LONG)SelectedDrive.ClusterSize[fs].Allowed); + } + if (SelectedDrive.ClusterSize[fs].Allowed != 0) { tmp[0] = 0; // Tell the user if we're going to use Large FAT32 or regular diff --git a/src/rufus.h b/src/rufus.h index d251f1b3..ebfd99da 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -53,6 +53,7 @@ #define MBR_UEFI_MARKER 0x49464555 // 'U', 'E', 'F', 'I', as a 32 bit little endian longword #define WRITE_RETRIES 3 #define FS_DEFAULT FS_FAT32 +#define SINGLE_CLUSTERSIZE_DEFAULT 0x00000100 #define BADBLOCK_PATTERNS {0xaa, 0x55, 0xff, 0x00} #define LARGE_FAT32_SIZE (32*1073741824LL) // Size at which we need to use fat32format #define UDF_FORMAT_SPEED 3.1f // Speed estimate at which we expect UDF drives to be formatted (GB/s) diff --git a/src/rufus.rc b/src/rufus.rc index 5ada8143..05033f08 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 206, 329 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Rufus 1.4.10.517" +CAPTION "Rufus 1.4.11.518" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN DEFPUSHBUTTON "Start",IDC_START,94,291,50,14 @@ -165,7 +165,7 @@ END RTL_IDD_DIALOG DIALOGEX 12, 12, 206, 329 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL -CAPTION "Rufus 1.4.10.517" +CAPTION "Rufus 1.4.11.518" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN DEFPUSHBUTTON "Start",IDC_START,94,291,50,14 @@ -428,8 +428,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,4,10,517 - PRODUCTVERSION 1,4,10,517 + FILEVERSION 1,4,11,518 + PRODUCTVERSION 1,4,11,518 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -446,13 +446,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "1.4.10.517" + VALUE "FileVersion", "1.4.11.518" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2014 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "1.4.10.517" + VALUE "ProductVersion", "1.4.11.518" END END BLOCK "VarFileInfo" diff --git a/src/smart.c b/src/smart.c index 33bb8c25..2fe02de5 100644 --- a/src/smart.c +++ b/src/smart.c @@ -179,7 +179,7 @@ static int SatAtaPassthrough(HANDLE hPhysical, ATA_PASSTHROUGH_CMD* Command, voi int t_length = 0; /* 0 -> no data transferred */ uint8_t Direction; - if (BufLen % 512 != 0) { + if (BufLen % SelectedDrive.Geometry.BytesPerSector != 0) { uprintf("SatAtaPassthrough: BufLen must be a multiple of \n"); return SPT_ERROR_BUFFER; }