From caa9b0642669d377d3864f23fcbb69d23d32bd80 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Tue, 11 Apr 2017 22:15:05 +0100 Subject: [PATCH] [core] work around Windows 10 CU potentially selecting the UEFI:NTFS partition for formatting * Should only happen with Windows 10 Creator Update (1703) * Closes #931 * Also silence the flow of bcdboot benign errors on WinToGo creation (unless USB Debug is enabled) * Also ensure WaitForLogical() will not actually spends 15 seconds max before giving up --- src/drive.c | 9 ++++++--- src/format.c | 16 +++++++++++++--- src/rufus.rc | 10 +++++----- src/stdio.c | 1 - 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/drive.c b/src/drive.c index 49687cb3..d072f01d 100644 --- a/src/drive.c +++ b/src/drive.c @@ -306,10 +306,13 @@ out: /* Wait for a logical drive to reappear - Used when a drive has just been repartitioned */ BOOL WaitForLogical(DWORD DriveIndex) { - DWORD i; + DWORD EndTime; char* LogicalPath = NULL; - for (i = 0; i < DRIVE_ACCESS_RETRIES; i++) { + // GetLogicalName() calls may be slow, so use the system time to + // make sure we don't spend more than DRIVE_ACCESS_TIMEOUT in wait. + EndTime = GetTickCount() + DRIVE_ACCESS_TIMEOUT; + do { LogicalPath = GetLogicalName(DriveIndex, FALSE, TRUE); if (LogicalPath != NULL) { free(LogicalPath); @@ -318,7 +321,7 @@ BOOL WaitForLogical(DWORD DriveIndex) if (IS_ERROR(FormatStatus)) // User cancel return FALSE; Sleep(DRIVE_ACCESS_TIMEOUT/DRIVE_ACCESS_RETRIES); - } + } while (GetTickCount() < EndTime); uprintf("Timeout while waiting for logical drive\n"); return FALSE; } diff --git a/src/format.c b/src/format.c index 18e70590..95a3bff1 100644 --- a/src/format.c +++ b/src/format.c @@ -61,7 +61,7 @@ static int task_number = 0; extern const int nb_steps[FS_MAX]; extern uint32_t dur_mins, dur_secs; static int fs_index = 0, wintogo_index = -1; -extern BOOL force_large_fat32, enable_ntfs_compression, lock_drive, zero_drive, disable_file_indexing; +extern BOOL force_large_fat32, enable_ntfs_compression, lock_drive, zero_drive, disable_file_indexing, usb_debug; uint8_t *grub2_buf = NULL; long grub2_len; static BOOL WritePBR(HANDLE hLogicalDrive); @@ -681,7 +681,7 @@ static BOOL FormatDrive(DWORD DriveIndex) BOOL r = FALSE; PF_DECL(FormatEx); PF_DECL(EnableVolumeCompression); - char FSType[32]; + char FSType[32], path[MAX_PATH]; char *locale, *VolumeName = NULL; WCHAR* wVolumeName = NULL; WCHAR wFSType[64]; @@ -715,6 +715,16 @@ static BOOL FormatDrive(DWORD DriveIndex) // a trailing backslash, but EnableCompression() fails without... wVolumeName[wcslen(wVolumeName)-1] = 0; // Remove trailing backslash + // Check if Windows picked the UEFI:NTFS partition + // NB: No need to do this for Large FAT32, as this only applies to NTFS + safe_strcpy(path, MAX_PATH, VolumeName); + safe_strcat(path, MAX_PATH, "EFI\\Rufus\\ntfs_x64.efi"); + if (PathFileExistsA(path)) { + uprintf("Windows selected the UEFI:NTFS partition for formatting - Retry needed", VolumeName); + FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_RETRY; + goto out; + } + // LoadLibrary("fmifs.dll") appears to changes the locale, which can lead to // problems with tolower(). Make sure we restore the locale. For more details, // see http://comments.gmane.org/gmane.comp.gnu.mingw.user/39300 @@ -1423,7 +1433,7 @@ static BOOL SetupWinToGo(const char* drive_name, BOOL use_ms_efi) uprintf("Enabling boot..."); static_sprintf(cmd, "%s\\bcdboot.exe %s\\Windows /v /f ALL /s %s", sysnative_dir, drive_name, (use_ms_efi)?ms_efi:drive_name); - if (RunCommand(cmd, sysnative_dir, TRUE) != 0) { + if (RunCommand(cmd, sysnative_dir, usb_debug) != 0) { // Try to continue... but report a failure uprintf("Failed to enable boot using command '%s'", cmd); FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_ISO_EXTRACT); diff --git a/src/rufus.rc b/src/rufus.rc index ab041706..fbacd961 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.14.1086" +CAPTION "Rufus 2.14.1087" FONT 8, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 @@ -334,8 +334,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,14,1086,0 - PRODUCTVERSION 2,14,1086,0 + FILEVERSION 2,14,1087,0 + PRODUCTVERSION 2,14,1087,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -352,13 +352,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "2.14.1086" + VALUE "FileVersion", "2.14.1087" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2017 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "2.14.1086" + VALUE "ProductVersion", "2.14.1087" END END BLOCK "VarFileInfo" diff --git a/src/stdio.c b/src/stdio.c index 0a8e8919..d0572f2c 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -294,7 +294,6 @@ const char* _StrError(DWORD error_code) case ERROR_NOT_READY: return lmprintf(MSG_079); default: - uprintf("Unknown error: %08X\n", error_code); SetLastError(error_code); return WindowsErrorString(); }