[DISK]
[reactos.git] / reactos / drivers / storage / class / disk / disk.c
index 015b8bb..0563702 100644 (file)
 #include <ntddscsi.h>
 #include <mountdev.h>
 #include <mountmgr.h>
+#include <ntiologc.h>
 #include <include/class2.h>
 #include <stdio.h>
 
 #define NDEBUG
 #include <debug.h>
 
-#define IO_WRITE_CACHE_ENABLED  ((NTSTATUS)0x80040020L)
-#define IO_WRITE_CACHE_DISABLED ((NTSTATUS)0x80040022L)
 
 #ifdef POOL_TAGGING
 #ifdef ExAllocatePool
@@ -385,11 +384,6 @@ Return Value:
     InitializationData.ClassShutdownFlush = ScsiDiskShutdownFlush;
     InitializationData.ClassCreateClose = NULL;
 
-    //
-    // HACK! Please check below to the implementation of the function
-    //
-    DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = ScsiDiskFileSystemControl;
-
     //
     // Call the class init routine
     //
@@ -511,7 +505,6 @@ Return Value:
     // SRB zone elements to allocate.
     //
 
-    adapterDisk = 0;
     adapterInfo = (PVOID) buffer;
 
     adapterDisk = ScsiClassFindUnclaimedDevices(InitializationData, adapterInfo);
@@ -1519,6 +1512,15 @@ Return Value:
     ULONG transferByteCount = currentIrpStack->Parameters.Read.Length;
     LARGE_INTEGER startingOffset;
 
+    //
+    // HACK: How can we end here with null sector size?!
+    //
+
+    if (deviceExtension->DiskGeometry->Geometry.BytesPerSector == 0) {
+        DPRINT1("Hack! Received invalid sector size\n");
+        deviceExtension->DiskGeometry->Geometry.BytesPerSector = 512;
+    }
+
     //
     // Verify parameters of this request.
     // Check that ending sector is within partition and
@@ -1555,6 +1557,18 @@ Return Value:
             Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
         }
 
+        if (startingOffset.QuadPart > deviceExtension->PartitionLength.QuadPart) {
+            DPRINT1("Reading beyond partition end! startingOffset: %I64d, PartitionLength: %I64d\n", startingOffset.QuadPart, deviceExtension->PartitionLength.QuadPart);
+        }
+
+        if (transferByteCount & (deviceExtension->DiskGeometry->Geometry.BytesPerSector - 1)) {
+            DPRINT1("Not reading sectors! TransferByteCount: %lu, BytesPerSector: %lu\n", transferByteCount, deviceExtension->DiskGeometry->Geometry.BytesPerSector);
+        }
+
+        if (Irp->IoStatus.Status == STATUS_DEVICE_NOT_READY) {
+            DPRINT1("Failing due to device not ready!\n");
+        }
+
         return STATUS_INVALID_PARAMETER;
     }
 
@@ -2233,6 +2247,11 @@ Return Value:
 
             PPARTITION_INFORMATION outputBuffer;
 
+            if (diskData->PartitionNumber == 0) {
+                DPRINT1("HACK: Handling partition 0 request!\n");
+                //ASSERT(FALSE);
+            }
+
             //
             // Update the geometry in case it has changed.
             //
@@ -2254,12 +2273,6 @@ Return Value:
             //
 
             diskData->DriveNotReady = FALSE;
-// HACK: ReactOS partition numbers must be wrong (>0 part)
-            if (diskData->PartitionType == 0 && (diskData->PartitionNumber > 0)) {
-
-                status = STATUS_INVALID_DEVICE_REQUEST;
-                break;
-            }
 
             outputBuffer =
                     (PPARTITION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
@@ -2296,6 +2309,7 @@ Return Value:
             status = STATUS_INFO_LENGTH_MISMATCH;
 
         }
+#if 0 // HACK: ReactOS partition numbers must be wrong
         else if (diskData->PartitionNumber == 0) {
 
             //
@@ -2306,10 +2320,16 @@ Return Value:
             status = STATUS_INVALID_DEVICE_REQUEST;
 
         }
+#endif
         else {
 
             PPARTITION_INFORMATION_EX outputBuffer;
 
+            if (diskData->PartitionNumber == 0) {
+                DPRINT1("HACK: Handling partition 0 request!\n");
+                //ASSERT(FALSE);
+            }
+
             //
             // Update the geometry in case it has changed.
             //
@@ -2503,7 +2523,7 @@ Return Value:
                     partitionEntry = &partitionList->PartitionEntry[i];
 
                     //
-                    // Check if empty, or describes extended partiton or hasn't changed.
+                    // Check if empty, or describes extended partition or hasn't changed.
                     //
 
                     if (partitionEntry->PartitionType == PARTITION_ENTRY_UNUSED ||
@@ -4263,7 +4283,7 @@ diskMatched:
     DeviceExtension->DiskGeometry->Geometry.SectorsPerTrack = sectorsPerTrack;
     DeviceExtension->DiskGeometry->Geometry.TracksPerCylinder = tracksPerCylinder;
     DeviceExtension->DiskGeometry->Geometry.Cylinders.QuadPart = (LONGLONG)cylinders;
-    DeviceExtension->DiskGeometry->DiskSize.QuadPart = cylinders * tracksPerCylinder * sectorsPerTrack *
+    DeviceExtension->DiskGeometry->DiskSize.QuadPart = (LONGLONG)cylinders * tracksPerCylinder * sectorsPerTrack *
                                                        DeviceExtension->DiskGeometry->Geometry.BytesPerSector;
 
     DebugPrint((3,
@@ -4864,7 +4884,7 @@ Return Value:
             partitionEntry = &partitionList->PartitionEntry[partition];
 
             //
-            // Check if empty, or describes extended partiton or hasn't changed.
+            // Check if empty, or describes extended partition or hasn't changed.
             //
 
             if (partitionEntry->PartitionType == PARTITION_ENTRY_UNUSED ||
@@ -4974,7 +4994,7 @@ Return Value:
         partitionEntry = &partitionList->PartitionEntry[partition];
 
         //
-        // Check if empty, or describes an extended partiton.
+        // Check if empty, or describes an extended partition.
         //
 
         if (partitionEntry->PartitionType == PARTITION_ENTRY_UNUSED ||
@@ -5213,55 +5233,3 @@ Return Value:
 
 } // end UpdateDeviceObjects()
 
-//
-// This function is supposed only to support NTFS tools
-// from M. Russinovich. This is kind of huge hack and is
-// totally undocumented :-).
-//
-NTSTATUS
-NtfsRussinovichism(PDEVICE_OBJECT DeviceObject,
-                   PIRP Irp)
-{
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
-}
-
-//
-// Hack: this function is not supposed to be implemented
-// Even though it's required to enable some M. Russinovich
-// to directly request disks so that they can dump NTFS data
-// without going through the driver.
-// We don't expect doing more from here, hence the limited
-// implementation and support.
-//
-NTSTATUS
-NTAPI
-ScsiDiskFileSystemControl(PDEVICE_OBJECT DeviceObject,
-                          PIRP Irp)
-{
-    PIO_STACK_LOCATION Stack;
-    NTSTATUS Status;
-
-    DPRINT1("ScsiDiskFileSystemControl(%p, %p)\n", DeviceObject, Irp);
-
-    Stack = IoGetCurrentIrpStackLocation(Irp);
-
-    switch (Stack->MinorFunction)
-    {
-        case IRP_MN_USER_FS_REQUEST:
-            Status = NtfsRussinovichism(DeviceObject, Irp);
-            break;
-
-        default:
-            DPRINT("MinorFunction %d\n", Stack->MinorFunction);
-            Status = STATUS_INVALID_DEVICE_REQUEST;
-            break;
-    }
-
-    Irp->IoStatus.Status = Status;
-    Irp->IoStatus.Information = 0;
-
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return Status;
-}