[Wine-patches] [4/5] mountmgr: Write information about USBSTOR device to registry.

Alexander Morozov =?iso-8859-1?q?amorozov_=CE=C1_etersoft=2Eru?=
Ср Ноя 12 12:45:55 MSK 2008


Ветка eterhack, баг 2581
----------- следующая часть -----------
From f7413e2db54facb69f75914c7e39e90b4fa90254 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Tue, 11 Nov 2008 16:09:03 +0300
Subject: [PATCH] mountmgr: Write information about USBSTOR device to registry.

---
 dlls/mountmgr.sys/Makefile.in |    2 +-
 dlls/mountmgr.sys/device.c    |   63 ++++++++++++++++++++++++++++++++++++++++-
 dlls/mountmgr.sys/diskarb.c   |    3 +-
 dlls/mountmgr.sys/hal.c       |   32 ++++++++++++++++++++-
 dlls/mountmgr.sys/mountmgr.c  |    2 +-
 dlls/mountmgr.sys/mountmgr.h  |    4 ++-
 6 files changed, 100 insertions(+), 6 deletions(-)

diff --git a/dlls/mountmgr.sys/Makefile.in b/dlls/mountmgr.sys/Makefile.in
index 2996c1c..554cc08 100644
--- a/dlls/mountmgr.sys/Makefile.in
+++ b/dlls/mountmgr.sys/Makefile.in
@@ -3,7 +3,7 @@ TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = mountmgr.sys
-IMPORTS   = uuid advapi32 ntoskrnl.exe kernel32 ntdll
+IMPORTS   = uuid advapi32 ntoskrnl.exe kernel32 ntdll setupapi
 DELAYIMPORTS = user32
 EXTRADLLFLAGS = -Wb,--subsystem,native
 EXTRADEFS = @HALINCL@
diff --git a/dlls/mountmgr.sys/device.c b/dlls/mountmgr.sys/device.c
index df22caf..eb48d3f 100644
--- a/dlls/mountmgr.sys/device.c
+++ b/dlls/mountmgr.sys/device.c
@@ -29,10 +29,14 @@
 #include <sys/types.h>
 #include <dirent.h>
 
+#define INITGUID
+
 #include "mountmgr.h"
 #include "winreg.h"
 #include "winuser.h"
 #include "dbt.h"
+#include "setupapi.h"
+#include "devguid.h"
 
 #include "wine/library.h"
 #include "wine/list.h"
@@ -475,9 +479,63 @@ static void create_drive_devices(void)
     RtlFreeHeap( GetProcessHeap(), 0, path );
 }
 
+/* write information about USBSTOR device to registry */
+static void register_usbstor_device( const char *vendor, const char *product,
+                                     const char *revision, const char *serial )
+{
+    static const WCHAR usbstorW[] = {'U','S','B','S','T','O','R',0};
+    static const WCHAR disk_idW[] = {'%','s','\\','D','i','s','k','&','V','e','n','_',
+                                     '%','s','&','P','r','o','d','_','%','s','&',
+                                     'R','e','v','_','%','s','\\','%','s','&','0',0};
+    LPWSTR devnameW, vendorW, productW, revisionW, serialW;
+    size_t size;
+    HDEVINFO set;
+
+    size = sizeof(disk_idW) - 22 + sizeof(usbstorW) + (strlen(vendor)
+            + strlen(product) + strlen(revision) + strlen(serial)) * sizeof(WCHAR);
+    devnameW = RtlAllocateHeap( GetProcessHeap(), 0, size + (strlen(vendor)
+                                + strlen(product) + strlen(revision)
+                                + strlen(serial) + 4) * sizeof(WCHAR) );
+    if (!devnameW) return;
+
+    vendorW = devnameW + size;
+    size = (strlen(vendor) + 1) * sizeof(WCHAR);
+    MultiByteToWideChar( CP_ACP, 0, vendor, -1, vendorW, size );
+
+    productW = vendorW + size;
+    size = (strlen(product) + 1) * sizeof(WCHAR);
+    MultiByteToWideChar( CP_ACP, 0, product, -1, productW, size );
+
+    revisionW = productW + size;
+    size = (strlen(revision) + 1) * sizeof(WCHAR);
+    MultiByteToWideChar( CP_ACP, 0, revision, -1, revisionW, size );
+
+    serialW = revisionW + size;
+    size = (strlen(serial) + 1) * sizeof(WCHAR);
+    MultiByteToWideChar( CP_ACP, 0, serial, -1, serialW, size );
+
+    sprintfW( devnameW, disk_idW, usbstorW, vendorW, productW, revisionW, serialW );
+
+    set = SetupDiGetClassDevsW( NULL, usbstorW, 0, DIGCF_ALLCLASSES );
+    if (set != INVALID_HANDLE_VALUE)
+    {
+        SP_DEVINFO_DATA devInfo;
+
+        devInfo.cbSize = sizeof(SP_DEVINFO_DATA);
+        if (SetupDiCreateDeviceInfoW( set, devnameW, &GUID_DEVCLASS_DISKDRIVE,
+                                      NULL, NULL, 0, &devInfo ))
+            SetupDiRegisterDeviceInfo( set, &devInfo, 0, NULL, NULL, NULL );
+        SetupDiDestroyDeviceInfoList( set );
+    }
+
+    RtlFreeHeap( GetProcessHeap(), 0, devnameW );
+}
+
 /* create a new dos drive */
 NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
