mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-28 13:44:15 -04:00
[core] fixed non detection of USB drives on some platforms
* STORAGE_DEVICE_NUMBER.DeviceNumber is not unique! Optical drives and HDDs can have the same number * Use GetDriveType() to filter unwanted devices * closes #32
This commit is contained in:
parent
4eaae9a7f8
commit
bb0c0ecb1c
2 changed files with 16 additions and 6 deletions
10
src/drive.c
10
src/drive.c
|
@ -52,6 +52,7 @@ HANDLE GetDriveHandle(DWORD DriveIndex, char* DriveLetter, BOOL bWriteAccess, BO
|
|||
DWORD size;
|
||||
HANDLE hDrive = INVALID_HANDLE_VALUE;
|
||||
STORAGE_DEVICE_NUMBER_REDEF device_number = {0};
|
||||
UINT drive_type;
|
||||
char drives[26*4]; /* "D:\", "E:\", etc. */
|
||||
char *drive = drives;
|
||||
char logical_drive[] = "\\\\.\\#:";
|
||||
|
@ -94,6 +95,15 @@ HANDLE GetDriveHandle(DWORD DriveIndex, char* DriveLetter, BOOL bWriteAccess, BO
|
|||
if (*drive < 'C') {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* IOCTL_STORAGE_GET_DEVICE_NUMBER's STORAGE_DEVICE_NUMBER.DeviceNumber is
|
||||
not unique! An HDD, a DVD and probably other drives can have the same
|
||||
value there => Use GetDriveType() to filter out unwanted devices.
|
||||
See https://github.com/pbatard/rufus/issues/32 for details. */
|
||||
drive_type = GetDriveTypeA(drive);
|
||||
if ((drive_type != DRIVE_REMOVABLE) && (drive_type != DRIVE_FIXED))
|
||||
continue;
|
||||
|
||||
safe_sprintf(logical_drive, sizeof(logical_drive), "\\\\.\\%c:", drive[0]);
|
||||
hDrive = CreateFileA(logical_drive, GENERIC_READ|(bWriteAccess?GENERIC_WRITE:0),
|
||||
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue