[Wine-patches] [eterhack 1/5] mountmgr.sys: Add wine-specific IOCTL_STORAGE_USB_DEVICE_ADDRESS.

Alexander Morozov amorozov на etersoft.ru
Вт Июн 23 16:16:48 MSD 2009


---
 dlls/mountmgr.sys/device.c   |   26 +++++++++++++++++++++++++-
 dlls/mountmgr.sys/diskarb.c  |    2 +-
 dlls/mountmgr.sys/hal.c      |   39 ++++++++++++++++++++++++++++++++++++++-
 dlls/mountmgr.sys/mountmgr.c |    2 +-
 dlls/mountmgr.sys/mountmgr.h |    4 ++--
 include/ntddstor.h           |   13 +++++++++++++
 6 files changed, 80 insertions(+), 6 deletions(-)

diff --git a/dlls/mountmgr.sys/device.c b/dlls/mountmgr.sys/device.c
index 475e7a1..5418bfa 100644
--- a/dlls/mountmgr.sys/device.c
+++ b/dlls/mountmgr.sys/device.c
@@ -77,6 +77,8 @@ struct dos_drive
     char                 *unix_mount;  /* unix mount point path */
     STORAGE_BUS_TYPE      bus_type;    /* bus type */
     UNICODE_STRING        usbstor;     /* USBSTOR device symlink */
+    int                   usb_bus;     /* USB bus number */
+    int                   usb_addr;    /* USB device address */
 };
 
 static struct list drives_list = LIST_INIT(drives_list);
@@ -602,7 +604,7 @@ NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
                          const char *mount_point, enum device_type type,
                          STORAGE_BUS_TYPE bus, const char *vendor,
                          const char *product, const char *revision,
-                         const char *serial )
+                         const char *serial, int usb_bus, int usb_addr )
 {
     struct dos_drive *drive, *next;
 
@@ -638,6 +640,8 @@ found:
     RtlFreeHeap( GetProcessHeap(), 0, drive->unix_device );
     drive->unix_device = strdupA( device );
     drive->bus_type = bus;
+    drive->usb_bus = usb_bus;
+    drive->usb_addr = usb_addr;
     set_drive_letter( drive, letter );
     set_unix_mount_point( drive, mount_point );
 
@@ -804,6 +808,26 @@ static NTSTATUS WINAPI harddisk_ioctl( DEVICE_OBJECT *device, IRP *irp )
         }
         break;
     }
+    case IOCTL_STORAGE_USB_DEVICE_ADDRESS:
+    {
+        struct usb_device_address *usbda = irp->AssociatedIrp.SystemBuffer;
+
+        if (!drive->usb_addr)
+        {
+            status = STATUS_INVALID_DEVICE_REQUEST;
+            break;
+        }
+        if (irpsp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(*usbda))
+        {
+            status = STATUS_INVALID_PARAMETER;
+            break;
+        }
+        usbda->bus = drive->usb_bus;
+        usbda->addr = drive->usb_addr;
+        irp->IoStatus.Information = sizeof(*usbda);
+        status = STATUS_SUCCESS;
+        break;
+    }
     default:
         FIXME( "unsupported ioctl %x\n", irpsp->Parameters.DeviceIoControl.IoControlCode );
         status = STATUS_NOT_SUPPORTED;
diff --git a/dlls/mountmgr.sys/diskarb.c b/dlls/mountmgr.sys/diskarb.c
index 5b1d035..62b71d6 100644
--- a/dlls/mountmgr.sys/diskarb.c
+++ b/dlls/mountmgr.sys/diskarb.c
@@ -70,7 +70,7 @@ 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 */ , NULL, NULL, NULL, NULL );
+                    BusTypeUnknown /* FIXME */ , NULL, NULL, NULL, NULL, 0, 0 );
 done:
     CFRelease( dict );
 }
diff --git a/dlls/mountmgr.sys/hal.c b/dlls/mountmgr.sys/hal.c
index df50ab0..6142930 100644
--- a/dlls/mountmgr.sys/hal.c
+++ b/dlls/mountmgr.sys/hal.c
@@ -25,6 +25,7 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/time.h>
 
 #include "mountmgr.h"
@@ -105,6 +106,30 @@ static LONG WINAPI assert_fault(EXCEPTION_POINTERS *eptr)
     return EXCEPTION_CONTINUE_SEARCH;
 }
 
