[RAMDISK]
authorPierre Schweitzer <pierre@reactos.org>
Mon, 29 Dec 2014 18:00:50 +0000 (18:00 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Mon, 29 Dec 2014 18:00:50 +0000 (18:00 +0000)
Implement RamdiskQueryId() which is used in case of IRP_MJ_PNP + IRP_MN_QUERY_ID

svn path=/trunk/; revision=65895

reactos/drivers/storage/class/ramdisk/ramdisk.c

index 30210e5..4ed13c3 100644 (file)
@@ -2022,6 +2022,131 @@ RamdiskRemoveBusDevice(IN PDEVICE_OBJECT DeviceObject,
     return Status;
 }
 
+NTSTATUS
+NTAPI
+RamdiskQueryId(IN PRAMDISK_DRIVE_EXTENSION DriveExtension,
+               IN PIRP Irp)
+{
+    NTSTATUS Status;
+    PIO_STACK_LOCATION IoStackLocation;
+    PWSTR OutputString = NULL;
+    ULONG StringLength;
+
+    Status = STATUS_SUCCESS;
+    IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
+
+    //
+    // Get what is being queried
+    //
+    switch (IoStackLocation->Parameters.QueryId.IdType)
+    {
+        case BusQueryDeviceID:
+
+            //
+            // Allocate a buffer long enough to receive Ramdisk\RamDisk in any case
+            // In case we don't have RAMDISK_REGISTRY_DISK, we then need two more
+            // chars to store Ramdisk\RamVolume instead
+            //
+            StringLength = 4 * (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK) + sizeof(L"Ramdisk\\RamDisk");
+            OutputString = ExAllocatePoolWithTag(PagedPool, StringLength, 'dmaR');
+            if (OutputString == NULL)
+            {
+                Status = STATUS_INSUFFICIENT_RESOURCES;
+                break;
+            }
+
+            wcsncpy(OutputString, L"Ramdisk\\", StringLength / sizeof(WCHAR));
+            if (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK)
+            {
+                wcsncat(OutputString, L"RamVolume", StringLength / sizeof(WCHAR));
+            }
+            else
+            {
+                wcsncat(OutputString, L"RamDisk", StringLength / sizeof(WCHAR));
+            }
+
+            break;
+
+        case BusQueryHardwareIDs:
+
+            //
+            // Allocate a buffer long enough to receive Ramdisk\RamDisk in any case
+            // In case we don't have RAMDISK_REGISTRY_DISK, we then need two more
+            // chars to store Ramdisk\RamVolume instead
+            // We also need an extra char, because it is required that the string
+            // is null-terminated twice
+            //
+            StringLength = 4 * (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK) +
+                           sizeof(UNICODE_NULL) + sizeof(L"Ramdisk\\RamDisk");
+            OutputString = ExAllocatePoolWithTag(PagedPool, StringLength, 'dmaR');
+            if (OutputString == NULL)
+            {
+                Status = STATUS_INSUFFICIENT_RESOURCES;
+                break;
+            }
+
+            wcsncpy(OutputString, L"Ramdisk\\", StringLength / sizeof(WCHAR));
+            if (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK)
+            {
+                wcsncat(OutputString, L"RamVolume", StringLength / sizeof(WCHAR));
+            }
+            else
+            {
+                wcsncat(OutputString, L"RamDisk", StringLength / sizeof(WCHAR));
+            }
+            OutputString[(StringLength / sizeof(WCHAR)) - 1] = UNICODE_NULL;
+
+            break;
+
+        case BusQueryCompatibleIDs:
+
+            if (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK)
+            {
+                Status = STATUS_INVALID_DEVICE_REQUEST;
+                break;
+            }
+
+            StringLength = sizeof(L"GenDisk");
+            OutputString = ExAllocatePoolWithTag(PagedPool, StringLength, 'dmaR');
+            if (OutputString == NULL)
+            {
+                Status = STATUS_INSUFFICIENT_RESOURCES;
+                break;
+            }
+
+            wcsncpy(OutputString, L"GenDisk", StringLength / sizeof(WCHAR));
+            OutputString[(StringLength / sizeof(WCHAR)) - 1] = UNICODE_NULL;
+
+            break;
+
+        case BusQueryInstanceID:
+
+            OutputString = ExAllocatePoolWithTag(PagedPool, DriveExtension->GuidString.MaximumLength, 'dmaR');
+            if (OutputString == NULL)
+            {
+                Status = STATUS_INSUFFICIENT_RESOURCES;
+                break;
+            }
+
+            wcsncpy(OutputString, DriveExtension->GuidString.Buffer, DriveExtension->GuidString.MaximumLength / sizeof(WCHAR));
+
+            break;
+
+        case BusQueryDeviceSerialNumber:
+            
+            //
+            // Nothing to do
+            //
+
+            break;
+    }
+
+    Irp->IoStatus.Status = Status;
+    Irp->IoStatus.Information = (ULONG_PTR)OutputString;
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    return Status;
+}
+
 NTSTATUS
 NTAPI
 RamdiskPnp(IN PDEVICE_OBJECT DeviceObject,
@@ -2150,7 +2275,7 @@ RamdiskPnp(IN PDEVICE_OBJECT DeviceObject,
             //
             if (DeviceExtension->Type == RamdiskDrive)
             {
-                UNIMPLEMENTED_DBGBREAK("PnP IRP: %lx\n", Minor);
+                Status = RamdiskQueryId((PRAMDISK_DRIVE_EXTENSION)DeviceExtension, Irp);
             }
             break;