[CLASS2]: - In ScsiClassCreateDeviceObject() don't drop received object name and...
authorPierre Schweitzer <pierre@reactos.org>
Tue, 3 Oct 2017 18:57:50 +0000 (20:57 +0200)
committerPierre Schweitzer <pierre@reactos.org>
Tue, 3 Oct 2017 19:34:00 +0000 (21:34 +0200)
- Implement support for the IOCTL_MOUNTDEV_QUERY_DEVICE_NAME IOCTL; return the store device name

drivers/storage/class/class2/class2.c
drivers/storage/class/include/class2.h

index 20f55ef..48598e3 100644 (file)
@@ -4041,9 +4041,9 @@ Return Value:
         goto SetStatusAndReturn;
     }
 
-    if (irpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_MOUNTDEV_QUERY_DEVICE_NAME || 
-        irpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_MOUNTDEV_QUERY_UNIQUE_ID ||
+    if (irpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_MOUNTDEV_QUERY_UNIQUE_ID ||
         irpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_MOUNTDEV_QUERY_SUGGESTED_LINK_NAME) {
+
         UNIMPLEMENTED;
         Irp->IoStatus.Information = 0;
         Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
@@ -4052,6 +4052,40 @@ Return Value:
         goto SetStatusAndReturn;
     }
 
+    if (irpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_MOUNTDEV_QUERY_DEVICE_NAME) {
+
+        PMOUNTDEV_NAME name = Irp->AssociatedIrp.SystemBuffer;
+
+        if (irpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(MOUNTDEV_NAME)) {
+
+            Irp->IoStatus.Information = 0;
+            Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
+            IoCompleteRequest(Irp, IO_NO_INCREMENT);
+            status = STATUS_BUFFER_TOO_SMALL;
+            goto SetStatusAndReturn;
+        }
+
+        RtlZeroMemory(name, sizeof(MOUNTDEV_NAME));
+        name->NameLength = deviceExtension->DeviceName.Length;
+
+        if (irpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(USHORT) + name->NameLength) {
+
+            Irp->IoStatus.Information = sizeof(MOUNTDEV_NAME);
+            Irp->IoStatus.Status = STATUS_BUFFER_OVERFLOW;
+            IoCompleteRequest(Irp, IO_NO_INCREMENT);
+            status = STATUS_BUFFER_OVERFLOW;
+            goto SetStatusAndReturn;
+        }
+
+        RtlCopyMemory(name->Name, deviceExtension->DeviceName.Buffer,
+                      name->NameLength);
+        status = STATUS_SUCCESS;
+        Irp->IoStatus.Status = STATUS_SUCCESS;
+        Irp->IoStatus.Information = sizeof(USHORT) + name->NameLength;
+        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+        goto SetStatusAndReturn;
+    }
+
     srb = ExAllocatePool(NonPagedPool, SCSI_REQUEST_BLOCK_SIZE);
 
     if (srb == NULL) {
@@ -4691,20 +4725,14 @@ Return Value:
         } else {
             deviceExtension->PhysicalDevice = deviceObject;
         }
+
+        deviceExtension->DeviceName = ntUnicodeString;
     }
 
     deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
 
     *DeviceObject = deviceObject;
 
-    RtlFreeUnicodeString(&ntUnicodeString);
-
-    //
-    // Indicate the ntUnicodeString is free.
-    //
-
-    ntUnicodeString.Buffer = NULL;
-
     return status;
 }
 
index 047e48d..e1e0cf0 100644 (file)
@@ -132,6 +132,7 @@ typedef struct _DEVICE_EXTENSION
   HANDLE MediaChangeEventHandle;
   BOOLEAN MediaChangeNoMedia;
   ULONG MediaChangeCount;
+  UNICODE_STRING DeviceName;
 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;