-                         const char *mount_point, DWORD type, STORAGE_BUS_TYPE bus )
+                         const char *mount_point, DWORD type, STORAGE_BUS_TYPE bus,
+                         const char *vendor, const char *product,
+                         const char *revision, const char *serial )
 {
     struct dos_drive *drive, *next;
 
@@ -539,6 +597,9 @@ found:
             RegCloseKey( hkey );
         }
 
+        if (bus == BusTypeUsb && vendor && product && revision && serial)
+            register_usbstor_device( vendor, product, revision, serial );
+
         if (udi) send_notify( drive->drive, DBT_DEVICEARRIVAL );
     }
     return STATUS_SUCCESS;
diff --git a/dlls/mountmgr.sys/diskarb.c b/dlls/mountmgr.sys/diskarb.c
index b89ade9..6b2a843 100644
--- a/dlls/mountmgr.sys/diskarb.c
+++ b/dlls/mountmgr.sys/diskarb.c
@@ -69,7 +69,8 @@ static void appeared_callback( DADiskRef disk, void *context )
 
     TRACE( "got mount notification for '%s' on '%s'\n", device, mount_point );
 
-    add_dos_device( -1, device, device, mount_point, type, BusTypeUnknown );
+    add_dos_device( -1, device, device, mount_point, type, BusTypeUnknown,
+                    NULL, NULL, NULL, NULL );
 done:
     CFRelease( dict );
 }
diff --git a/dlls/mountmgr.sys/hal.c b/dlls/mountmgr.sys/hal.c
index 03c21dc..46b033b 100644
--- a/dlls/mountmgr.sys/hal.c
+++ b/dlls/mountmgr.sys/hal.c
@@ -114,6 +114,11 @@ static void new_device( LibHalContext *ctx, const char *udi )
     char *device = NULL;
     char *type = NULL;
     char *bus = NULL;
+    char *vendor = NULL;
+    char *product = NULL;
+    char *revision = NULL;
+    char *prev = NULL;
+    char *serial = NULL;
     DWORD drive_type;
     STORAGE_BUS_TYPE bus_type = BusTypeUnknown;
 
@@ -151,7 +156,28 @@ static void new_device( LibHalContext *ctx, const char *udi )
     else if (!strcmp( type, "floppy" )) drive_type = DRIVE_REMOVABLE;
     else drive_type = DRIVE_REMOVABLE_DISK;  /* FIXME: default to removable */
 
-    add_dos_device( -1, udi, device, mount_point, drive_type, bus_type );
+    if (!(vendor = p_libhal_device_get_property_string( ctx, parent, "info.vendor", NULL )))
+        p_dbus_error_free( &error );
+
+    if (!(product = p_libhal_device_get_property_string( ctx, parent, "info.product", NULL )))
+        p_dbus_error_free( &error );
+
+    if (!(revision = p_libhal_device_get_property_string( ctx, parent, "storage.firmware_version", NULL )))
+        p_dbus_error_free( &error );
+
+    do {
+        prev = p_libhal_device_get_property_string( ctx, parent, "info.parent", NULL );
+        if (!prev)
+            p_dbus_error_free( &error );
+        else
+            serial = p_libhal_device_get_property_string( ctx, prev, "usb_device.serial", NULL );
+        p_libhal_free_string( parent );
+        parent = prev;
+        prev = NULL;
+    } while (parent && !serial);
+
+    add_dos_device( -1, udi, device, mount_point, drive_type, bus_type, vendor,
+                    product, revision, serial );
 
     /* add property watch for mount point */
     p_libhal_device_add_property_watch( ctx, udi, &error );
@@ -162,6 +188,10 @@ done:
     if (device) p_libhal_free_string( device );
     if (mount_point) p_libhal_free_string( mount_point );
     if (bus) p_libhal_free_string( bus );
+    if (vendor) p_libhal_free_string( vendor );
+    if (product) p_libhal_free_string( product );
+    if (revision) p_libhal_free_string( revision );
+    if (serial) p_libhal_free_string( serial );
     p_dbus_error_free( &error );
 }
 
diff --git a/dlls/mountmgr.sys/mountmgr.c b/dlls/mountmgr.sys/mountmgr.c
index 45ca690..510bb7d 100644
--- a/dlls/mountmgr.sys/mountmgr.c
+++ b/dlls/mountmgr.sys/mountmgr.c
@@ -257,7 +257,7 @@ static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize )
         TRACE( "defining %c: dev %s mount %s type %u\n",
                letter, debugstr_a(device), debugstr_a(mount_point), input->type );
         return add_dos_device( letter - 'a', NULL, device, mount_point,
-                               input->type, BusTypeUnknown );
+                               input->type, BusTypeUnknown, NULL, NULL, NULL, NULL );
     }
     else
     {
diff --git a/dlls/mountmgr.sys/mountmgr.h b/dlls/mountmgr.sys/mountmgr.h
index 24e7aa9..b5ba485 100644
--- a/dlls/mountmgr.sys/mountmgr.h
+++ b/dlls/mountmgr.sys/mountmgr.h
@@ -41,7 +41,9 @@ extern void initialize_diskarbitration(void);
 /* device functions */
 
 extern NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
-                                const char *mount_point, DWORD type, STORAGE_BUS_TYPE bus );
+                                const char *mount_point, DWORD type, STORAGE_BUS_TYPE bus,
+                                const char *vendor, const char *product,
+                                const char *revision, const char *serial );
 extern NTSTATUS remove_dos_device( int letter, const char *udi );
 extern NTSTATUS query_dos_device( int letter, DWORD *type, const char **device, const char **mount_point );
 extern NTSTATUS WINAPI harddisk_driver_entry( DRIVER_OBJECT *driver, UNICODE_STRING *path );
-- 
1.5.6.5.GIT



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