+static int get_num_from_file( const char *path, const char *filename )
+{
+    char *fullpath, str[16];
+    int fd, num = 0;
+
+    fullpath = RtlAllocateHeap( GetProcessHeap(), 0,
+            strlen(path) + strlen(filename) + 2 );
+    if (!fullpath) return 0;
+    strcpy( fullpath, path );
+    strcat( fullpath, "/" );
+    strcat( fullpath, filename );
+    if ((fd = open( fullpath, O_RDONLY )) >= 0)
+    {
+        if ((num = read( fd, str, sizeof(str) - 1 )) > 0)
+        {
+            str[num] = 0;
+            num = atoi( str );
+        }
+        close( fd );
+    }
+    RtlFreeHeap( GetProcessHeap(), 0, fullpath );
+    return num;
+}
+
 /* HAL callback for new device */
 static void new_device( LibHalContext *ctx, const char *udi )
 {
@@ -119,8 +144,10 @@ static void new_device( LibHalContext *ctx, const char *udi )
     char *revision = NULL;
     char *prev = NULL;
     char *serial = NULL;
+    char *sysfs_path;
     enum device_type drive_type;
     STORAGE_BUS_TYPE bus_type;
+    int usb_bus = 0, usb_addr = 0;
 
     p_dbus_error_init( &error );
 
@@ -156,13 +183,23 @@ static void new_device( LibHalContext *ctx, const char *udi )
         {
             serial = p_libhal_device_get_property_string( ctx, prev, "usb_device.serial", NULL );
         }
+        if (serial)
+        {
+            sysfs_path = p_libhal_device_get_property_string( ctx, prev, "linux.sysfs_path", NULL );
+            if (sysfs_path)
+            {
+                usb_bus = get_num_from_file( sysfs_path, "busnum" );
+                usb_addr = get_num_from_file( sysfs_path, "devnum" );
+                p_libhal_free_string( sysfs_path );
+            }
+        }
         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 );
+                    vendor, product, revision, serial, usb_bus, usb_addr );
 
     /* add property watch for mount point */
     p_libhal_device_add_property_watch( ctx, udi, &error );
diff --git a/dlls/mountmgr.sys/mountmgr.c b/dlls/mountmgr.sys/mountmgr.c
index 22402d0..c0fedba 100644
--- a/dlls/mountmgr.sys/mountmgr.c
+++ b/dlls/mountmgr.sys/mountmgr.c
@@ -267,7 +267,7 @@ static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize )
         case DRIVE_FIXED:     type = DEVICE_HARDDISK_VOL; break;
         }
         return add_dos_device( letter - 'a', NULL, device, mount_point,
-                               type, BusTypeUnknown, NULL, NULL, NULL, NULL );
+                               type, BusTypeUnknown, NULL, NULL, NULL, NULL, 0, 0 );
     }
     else
     {
diff --git a/dlls/mountmgr.sys/mountmgr.h b/dlls/mountmgr.sys/mountmgr.h
index 638e546..6697e09 100644
--- a/dlls/mountmgr.sys/mountmgr.h
+++ b/dlls/mountmgr.sys/mountmgr.h
@@ -29,10 +29,10 @@
 #include "winbase.h"
 #include "winternl.h"
 #include "winioctl.h"
+#define WINE_MOUNTMGR_EXTENSIONS
 #include "ntddstor.h"
 #include "ntddcdrm.h"
 #include "ddk/wdm.h"
-#define WINE_MOUNTMGR_EXTENSIONS
 #include "ddk/mountmgr.h"
 
 extern void initialize_hal(void);
@@ -55,7 +55,7 @@ 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, const char *vendor,
                                 const char *product, const char *revision,
-                                const char *serial );
+                                const char *serial, int usb_bus, int usb_addr );
 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 );
diff --git a/include/ntddstor.h b/include/ntddstor.h
index cf54be6..0b16f28 100644
--- a/include/ntddstor.h
+++ b/include/ntddstor.h
@@ -41,6 +41,19 @@ extern "C" {
 #define IOCTL_STORAGE_GET_DEVICE_NUMBER CTL_CODE(IOCTL_STORAGE_BASE, 0x0420, METHOD_BUFFERED, FILE_ANY_ACCESS)
 #define IOCTL_STORAGE_QUERY_PROPERTY    CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
+/* Wine extensions */
+#ifdef WINE_MOUNTMGR_EXTENSIONS
+
+#define IOCTL_STORAGE_USB_DEVICE_ADDRESS CTL_CODE(IOCTL_STORAGE_BASE, 0x0600, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+struct usb_device_address
+{
+    ULONG bus;
+    ULONG addr;
+};
+
+#endif
+
 DEFINE_GUID(DiskClassGuid,
   0x53f56307, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
 DEFINE_GUID(CdRomClassGuid,
-- 
1.6.3.2



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