From 0af098a409c7afe7c4d13d934b52ddb933065a33 Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 28 Mar 2014 23:32:30 +1100 Subject: [PATCH 1/5] Update rufus.c Lines 686 to 690 fix issue where some devices would not be detected if not in USBSTOR. CM_Get_Device_ID_List_SizeA often returned a list size larger than actually required. Thus causing early termination of the full list. Rest of the code adds MS VHD Loopback mounted drives so you can now indirectly use VHD (and VHDX in Windows 8) images. --- src/rufus.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/rufus.c b/src/rufus.c index 1393bec9..a05411ef 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -627,10 +627,13 @@ static BOOL GetUSBDevices(DWORD devnum) { // The first two are standard Microsoft drivers (including the Windows 8 UASP one). // The rest are the vendor UASP drivers I know of so far - list may be incomplete! - const char* usbstor_name[] = { "USBSTOR", "UASPSTOR", "VUSBSTOR", "EtronSTOR" }; + // The last is Microsofts VHD Mount driver to mount a VHD to a drive letter. + const char* usbstor_name[] = { "USBSTOR", "UASPSTOR", "VUSBSTOR", "EtronSTOR", "vhdmp" }; const char* scsi_name = "SCSI"; + // Microsoft VHD Loopback Controller name + const char* msvhd_name = "MsVhdHba"; char letter_name[] = " (?:)"; - BOOL found = FALSE, is_SCSI, is_UASP; + BOOL found = FALSE, is_SCSI, is_UASP, is_MSVHD; HDEVINFO dev_info = NULL; SP_DEVINFO_DATA dev_info_data; SP_DEVICE_INTERFACE_DATA devint_data; @@ -680,7 +683,11 @@ static BOOL GetUSBDevices(DWORD devnum) for (s=0, i=0; s 1) { CM_Get_Device_ID_ListA(usbstor_name[s], &devid_list[i], list_size[s], CM_GETIDLIST_FILTER_SERVICE); - i += list_size[s]-1; + // list_size is sometimes larger than required thus we need to find the real end + for (i += list_size[s]; i > 2; i--) { + if ((devid_list[i-2] != '\0') && (devid_list[i-1] == '\0') && (devid_list[i] == '\0')) + break; + } } } @@ -699,6 +706,7 @@ static BOOL GetUSBDevices(DWORD devnum) memset(buffer, 0, sizeof(buffer)); vid = 0; pid = 0; is_UASP = FALSE; + is_MSVHD = FALSE; if (!SetupDiGetDeviceRegistryPropertyA(dev_info, &dev_info_data, SPDRP_FRIENDLYNAME, &datatype, (LPBYTE)buffer, sizeof(buffer), &size)) { uprintf("SetupDiGetDeviceRegistryProperty (Friendly Name) failed: %s\n", WindowsErrorString()); @@ -718,6 +726,10 @@ static BOOL GetUSBDevices(DWORD devnum) // The ID is in the form USB_VENDOR_BUSID\VID_xxxx&PID_xxxx\... if (devid[j] == '\\') post_backslash = TRUE; + // Check if this is a VHD + is_MSVHD = (safe_strstr(devid, msvhd_name) != NULL); + if (is_MSVHD) + break; if (!post_backslash) continue; if (devid[j] == '_') { @@ -729,7 +741,7 @@ static BOOL GetUSBDevices(DWORD devnum) } } } - if ((vid == 0) && (pid == 0)) { + if ((vid == 0) && (pid == 0) && !is_MSVHD) { if (is_SCSI) { // If we have an SCSI drive and couldn't get a VID:PID, we are most likely // dealing with a system drive => eliminate it! From 1c50b99bae2972299d5a1508bb04498a68db757e Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 28 Mar 2014 23:33:58 +1100 Subject: [PATCH 2/5] Update rufus.h Adds safe_strstr required by MS VHD Loopback updates --- src/rufus.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rufus.h b/src/rufus.h index f471c80d..e412549b 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -85,6 +85,7 @@ #define safe_stricmp(str1, str2) _stricmp(((str1==NULL)?"":str1), ((str2==NULL)?"":str2)) #define safe_strncmp(str1, str2, count) strncmp(((str1==NULL)?"":str1), ((str2==NULL)?"":str2), count) #define safe_strnicmp(str1, str2, count) _strnicmp(((str1==NULL)?"":str1), ((str2==NULL)?"":str2), count) +#define safe_strstr(str1, str2) strstr(((str1==NULL)?"":str1), ((str2==NULL)?"":str2)) #define safe_closehandle(h) do {if ((h != INVALID_HANDLE_VALUE) && (h != NULL)) {CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0) #define safe_unlockclose(h) do {if ((h != INVALID_HANDLE_VALUE) && (h != NULL)) {UnlockDrive(h); CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0) #define safe_sprintf(dst, count, ...) do {_snprintf(dst, count, __VA_ARGS__); (dst)[(count)-1] = 0; } while(0) From e1b65ad81be94d3bd4ca97d81c541bbd28734f53 Mon Sep 17 00:00:00 2001 From: Scott Date: Sun, 30 Mar 2014 00:49:09 +1100 Subject: [PATCH 3/5] Upstream merge --- src/rufus.c | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/src/rufus.c b/src/rufus.c index a2ba3ef9..a156810a 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -633,7 +633,7 @@ static BOOL GetUSBDevices(DWORD devnum) // The rest are the vendor UASP drivers I know of so far - list may be incomplete! const char* storage_name[] = { "USBSTOR", "UASPSTOR", "VUSBSTOR", "ETRONSTOR" }; const char* scsi_name = "SCSI"; - const char* vhd_name[] = { "Microsoft Virtual Disk", "Msft Virtual Disk SCSI Disk Device" }; + const char* vhd_name = "Microsoft Virtual Disk"; char letter_name[] = " (?:)"; BOOL found = FALSE, is_SCSI, is_UASP, is_VHD; HDEVINFO dev_info = NULL; @@ -713,33 +713,28 @@ static BOOL GetUSBDevices(DWORD devnum) uprintf("SetupDiGetDeviceRegistryProperty (Friendly Name) failed: %s\n", WindowsErrorString()); // We can afford a failure on this call - just replace the name with "USB Storage Device (Generic)" safe_strcpy(buffer, sizeof(buffer), lmprintf(MSG_045)); + } else if (safe_stricmp(buffer, vhd_name) == 0) { + is_VHD = TRUE; } else { - for (j = 0; j < ARRAYSIZE(vhd_name); j++) { - if (safe_stricmp(buffer, vhd_name[j]) == 0) { - is_VHD = TRUE; - } - } - if (is_VHD == FALSE) { - // Get the VID:PID of the device. We could avoid doing this lookup every time by keeping - // a lookup table, but there shouldn't be that many USB storage devices connected... - for (devid = devid_list; *devid; devid += strlen(devid) + 1) { - if ( (CM_Locate_DevNodeA(&parent_inst, devid, 0) == 0) - && (CM_Get_Child(&device_inst, parent_inst, 0) == 0) - && (device_inst == dev_info_data.DevInst) ) { - BOOL post_backslash = FALSE; - // If we're not dealing with the USBSTOR part of our list, then this is an UASP device - is_UASP = ((((uintptr_t)devid)+2) >= ((uintptr_t)devid_list)+list_size[0]); - for (j=0, k=0; (j= ((uintptr_t)devid_list)+list_size[0]); + for (j=0, k=0; (j Date: Sun, 30 Mar 2014 00:52:25 +1100 Subject: [PATCH 4/5] Upstream merge --- src/rufus.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rufus.h b/src/rufus.h index 37b15e39..61d75111 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -85,7 +85,6 @@ #define safe_stricmp(str1, str2) _stricmp(((str1==NULL)?"":str1), ((str2==NULL)?"":str2)) #define safe_strncmp(str1, str2, count) strncmp(((str1==NULL)?"":str1), ((str2==NULL)?"":str2), count) #define safe_strnicmp(str1, str2, count) _strnicmp(((str1==NULL)?"":str1), ((str2==NULL)?"":str2), count) -#define safe_strstr(str1, str2) strstr(((str1==NULL)?"":str1), ((str2==NULL)?"":str2)) #define safe_closehandle(h) do {if ((h != INVALID_HANDLE_VALUE) && (h != NULL)) {CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0) #define safe_unlockclose(h) do {if ((h != INVALID_HANDLE_VALUE) && (h != NULL)) {UnlockDrive(h); CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0) #define safe_sprintf(dst, count, ...) do {_snprintf(dst, count, __VA_ARGS__); (dst)[(count)-1] = 0; } while(0) From 58b526048ab5e6cd1f1f6389dc209613f448922c Mon Sep 17 00:00:00 2001 From: Scott Date: Sun, 30 Mar 2014 00:55:30 +1100 Subject: [PATCH 5/5] Slight update to include more VHD names Why can't Microsoft just be consistent? --- src/rufus.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/rufus.c b/src/rufus.c index a156810a..a2ba3ef9 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -633,7 +633,7 @@ static BOOL GetUSBDevices(DWORD devnum) // The rest are the vendor UASP drivers I know of so far - list may be incomplete! const char* storage_name[] = { "USBSTOR", "UASPSTOR", "VUSBSTOR", "ETRONSTOR" }; const char* scsi_name = "SCSI"; - const char* vhd_name = "Microsoft Virtual Disk"; + const char* vhd_name[] = { "Microsoft Virtual Disk", "Msft Virtual Disk SCSI Disk Device" }; char letter_name[] = " (?:)"; BOOL found = FALSE, is_SCSI, is_UASP, is_VHD; HDEVINFO dev_info = NULL; @@ -713,28 +713,33 @@ static BOOL GetUSBDevices(DWORD devnum) uprintf("SetupDiGetDeviceRegistryProperty (Friendly Name) failed: %s\n", WindowsErrorString()); // We can afford a failure on this call - just replace the name with "USB Storage Device (Generic)" safe_strcpy(buffer, sizeof(buffer), lmprintf(MSG_045)); - } else if (safe_stricmp(buffer, vhd_name) == 0) { - is_VHD = TRUE; } else { - // Get the VID:PID of the device. We could avoid doing this lookup every time by keeping - // a lookup table, but there shouldn't be that many USB storage devices connected... - for (devid = devid_list; *devid; devid += strlen(devid) + 1) { - if ( (CM_Locate_DevNodeA(&parent_inst, devid, 0) == 0) - && (CM_Get_Child(&device_inst, parent_inst, 0) == 0) - && (device_inst == dev_info_data.DevInst) ) { - BOOL post_backslash = FALSE; - // If we're not dealing with the USBSTOR part of our list, then this is an UASP device - is_UASP = ((((uintptr_t)devid)+2) >= ((uintptr_t)devid_list)+list_size[0]); - for (j=0, k=0; (j= ((uintptr_t)devid_list)+list_size[0]); + for (j=0, k=0; (j