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

Alexander Morozov =?iso-8859-1?q?amorozov_=CE=C1_etersoft=2Eru?=
Пн Дек 1 18:10:06 MSK 2008


----------- следующая часть -----------
From 485c614c4db15e0da54035b3f663d4a65406b378 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Tue, 25 Nov 2008 14:58:34 +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 a220b75..e66117c 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"
@@ -488,10 +492,64 @@ 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, enum device_type type,
-                         STORAGE_BUS_TYPE bus )
+                         STORAGE_BUS_TYPE bus, const char *vendor,
+                         const char *product, const char *revision,
+                         const char *serial )
 {
     struct dos_drive *drive, *next;
 
@@ -554,6 +612,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 1a33ac6..5b1d035 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 /* FIXME */ );
+    add_dos_device( -1, device, device, mount_point, type,
+                    BusTypeUnknown /* FIXME */ , NULL, NULL, NULL, NULL );
 done:
     CFRelease( dict );
 }
diff --git a/dlls/mountmgr.sys/hal.c b/dlls/mountmgr.sys/hal.c
index d9d1ec2..8e066e5 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;
     enum device_type drive_type;
     STORAGE_BUS_TYPE bus_type;
 
@@ -145,7 +150,28 @@ static void new_device( LibHalContext *ctx, const char *udi )
     else if (type && !strcmp( type, "disk" )) drive_type = DEVICE_HARDDISK;
     else drive_type = DEVICE_UNKNOWN;
 
-    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 );
@@ -156,6 +182,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 18000ca..e5aa0f9 100644
--- a/dlls/mountmgr.sys/mountmgr.c
+++ b/dlls/mountmgr.sys/mountmgr.c
@@ -266,7 +266,7 @@ static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize )
         case DRIVE_RAMDISK:   type = DEVICE_RAMDISK; break;
         }
         return add_dos_device( letter - 'a', NULL, device, mount_point,
-                               type, BusTypeUnknown );
+                               type, BusTypeUnknown, NULL, NULL, NULL, NULL );
     }
     else
     {
diff --git a/dlls/mountmgr.sys/mountmgr.h b/dlls/mountmgr.sys/mountmgr.h
index 1ba695e..638e546 100644
--- a/dlls/mountmgr.sys/mountmgr.h
+++ b/dlls/mountmgr.sys/mountmgr.h
@@ -53,7 +53,9 @@ enum device_type
 
 extern NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
                                 const char *mount_point, enum device_type type,
-                                STORAGE_BUS_TYPE bus );
+                                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, enum device_type *type,
                                   const char **device, const char **mount_point );
-- 
1.6.0.2.GIT



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