[core] minor drive.c improvements

* Double the timeout when searching for conflicting processes on error
  and improve the disk extent/drive number error messages.
This commit is contained in:
Pete Batard 2023-03-08 13:03:25 +00:00
parent 8449accb55
commit ed80d696f4
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
2 changed files with 21 additions and 16 deletions

View File

@ -1,7 +1,7 @@
/* /*
* Rufus: The Reliable USB Formatting Utility * Rufus: The Reliable USB Formatting Utility
* Drive access function calls * Drive access function calls
* Copyright © 2011-2022 Pete Batard <pete@akeo.ie> * Copyright © 2011-2023 Pete Batard <pete@akeo.ie>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -203,7 +203,9 @@ static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWr
uprintf("Could not lock access to %s: %s", Path, WindowsErrorString()); uprintf("Could not lock access to %s: %s", Path, WindowsErrorString());
// See if we can report the processes are accessing the drive // See if we can report the processes are accessing the drive
if (!IS_ERROR(FormatStatus) && (access_mask == 0)) if (!IS_ERROR(FormatStatus) && (access_mask == 0))
access_mask = SearchProcess(DevPath, SEARCH_PROCESS_TIMEOUT, TRUE, TRUE, FALSE); // Double the search process timeout here, as Windows is so bloated with processes
// that 10 seconds has become way too small to get much of any results these days...
access_mask = SearchProcess(DevPath, 2 * SEARCH_PROCESS_TIMEOUT, TRUE, TRUE, FALSE);
// Try to continue if the only access rights we saw were for read-only // Try to continue if the only access rights we saw were for read-only
if ((access_mask & 0x07) != 0x01) if ((access_mask & 0x07) != 0x01)
safe_closehandle(hDrive); safe_closehandle(hDrive);
@ -252,10 +254,10 @@ char* GetLogicalName(DWORD DriveIndex, uint64_t PartitionOffset, BOOL bKeepTrail
static const char* ignore_device[] = { "\\Device\\CdRom", "\\Device\\Floppy" }; static const char* ignore_device[] = { "\\Device\\CdRom", "\\Device\\Floppy" };
static const char* volume_start = "\\\\?\\"; static const char* volume_start = "\\\\?\\";
char *ret = NULL, volume_name[MAX_PATH], path[MAX_PATH]; char *ret = NULL, volume_name[MAX_PATH], path[MAX_PATH];
BOOL bPrintHeader = TRUE; BOOL r, bPrintHeader = TRUE;
HANDLE hDrive = INVALID_HANDLE_VALUE, hVolume = INVALID_HANDLE_VALUE; HANDLE hDrive = INVALID_HANDLE_VALUE, hVolume = INVALID_HANDLE_VALUE;
VOLUME_DISK_EXTENTS_REDEF DiskExtents; VOLUME_DISK_EXTENTS_REDEF DiskExtents;
DWORD size; DWORD size = 0;
UINT drive_type; UINT drive_type;
StrArray found_name; StrArray found_name;
uint64_t found_offset[MAX_PARTITIONS] = { 0 }; uint64_t found_offset[MAX_PARTITIONS] = { 0 };
@ -312,9 +314,10 @@ char* GetLogicalName(DWORD DriveIndex, uint64_t PartitionOffset, BOOL bKeepTrail
continue; continue;
} }
if ((!DeviceIoControl(hDrive, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, r = DeviceIoControl(hDrive, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0,
&DiskExtents, sizeof(DiskExtents), &size, NULL)) || (size <= 0)) { &DiskExtents, sizeof(DiskExtents), &size, NULL);
suprintf("Could not get Disk Extents: %s", WindowsErrorString()); if ((!r) || (size == 0)) {
suprintf("Could not get Disk Extents: %s", r ? "(empty data)" : WindowsErrorString());
safe_closehandle(hDrive); safe_closehandle(hDrive);
continue; continue;
} }
@ -1059,15 +1062,17 @@ int GetDriveNumber(HANDLE hDrive, char* path)
{ {
STORAGE_DEVICE_NUMBER_REDEF DeviceNumber; STORAGE_DEVICE_NUMBER_REDEF DeviceNumber;
VOLUME_DISK_EXTENTS_REDEF DiskExtents; VOLUME_DISK_EXTENTS_REDEF DiskExtents;
DWORD size; DWORD size = 0;
BOOL s;
int r = -1; int r = -1;
if (!DeviceIoControl(hDrive, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, if (!DeviceIoControl(hDrive, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0,
&DiskExtents, sizeof(DiskExtents), &size, NULL) || (size <= 0) || (DiskExtents.NumberOfDiskExtents < 1) ) { &DiskExtents, sizeof(DiskExtents), &size, NULL) || (size <= 0) || (DiskExtents.NumberOfDiskExtents < 1) ) {
// DiskExtents are NO_GO (which is the case for external USB HDDs...) // DiskExtents are NO_GO (which is the case for external USB HDDs...)
if(!DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, s = DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &DeviceNumber, sizeof(DeviceNumber),
&DeviceNumber, sizeof(DeviceNumber), &size, NULL ) || (size <= 0)) { &size, NULL);
uprintf("Could not get device number for device %s: %s", path, WindowsErrorString()); if ((!s) || (size == 0)) {
uprintf("Could not get device number for device %s %s", path, s ? "(empty data)" : WindowsErrorString());
return -1; return -1;
} }
r = (int)DeviceNumber.DeviceNumber; r = (int)DeviceNumber.DeviceNumber;

View File

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326 IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.22.1988" CAPTION "Rufus 3.22.1989"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0 FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -392,8 +392,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,22,1988,0 FILEVERSION 3,22,1989,0
PRODUCTVERSION 3,22,1988,0 PRODUCTVERSION 3,22,1989,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -411,13 +411,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie" VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting" VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.22.1988" VALUE "FileVersion", "3.22.1989"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2023 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2023 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.22.exe" VALUE "OriginalFilename", "rufus-3.22.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.22.1988" VALUE "ProductVersion", "3.22.1989"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"