[Wine-patches] [eter-1.0.12] [eterhack] mountmgr.sys: Generate unique Driver records for flash drives (eterbug #6508).

Alexander Morozov amorozov на etersoft.ru
Чт Мар 10 21:33:52 MSK 2011


----------- следующая часть -----------
From 90ed19fc162377a683fb44830aad62d7024b74aa Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Thu, 10 Mar 2011 21:14:07 +0300
Subject: [eterhack] mountmgr.sys: Generate unique Driver records for flash drives (eterbug #6508).

---
 dlls/mountmgr.sys/usbhub.c |   66 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/dlls/mountmgr.sys/usbhub.c b/dlls/mountmgr.sys/usbhub.c
index 1bed9b7..ef9e174 100644
--- a/dlls/mountmgr.sys/usbhub.c
+++ b/dlls/mountmgr.sys/usbhub.c
@@ -1518,22 +1518,65 @@ static BOOL is_mass_storage( struct usb_device *dev )
 
 #endif
 
+static int get_driver_num(void)
+{
+    static const WCHAR drv_patternW[] = {'{','3','6','F','C','9','E','6','0','-',
+                                         'C','4','6','5','-','1','1','C','F','-',
+                                         '8','0','5','6','-','4','4','4','5',
+                                         '5','3','5','4','0','0','0','0','}',
+                                         '\\',0};
+
+    SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
+    HDEVINFO set;
+    DWORD i = 0, size, pattern_len = sizeof(drv_patternW) / sizeof(WCHAR) - 1;
+    int n, max = -1;
+    BOOL ret;
+    WCHAR *buf, *ep;
+
+    set = SetupDiGetClassDevsW( NULL, usbW, 0, DIGCF_ALLCLASSES );
+    if (set == INVALID_HANDLE_VALUE) return -1;
+
+    while (SetupDiEnumDeviceInfo( set, i++, &devInfo ))
+    {
+        SetupDiGetDeviceRegistryPropertyW( set, &devInfo, SPDRP_DRIVER, NULL,
+                NULL, 0, &size );
+        buf = HeapAlloc( GetProcessHeap(), 0, size );
+        if (buf == NULL)
+        {
+            SetupDiDestroyDeviceInfoList( set );
+            return -1;
+        }
+        ret = SetupDiGetDeviceRegistryPropertyW( set, &devInfo, SPDRP_DRIVER,
+                NULL, (BYTE *)buf, size, NULL );
+        if (ret && !strncmpiW( buf, drv_patternW, pattern_len ))
+        {
+            n = strtolW( buf + pattern_len, &ep, 10 );
+            if (!*ep && n > max)
+                max = n;
+        }
+        HeapFree( GetProcessHeap(), 0, buf );
+    }
+    SetupDiDestroyDeviceInfoList( set );
+    return max + 1;
+}
+
 static void register_usb_device( USHORT vid, USHORT pid, void *dev )
 {
     static const WCHAR id_fmtW[] = {'U','S','B',
                                     '\\','V','i','d','_','%','0','4','x',
                                     '&','P','i','d','_','%','0','4','x',
                                     '\\','%','s',0};
-    static const WCHAR driverW[] = {'{','3','6','F','C','9','E','6','0','-',
-                                    'C','4','6','5','-','1','1','C','F','-',
-                                    '8','0','5','6','-','4','4','4','5',
-                                    '5','3','5','4','0','0','0','0','}',
-                                    '\\','0','0','0','0',0};
+    static const WCHAR driver_fmtW[] = {'{','3','6','F','C','9','E','6','0','-',
+                                        'C','4','6','5','-','1','1','C','F','-',
+                                        '8','0','5','6','-','4','4','4','5',
+                                        '5','3','5','4','0','0','0','0','}',
+                                        '\\','%','0','4','d',0};
 
     struct DeviceInstance *instance;
     HDEVINFO set = INVALID_HANDLE_VALUE;
     SP_DEVINFO_DATA devInfo;
-    WCHAR *devnameW = NULL, *instance_idW = NULL;
+    WCHAR *devnameW = NULL, *instance_idW = NULL, *driverW;
+    int driver_n;
     char *instance_id;
     ULONG size;
 
@@ -1574,8 +1617,17 @@ static void register_usb_device( USHORT vid, USHORT pid, void *dev )
         SetupDiRegisterDeviceInfo( set, &devInfo, 0, NULL, NULL, NULL );
         /* This is need for Consultant+ for flash drive */
         if (is_mass_storage( dev ))
+        {
+            driver_n = get_driver_num();
+            if (driver_n < 0) goto done;
+            size = sizeof(driver_fmtW);
+            driverW = HeapAlloc( GetProcessHeap(), 0, size );
+            if (driverW == NULL) goto done;
+            snprintfW( driverW, size / sizeof(WCHAR), driver_fmtW, driver_n );
             SetupDiSetDeviceRegistryPropertyW( set, &devInfo, SPDRP_DRIVER,
-                    (BYTE *)driverW, sizeof(driverW) );
+                    (BYTE *)driverW, size );
+            HeapFree( GetProcessHeap(), 0, driverW );
+        }
     }
 done:
     if (set != INVALID_HANDLE_VALUE)
-- 
1.7.4.1



Подробная информация о списке рассылки Wine-patches