[Wine-patches] [3/5] mountmgr: Add a partial implementation of IOCTL_STORAGE_QUERY_PROPERTY.

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


----------- следующая часть -----------
From 28b0f07b5c1d622aa77fe3b15cfd7ca5ba93209b Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Wed, 26 Nov 2008 13:19:41 +0300
Subject: [PATCH] mountmgr: Add a partial implementation of IOCTL_STORAGE_QUERY_PROPERTY.

---
 dlls/mountmgr.sys/device.c   |   47 +++++++++++++++++++++++++++++++++++++++--
 dlls/mountmgr.sys/diskarb.c  |    2 +-
 dlls/mountmgr.sys/hal.c      |   11 +++++++++-
 dlls/mountmgr.sys/mountmgr.c |    3 +-
 dlls/mountmgr.sys/mountmgr.h |    3 +-
 5 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/dlls/mountmgr.sys/device.c b/dlls/mountmgr.sys/device.c
index 43c5685..a220b75 100644
--- a/dlls/mountmgr.sys/device.c
+++ b/dlls/mountmgr.sys/device.c
@@ -71,6 +71,7 @@ struct dos_drive
     struct mount_point   *volume;      /* Volume{xxx} mount point */
     char                 *unix_device; /* unix device path */
     char                 *unix_mount;  /* unix mount point path */
+    STORAGE_BUS_TYPE      bus_type;    /* bus type */
 };
 
 static struct list drives_list = LIST_INIT(drives_list);
@@ -205,6 +206,7 @@ static NTSTATUS create_disk_device( const char *udi, enum device_type type, stru
         drive->unix_device = NULL;
         drive->unix_mount  = NULL;
         drive->symlink.Buffer = NULL;
+        drive->bus_type = BusTypeUnknown;
         if (udi)
         {
             if (!(drive->udi = HeapAlloc( GetProcessHeap(), 0, strlen(udi)+1 )))
@@ -488,7 +490,8 @@ static void create_drive_devices(void)
 
 /* 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 )
+                         const char *mount_point, enum device_type type,
+                         STORAGE_BUS_TYPE bus )
 {
     struct dos_drive *drive, *next;
 
@@ -523,6 +526,7 @@ NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
 found:
     RtlFreeHeap( GetProcessHeap(), 0, drive->unix_device );
     drive->unix_device = strdupA( device );
+    drive->bus_type = bus;
     set_drive_letter( drive, letter );
     set_unix_mount_point( drive, mount_point );
 
@@ -530,9 +534,9 @@ found:
     {
         HKEY hkey;
 
-        TRACE( "added device %c: udi %s for %s on %s type %u\n",
+        TRACE( "added device %c: udi %s for %s on %s type %u bus %u\n",
                     'a' + drive->drive, wine_dbgstr_a(udi), wine_dbgstr_a(device),
-                    wine_dbgstr_a(mount_point), type );
+                    wine_dbgstr_a(mount_point), type, bus );
 
         /* hack: force the drive type in the registry */
         if (!RegCreateKeyW( HKEY_LOCAL_MACHINE, drives_keyW, &hkey ))
@@ -648,6 +652,43 @@ static NTSTATUS WINAPI harddisk_ioctl( DEVICE_OBJECT *device, IRP *irp )
     case IOCTL_CDROM_READ_TOC:
         irp->IoStatus.u.Status = STATUS_INVALID_DEVICE_REQUEST;
         break;
+    case IOCTL_STORAGE_QUERY_PROPERTY:
+    {
+        STORAGE_PROPERTY_QUERY *spq;
+        STORAGE_DEVICE_DESCRIPTOR sdd;
+        size_t sdd_size = sizeof(STORAGE_DEVICE_DESCRIPTOR);
+        DWORD len = min( sdd_size, irpsp->Parameters.DeviceIoControl.OutputBufferLength );
+
+        switch (drive->type)
+        {
+        case DEVICE_HARDDISK:
+        case DEVICE_HARDDISK_VOL:
+        case DEVICE_CDROM:
+            if (irpsp->Parameters.DeviceIoControl.InputBufferLength
+                    < sizeof(STORAGE_PROPERTY_QUERY))
+            {
+                irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
+                break;
+            }
+            spq = irp->AssociatedIrp.SystemBuffer;
+            if (spq->PropertyId != StorageDeviceProperty ||
+                    spq->QueryType != PropertyStandardQuery)
+            {
+                irp->IoStatus.u.Status = STATUS_NOT_SUPPORTED;
+                break;
+            }
+            RtlZeroMemory( &sdd, sdd_size );
+            sdd.Size = sdd_size;
+            sdd.BusType = drive->bus_type;
+            memcpy( irp->AssociatedIrp.SystemBuffer, &sdd, len );
+            irp->IoStatus.Information = len;
+            irp->IoStatus.u.Status = STATUS_SUCCESS;
+            break;
+        default:
+            irp->IoStatus.u.Status = STATUS_INVALID_DEVICE_REQUEST;
+        }
+        break;
+    }
     default:
         FIXME( "unsupported ioctl %x\n", irpsp->Parameters.DeviceIoControl.IoControlCode );
         irp->IoStatus.u.Status = STATUS_NOT_SUPPORTED;
diff --git a/dlls/mountmgr.sys/diskarb.c b/dlls/mountmgr.sys/diskarb.c
index 3296d04..1a33ac6 100644
--- a/dlls/mountmgr.sys/diskarb.c
+++ b/dlls/mountmgr.sys/diskarb.c
@@ -69,7 +69,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 );
+    add_dos_device( -1, device, device, mount_point, type, BusTypeUnknown /* FIXME */ );
 done:
     CFRelease( dict );
 }
diff --git a/dlls/mountmgr.sys/hal.c b/dlls/mountmgr.sys/hal.c
index df908f9..d9d1ec2 100644
--- a/dlls/mountmgr.sys/hal.c
+++ b/dlls/mountmgr.sys/hal.c
@@ -113,7 +113,9 @@ static void new_device( LibHalContext *ctx, const char *udi )
     char *mount_point = NULL;
     char *device = NULL;
     char *type = NULL;
+    char *bus = NULL;
     enum device_type drive_type;
+    STORAGE_BUS_TYPE bus_type;
 
     p_dbus_error_init( &error );
 
@@ -129,6 +131,12 @@ static void new_device( LibHalContext *ctx, const char *udi )
     if (!p_libhal_device_get_property_bool( ctx, parent, "storage.removable", &error ))
         goto done;
 
+    if (!(bus = p_libhal_device_get_property_string( ctx, parent, "storage.bus", &error )))
+        p_dbus_error_free( &error );
+
+    if (bus && !strcmp( bus, "usb" )) bus_type = BusTypeUsb;
+    else bus_type = BusTypeUnknown;
+
     if (!(type = p_libhal_device_get_property_string( ctx, parent, "storage.drive_type", &error )))
         p_dbus_error_free( &error );  /* ignore error */
 
@@ -137,7 +145,7 @@ 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 );
+    add_dos_device( -1, udi, device, mount_point, drive_type, bus_type );
 
     /* add property watch for mount point */
     p_libhal_device_add_property_watch( ctx, udi, &error );
@@ -147,6 +155,7 @@ done:
     if (parent) p_libhal_free_string( parent );
     if (device) p_libhal_free_string( device );
     if (mount_point) p_libhal_free_string( mount_point );
+    if (bus) p_libhal_free_string( bus );
     p_dbus_error_free( &error );
 }
 
diff --git a/dlls/mountmgr.sys/mountmgr.c b/dlls/mountmgr.sys/mountmgr.c
index 0c0850f..18000ca 100644
--- a/dlls/mountmgr.sys/mountmgr.c
+++ b/dlls/mountmgr.sys/mountmgr.c
@@ -265,7 +265,8 @@ static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize )
         case DRIVE_CDROM:     type = DEVICE_CDROM; break;
         case DRIVE_RAMDISK:   type = DEVICE_RAMDISK; break;
         }
-        return add_dos_device( letter - 'a', NULL, device, mount_point, type );
+        return add_dos_device( letter - 'a', NULL, device, mount_point,
+                               type, BusTypeUnknown );
     }
     else
     {
diff --git a/dlls/mountmgr.sys/mountmgr.h b/dlls/mountmgr.sys/mountmgr.h
index e8f7d5d..1ba695e 100644
--- a/dlls/mountmgr.sys/mountmgr.h
+++ b/dlls/mountmgr.sys/mountmgr.h
@@ -52,7 +52,8 @@ enum device_type
 };
 
 extern NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
-                                const char *mount_point, enum device_type type );
+                                const char *mount_point, enum device_type type,
+                                STORAGE_BUS_TYPE bus );
 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