[DISK] Properly implement querying partition information for partition 0.
authorPierre Schweitzer <pierre@reactos.org>
Sun, 24 Dec 2017 20:54:09 +0000 (21:54 +0100)
committerPierre Schweitzer <pierre@reactos.org>
Sun, 24 Dec 2017 20:58:47 +0000 (21:58 +0100)
In spite of what was implemented in our NT DDK sample, this is a legit operation.

This may have been turned legit starting NT5 (reminder, our implementation is
NT4 based...). So, in this situation, just return the information about the whole
disk (and not a random size) and also, mark everything with default values.

See disk_new for an example of how it works in NT5+.

CORE-14124

drivers/storage/class/disk/disk.c

index e0c7756..cb84565 100644 (file)
@@ -2235,58 +2235,69 @@ Return Value:
             sizeof(PARTITION_INFORMATION)) {
 
             status = STATUS_INFO_LENGTH_MISMATCH;
             sizeof(PARTITION_INFORMATION)) {
 
             status = STATUS_INFO_LENGTH_MISMATCH;
-
+            break;
         }
         }
-#if 0 // HACK: ReactOS partition numbers must be wrong
-        else if (diskData->PartitionNumber == 0) {
+
+        //
+        // Update the geometry in case it has changed.
+        //
+
+        status = UpdateRemovableGeometry (DeviceObject, Irp);
+
+        if (!NT_SUCCESS(status)) {
 
             //
 
             //
-            // Partition zero is not a partition so this is not a
-            // reasonable request.
+            // Note the drive is not ready.
             //
 
             //
 
-            status = STATUS_INVALID_DEVICE_REQUEST;
-
+            diskData->DriveNotReady = TRUE;
+            break;
         }
         }
-#endif
-        else {
 
 
-            PPARTITION_INFORMATION outputBuffer;
+        //
+        // Note the drive is now ready.
+        //
 
 
-            if (diskData->PartitionNumber == 0) {
-                DPRINT1("HACK: Handling partition 0 request!\n");
-                //ASSERT(FALSE);
-            }
+        diskData->DriveNotReady = FALSE;
 
 
-            //
-            // Update the geometry in case it has changed.
-            //
+        //
+        // Handle the case were we query the whole disk
+        //
 
 
-            status = UpdateRemovableGeometry (DeviceObject, Irp);
+        if (diskData->PartitionNumber == 0) {
 
 
-            if (!NT_SUCCESS(status)) {
+            PPARTITION_INFORMATION outputBuffer;
 
 
-                //
-                // Note the drive is not ready.
-                //
+            outputBuffer =
+                    (PPARTITION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
 
 
-                diskData->DriveNotReady = TRUE;
-                break;
-            }
+            outputBuffer->PartitionType = PARTITION_ENTRY_UNUSED;
+            outputBuffer->StartingOffset = deviceExtension->StartingOffset;
+            outputBuffer->PartitionLength.QuadPart = deviceExtension->PartitionLength.QuadPart;
+            outputBuffer->HiddenSectors = 0;
+            outputBuffer->PartitionNumber = diskData->PartitionNumber;
+            outputBuffer->BootIndicator = FALSE;
+            outputBuffer->RewritePartition = FALSE;
+            outputBuffer->RecognizedPartition = FALSE;
+
+            status = STATUS_SUCCESS;
+            Irp->IoStatus.Information = sizeof(PARTITION_INFORMATION);
+
+        } else {
+
+            PPARTITION_INFORMATION outputBuffer;
 
             //
 
             //
-            // Note the drive is now ready.
+            // We query a single partition here
+            // FIXME: this can only work for MBR-based disks, check for this!
             //
 
             //
 
-            diskData->DriveNotReady = FALSE;
-
             outputBuffer =
                     (PPARTITION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
 
             outputBuffer->PartitionType = diskData->PartitionType;
             outputBuffer->StartingOffset = deviceExtension->StartingOffset;
             outputBuffer =
                     (PPARTITION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
 
             outputBuffer->PartitionType = diskData->PartitionType;
             outputBuffer->StartingOffset = deviceExtension->StartingOffset;
-            outputBuffer->PartitionLength.QuadPart = (diskData->PartitionNumber) ?
-                deviceExtension->PartitionLength.QuadPart : 0x1FFFFFFFFFFFFFFFLL; // HACK
+            outputBuffer->PartitionLength.QuadPart = deviceExtension->PartitionLength.QuadPart;
             outputBuffer->HiddenSectors = diskData->HiddenSectors;
             outputBuffer->PartitionNumber = diskData->PartitionNumber;
             outputBuffer->BootIndicator = diskData->BootIndicator;
             outputBuffer->HiddenSectors = diskData->HiddenSectors;
             outputBuffer->PartitionNumber = diskData->PartitionNumber;
             outputBuffer->BootIndicator = diskData->BootIndicator;