mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[core] fix drives not being detected when LVM is in use
* Also use IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS to retrieve the disk number as IOCTL_STORAGE_GET_DEVICE_NUMBER will fail for LVM * Closes #290
This commit is contained in:
parent
1af5cc0e41
commit
11917179b9
4 changed files with 29 additions and 33 deletions
20
src/drive.c
20
src/drive.c
|
@ -269,8 +269,8 @@ HANDLE GetLogicalHandle(DWORD DriveIndex, BOOL bWriteAccess, BOOL bLockDrive)
|
||||||
static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT* drive_type)
|
static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT* drive_type)
|
||||||
{
|
{
|
||||||
DWORD size;
|
DWORD size;
|
||||||
BOOL r = FALSE;
|
BOOL s, r = FALSE;
|
||||||
STORAGE_DEVICE_NUMBER_REDEF device_number = {0};
|
VOLUME_DISK_EXTENTS DiskExtents;
|
||||||
HANDLE hDrive = INVALID_HANDLE_VALUE;
|
HANDLE hDrive = INVALID_HANDLE_VALUE;
|
||||||
UINT _drive_type;
|
UINT _drive_type;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -293,7 +293,7 @@ static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT*
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = TRUE;
|
r = TRUE; // Required to detect drives that don't have volumes assigned
|
||||||
for (drive = drives ;*drive; drive += safe_strlen(drive)+1) {
|
for (drive = drives ;*drive; drive += safe_strlen(drive)+1) {
|
||||||
if (!isalpha(*drive))
|
if (!isalpha(*drive))
|
||||||
continue;
|
continue;
|
||||||
|
@ -318,13 +318,15 @@ static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT*
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL,
|
s = DeviceIoControl(hDrive, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0,
|
||||||
0, &device_number, sizeof(device_number), &size, NULL) && (size > 0);
|
&DiskExtents, sizeof(DiskExtents), &size, NULL) && (size > 0) && (DiskExtents.NumberOfDiskExtents >= 1);
|
||||||
safe_closehandle(hDrive);
|
safe_closehandle(hDrive);
|
||||||
if (!r) {
|
if (!s) {
|
||||||
uprintf("Could not get device number for device %s: %s\n",
|
uprintf("Could not get device number for %c: - %s\n", drive[0], WindowsErrorString());
|
||||||
logical_drive, WindowsErrorString());
|
} else if (DiskExtents.NumberOfDiskExtents >= 2) {
|
||||||
} else if (device_number.DeviceNumber == DriveIndex) {
|
uprintf("Ignoring drive %c: as it spans multiple disks (RAID?)", drive[0]);
|
||||||
|
} else if (DiskExtents.Extents[0].DiskNumber == DriveIndex) {
|
||||||
|
r = TRUE;
|
||||||
if (drive_letters != NULL)
|
if (drive_letters != NULL)
|
||||||
drive_letters[i++] = *drive;
|
drive_letters[i++] = *drive;
|
||||||
// The drive type should be the same for all volumes, so we can overwrite
|
// The drive type should be the same for all volumes, so we can overwrite
|
||||||
|
|
23
src/rufus.c
23
src/rufus.c
|
@ -642,12 +642,12 @@ static BOOL GetUSBDevices(DWORD devnum)
|
||||||
const char* usbstor_name[] = { "USBSTOR", "UASPSTOR", "VUSBSTOR", "EtronSTOR" };
|
const char* usbstor_name[] = { "USBSTOR", "UASPSTOR", "VUSBSTOR", "EtronSTOR" };
|
||||||
const char* scsi_name = "SCSI";
|
const char* scsi_name = "SCSI";
|
||||||
char letter_name[] = " (?:)";
|
char letter_name[] = " (?:)";
|
||||||
BOOL r, found = FALSE, is_SCSI, is_UASP;
|
BOOL found = FALSE, is_SCSI, is_UASP;
|
||||||
HDEVINFO dev_info = NULL;
|
HDEVINFO dev_info = NULL;
|
||||||
SP_DEVINFO_DATA dev_info_data;
|
SP_DEVINFO_DATA dev_info_data;
|
||||||
SP_DEVICE_INTERFACE_DATA devint_data;
|
SP_DEVICE_INTERFACE_DATA devint_data;
|
||||||
PSP_DEVICE_INTERFACE_DETAIL_DATA_A devint_detail_data;
|
PSP_DEVICE_INTERFACE_DETAIL_DATA_A devint_detail_data;
|
||||||
STORAGE_DEVICE_NUMBER_REDEF device_number;
|
VOLUME_DISK_EXTENTS DiskExtents;
|
||||||
DEVINST parent_inst, device_inst;
|
DEVINST parent_inst, device_inst;
|
||||||
DWORD size, i, j, k, datatype, drive_index;
|
DWORD size, i, j, k, datatype, drive_index;
|
||||||
ULONG list_size[ARRAYSIZE(usbstor_name)], full_list_size;
|
ULONG list_size[ARRAYSIZE(usbstor_name)], full_list_size;
|
||||||
|
@ -798,20 +798,21 @@ static BOOL GetUSBDevices(DWORD devnum)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&device_number, 0, sizeof(device_number));
|
if (!DeviceIoControl(hDrive, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0,
|
||||||
r = DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER,
|
&DiskExtents, sizeof(DiskExtents), &size, NULL) || (size <= 0) || (DiskExtents.NumberOfDiskExtents < 1) ) {
|
||||||
NULL, 0, &device_number, sizeof(device_number), &size, NULL );
|
uprintf("Could not get device number for device %s: %s\n", devint_detail_data->DevicePath, WindowsErrorString());
|
||||||
if (!r || size <= 0) {
|
|
||||||
uprintf("IOCTL_STORAGE_GET_DEVICE_NUMBER (GetUSBDevices) failed: %s\n", WindowsErrorString());
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_number.DeviceNumber >= MAX_DRIVES) {
|
if (DiskExtents.NumberOfDiskExtents >= 2) {
|
||||||
|
uprintf("Ignoring drive '%s' as it spans multiple disks (RAID?)", devint_detail_data->DevicePath);
|
||||||
|
continue;
|
||||||
|
} else if (DiskExtents.Extents[0].DiskNumber >= MAX_DRIVES) {
|
||||||
uprintf("Device Number %d is too big - ignoring device\n");
|
uprintf("Device Number %d is too big - ignoring device\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
drive_index = device_number.DeviceNumber + DRIVE_INDEX_MIN;
|
drive_index = DiskExtents.Extents[0].DiskNumber + DRIVE_INDEX_MIN;
|
||||||
if (!IsMediaPresent(drive_index)) {
|
if (!IsMediaPresent(drive_index)) {
|
||||||
uprintf("Device eliminated because it appears to contain no media\n");
|
uprintf("Device eliminated because it appears to contain no media\n");
|
||||||
safe_closehandle(hDrive);
|
safe_closehandle(hDrive);
|
||||||
|
@ -831,7 +832,7 @@ static BOOL GetUSBDevices(DWORD devnum)
|
||||||
|
|
||||||
// The empty string is returned for drives that don't have any volumes assigned
|
// The empty string is returned for drives that don't have any volumes assigned
|
||||||
if (drive_letters[0] == 0) {
|
if (drive_letters[0] == 0) {
|
||||||
entry = lmprintf(MSG_046, label, device_number.DeviceNumber);
|
entry = lmprintf(MSG_046, label, DiskExtents.Extents[0].DiskNumber);
|
||||||
} else {
|
} else {
|
||||||
// We have multiple volumes assigned to the same device (multiple partitions)
|
// We have multiple volumes assigned to the same device (multiple partitions)
|
||||||
// If that is the case, use "Multiple Volumes" instead of the label
|
// If that is the case, use "Multiple Volumes" instead of the label
|
||||||
|
@ -860,7 +861,7 @@ static BOOL GetUSBDevices(DWORD devnum)
|
||||||
StrArrayAdd(&DriveLabel, label);
|
StrArrayAdd(&DriveLabel, label);
|
||||||
|
|
||||||
IGNORE_RETVAL(ComboBox_SetItemData(hDeviceList, ComboBox_AddStringU(hDeviceList, entry),
|
IGNORE_RETVAL(ComboBox_SetItemData(hDeviceList, ComboBox_AddStringU(hDeviceList, entry),
|
||||||
device_number.DeviceNumber + DRIVE_INDEX_MIN));
|
DiskExtents.Extents[0].DiskNumber + DRIVE_INDEX_MIN));
|
||||||
maxwidth = max(maxwidth, GetEntryWidth(hDeviceList, entry));
|
maxwidth = max(maxwidth, GetEntryWidth(hDeviceList, entry));
|
||||||
safe_closehandle(hDrive);
|
safe_closehandle(hDrive);
|
||||||
safe_free(devint_detail_data);
|
safe_free(devint_detail_data);
|
||||||
|
|
|
@ -422,13 +422,6 @@ static __inline HMODULE GetDLLHandle(char* szDLLName)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* We need a redef of this MS structure */
|
|
||||||
typedef struct {
|
|
||||||
DWORD DeviceType;
|
|
||||||
ULONG DeviceNumber;
|
|
||||||
ULONG PartitionNumber;
|
|
||||||
} STORAGE_DEVICE_NUMBER_REDEF;
|
|
||||||
|
|
||||||
/* Custom application errors */
|
/* Custom application errors */
|
||||||
#define FAC(f) (f<<16)
|
#define FAC(f) (f<<16)
|
||||||
#define APPERR(err) (APPLICATION_ERROR_MASK|err)
|
#define APPERR(err) (APPLICATION_ERROR_MASK|err)
|
||||||
|
|
12
src/rufus.rc
12
src/rufus.rc
|
@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
||||||
|
|
||||||
IDD_DIALOG DIALOGEX 12, 12, 206, 329
|
IDD_DIALOG DIALOGEX 12, 12, 206, 329
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
CAPTION "Rufus 1.4.4.423"
|
CAPTION "Rufus 1.4.4.424"
|
||||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
BEGIN
|
BEGIN
|
||||||
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
||||||
|
@ -165,7 +165,7 @@ END
|
||||||
RTL_IDD_DIALOG DIALOGEX 12, 12, 206, 329
|
RTL_IDD_DIALOG DIALOGEX 12, 12, 206, 329
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
|
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
|
||||||
CAPTION "Rufus 1.4.4.423"
|
CAPTION "Rufus 1.4.4.424"
|
||||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
BEGIN
|
BEGIN
|
||||||
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
||||||
|
@ -427,8 +427,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 1,4,4,423
|
FILEVERSION 1,4,4,424
|
||||||
PRODUCTVERSION 1,4,4,423
|
PRODUCTVERSION 1,4,4,424
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -445,13 +445,13 @@ BEGIN
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
||||||
VALUE "FileDescription", "Rufus"
|
VALUE "FileDescription", "Rufus"
|
||||||
VALUE "FileVersion", "1.4.4.423"
|
VALUE "FileVersion", "1.4.4.424"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011-2014 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011-2014 Pete Batard (GPL v3)"
|
||||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||||
VALUE "OriginalFilename", "rufus.exe"
|
VALUE "OriginalFilename", "rufus.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "1.4.4.423"
|
VALUE "ProductVersion", "1.4.4.424"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
Loading…
Reference in a new issue