Improved disk driver stack.
authorEric Kohl <eric.kohl@reactos.org>
Mon, 14 Jan 2002 01:45:03 +0000 (01:45 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Mon, 14 Jan 2002 01:45:03 +0000 (01:45 +0000)
svn path=/trunk/; revision=2507

reactos/drivers/storage/atapi/atapi.c
reactos/drivers/storage/atapi/atapi.h
reactos/drivers/storage/class2/class2.c
reactos/drivers/storage/disk/disk.c
reactos/drivers/storage/include/class2.h
reactos/drivers/storage/include/ntddscsi.h
reactos/drivers/storage/include/scsi.h
reactos/drivers/storage/include/srb.h
reactos/drivers/storage/scsiport/scsiport.c
reactos/drivers/storage/scsiport/scsiport.edf

index 4b80e8a..7b633a0 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: atapi.c,v 1.2 2001/11/01 00:30:29 ekohl Exp $
+/* $Id: atapi.c,v 1.3 2002/01/14 01:43:02 ekohl Exp $
  *
  * COPYRIGHT:   See COPYING in the top level directory
  * PROJECT:     ReactOS ATAPI miniport driver
@@ -29,6 +29,7 @@
 #include <debug.h>
 
 #include "../include/srb.h"
+#include "../include/ntddscsi.h"
 
 #include "atapi.h"
 #include "partitio.h"
@@ -141,12 +142,15 @@ static int IDEPolledRead(IN WORD Address,
                          OUT BYTE *Buffer);
 static NTSTATUS STDCALL IDEDispatchOpenClose(IN PDEVICE_OBJECT pDO, IN PIRP Irp);
 static NTSTATUS STDCALL IDEDispatchReadWrite(IN PDEVICE_OBJECT pDO, IN PIRP Irp);
-static NTSTATUS STDCALL IDEDispatchDeviceControl(IN PDEVICE_OBJECT pDO, IN PIRP Irp);
 
 static NTSTATUS STDCALL
-AtapiDispatchScsi(IN PDEVICE_OBJECT pDO,
+AtapiDispatchScsi(IN PDEVICE_OBJECT DeviceObject,
                  IN PIRP Irp);
 
+static NTSTATUS STDCALL
+AtapiDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject,
+                          IN PIRP Irp);
+
 static VOID STDCALL
 IDEStartIo(IN PDEVICE_OBJECT DeviceObject,
           IN PIRP Irp);
@@ -246,7 +250,7 @@ DriverEntry(IN PDRIVER_OBJECT DriverObject,
   DriverObject->MajorFunction[IRP_MJ_CLOSE] = IDEDispatchOpenClose;
   DriverObject->MajorFunction[IRP_MJ_READ] = IDEDispatchReadWrite;
   DriverObject->MajorFunction[IRP_MJ_WRITE] = IDEDispatchReadWrite;
-  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = IDEDispatchDeviceControl;
+  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = AtapiDispatchDeviceControl;
   DriverObject->MajorFunction[IRP_MJ_SCSI] = AtapiDispatchScsi;
 
   Status = AtapiFindControllers(DriverObject);
@@ -281,11 +285,12 @@ AtapiFindControllers(IN PDRIVER_OBJECT DriverObject)
     {
       for (Slot = 0; Slot < 256; Slot++)
        {
-         Size = HalGetBusData(PCIConfiguration,
-                              Bus,
-                              Slot,
-                              &PciConfig,
-                              sizeof(PCI_COMMON_CONFIG));
+         Size = ScsiPortGetBusData(NULL,
+                                   PCIConfiguration,
+                                   Bus,
+                                   Slot,
+                                   &PciConfig,
+                                   sizeof(PCI_COMMON_CONFIG));
          if (Size != 0)
            {
              if ((PciConfig.BaseClass == 0x01) &&
@@ -446,7 +451,7 @@ AtapiFindControllers(IN PDRIVER_OBJECT DriverObject)
     }
 
   DPRINT1("AtapiFindControllers() done!\n");
-for(;;);
+//for(;;);
   return(ReturnedStatus);
 }
 
@@ -538,7 +543,7 @@ AtapiCreateController(IN PDRIVER_OBJECT DriverObject,
       return(Status);
    }
 
-  AtapiFindDrives(ControllerExtension);
+//  AtapiFindDrives(ControllerExtension);
 
   return(STATUS_SUCCESS);
 }
@@ -563,17 +568,20 @@ AtapiCreatePortDevice(IN PDRIVER_OBJECT DriverObject,
   RtlInitUnicodeString(&DeviceName,
                       NameBuffer);
 
+  DPRINT1("Creating device: %wZ\n", &DeviceName);
+
   /* Create the port device */
   Status = IoCreateDevice(DriverObject,
                          sizeof(ATAPI_PORT_EXTENSION),
                          &DeviceName,
-                         FILE_DEVICE_DISK,
+                         FILE_DEVICE_CONTROLLER,
                          0,
                          TRUE,
                          &PortDeviceObject);
   if (!NT_SUCCESS(Status))
     {
-      DbgPrint("IoCreateDevice call failed\n");
+      DPRINT1("IoCreateDevice call failed! (Status 0x%lX)\n", Status);
+//      DbgPrint("IoCreateDevice call failed\n");
       return(Status);
     }
   DPRINT1("Created device: %wZ\n", &DeviceName);
@@ -628,11 +636,11 @@ AtapiFindDrives(PIDE_CONTROLLER_EXTENSION ControllerExtension)
       /* select drive */
       IDEWriteDriveHead(ControllerExtension->CommandPortBase,
                        IDE_DH_FIXED | (DriveIndex ? IDE_DH_DRV1 : 0));
-      KeStallExecutionProcessor(500);
+      ScsiPortStallExecution(500);
       IDEWriteCylinderHigh(ControllerExtension->CommandPortBase, 0);
       IDEWriteCylinderLow(ControllerExtension->CommandPortBase, 0);
       IDEWriteCommand(ControllerExtension->CommandPortBase, 0x08); /* IDE_COMMAND_ATAPI_RESET */
-//      KeStallExecutionProcessor(1000*1000);
+//      ScsiPortStallExecution(1000*1000);
 //      IDEWriteDriveHead(ControllerExtension->CommandPortBase,
 //                     IDE_DH_FIXED | (DriveIndex ? IDE_DH_DRV1 : 0));
 //                     IDE_DH_FIXED);
@@ -643,7 +651,7 @@ AtapiFindDrives(PIDE_CONTROLLER_EXTENSION ControllerExtension)
            {
              break;
            }
-         KeStallExecutionProcessor(150);
+         ScsiPortStallExecution(150);
        }
       if (Retries >= IDE_RESET_BUSY_TIMEOUT * 1000)
        {
@@ -716,7 +724,7 @@ IDEResetController(IN WORD CommandPort,
   IDEWriteDriveControl(ControlPort, IDE_DC_SRST);
 
     //  Wait for min. 25 microseconds
-  KeStallExecutionProcessor(IDE_RESET_PULSE_LENGTH);
+  ScsiPortStallExecution(IDE_RESET_PULSE_LENGTH);
 
     //  Negate drive reset line
   IDEWriteDriveControl(ControlPort, 0);
@@ -728,7 +736,7 @@ IDEResetController(IN WORD CommandPort,
         {
           break;
         }
-      KeStallExecutionProcessor(10);
+      ScsiPortStallExecution(10);
     }
    CHECKPOINT;
   if (Retries >= IDE_RESET_BUSY_TIMEOUT * 1000)
@@ -1201,7 +1209,7 @@ IDECreateDevice(IN PDRIVER_OBJECT DriverObject,
 //    int  0 is success, non 0 is an error code
 //
 
-static int 
+static int
 IDEPolledRead(IN WORD Address,
               IN BYTE PreComp,
               IN BYTE SectorCnt,
@@ -1215,16 +1223,15 @@ IDEPolledRead(IN WORD Address,
   BYTE   Status;
   int    RetryCount;
 
-  /*  Wait for STATUS.BUSY to clear  */
+  /*  Wait for STATUS.BUSY and STATUS.DRQ to clear  */
   for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++)
     {
       Status = IDEReadStatus(Address);
       if (!(Status & IDE_SR_BUSY) && !(Status & IDE_SR_DRQ))
-//      if (!(Status & IDE_SR_BUSY))
         {
           break;
         }
-      KeStallExecutionProcessor(10);
+      ScsiPortStallExecution(10);
     }
   if (RetryCount == IDE_MAX_BUSY_RETRIES)
     {
@@ -1235,16 +1242,15 @@ IDEPolledRead(IN WORD Address,
   /*  Write Drive/Head to select drive  */
   IDEWriteDriveHead(Address, IDE_DH_FIXED | DrvHead);
 
-  /*  Wait for STATUS.BUSY to clear and STATUS.DRQ to clear  */
+  /*  Wait for STATUS.BUSY and STATUS.DRQ to clear  */
   for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++)
     {
       Status = IDEReadStatus(Address);
-//      if (!(Status & IDE_SR_BUSY) && (Status & IDE_SR_DRDY))
       if (!(Status & IDE_SR_BUSY) && !(Status & IDE_SR_DRQ))
         {
           break;
         }
-      KeStallExecutionProcessor(10);
+      ScsiPortStallExecution(10);
     }
   if (RetryCount >= IDE_MAX_BUSY_RETRIES)
     {
@@ -1283,7 +1289,7 @@ IDEPolledRead(IN WORD Address,
 
   /*  Issue the command  */
   IDEWriteCommand(Address, Command);
-  KeStallExecutionProcessor(50);
+  ScsiPortStallExecution(50);
 
   while (1)
     {
@@ -1293,18 +1299,11 @@ IDEPolledRead(IN WORD Address,
           Status = IDEReadStatus(Address);
           if (!(Status & IDE_SR_BUSY))
             {
-/*
               if (Status & IDE_SR_ERR)
                 {
-                  BYTE  Err = IDEReadError(Address);
                   CHECKPOINT1;
-                  return Err;
-                }
-              else if (Status & IDE_SR_DRQ)
-                {
-                  break;
+                  return IDE_ER_ABRT;
                 }
-*/
               if (Status & IDE_SR_DRQ)
                 {
                   break;
@@ -1315,7 +1314,7 @@ IDEPolledRead(IN WORD Address,
                   return IDE_ER_ABRT;
                 }
             }
-          KeStallExecutionProcessor(10);
+          ScsiPortStallExecution(10);
         }
       if (RetryCount >= IDE_MAX_POLL_RETRIES)
         {
@@ -1470,10 +1469,11 @@ DPRINT("AdjOffset:%ld:%ld + Length:%ld = AdjExtent:%ld:%ld\n",
   return  STATUS_PENDING;
 }
 
-//    IDEDispatchDeviceControl
+
+//    AtapiDispatchScsi
 //
 //  DESCRIPTION:
-//    Answer requests for device control calls
+//    Answer requests for SCSI calls
 //
 //  RUN LEVEL:
 //    PASSIVE_LEVEL
@@ -1485,162 +1485,25 @@ DPRINT("AdjOffset:%ld:%ld + Length:%ld = AdjExtent:%ld:%ld\n",
 //    NTSTATUS
 //
 
-static  NTSTATUS STDCALL
-IDEDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject,
-                         IN PIRP Irp)
+static NTSTATUS STDCALL
+AtapiDispatchScsi(IN PDEVICE_OBJECT DeviceObject,
+                 IN PIRP Irp)
 {
-  NTSTATUS  RC;
-  ULONG     ControlCode, InputLength, OutputLength;
-  PIO_STACK_LOCATION     IrpStack;
-  PIDE_DEVICE_EXTENSION  DeviceExtension;
-  PIDE_DEVICE_EXTENSION  DiskDeviceExtension;
-  CCHAR Increment;
-
-  RC = STATUS_SUCCESS;
-  IrpStack = IoGetCurrentIrpStackLocation(Irp);
-  ControlCode = IrpStack->Parameters.DeviceIoControl.IoControlCode;
-  InputLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
-  OutputLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
-  DeviceExtension = (PIDE_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
-  DiskDeviceExtension = (PIDE_DEVICE_EXTENSION)DeviceExtension->DiskExtension;
-  Increment = IO_NO_INCREMENT;
-
-    //  A huge switch statement in a Windows program?! who would have thought?
-  switch (ControlCode)
-    {
-    case IOCTL_DISK_GET_DRIVE_GEOMETRY:
-      if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength <
-          sizeof(DISK_GEOMETRY))
-        {
-          Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
-        }
-      else
-        {
-          PDISK_GEOMETRY Geometry;
-
-          Geometry = (PDISK_GEOMETRY) Irp->AssociatedIrp.SystemBuffer;
-
-          Geometry->MediaType = FixedMedia;
-          Geometry->Cylinders.QuadPart = DiskDeviceExtension->LogicalCylinders;
-          Geometry->TracksPerCylinder = DiskDeviceExtension->SectorsPerLogTrk /
-              DiskDeviceExtension->SectorsPerLogCyl;
-          Geometry->SectorsPerTrack = DiskDeviceExtension->SectorsPerLogTrk;
-          Geometry->BytesPerSector = DiskDeviceExtension->BytesPerSector;
-
-          Irp->IoStatus.Status = STATUS_SUCCESS;
-          Irp->IoStatus.Information = sizeof(DISK_GEOMETRY);
-        }
-      break;
-
-    case IOCTL_DISK_GET_PARTITION_INFO:
-      if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength <
-          sizeof(PARTITION_INFORMATION))
-        {
-          Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
-        }
-      else if (DeviceExtension != DiskDeviceExtension)
-        {
-          Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
-        }
-      else
-        {
-          PPARTITION_INFORMATION Buffer;
-
-          Buffer = (PPARTITION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
-          Buffer->PartitionType = DeviceExtension->PartitionInfo.PartitionType;
-          Buffer->BootIndicator = DeviceExtension->PartitionInfo.BootIndicator;
-          Buffer->PartitionNumber = DeviceExtension->PartitionInfo.PartitionNumber;
-          Buffer->StartingOffset = DeviceExtension->PartitionInfo.StartingOffset;
-          Buffer->PartitionLength = DeviceExtension->PartitionInfo.PartitionLength;
-          Buffer->HiddenSectors = DeviceExtension->PartitionInfo.HiddenSectors;
-          Buffer->RecognizedPartition = TRUE;
-          Buffer->RewritePartition = FALSE;
-
-          Irp->IoStatus.Status = STATUS_SUCCESS;
-          Irp->IoStatus.Information = sizeof(PARTITION_INFORMATION);
-        }
-
-    case IOCTL_DISK_SET_PARTITION_INFO:
-      RC = STATUS_INVALID_DEVICE_REQUEST;
-      Irp->IoStatus.Status = RC;
-      Irp->IoStatus.Information = 0;
-      break;
-
-    case IOCTL_DISK_GET_DRIVE_LAYOUT:
-      if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength <
-          sizeof(DRIVE_LAYOUT_INFORMATION))
-        {
-          Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
-        }
-      else
-        {
-          PDRIVE_LAYOUT_INFORMATION PartitionList;
-
-          RC = IoReadPartitionTable(DiskDeviceExtension->DeviceObject,
-                                    DiskDeviceExtension->BytesPerSector,
-                                    FALSE,
-                                    &PartitionList);
-          if (!NT_SUCCESS(RC))
-            {
-              Irp->IoStatus.Status = RC;
-            }
-          else
-            {
-              ULONG BufferSize;
-
-              BufferSize = FIELD_OFFSET(DRIVE_LAYOUT_INFORMATION,
-                                        PartitionEntry[0]);
-              BufferSize += PartitionList->PartitionCount * sizeof(PARTITION_INFORMATION);
-
-              if (BufferSize > IrpStack->Parameters.DeviceIoControl.OutputBufferLength)
-                {
-                  Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
-                }
-              else
-                {
-                  RtlMoveMemory(Irp->AssociatedIrp.SystemBuffer,
-                                PartitionList,
-                                BufferSize);
-                  Irp->IoStatus.Status = STATUS_SUCCESS;
-                  Irp->IoStatus.Information = BufferSize;
-                }
-              ExFreePool(PartitionList);
-            }
-        }
-        Increment = IO_DISK_INCREMENT;
-        break;
-
+  DPRINT1("AtapiDispatchScsi()\n");
 
-    case IOCTL_DISK_SET_DRIVE_LAYOUT:
-    case IOCTL_DISK_VERIFY:
-    case IOCTL_DISK_FORMAT_TRACKS:
-    case IOCTL_DISK_PERFORMANCE:
-    case IOCTL_DISK_IS_WRITABLE:
-    case IOCTL_DISK_LOGGING:
-    case IOCTL_DISK_FORMAT_TRACKS_EX:
-    case IOCTL_DISK_HISTOGRAM_STRUCTURE:
-    case IOCTL_DISK_HISTOGRAM_DATA:
-    case IOCTL_DISK_HISTOGRAM_RESET:
-    case IOCTL_DISK_REQUEST_STRUCTURE:
-    case IOCTL_DISK_REQUEST_DATA:
-
-      //  If we get here, something went wrong.  inform the requestor
-    default:
-      RC = STATUS_INVALID_DEVICE_REQUEST;
-      Irp->IoStatus.Status = RC;
-      Irp->IoStatus.Information = 0;
-      break;
-    }
+  Irp->IoStatus.Status = STATUS_SUCCESS;
+  Irp->IoStatus.Information = 0;
 
-  IoCompleteRequest(Irp, Increment);
+  IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-  return  RC;
+  return(STATUS_SUCCESS);
 }
 
-//    AtapiDispatchScsi
+
+//    AtapiDispatchDeviceControl
 //
 //  DESCRIPTION:
-//    Answer requests for Scsi calls
+//    Answer requests for device control calls
 //
 //  RUN LEVEL:
 //    PASSIVE_LEVEL
@@ -1653,18 +1516,56 @@ IDEDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject,
 //
 
 static NTSTATUS STDCALL
-AtapiDispatchScsi(IN PDEVICE_OBJECT pDO,
-                 IN PIRP Irp)
+AtapiDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject,
+                          IN PIRP Irp)
 {
-  DPRINT1("AtapiDispatchScsi()\n");
+  PIO_STACK_LOCATION Stack;
+
+  DPRINT1("AtapiDispatchDeviceControl()\n");
 
   Irp->IoStatus.Status = STATUS_SUCCESS;
-  Irp->IoStatus.Information = FILE_OPENED;
+  Irp->IoStatus.Information = 0;
+
+  Stack = IoGetCurrentIrpStackLocation(Irp);
+
+  switch (Stack->Parameters.DeviceIoControl.IoControlCode)
+    {
+      case IOCTL_SCSI_GET_CAPABILITIES:
+       {
+         PIO_SCSI_CAPABILITIES Capabilities;
+
+         DPRINT1("  IOCTL_SCSI_GET_CAPABILITIES\n");
+
+         Capabilities = (PIO_SCSI_CAPABILITIES)(*((PIO_SCSI_CAPABILITIES*)Irp->AssociatedIrp.SystemBuffer));
+         Capabilities->Length = sizeof(IO_SCSI_CAPABILITIES);
+         Capabilities->MaximumTransferLength = 65536; /* FIXME: preliminary values!!! */
+         Capabilities->MaximumPhysicalPages = 1;
+         Capabilities->SupportedAsynchronousEvents = 0;
+         Capabilities->AlignmentMask = 0;
+         Capabilities->TaggedQueuing = FALSE;
+         Capabilities->AdapterScansDown = FALSE;
+         Capabilities->AdapterUsesPio = TRUE;
+
+         Irp->IoStatus.Information = sizeof(IO_SCSI_CAPABILITIES);
+       }
+       break;
+
+      case IOCTL_SCSI_GET_INQUIRY_DATA:
+       DPRINT1("  IOCTL_SCSI_GET_INQUIRY_DATA\n");
+       break;
+
+      default:
+       DPRINT1("  unknown ioctl code: 0x%lX\n",
+               Stack->Parameters.DeviceIoControl.IoControlCode);
+       break;
+    }
+
   IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-  return STATUS_SUCCESS;
+  return(STATUS_SUCCESS);
 }
 
+
 //    IDEStartIo
 //
 //  DESCRIPTION:
@@ -1837,7 +1738,7 @@ IDEStartController(IN OUT PVOID Context)
         {
           break;
         }
-      KeStallExecutionProcessor(10);
+      ScsiPortStallExecution(10);
     }
   DPRINT ("status=%02x\n", Status);
   DPRINT ("waited %ld usecs for busy to clear\n", Retries * 10);
@@ -1873,7 +1774,7 @@ IDEStartController(IN OUT PVOID Context)
         {
           break;
         }
-      KeStallExecutionProcessor(10);
+      ScsiPortStallExecution(10);
     }
   DPRINT ("waited %ld usecs for busy to clear after drive select\n", Retries * 10);
   if (Retries >= IDE_MAX_BUSY_RETRIES)
@@ -1921,7 +1822,7 @@ IDEStartController(IN OUT PVOID Context)
             {
               break;
             }
-          KeStallExecutionProcessor(10);
+          ScsiPortStallExecution(10);
         }
       if (Retries >= IDE_MAX_BUSY_RETRIES)
         {
@@ -1977,7 +1878,7 @@ IDEBeginControllerReset(PIDE_CONTROLLER_EXTENSION ControllerExtension)
         {
           break;
         }
-      KeStallExecutionProcessor(10);
+      ScsiPortStallExecution(10);
     }
   if (Retries == IDE_MAX_RESET_RETRIES)
     {
@@ -2105,7 +2006,7 @@ IDEIsr(IN PKINTERRUPT Interrupt,
               !(IDEReadStatus(ControllerExtension->CommandPortBase) & IDE_SR_DRQ);
               Retries++) 
             {
-              KeStallExecutionProcessor(10);
+              ScsiPortStallExecution(10);
             }
 
             //  Copy the block of data
@@ -2120,7 +2021,7 @@ IDEIsr(IN PKINTERRUPT Interrupt,
                   (IDEReadStatus(ControllerExtension->CommandPortBase) & IDE_SR_BUSY);
                   Retries++) 
                 {
-                  KeStallExecutionProcessor(10);
+                  ScsiPortStallExecution(10);
                 }
 
                 //  Check for data overrun
@@ -2167,7 +2068,7 @@ IDEIsr(IN PKINTERRUPT Interrupt,
                   (IDEReadStatus(ControllerExtension->CommandPortBase) & IDE_SR_BUSY);
                    Retries++) 
                 {
-                  KeStallExecutionProcessor(10);
+                  ScsiPortStallExecution(10);
                 }
 
                 //  Check for data overrun
@@ -2415,4 +2316,4 @@ IDEIoTimer(PDEVICE_OBJECT DeviceObject,
     }
 }
 
-
+/* EOF */
index 817ceb8..cb93059 100644 (file)
@@ -72,49 +72,49 @@ extern "C" {
 //  Each macro takes an address of the command port block, and data
 //
 #define IDEReadError(Address) \
-  (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_ERROR)))
+  (ScsiPortReadPortUchar((PUCHAR)((Address) + IDE_REG_ERROR)))
 #define IDEWritePrecomp(Address, Data) \
-  (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_PRECOMP), (Data)))
+  (ScsiPortWritePortUchar((PUCHAR)((Address) + IDE_REG_PRECOMP), (Data)))
 #define IDEReadSectorCount(Address) \
-  (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_CNT)))
+  (ScsiPortReadPortUchar((PUCHAR)((Address) + IDE_REG_SECTOR_CNT)))
 #define IDEWriteSectorCount(Address, Data) \
-  (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_CNT), (Data)))
+  (ScsiPortWritePortUchar((PUCHAR)((Address) + IDE_REG_SECTOR_CNT), (Data)))
 #define IDEReadSectorNum(Address) \
-  (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_NUM)))
+  (ScsiPortReadPortUchar((PUCHAR)((Address) + IDE_REG_SECTOR_NUM)))
 #define IDEWriteSectorNum(Address, Data) \
-  (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_NUM), (Data)))
+  (ScsiPortWritePortUchar((PUCHAR)((Address) + IDE_REG_SECTOR_NUM), (Data)))
 #define IDEReadCylinderLow(Address) \
-  (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_LOW)))
+  (ScsiPortReadPortUchar((PUCHAR)((Address) + IDE_REG_CYL_LOW)))
 #define IDEWriteCylinderLow(Address, Data) \
-  (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_LOW), (Data)))
+  (ScsiPortWritePortUchar((PUCHAR)((Address) + IDE_REG_CYL_LOW), (Data)))
 #define IDEReadCylinderHigh(Address) \
-  (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_HIGH)))
+  (ScsiPortReadPortUchar((PUCHAR)((Address) + IDE_REG_CYL_HIGH)))
 #define IDEWriteCylinderHigh(Address, Data) \
-  (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_HIGH), (Data)))
+  (ScsiPortWritePortUchar((PUCHAR)((Address) + IDE_REG_CYL_HIGH), (Data)))
 #define IDEReadDriveHead(Address) \
-  (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DRV_HEAD)))
+  (ScsiPortReadPortUchar((PUCHAR)((Address) + IDE_REG_DRV_HEAD)))
 #define IDEWriteDriveHead(Address, Data) \
-  (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DRV_HEAD), (Data)))
+  (ScsiPortWritePortUchar((PUCHAR)((Address) + IDE_REG_DRV_HEAD), (Data)))
 #define IDEReadStatus(Address) \
-  (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_STATUS)))
+  (ScsiPortReadPortUchar((PUCHAR)((Address) + IDE_REG_STATUS)))
 #define IDEWriteCommand(Address, Data) \
-  (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_COMMAND), (Data)))
+  (ScsiPortWritePortUchar((PUCHAR)((Address) + IDE_REG_COMMAND), (Data)))
 
 
 //
 //  Data block read and write commands
 //
 #define IDEReadBlock(Address, Buffer, Count) \
-  (READ_PORT_BUFFER_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2))
+  (ScsiPortReadPortBufferUshort((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2))
 #define IDEWriteBlock(Address, Buffer, Count) \
-  (WRITE_PORT_BUFFER_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2))
+  (ScsiPortWritePortBufferUshort((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2))
 
 //
 //  Access macros for control registers
 //  Each macro takes an address of the control port blank and data
 //
 #define IDEWriteDriveControl(Address, Data) \
-  (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DEV_CNTRL), (Data)))
+  (ScsiPortWritePortUchar((PUCHAR)((Address) + IDE_REG_DEV_CNTRL), (Data)))
 
 //    IDE_DEVICE_EXTENSION
 //
index 49d2179..be78744 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: class2.c,v 1.1 2001/07/23 06:12:07 ekohl Exp $
+/* $Id: class2.c,v 1.2 2002/01/14 01:43:26 ekohl Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
 #include "../include/scsi.h"
 #include "../include/class2.h"
 
+//#define NDEBUG
+#include <debug.h>
 
-#define UNIMPLEMENTED do {DbgPrint("%s:%d: Function not implemented", __FILE__, __LINE__); for(;;);} while (0)
+//#define UNIMPLEMENTED do {DbgPrint("%s:%d: Function not implemented", __FILE__, __LINE__); for(;;);} while (0)
 
 #define VERSION "0.0.1"
 
+#define INQUIRY_DATA_SIZE 2048
+
+
+static NTSTATUS STDCALL
+ScsiClassCreateClose(IN PDEVICE_OBJECT DeviceObject,
+                    IN PIRP Irp);
+
+static NTSTATUS STDCALL
+ScsiClassReadWrite(IN PDEVICE_OBJECT DeviceObject,
+                  IN PIRP Irp);
+
+static NTSTATUS STDCALL
+ScsiClassScsiDispatch(IN PDEVICE_OBJECT DeviceObject,
+                    IN PIRP Irp);
+
+static NTSTATUS STDCALL
+ScsiClassDeviceDispatch(IN PDEVICE_OBJECT DeviceObject,
+                      IN PIRP Irp);
+
+static NTSTATUS STDCALL
+ScsiClassShutdownFlush(IN PDEVICE_OBJECT DeviceObject,
+                      IN PIRP Irp);
+
 //  -------------------------------------------------------  Public Interface
 
 //    DriverEntry
@@ -39,7 +64,7 @@ NTSTATUS STDCALL
 DriverEntry(IN PDRIVER_OBJECT DriverObject,
            IN PUNICODE_STRING RegistryPath)
 {
-  DbgPrint("ScsiPort Driver %s\n", VERSION);
+  DbgPrint("Class Driver %s\n", VERSION);
   return(STATUS_SUCCESS);
 }
 
@@ -66,9 +91,9 @@ ScsiClassDebugPrint(IN ULONG DebugPrintLevel,
 
 
 NTSTATUS STDCALL
-ScsiClassAsynchronousCompletion(PDEVICE_OBJECT DeviceObject,
-                               PIRP Irp,
-                               PVOID Context)
+ScsiClassAsynchronousCompletion(IN PDEVICE_OBJECT DeviceObject,
+                               IN PIRP Irp,
+                               IN PVOID Context)
 {
   UNIMPLEMENTED;
 }
@@ -125,7 +150,8 @@ ULONG STDCALL
 ScsiClassFindUnclaimedDevices(PCLASS_INIT_DATA InitializationData,
                              PSCSI_ADAPTER_BUS_INFO AdapterInformation)
 {
-  UNIMPLEMENTED;
+  DPRINT("ScsiClassFindUnclaimedDevices() called!\n");
+  return(0);
 }
 
 
@@ -133,7 +159,42 @@ NTSTATUS STDCALL
 ScsiClassGetCapabilities(PDEVICE_OBJECT PortDeviceObject,
                         PIO_SCSI_CAPABILITIES *PortCapabilities)
 {
-  UNIMPLEMENTED;
+  IO_STATUS_BLOCK IoStatusBlock;
+  NTSTATUS Status;
+  KEVENT Event;
+  PIRP Irp;
+
+  KeInitializeEvent(&Event,
+                   NotificationEvent,
+                   FALSE);
+
+  Irp = IoBuildDeviceIoControlRequest(IOCTL_SCSI_GET_CAPABILITIES,
+                                     PortDeviceObject,
+                                     NULL,
+                                     0,
+                                     PortCapabilities,
+                                     sizeof(PVOID),
+                                     FALSE,
+                                     &Event,
+                                     &IoStatusBlock);
+  if (Irp == NULL)
+    {
+      return(STATUS_INSUFFICIENT_RESOURCES);
+    }
+
+  Status = IoCallDriver(PortDeviceObject,
+                       Irp);
+  if (Status == STATUS_PENDING)
+    {
+      KeWaitForSingleObject(&Event,
+                           Suspended,
+                           KernelMode,
+                           FALSE,
+                           NULL);
+      return(IoStatusBlock.Status);
+    }
+
+  return(Status);
 }
 
 
@@ -141,7 +202,58 @@ NTSTATUS STDCALL
 ScsiClassGetInquiryData(PDEVICE_OBJECT PortDeviceObject,
                        PSCSI_ADAPTER_BUS_INFO *ConfigInfo)
 {
-  UNIMPLEMENTED;
+  PSCSI_ADAPTER_BUS_INFO Buffer;
+  IO_STATUS_BLOCK IoStatusBlock;
+  NTSTATUS Status;
+  KEVENT Event;
+  PIRP Irp;
+
+  Buffer = ExAllocatePool(NonPagedPool, /* FIXME: use paged pool */
+                         INQUIRY_DATA_SIZE);
+  *ConfigInfo = Buffer;
+
+  if (Buffer == NULL)
+    {
+      return(STATUS_INSUFFICIENT_RESOURCES);
+    }
+
+  KeInitializeEvent(&Event,
+                   NotificationEvent,
+                   FALSE);
+
+  Irp = IoBuildDeviceIoControlRequest(IOCTL_SCSI_GET_INQUIRY_DATA,
+                                     PortDeviceObject,
+                                     NULL,
+                                     0,
+                                     Buffer,
+                                     INQUIRY_DATA_SIZE,
+                                     FALSE,
+                                     &Event,
+                                     &IoStatusBlock);
+  if (Irp == NULL)
+    {
+      return(STATUS_INSUFFICIENT_RESOURCES);
+    }
+
+  Status = IoCallDriver(PortDeviceObject,
+                       Irp);
+  if (Status == STATUS_PENDING)
+    {
+      KeWaitForSingleObject(&Event,
+                           Suspended,
+                           KernelMode,
+                           FALSE,
+                           NULL);
+      Status = IoStatusBlock.Status;
+    }
+
+  if (!NT_SUCCESS(Status))
+    {
+      ExFreePool(Buffer);
+      *ConfigInfo = NULL;
+    }
+
+  return(Status);
 }
 
 
@@ -150,7 +262,66 @@ ScsiClassInitialize(PVOID Argument1,
                    PVOID Argument2,
                    PCLASS_INIT_DATA InitializationData)
 {
-  UNIMPLEMENTED;
+  PDRIVER_OBJECT DriverObject = Argument1;
+  WCHAR NameBuffer[80];
+  UNICODE_STRING PortName;
+  ULONG PortNumber = 0;
+  PDEVICE_OBJECT PortDeviceObject;
+  PFILE_OBJECT FileObject;
+  BOOLEAN DiskFound = FALSE;
+  NTSTATUS Status;
+
+  DriverObject->MajorFunction[IRP_MJ_CREATE] = ScsiClassCreateClose;
+  DriverObject->MajorFunction[IRP_MJ_CLOSE] = ScsiClassCreateClose;
+  DriverObject->MajorFunction[IRP_MJ_READ] = ScsiClassReadWrite;
+  DriverObject->MajorFunction[IRP_MJ_WRITE] = ScsiClassReadWrite;
+  DriverObject->MajorFunction[IRP_MJ_SCSI] = ScsiClassScsiDispatch;
+  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = ScsiClassDeviceDispatch;
+  DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = ScsiClassShutdownFlush;
+  DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = ScsiClassShutdownFlush;
+  if (InitializationData->ClassStartIo)
+    {
+      DriverObject->DriverStartIo = InitializationData->ClassStartIo;
+    }
+
+  /* look for ScsiPortX scsi port devices */
+  do
+    {
+      swprintf(NameBuffer,
+              L"\\Device\\ScsiPort%lu",
+               PortNumber);
+      RtlInitUnicodeString(&PortName,
+                          NameBuffer);
+      DPRINT1("Checking scsi port %ld\n", PortNumber);
+      Status = IoGetDeviceObjectPointer(&PortName,
+                                       FILE_READ_ATTRIBUTES,
+                                       &FileObject,
+                                       &PortDeviceObject);
+      DPRINT1("Status 0x%08lX\n", Status);
+      if (NT_SUCCESS(Status))
+       {
+         DPRINT1("ScsiPort%lu found.\n", PortNumber);
+
+         /* Check scsi port for attached disk drives */
+         if (InitializationData->ClassFindDevices(DriverObject,
+                                                  Argument2,
+                                                  InitializationData,
+                                                  PortDeviceObject,
+                                                  PortNumber))
+           {
+             DiskFound = TRUE;
+           }
+
+         ObDereferenceObject(PortDeviceObject);
+         ObDereferenceObject(FileObject);
+       }
+       PortNumber++;
+    }
+  while (NT_SUCCESS(Status));
+
+for(;;);
+
+  return((DiskFound == TRUE) ? STATUS_SUCCESS : STATUS_NO_SUCH_DEVICE);
 }
 
 
@@ -211,21 +382,21 @@ ScsiClassModeSense(PDEVICE_OBJECT DeviceObject,
 
 
 ULONG STDCALL
-ScsiClassQueryTimeOutRegistryValue(PUNICODE_STRING RegistryPath)
+ScsiClassQueryTimeOutRegistryValue(IN PUNICODE_STRING RegistryPath)
 {
   UNIMPLEMENTED;
 }
 
 
 NTSTATUS STDCALL
-ScsiClassReadDriveCapacity(PDEVICE_OBJECT DeviceObject)
+ScsiClassReadDriveCapacity(IN PDEVICE_OBJECT DeviceObject)
 {
   UNIMPLEMENTED;
 }
 
 
 VOID STDCALL
-ScsiClassReleaseQueue(PDEVICE_OBJECT DeviceObject)
+ScsiClassReleaseQueue(IN PDEVICE_OBJECT DeviceObject)
 {
   UNIMPLEMENTED;
 }
@@ -262,4 +433,65 @@ ScsiClassSplitRequest(PDEVICE_OBJECT DeviceObject,
   UNIMPLEMENTED;
 }
 
+
+/* Internal Routines **************/
+
+static NTSTATUS STDCALL
+ScsiClassCreateClose(IN PDEVICE_OBJECT DeviceObject,
+                    IN PIRP Irp)
+{
+  Irp->IoStatus.Status = STATUS_SUCCESS;
+  Irp->IoStatus.Information = 0;
+  IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+  return(STATUS_SUCCESS);
+}
+
+static NTSTATUS STDCALL
+ScsiClassReadWrite(IN PDEVICE_OBJECT DeviceObject,
+                  IN PIRP Irp)
+{
+  Irp->IoStatus.Status = STATUS_SUCCESS;
+  Irp->IoStatus.Information = 0;
+  IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+  return(STATUS_SUCCESS);
+}
+
+
+static NTSTATUS STDCALL
+ScsiClassScsiDispatch(IN PDEVICE_OBJECT DeviceObject,
+                     IN PIRP Irp)
+{
+  Irp->IoStatus.Status = STATUS_SUCCESS;
+  Irp->IoStatus.Information = 0;
+  IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+  return(STATUS_SUCCESS);
+}
+
+
+static NTSTATUS STDCALL
+ScsiClassDeviceDispatch(IN PDEVICE_OBJECT DeviceObject,
+                       IN PIRP Irp)
+{
+  Irp->IoStatus.Status = STATUS_SUCCESS;
+  Irp->IoStatus.Information = 0;
+  IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+  return(STATUS_SUCCESS);
+}
+
+
+static NTSTATUS STDCALL
+ScsiClassShutdownFlush(IN PDEVICE_OBJECT DeviceObject,
+                      IN PIRP Irp)
+{
+  Irp->IoStatus.Status = STATUS_SUCCESS;
+  Irp->IoStatus.Information = 0;
+  IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+  return(STATUS_SUCCESS);
+}
+
 /* EOF */
index a2b6bbf..cb2e316 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: disk.c,v 1.1 2001/07/24 10:21:15 ekohl Exp $
+/* $Id: disk.c,v 1.2 2002/01/14 01:44:03 ekohl Exp $
  *
  */
 
@@ -6,82 +6,37 @@
 
 #include <ddk/ntddk.h>
 
+#include "../include/scsi.h"
+#include "../include/class2.h"
+#include "../include/ntddscsi.h"
+
 //#define NDEBUG
 #include <debug.h>
 
-//#include "ide.h"
-//#include "partitio.h"
-
 #define VERSION "V0.0.1"
 
 
-static NTSTATUS DiskCreateDevices(VOID);
-static BOOLEAN DiskFindDiskDrives(PDEVICE_OBJECT PortDeviceObject, ULONG PortNumber);
+//static NTSTATUS
+//DiskCreateDevices(VOID);
 
 
-/*
- *  DiskOpenClose
- *
- *  DESCRIPTION:
- *    Answer requests for Open/Close calls: a null operation
- *
- *  RUN LEVEL:
- *    PASSIVE_LEVEL
- *
- *  ARGUMENTS:
- *    Standard dispatch arguments
- *
- *  RETURNS:
- *    NTSTATUS
-*/
-#if 0
-static NTSTATUS STDCALL
-DiskOpenClose(IN PDEVICE_OBJECT pDO,
-             IN PIRP Irp)
-{
-   Irp->IoStatus.Status = STATUS_SUCCESS;
-   Irp->IoStatus.Information = FILE_OPENED;
-   IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-   return STATUS_SUCCESS;
-}
-#endif
+BOOLEAN STDCALL
+DiskClassFindDevices(PDRIVER_OBJECT DriverObject,
+                    PUNICODE_STRING RegistryPath,
+                    PCLASS_INIT_DATA InitializationData,
+                    PDEVICE_OBJECT PortDeviceObject,
+                    ULONG PortNumber);
 
 
-static NTSTATUS STDCALL
-DiskClassReadWrite(IN PDEVICE_OBJECT pDO,
-                  IN PIRP Irp)
-{
-   Irp->IoStatus.Status = STATUS_SUCCESS;
-   Irp->IoStatus.Information = 0;
-   IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-   return STATUS_SUCCESS;
-}
-
-
-static NTSTATUS STDCALL
-DiskClassDeviceControl(IN PDEVICE_OBJECT pDO,
-                      IN PIRP Irp)
-{
-   Irp->IoStatus.Status = STATUS_SUCCESS;
-   Irp->IoStatus.Information = 0;
-   IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-   return STATUS_SUCCESS;
-}
+NTSTATUS STDCALL
+DiskClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
+                      IN PIRP Irp);
 
+NTSTATUS STDCALL
+DiskClassShutdownFlush(IN PDEVICE_OBJECT DeviceObject,
+                      IN PIRP Irp);
 
-static NTSTATUS STDCALL
-DiskClassShutdownFlush(IN PDEVICE_OBJECT pDO,
-                      IN PIRP Irp)
-{
-   Irp->IoStatus.Status = STATUS_SUCCESS;
-   Irp->IoStatus.Information = 0;
-   IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-   return STATUS_SUCCESS;
-}
 
 
 //    DriverEntry
@@ -107,84 +62,112 @@ NTSTATUS STDCALL
 DriverEntry(IN PDRIVER_OBJECT DriverObject,
            IN PUNICODE_STRING RegistryPath)
 {
-   NTSTATUS Status;
+  CLASS_INIT_DATA InitData;
+
+  DbgPrint("Disk Class Driver %s\n", VERSION);
+
+  InitData.InitializationDataSize = sizeof(CLASS_INIT_DATA);
+  InitData.DeviceExtensionSize = sizeof(DEVICE_EXTENSION);     // + sizeof(DISK_DATA)
+  InitData.DeviceType = FILE_DEVICE_DISK;
+  InitData.DeviceCharacteristics = 0;
+
+  InitData.ClassError = NULL;                          // DiskClassProcessError;
+  InitData.ClassReadWriteVerification = NULL;          // DiskClassReadWriteVerification;
+  InitData.ClassFindDeviceCallBack = NULL;             // DiskClassDeviceVerification;
+  InitData.ClassFindDevices = DiskClassFindDevices;
+  InitData.ClassDeviceControl = DiskClassDeviceControl;
+  InitData.ClassShutdownFlush = DiskClassShutdownFlush;
+  InitData.ClassCreateClose = NULL;
+  InitData.ClassStartIo = NULL;
+
+  return(ScsiClassInitialize(DriverObject,
+                            RegistryPath,
+                            &InitData));
+}
 
-   DbgPrint("Disk Class Driver %s\n", VERSION);
 
-   /* Export other driver entry points... */
-//   DriverObject->DriverStartIo = IDEStartIo;
-//   DriverObject->MajorFunction[IRP_MJ_CREATE] = DiskClassOpenClose;
-//   DriverObject->MajorFunction[IRP_MJ_CLOSE] = DiskClassOpenClose;
-   DriverObject->MajorFunction[IRP_MJ_READ] = DiskClassReadWrite;
-   DriverObject->MajorFunction[IRP_MJ_WRITE] = DiskClassReadWrite;
-   DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DiskClassDeviceControl;
-   DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = DiskClassShutdownFlush;
-   DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = DiskClassShutdownFlush;
+//    DiskClassFindDevices
+//
+//  DESCRIPTION:
+//    This function searches for device that are attached to the given scsi port.
+//
+//  RUN LEVEL:
+//    PASSIVE_LEVEL
+//
+//  ARGUMENTS:
+//    IN  PDRIVER_OBJECT   DriverObject        System allocated Driver Object for this driver
+//    IN  PUNICODE_STRING  RegistryPath        Name of registry driver service key
+//    IN  PCLASS_INIT_DATA InitializationData  Pointer to the main initialization data
+//    IN PDEVICE_OBJECT    PortDeviceObject    Scsi port device object
+//    IN ULONG             PortNumber          Port number
+//
+//  RETURNS:
+//    TRUE: At least one disk drive was found
+//    FALSE: No disk drive found
+//
 
-   Status = DiskCreateDevices();
-   DPRINT("Status 0x%08X\n", Status);
+BOOLEAN STDCALL
+DiskClassFindDevices(PDRIVER_OBJECT DriverObject,
+                    PUNICODE_STRING RegistryPath,
+                    PCLASS_INIT_DATA InitializationData,
+                    PDEVICE_OBJECT PortDeviceObject,
+                    ULONG PortNumber)
+{
+  PIO_SCSI_CAPABILITIES PortCapabilities = NULL;
+  PSCSI_ADAPTER_BUS_INFO AdapterBusInfo;
+  PCHAR Buffer;
+  ULONG DeviceCount;
+  NTSTATUS Status;
+//  PCONFIGURATION_INFORMATION ConfigInfo;
+
+  DPRINT1("DiskClassFindDevices() called.\n");
+
+  /* Get port capabilities */
+  Status = ScsiClassGetCapabilities(PortDeviceObject,
+                                   &PortCapabilities);
+  if (!NT_SUCCESS(Status))
+    {
+      DPRINT("ScsiClassGetCapabilities() failed! (Status 0x%lX)\n", Status);
+      return(FALSE);
+    }
 
-   DPRINT("Returning from DriverEntry\n");
-   return STATUS_SUCCESS;
-}
+//  DPRINT1("MaximumTransferLength: %lu\n", Capabilities.MaximumTransferLength);
 
+  /* Get inquiry data */
+  Status = ScsiClassGetInquiryData(PortDeviceObject,
+                                  (PSCSI_ADAPTER_BUS_INFO *)&Buffer);
+  if (!NT_SUCCESS(Status))
+    {
+      DPRINT("ScsiClassGetInquiryData() failed! (Status 0x%lX)\n", Status);
+      return(FALSE);
+    }
 
+  /* Get number of unclaimed devices */
+  AdapterBusInfo = (PSCSI_ADAPTER_BUS_INFO)Buffer;
+  DeviceCount = ScsiClassFindUnclaimedDevices(InitializationData,
+                                             AdapterBusInfo);
+  if (DeviceCount == 0)
+    {
+      DPRINT("ScsiClassFindUnclaimedDevices() returned 0!");
+      return(FALSE);
+    }
+
+//  ConfigInfo = IoGetConfigurationInformation();
+//  DPRINT1("Number of SCSI ports: %lu\n", ConfigInfo->ScsiPortCount);
 
-static NTSTATUS
-DiskCreateDevices(VOID)
-{
-   WCHAR NameBuffer[80];
-   UNICODE_STRING PortName;
-   ULONG PortNumber = 0;
-   PDEVICE_OBJECT PortDeviceObject;
-   PFILE_OBJECT FileObject;
-   BOOLEAN DiskFound = FALSE;
-   NTSTATUS Status;
-   
-   DPRINT1("DiskCreateDevices() called.\n");
-   
-   /* look for ScsiPortX scsi port devices */
-   do
-     {
-       swprintf(NameBuffer,
-                L"\\Device\\ScsiPort%ld",
-                PortNumber);
-       RtlInitUnicodeString(&PortName,
-                            NameBuffer);
-       DPRINT1("Checking scsi port %ld\n", PortNumber);
-       Status = IoGetDeviceObjectPointer(&PortName,
-                                         FILE_READ_ATTRIBUTES,
-                                         &FileObject,
-                                         &PortDeviceObject);
-       DPRINT1("Status 0x%08lX\n", Status);
-       if (NT_SUCCESS(Status))
-         {
-            DPRINT1("ScsiPort%ld found.\n", PortNumber);
-
-            /* Check scsi port for attached disk drives */
-            DiskFound = DiskFindDiskDrives(PortDeviceObject, PortNumber);
-         }
-       PortNumber++;
-     }
-   while (NT_SUCCESS(Status));
-
-   return(STATUS_SUCCESS);
-}
 
 
-static BOOLEAN
-DiskFindDiskDrives(PDEVICE_OBJECT PortDeviceObject,
-                  ULONG PortNumber)
-{
-   DPRINT1("DiskFindDiskDevices() called.\n");
 
-   return TRUE;
+  ExFreePool(Buffer);
+
+  return(TRUE);
 }
 
+
 //    IDECreateDevice
 //
 //  DESCRIPTION:
-//    Creates a device by calling IoCreateDevice and a sylbolic link for Win32
+//    Creates a device by calling IoCreateDevice and a symbolic link for Win32
 //
 //  RUN LEVEL:
 //    PASSIVE_LEVEL
@@ -306,7 +289,7 @@ IDECreateDevice(IN PDRIVER_OBJECT DriverObject,
 
 
 
-//    IDEDispatchDeviceControl
+//    DiskClassDeviceControl
 //
 //  DESCRIPTION:
 //    Answer requests for device control calls
@@ -320,11 +303,14 @@ IDECreateDevice(IN PDRIVER_OBJECT DriverObject,
 //  RETURNS:
 //    NTSTATUS
 //
-#if 0
-static  NTSTATUS  STDCALL
-IDEDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject,
-                         IN PIRP Irp) 
+
+NTSTATUS STDCALL
+DiskClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
+                      IN PIRP Irp)
 {
+  DPRINT("DiskClassDeviceControl() called!\n");
+
+#if 0
   NTSTATUS  RC;
   ULONG     ControlCode, InputLength, OutputLength;
   PIO_STACK_LOCATION     IrpStack;
@@ -391,8 +377,43 @@ IDEDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject,
   IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
   return  RC;
-}
 #endif
 
+  Irp->IoStatus.Status = STATUS_SUCCESS;
+  Irp->IoStatus.Information = 0;
+  IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+  return(STATUS_SUCCESS);
+}
+
+
+//    DiskClassShutdownFlush
+//
+//  DESCRIPTION:
+//    Answer requests for shutdown and flush calls
+//
+//  RUN LEVEL:
+//    PASSIVE_LEVEL
+//
+//  ARGUMENTS:
+//    Standard dispatch arguments
+//
+//  RETURNS:
+//    NTSTATUS
+//
+
+NTSTATUS STDCALL
+DiskClassShutdownFlush(IN PDEVICE_OBJECT DeviceObject,
+                      IN PIRP Irp)
+{
+  DPRINT("DiskClassShutdownFlush() called!\n");
+
+  Irp->IoStatus.Status = STATUS_SUCCESS;
+  Irp->IoStatus.Information = 0;
+  IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+  return(STATUS_SUCCESS);
+}
+
 
 /* EOF */
index 8059991..86377a6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: class2.h,v 1.1 2001/07/23 06:12:34 ekohl Exp $
+/* $Id: class2.h,v 1.2 2002/01/14 01:44:18 ekohl Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -67,53 +67,89 @@ typedef struct _CLASS_INIT_DATA
 
 typedef struct _DEVICE_EXTENSION
 {
-  ULONG Dummy;
+  PDEVICE_OBJECT DeviceObject;
+  PDEVICE_OBJECT PortDeviceObject;
+  LARGE_INTEGER PartitionLength;
+  LARGE_INTEGER StartingOffset;
+  ULONG DMByteSkew;
+  ULONG DMSkew;
+  BOOLEAN DMActive;
+  PCLASS_ERROR ClassError;
+  PCLASS_READ_WRITE ClassReadWriteVerification;
+  PCLASS_FIND_DEVICES ClassFindDevices;
+  PCLASS_DEVICE_CONTROL ClassDeviceControl;
+  PCLASS_SHUTDOWN_FLUSH ClassShutdownFlush;
+  PCLASS_CREATE_CLOSE ClassCreateClose;
+  PDRIVER_STARTIO ClassStartIo;
+  PIO_SCSI_CAPABILITIES PortCapabilities;
+  PDISK_GEOMETRY DiskGeometry;
+  PDEVICE_OBJECT PhysicalDevice;
+  PSENSE_DATA SenseData;
+  ULONG TimeOutValue;
+  ULONG DeviceNumber;
+  ULONG SrbFlags;
+  ULONG ErrorCount;
+  KSPIN_LOCK SplitRequestSpinLock;
+  NPAGED_LOOKASIDE_LIST SrbLookasideListHead;
+  LONG LockCount;
+  UCHAR PortNumber;
+  UCHAR PathId;
+  UCHAR TargetId;
+  UCHAR Lun;
+  UCHAR SectorShift;
+  UCHAR ReservedByte;
+  USHORT DeviceFlags;
+  PKEVENT MediaChangeEvent;
+  HANDLE MediaChangeEventHandle;
+  BOOLEAN MediaChangeNoMedia;
+  ULONG MediaChangeCount;
 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
 
 
 /* FUNCTIONS ****************************************************************/
 
-NTSTATUS
-STDCALL
-ScsiClassAsynchronousCompletion (
-       IN      PDEVICE_OBJECT  DeviceObject,
-       IN      PIRP            Irp,
-       PVOID           Context
-       );
-
-VOID
-STDCALL
-ScsiClassBuildRequest (
-       IN      PDEVICE_OBJECT  DeviceObject,
-       IN      PIRP            Irp
-       );
-
-NTSTATUS
-STDCALL
-ScsiClassClaimDevice (
-       IN      PDEVICE_OBJECT          PortDeviceObject,
-       IN      PSCSI_INQUIRY_DATA      LunInfo,
-       IN      BOOLEAN                 Release,
-       OUT     PDEVICE_OBJECT          *NewPortDeviceObject OPTIONAL
-       );
-
-NTSTATUS
-STDCALL
-ScsiClassCreateDeviceObject (
-       IN      PDRIVER_OBJECT          DriverObject,
-       IN      PCCHAR                  ObjectNameBuffer,
-       IN      PDEVICE_OBJECT          PhysicalDeviceObject OPTIONAL,
-       IN OUT  PDEVICE_OBJECT          *DeviceObject,
-       IN      PCLASS_INIT_DATA        InitializationData
-       );
-
-NTSTATUS
-STDCALL
-ScsiClassDeviceControl (
-       PDEVICE_OBJECT DeviceObject,
-       PIRP Irp
-       );
+NTSTATUS STDCALL
+ScsiClassAsynchronousCompletion(IN PDEVICE_OBJECT DeviceObject,
+                               IN PIRP Irp,
+                               IN PVOID Context);
+
+VOID STDCALL
+ScsiClassBuildRequest(IN PDEVICE_OBJECT DeviceObject,
+                     IN PIRP Irp);
+
+NTSTATUS STDCALL
+ScsiClassClaimDevice(IN PDEVICE_OBJECT PortDeviceObject,
+                    IN PSCSI_INQUIRY_DATA LunInfo,
+                    IN BOOLEAN Release,
+                    OUT PDEVICE_OBJECT *NewPortDeviceObject OPTIONAL);
+
+NTSTATUS STDCALL
+ScsiClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
+                           IN PCCHAR ObjectNameBuffer,
+                           IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
+                           IN OUT PDEVICE_OBJECT *DeviceObject,
+                           IN PCLASS_INIT_DATA InitializationData);
+
+NTSTATUS STDCALL
+ScsiClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
+                      IN PIRP Irp);
+
+ULONG STDCALL
+ScsiClassFindUnclaimedDevices(IN PCLASS_INIT_DATA InitializationData,
+                             OUT PSCSI_ADAPTER_BUS_INFO AdapterInformation);
+
+NTSTATUS STDCALL
+ScsiClassGetCapabilities(IN PDEVICE_OBJECT PortDeviceObject,
+                        OUT PIO_SCSI_CAPABILITIES *PortCapabilities);
+
+NTSTATUS STDCALL
+ScsiClassGetInquiryData(IN PDEVICE_OBJECT PortDeviceObject,
+                       OUT PSCSI_ADAPTER_BUS_INFO *ConfigInfo);
 
+ULONG STDCALL
+ScsiClassInitialize(IN PVOID Argument1,
+                   IN PVOID Argument2,
+                   IN PCLASS_INIT_DATA InitializationData);
 
 
 
index 838ed51..9291062 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: ntddscsi.h,v 1.1 2001/07/23 06:12:34 ekohl Exp $
+/* $Id: ntddscsi.h,v 1.2 2002/01/14 01:44:18 ekohl Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
 #define __STORAGE_INCLUDE_NTDDSCSI_H
 
 
-typedef struct _SCSI_BUS_DATA
-{
-  UCHAR NumberOfLogicalUnits;
-  UCHAR InitiatorBusId;
-  ULONG InquiryDataOffset;
-}SCSI_BUS_DATA, *PSCSI_BUS_DATA;
+/* IOCTL codes */
 
+#define IOCTL_SCSI_PASS_THROUGH \
+       CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
+#define IOCTL_SCSI_MINIPORT \
+       CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
+#define IOCTL_SCSI_GET_INQUIRY_DATA \
+       CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0403, METHOD_BUFFERED, FILE_ANY_ACCESS)
+#define IOCTL_SCSI_GET_CAPABILITIES \
+       CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
+#define IOCTL_SCSI_PASS_THROUGH_DIRECT \
+       CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
+#define IOCTL_SCSI_GET_ADDRESS \
+       CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS)
+#define IOCTL_SCSI_RESCAN_BUS \
+       CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0407, METHOD_BUFFERED, FILE_ANY_ACCESS)
+#define IOCTL_SCSI_GET_DUMP_POINTERS \
+       CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0408, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
-typedef struct _SCSI_ADAPTER_BUS_INFO
-{
-  UCHAR NumberOfBuses;
-  SCSI_BUS_DATA BusData[1];
-} SCSI_ADAPTER_BUS_INFO, *PSCSI_ADAPTER_BUS_INFO;
 
 
+/* Used by IOCTL_SCSI_GET_CAPABILITIES */
+
 typedef struct _IO_SCSI_CAPABILITIES
 {
   ULONG Length;
@@ -39,6 +47,23 @@ typedef struct _IO_SCSI_CAPABILITIES
 } IO_SCSI_CAPABILITIES, *PIO_SCSI_CAPABILITIES;
 
 
+/* Used by IOCTL_SCSI_GET_INQUIRY_DATA */
+
+typedef struct _SCSI_BUS_DATA
+{
+  UCHAR NumberOfLogicalUnits;
+  UCHAR InitiatorBusId;
+  ULONG InquiryDataOffset;
+}SCSI_BUS_DATA, *PSCSI_BUS_DATA;
+
+
+typedef struct _SCSI_ADAPTER_BUS_INFO
+{
+  UCHAR NumberOfBuses;
+  SCSI_BUS_DATA BusData[1];
+} SCSI_ADAPTER_BUS_INFO, *PSCSI_ADAPTER_BUS_INFO;
+
+
 typedef struct _SCSI_INQUIRY_DATA
 {
   UCHAR PathId;
index 66ff5ac..625a5c5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: scsi.h,v 1.1 2001/07/23 06:12:34 ekohl Exp $
+/* $Id: scsi.h,v 1.2 2002/01/14 01:44:18 ekohl Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
 #ifndef __STORAGE_INCLUDE_SCSI_H
 #define __STORAGE_INCLUDE_SCSI_H
 
+//
+// Command Descriptor Block. Passed by SCSI controller chip over the SCSI bus
+//
+
+typedef union _CDB {
+
+    //
+    // Generic 6-Byte CDB
+    //
+
+    struct _CDB6GENERIC {
+       UCHAR  OperationCode;
+       UCHAR  Immediate : 1;
+       UCHAR  CommandUniqueBits : 4;
+       UCHAR  LogicalUnitNumber : 3;
+       UCHAR  CommandUniqueBytes[3];
+       UCHAR  Link : 1;
+       UCHAR  Flag : 1;
+       UCHAR  Reserved : 4;
+       UCHAR  VendorUnique : 2;
+    } CDB6GENERIC, *PCDB6GENERIC;
+
+    //
+    // Standard 6-byte CDB
+    //
+
+    struct _CDB6READWRITE {
+        UCHAR OperationCode;
+        UCHAR LogicalBlockMsb1 : 5;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR LogicalBlockMsb0;
+        UCHAR LogicalBlockLsb;
+        UCHAR TransferBlocks;
+        UCHAR Control;
+    } CDB6READWRITE, *PCDB6READWRITE;
+
+
+    //
+    // SCSI Inquiry CDB
+    //
+
+    struct _CDB6INQUIRY {
+        UCHAR OperationCode;
+        UCHAR Reserved1 : 5;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR PageCode;
+        UCHAR IReserved;
+        UCHAR AllocationLength;
+        UCHAR Control;
+    } CDB6INQUIRY, *PCDB6INQUIRY;
+
+    //
+    // SCSI Format CDB
+    //
+
+    struct _CDB6FORMAT {
+        UCHAR OperationCode;
+        UCHAR FormatControl : 5;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR FReserved1;
+        UCHAR InterleaveMsb;
+        UCHAR InterleaveLsb;
+        UCHAR FReserved2;
+    } CDB6FORMAT, *PCDB6FORMAT;
+
+    //
+    // Standard 10-byte CDB
+
+    struct _CDB10 {
+        UCHAR OperationCode;
+        UCHAR RelativeAddress : 1;
+        UCHAR Reserved1 : 2;
+        UCHAR ForceUnitAccess : 1;
+        UCHAR DisablePageOut : 1;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR LogicalBlockByte0;
+        UCHAR LogicalBlockByte1;
+        UCHAR LogicalBlockByte2;
+        UCHAR LogicalBlockByte3;
+        UCHAR Reserved2;
+        UCHAR TransferBlocksMsb;
+        UCHAR TransferBlocksLsb;
+        UCHAR Control;
+    } CDB10, *PCDB10;
+
+    //
+    // CD Rom Audio CDBs
+    //
+
+    struct _PAUSE_RESUME {
+        UCHAR OperationCode;
+        UCHAR Reserved1 : 5;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR Reserved2[6];
+        UCHAR Action;
+        UCHAR Control;
+    } PAUSE_RESUME, *PPAUSE_RESUME;
+
+    //
+    // Read Table of Contents
+    //
+
+    struct _READ_TOC {
+        UCHAR OperationCode;
+        UCHAR Reserved0 : 1;
+        UCHAR Msf : 1;
+        UCHAR Reserved1 : 3;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR Reserved2[4];
+        UCHAR StartingTrack;
+        UCHAR AllocationLength[2];
+        UCHAR Control : 6;
+        UCHAR Format : 2;
+    } READ_TOC, *PREAD_TOC;
+
+    struct _PLAY_AUDIO_MSF {
+        UCHAR OperationCode;
+        UCHAR Reserved1 : 5;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR Reserved2;
+        UCHAR StartingM;
+        UCHAR StartingS;
+        UCHAR StartingF;
+        UCHAR EndingM;
+        UCHAR EndingS;
+        UCHAR EndingF;
+        UCHAR Control;
+    } PLAY_AUDIO_MSF, *PPLAY_AUDIO_MSF;
+
+    //
+    // Read SubChannel Data
+    //
+
+    struct _SUBCHANNEL {
+        UCHAR OperationCode;
+        UCHAR Reserved0 : 1;
+        UCHAR Msf : 1;
+        UCHAR Reserved1 : 3;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR Reserved2 : 6;
+        UCHAR SubQ : 1;
+        UCHAR Reserved3 : 1;
+        UCHAR Format;
+        UCHAR Reserved4[2];
+        UCHAR TrackNumber;
+        UCHAR AllocationLength[2];
+        UCHAR Control;
+    } SUBCHANNEL, *PSUBCHANNEL;
+
+    //
+    // Read CD. Used by Atapi for raw sector reads.
+    //
+
+    struct _READ_CD {
+        UCHAR OperationCode;
+        UCHAR Reserved0 : 2;
+        UCHAR ExpectedSectorType : 3;
+        UCHAR Reserved1 : 3;
+        UCHAR StartingLBA[4];
+        UCHAR TransferBlocks[3];
+        UCHAR Reserved2 : 1;
+        UCHAR ErrorFlags : 2;
+        UCHAR IncludeEDC : 1;
+        UCHAR IncludeUserData : 1;
+        UCHAR HeaderCode : 2;
+        UCHAR IncludeSyncData : 1;
+        UCHAR SubChannelSelection : 3;
+        UCHAR Reserved3 : 5;
+        UCHAR Reserved4;
+    } READ_CD, *PREAD_CD;
+
+    //
+    // Plextor Read CD-DA
+    //
+
+    struct _PLXTR_READ_CDDA {
+        UCHAR OperationCode;
+        UCHAR Reserved0 : 5;
+        UCHAR LogicalUnitNumber :3;
+        UCHAR LogicalBlockByte0;
+        UCHAR LogicalBlockByte1;
+        UCHAR LogicalBlockByte2;
+        UCHAR LogicalBlockByte3;
+        UCHAR TransferBlockByte0;
+        UCHAR TransferBlockByte1;
+        UCHAR TransferBlockByte2;
+        UCHAR TransferBlockByte3;
+        UCHAR SubCode;
+        UCHAR Control;
+    } PLXTR_READ_CDDA, *PPLXTR_READ_CDDA;
+
+    //
+    // NEC Read CD-DA
+    //
+
+    struct _NEC_READ_CDDA {
+        UCHAR OperationCode;
+        UCHAR Reserved0;
+        UCHAR LogicalBlockByte0;
+        UCHAR LogicalBlockByte1;
+        UCHAR LogicalBlockByte2;
+        UCHAR LogicalBlockByte3;
+        UCHAR Reserved1;
+        UCHAR TransferBlockByte0;
+        UCHAR TransferBlockByte1;
+        UCHAR Control;
+    } NEC_READ_CDDA, *PNEC_READ_CDDA;
+
+    //
+    // Mode sense
+    //
+
+    struct _MODE_SENSE {
+        UCHAR OperationCode;
+        UCHAR Reserved1 : 3;
+        UCHAR Dbd : 1;
+        UCHAR Reserved2 : 1;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR PageCode : 6;
+        UCHAR Pc : 2;
+        UCHAR Reserved3;
+        UCHAR AllocationLength;
+        UCHAR Control;
+    } MODE_SENSE, *PMODE_SENSE;
+
+    struct _MODE_SENSE10 {
+        UCHAR OperationCode;
+        UCHAR Reserved1 : 3;
+        UCHAR Dbd : 1;
+        UCHAR Reserved2 : 1;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR PageCode : 6;
+        UCHAR Pc : 2;
+        UCHAR Reserved3[4];
+        UCHAR AllocationLength[2];
+        UCHAR Control;
+    } MODE_SENSE10, *PMODE_SENSE10;
+
+    //
+    // Mode select
+    //
+
+    struct _MODE_SELECT {
+        UCHAR OperationCode;
+        UCHAR SPBit : 1;
+        UCHAR Reserved1 : 3;
+        UCHAR PFBit : 1;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR Reserved2[2];
+        UCHAR ParameterListLength;
+        UCHAR Control;
+    } MODE_SELECT, *PMODE_SELECT;
+
+    struct _MODE_SELECT10 {
+        UCHAR OperationCode;
+        UCHAR SPBit : 1;
+        UCHAR Reserved1 : 3;
+        UCHAR PFBit : 1;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR Reserved2[5];
+        UCHAR ParameterListLength[2];
+        UCHAR Control;
+    } MODE_SELECT10, *PMODE_SELECT10;
+
+    struct _LOCATE {
+        UCHAR OperationCode;
+        UCHAR Immediate : 1;
+        UCHAR CPBit : 1;
+        UCHAR BTBit : 1;
+        UCHAR Reserved1 : 2;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR Reserved3;
+        UCHAR LogicalBlockAddress[4];
+        UCHAR Reserved4;
+        UCHAR Partition;
+        UCHAR Control;
+    } LOCATE, *PLOCATE;
+
+    struct _LOGSENSE {
+        UCHAR OperationCode;
+        UCHAR SPBit : 1;
+        UCHAR PPCBit : 1;
+        UCHAR Reserved1 : 3;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR PageCode : 6;
+        UCHAR PCBit : 2;
+        UCHAR Reserved2;
+        UCHAR Reserved3;
+        UCHAR ParameterPointer[2];  // [0]=MSB, [1]=LSB
+        UCHAR AllocationLength[2];  // [0]=MSB, [1]=LSB
+        UCHAR Control;
+    } LOGSENSE, *PLOGSENSE;
+
+    struct _PRINT {
+        UCHAR OperationCode;
+        UCHAR Reserved : 5;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR TransferLength[3];
+        UCHAR Control;
+    } PRINT, *PPRINT;
+
+    struct _SEEK {
+        UCHAR OperationCode;
+        UCHAR Reserved1 : 5;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR LogicalBlockAddress[4];
+        UCHAR Reserved2[3];
+        UCHAR Control;
+    } SEEK, *PSEEK;
+
+    struct _ERASE {
+        UCHAR OperationCode;
+        UCHAR Long : 1;
+        UCHAR Immediate : 1;
+        UCHAR Reserved1 : 3;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR Reserved2[3];
+        UCHAR Control;
+    } ERASE, *PERASE;
+
+    struct _START_STOP {
+        UCHAR OperationCode;
+        UCHAR Immediate: 1;
+        UCHAR Reserved1 : 4;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR Reserved2[2];
+        UCHAR Start : 1;
+        UCHAR LoadEject : 1;
+        UCHAR Reserved3 : 6;
+        UCHAR Control;
+    } START_STOP, *PSTART_STOP;
+
+    struct _MEDIA_REMOVAL {
+        UCHAR OperationCode;
+        UCHAR Reserved1 : 5;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR Reserved2[2];
+        UCHAR Prevent;
+        UCHAR Control;
+    } MEDIA_REMOVAL, *PMEDIA_REMOVAL;
+
+    //
+    // Tape CDBs
+    //
+
+    struct _SEEK_BLOCK {
+        UCHAR OperationCode;
+        UCHAR Immediate : 1;
+        UCHAR Reserved1 : 7;
+        UCHAR BlockAddress[3];
+        UCHAR Link : 1;
+        UCHAR Flag : 1;
+        UCHAR Reserved2 : 4;
+        UCHAR VendorUnique : 2;
+    } SEEK_BLOCK, *PSEEK_BLOCK;
+
+    struct _REQUEST_BLOCK_ADDRESS {
+        UCHAR OperationCode;
+        UCHAR Reserved1[3];
+        UCHAR AllocationLength;
+        UCHAR Link : 1;
+        UCHAR Flag : 1;
+        UCHAR Reserved2 : 4;
+        UCHAR VendorUnique : 2;
+    } REQUEST_BLOCK_ADDRESS, *PREQUEST_BLOCK_ADDRESS;
+
+    struct _PARTITION {
+        UCHAR OperationCode;
+        UCHAR Immediate : 1;
+        UCHAR Sel: 1;
+        UCHAR PartitionSelect : 6;
+        UCHAR Reserved1[3];
+        UCHAR Control;
+    } PARTITION, *PPARTITION;
+
+    struct _WRITE_TAPE_MARKS {
+        UCHAR OperationCode;
+        UCHAR Immediate : 1;
+        UCHAR WriteSetMarks: 1;
+        UCHAR Reserved : 3;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR TransferLength[3];
+        UCHAR Control;
+    } WRITE_TAPE_MARKS, *PWRITE_TAPE_MARKS;
+
+    struct _SPACE_TAPE_MARKS {
+        UCHAR OperationCode;
+        UCHAR Code : 3;
+        UCHAR Reserved : 2;
+        UCHAR LogicalUnitNumber : 3;
+        UCHAR NumMarksMSB ;
+        UCHAR NumMarks;
+        UCHAR NumMarksLSB;
+        union {
+            UCHAR value;
+            struct {
+                UCHAR Link : 1;
+                UCHAR Flag : 1;
+                UCHAR Reserved : 4;
+                UCHAR VendorUnique : 2;
+            } Fields;
+        } Byte6;
+    } SPACE_TAPE_MARKS, *PSPACE_TAPE_MARKS;
+
+    //
+    // Read tape position
+    //
+
+    struct _READ_POSITION {
+        UCHAR Operation;
+        UCHAR BlockType:1;
+        UCHAR Reserved1:4;
+        UCHAR Lun:3;
+        UCHAR Reserved2[7];
+        UCHAR Control;
+    } READ_POSITION, *PREAD_POSITION;
+
+    //
+    // ReadWrite for Tape
+    //
+
+    struct _CDB6READWRITETAPE {
+        UCHAR OperationCode;
+        UCHAR VendorSpecific : 5;
+        UCHAR Reserved : 3;
+        UCHAR TransferLenMSB;
+        UCHAR TransferLen;
+        UCHAR TransferLenLSB;
+        UCHAR Link : 1;
+        UCHAR Flag : 1;
+        UCHAR Reserved1 : 4;
+        UCHAR VendorUnique : 2;
+     } CDB6READWRITETAPE, *PCDB6READWRITETAPE;
+
+    //
+    // Atapi 2.5 Changer 12-byte CDBs
+    //
+
+    struct _LOAD_UNLOAD {
+        UCHAR OperationCode;
+        UCHAR Immediate : 1;
+        UCHAR Reserved1 : 7;
+        UCHAR Reserved2[2];
+        UCHAR Start : 1;
+        UCHAR LoadEject : 1;
+        UCHAR Reserved3: 6;
+        UCHAR Reserved4[3];
+        UCHAR Slot;
+        UCHAR Reserved5[3];
+    } LOAD_UNLOAD, *PLOAD_UNLOAD;
+
+    struct _MECH_STATUS {
+        UCHAR OperationCode;
+        UCHAR Reserved1[7];
+        UCHAR AllocationLength[2];
+        UCHAR Reserved2[2];
+    } MECH_STATUS, *PMECH_STATUS;
+
+} CDB, *PCDB;
+
+//
+// Command Descriptor Block constants.
+//
+
+#define CDB6GENERIC_LENGTH                   6
+#define CDB10GENERIC_LENGTH                  10
+#define CDB12GENERIC_LENGTH                  12
+
+#define SETBITON                             1
+#define SETBITOFF                            0
+//
+// Mode Sense/Select page constants.
+//
+
+#define MODE_PAGE_ERROR_RECOVERY        0x01
+#define MODE_PAGE_DISCONNECT            0x02
+#define MODE_PAGE_FORMAT_DEVICE         0x03
+#define MODE_PAGE_RIGID_GEOMETRY        0x04
+#define MODE_PAGE_FLEXIBILE             0x05
+#define MODE_PAGE_VERIFY_ERROR          0x07
+#define MODE_PAGE_CACHING               0x08
+#define MODE_PAGE_PERIPHERAL            0x09
+#define MODE_PAGE_CONTROL               0x0A
+#define MODE_PAGE_MEDIUM_TYPES          0x0B
+#define MODE_PAGE_NOTCH_PARTITION       0x0C
+#define MODE_SENSE_RETURN_ALL           0x3f
+#define MODE_SENSE_CURRENT_VALUES       0x00
+#define MODE_SENSE_CHANGEABLE_VALUES    0x40
+#define MODE_SENSE_DEFAULT_VAULES       0x80
+#define MODE_SENSE_SAVED_VALUES         0xc0
+#define MODE_PAGE_DEVICE_CONFIG         0x10
+#define MODE_PAGE_MEDIUM_PARTITION      0x11
+#define MODE_PAGE_DATA_COMPRESS         0x0f
+#define MODE_PAGE_CAPABILITIES          0x2A
+
+//
+// SCSI CDB operation codes
+//
+
+#define SCSIOP_TEST_UNIT_READY     0x00
+#define SCSIOP_REZERO_UNIT         0x01
+#define SCSIOP_REWIND              0x01
+#define SCSIOP_REQUEST_BLOCK_ADDR  0x02
+#define SCSIOP_REQUEST_SENSE       0x03
+#define SCSIOP_FORMAT_UNIT         0x04
+#define SCSIOP_READ_BLOCK_LIMITS   0x05
+#define SCSIOP_REASSIGN_BLOCKS     0x07
+#define SCSIOP_READ6               0x08
+#define SCSIOP_RECEIVE             0x08
+#define SCSIOP_WRITE6              0x0A
+#define SCSIOP_PRINT               0x0A
+#define SCSIOP_SEND                0x0A
+#define SCSIOP_SEEK6               0x0B
+#define SCSIOP_TRACK_SELECT        0x0B
+#define SCSIOP_SLEW_PRINT          0x0B
+#define SCSIOP_SEEK_BLOCK          0x0C
+#define SCSIOP_PARTITION           0x0D
+#define SCSIOP_READ_REVERSE        0x0F
+#define SCSIOP_WRITE_FILEMARKS     0x10
+#define SCSIOP_FLUSH_BUFFER        0x10
+#define SCSIOP_SPACE               0x11
+#define SCSIOP_INQUIRY             0x12
+#define SCSIOP_VERIFY6             0x13
+#define SCSIOP_RECOVER_BUF_DATA    0x14
+#define SCSIOP_MODE_SELECT         0x15
+#define SCSIOP_RESERVE_UNIT        0x16
+#define SCSIOP_RELEASE_UNIT        0x17
+#define SCSIOP_COPY                0x18
+#define SCSIOP_ERASE               0x19
+#define SCSIOP_MODE_SENSE          0x1A
+#define SCSIOP_START_STOP_UNIT     0x1B
+#define SCSIOP_STOP_PRINT          0x1B
+#define SCSIOP_LOAD_UNLOAD         0x1B
+#define SCSIOP_RECEIVE_DIAGNOSTIC  0x1C
+#define SCSIOP_SEND_DIAGNOSTIC     0x1D
+#define SCSIOP_MEDIUM_REMOVAL      0x1E
+#define SCSIOP_READ_CAPACITY       0x25
+#define SCSIOP_READ                0x28
+#define SCSIOP_WRITE               0x2A
+#define SCSIOP_SEEK                0x2B
+#define SCSIOP_LOCATE              0x2B
+#define SCSIOP_WRITE_VERIFY        0x2E
+#define SCSIOP_VERIFY              0x2F
+#define SCSIOP_SEARCH_DATA_HIGH    0x30
+#define SCSIOP_SEARCH_DATA_EQUAL   0x31
+#define SCSIOP_SEARCH_DATA_LOW     0x32
+#define SCSIOP_SET_LIMITS          0x33
+#define SCSIOP_READ_POSITION       0x34
+#define SCSIOP_SYNCHRONIZE_CACHE   0x35
+#define SCSIOP_COMPARE             0x39
+#define SCSIOP_COPY_COMPARE        0x3A
+#define SCSIOP_WRITE_DATA_BUFF     0x3B
+#define SCSIOP_READ_DATA_BUFF      0x3C
+#define SCSIOP_CHANGE_DEFINITION   0x40
+#define SCSIOP_READ_SUB_CHANNEL    0x42
+#define SCSIOP_READ_TOC            0x43
+#define SCSIOP_READ_HEADER         0x44
+#define SCSIOP_PLAY_AUDIO          0x45
+#define SCSIOP_PLAY_AUDIO_MSF      0x47
+#define SCSIOP_PLAY_TRACK_INDEX    0x48
+#define SCSIOP_PLAY_TRACK_RELATIVE 0x49
+#define SCSIOP_PAUSE_RESUME        0x4B
+#define SCSIOP_LOG_SELECT          0x4C
+#define SCSIOP_LOG_SENSE           0x4D
+#define SCSIOP_MODE_SELECT10       0x55
+#define SCSIOP_MODE_SENSE10        0x5A
+#define SCSIOP_LOAD_UNLOAD_SLOT    0xA6
+#define SCSIOP_MECHANISM_STATUS    0xBD
+#define SCSIOP_READ_CD             0xBE
+
+//
+// If the IMMED bit is 1, status is returned as soon
+// as the operation is initiated. If the IMMED bit
+// is 0, status is not returned until the operation
+// is completed.
+//
+
+#define CDB_RETURN_ON_COMPLETION   0
+#define CDB_RETURN_IMMEDIATE       1
+
+// end_ntminitape
+
+//
+// CDB Force media access used in extended read and write commands.
+//
+
+#define CDB_FORCE_MEDIA_ACCESS 0x08
+
+//
+// Denon CD ROM operation codes
+//
+
+#define SCSIOP_DENON_EJECT_DISC    0xE6
+#define SCSIOP_DENON_STOP_AUDIO    0xE7
+#define SCSIOP_DENON_PLAY_AUDIO    0xE8
+#define SCSIOP_DENON_READ_TOC      0xE9
+#define SCSIOP_DENON_READ_SUBCODE  0xEB
+
+//
+// SCSI Bus Messages
+//
+
+#define SCSIMESS_ABORT                0x06
+#define SCSIMESS_ABORT_WITH_TAG       0x0D
+#define SCSIMESS_BUS_DEVICE_RESET     0X0C
+#define SCSIMESS_CLEAR_QUEUE          0X0E
+#define SCSIMESS_COMMAND_COMPLETE     0X00
+#define SCSIMESS_DISCONNECT           0X04
+#define SCSIMESS_EXTENDED_MESSAGE     0X01
+#define SCSIMESS_IDENTIFY             0X80
+#define SCSIMESS_IDENTIFY_WITH_DISCON 0XC0
+#define SCSIMESS_IGNORE_WIDE_RESIDUE  0X23
+#define SCSIMESS_INITIATE_RECOVERY    0X0F
+#define SCSIMESS_INIT_DETECTED_ERROR  0X05
+#define SCSIMESS_LINK_CMD_COMP        0X0A
+#define SCSIMESS_LINK_CMD_COMP_W_FLAG 0X0B
+#define SCSIMESS_MESS_PARITY_ERROR    0X09
+#define SCSIMESS_MESSAGE_REJECT       0X07
+#define SCSIMESS_NO_OPERATION         0X08
+#define SCSIMESS_HEAD_OF_QUEUE_TAG    0X21
+#define SCSIMESS_ORDERED_QUEUE_TAG    0X22
+#define SCSIMESS_SIMPLE_QUEUE_TAG     0X20
+#define SCSIMESS_RELEASE_RECOVERY     0X10
+#define SCSIMESS_RESTORE_POINTERS     0X03
+#define SCSIMESS_SAVE_DATA_POINTER    0X02
+#define SCSIMESS_TERMINATE_IO_PROCESS 0X11
+
+//
+// SCSI Extended Message operation codes
+//
+
+#define SCSIMESS_MODIFY_DATA_POINTER  0X00
+#define SCSIMESS_SYNCHRONOUS_DATA_REQ 0X01
+#define SCSIMESS_WIDE_DATA_REQUEST    0X03
+
+//
+// SCSI Extended Message Lengths
+//
+
+#define SCSIMESS_MODIFY_DATA_LENGTH   5
+#define SCSIMESS_SYNCH_DATA_LENGTH    3
+#define SCSIMESS_WIDE_DATA_LENGTH     2
+
+//
+// SCSI extended message structure
+//
+
+#pragma pack (1)
+typedef struct _SCSI_EXTENDED_MESSAGE {
+    UCHAR InitialMessageCode;
+    UCHAR MessageLength;
+    UCHAR MessageType;
+    union _EXTENDED_ARGUMENTS {
+
+        struct {
+            UCHAR Modifier[4];
+        } Modify;
+
+        struct {
+            UCHAR TransferPeriod;
+            UCHAR ReqAckOffset;
+        } Synchronous;
+
+        struct{
+            UCHAR Width;
+        } Wide;
+    }ExtendedArguments;
+}SCSI_EXTENDED_MESSAGE, *PSCSI_EXTENDED_MESSAGE;
+#pragma pack ()
+
+//
+// SCSI bus status codes.
+//
+
+#define SCSISTAT_GOOD                  0x00
+#define SCSISTAT_CHECK_CONDITION       0x02
+#define SCSISTAT_CONDITION_MET         0x04
+#define SCSISTAT_BUSY                  0x08
+#define SCSISTAT_INTERMEDIATE          0x10
+#define SCSISTAT_INTERMEDIATE_COND_MET 0x14
+#define SCSISTAT_RESERVATION_CONFLICT  0x18
+#define SCSISTAT_COMMAND_TERMINATED    0x22
+#define SCSISTAT_QUEUE_FULL            0x28
+
+//
+// Enable Vital Product Data Flag (EVPD)
+// used with INQUIRY command.
+//
+
+#define CDB_INQUIRY_EVPD           0x01
+
+//
+// Defines for format CDB
+//
+
+#define LUN0_FORMAT_SAVING_DEFECT_LIST 0
+#define USE_DEFAULTMSB  0
+#define USE_DEFAULTLSB  0
+
+#define START_UNIT_CODE 0x01
+#define STOP_UNIT_CODE  0x00
+
+// begin_ntminitape
+
+//
+// Inquiry buffer structure. This is the data returned from the target
+// after it receives an inquiry.
+//
+// This structure may be extended by the number of bytes specified
+// in the field AdditionalLength. The defined size constant only
+// includes fields through ProductRevisionLevel.
+//
+// The NT SCSI drivers are only interested in the first 36 bytes of data.
+//
+
+#define INQUIRYDATABUFFERSIZE 36
+
 
 typedef struct _INQUIRYDATA
 {
@@ -36,6 +753,572 @@ typedef struct _INQUIRYDATA
   UCHAR Reserved3[40];
 } INQUIRYDATA, *PINQUIRYDATA;
 
+//
+// Inquiry defines. Used to interpret data returned from target as result
+// of inquiry command.
+//
+// DeviceType field
+//
+
+#define DIRECT_ACCESS_DEVICE            0x00    // disks
+#define SEQUENTIAL_ACCESS_DEVICE        0x01    // tapes
+#define PRINTER_DEVICE                  0x02    // printers
+#define PROCESSOR_DEVICE                0x03    // scanners, printers, etc
+#define WRITE_ONCE_READ_MULTIPLE_DEVICE 0x04    // worms
+#define READ_ONLY_DIRECT_ACCESS_DEVICE  0x05    // cdroms
+#define SCANNER_DEVICE                  0x06    // scanners
+#define OPTICAL_DEVICE                  0x07    // optical disks
+#define MEDIUM_CHANGER                  0x08    // jukebox
+#define COMMUNICATION_DEVICE            0x09    // network
+#define LOGICAL_UNIT_NOT_PRESENT_DEVICE 0x7F
+#define DEVICE_QUALIFIER_NOT_SUPPORTED  0x03
+
+//
+// DeviceTypeQualifier field
+//
+
+#define DEVICE_CONNECTED 0x00
+
+
+/* Sense Data Format */
+
+typedef struct _SENSE_DATA
+{
+  UCHAR ErrorCode:7;
+  UCHAR Valid:1;
+  UCHAR SegmentNumber;
+  UCHAR SenseKey:4;
+  UCHAR Reserved:1;
+  UCHAR IncorrectLength:1;
+  UCHAR EndOfMedia:1;
+  UCHAR FileMark:1;
+  UCHAR Information[4];
+  UCHAR AdditionalSenseLength;
+  UCHAR CommandSpecificInformation[4];
+  UCHAR AdditionalSenseCode;
+  UCHAR AdditionalSenseCodeQualifier;
+  UCHAR FieldReplaceableUnitCode;
+  UCHAR SenseKeySpecific[3];
+} SENSE_DATA, *PSENSE_DATA;
+
+
+/* Default request sense buffer size */
+
+#define SENSE_BUFFER_SIZE 18
+
+/* Sense codes */
+
+#define SCSI_SENSE_NO_SENSE         0x00
+#define SCSI_SENSE_RECOVERED_ERROR  0x01
+#define SCSI_SENSE_NOT_READY        0x02
+#define SCSI_SENSE_MEDIUM_ERROR     0x03
+#define SCSI_SENSE_HARDWARE_ERROR   0x04
+#define SCSI_SENSE_ILLEGAL_REQUEST  0x05
+#define SCSI_SENSE_UNIT_ATTENTION   0x06
+#define SCSI_SENSE_DATA_PROTECT     0x07
+#define SCSI_SENSE_BLANK_CHECK      0x08
+#define SCSI_SENSE_UNIQUE           0x09
+#define SCSI_SENSE_COPY_ABORTED     0x0A
+#define SCSI_SENSE_ABORTED_COMMAND  0x0B
+#define SCSI_SENSE_EQUAL            0x0C
+#define SCSI_SENSE_VOL_OVERFLOW     0x0D
+#define SCSI_SENSE_MISCOMPARE       0x0E
+#define SCSI_SENSE_RESERVED         0x0F
+
+/* Additional tape bit */
+
+#define SCSI_ILLEGAL_LENGTH         0x20
+#define SCSI_EOM                    0x40
+#define SCSI_FILE_MARK              0x80
+
+/* Additional Sense codes */
+
+#define SCSI_ADSENSE_NO_SENSE       0x00
+#define SCSI_ADSENSE_LUN_NOT_READY  0x04
+#define SCSI_ADSENSE_ILLEGAL_COMMAND 0x20
+#define SCSI_ADSENSE_ILLEGAL_BLOCK  0x21
+#define SCSI_ADSENSE_INVALID_LUN    0x25
+#define SCSI_ADSENSE_INVALID_CDB    0x24
+#define SCSI_ADSENSE_MUSIC_AREA     0xA0
+#define SCSI_ADSENSE_DATA_AREA      0xA1
+#define SCSI_ADSENSE_VOLUME_OVERFLOW 0xA7
+
+#define SCSI_ADSENSE_NO_MEDIA_IN_DEVICE 0x3a
+#define SCSI_ADWRITE_PROTECT        0x27
+#define SCSI_ADSENSE_MEDIUM_CHANGED 0x28
+#define SCSI_ADSENSE_BUS_RESET      0x29
+#define SCSI_ADSENSE_TRACK_ERROR    0x14
+#define SCSI_ADSENSE_SEEK_ERROR     0x15
+#define SCSI_ADSENSE_REC_DATA_NOECC 0x17
+#define SCSI_ADSENSE_REC_DATA_ECC   0x18
+
+/* Additional sense code qualifier */
+
+#define SCSI_SENSEQ_FORMAT_IN_PROGRESS 0x04
+#define SCSI_SENSEQ_INIT_COMMAND_REQUIRED 0x02
+#define SCSI_SENSEQ_MANUAL_INTERVENTION_REQUIRED 0x03
+#define SCSI_SENSEQ_BECOMING_READY 0x01
+#define SCSI_SENSEQ_FILEMARK_DETECTED 0x01
+#define SCSI_SENSEQ_SETMARK_DETECTED 0x03
+#define SCSI_SENSEQ_END_OF_MEDIA_DETECTED 0x02
+#define SCSI_SENSEQ_BEGINNING_OF_MEDIA_DETECTED 0x04
+
+
+//
+// SCSI IO Device Control Codes
+//
+
+#define FILE_DEVICE_SCSI 0x0000001b
+
+#define IOCTL_SCSI_EXECUTE_IN   ((FILE_DEVICE_SCSI << 16) + 0x0011)
+#define IOCTL_SCSI_EXECUTE_OUT  ((FILE_DEVICE_SCSI << 16) + 0x0012)
+#define IOCTL_SCSI_EXECUTE_NONE ((FILE_DEVICE_SCSI << 16) + 0x0013)
+
+//
+// SMART support in atapi
+//
+
+#define IOCTL_SCSI_MINIPORT_SMART_VERSION           ((FILE_DEVICE_SCSI << 16) + 0x0500)
+#define IOCTL_SCSI_MINIPORT_IDENTIFY                ((FILE_DEVICE_SCSI << 16) + 0x0501)
+#define IOCTL_SCSI_MINIPORT_READ_SMART_ATTRIBS      ((FILE_DEVICE_SCSI << 16) + 0x0502)
+#define IOCTL_SCSI_MINIPORT_READ_SMART_THRESHOLDS   ((FILE_DEVICE_SCSI << 16) + 0x0503)
+#define IOCTL_SCSI_MINIPORT_ENABLE_SMART            ((FILE_DEVICE_SCSI << 16) + 0x0504)
+#define IOCTL_SCSI_MINIPORT_DISABLE_SMART           ((FILE_DEVICE_SCSI << 16) + 0x0505)
+#define IOCTL_SCSI_MINIPORT_RETURN_STATUS           ((FILE_DEVICE_SCSI << 16) + 0x0506)
+#define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTOSAVE ((FILE_DEVICE_SCSI << 16) + 0x0507)
+#define IOCTL_SCSI_MINIPORT_SAVE_ATTRIBUTE_VALUES   ((FILE_DEVICE_SCSI << 16) + 0x0508)
+#define IOCTL_SCSI_MINIPORT_EXECUTE_OFFLINE_DIAGS   ((FILE_DEVICE_SCSI << 16) + 0x0509)
+
+//
+// Read Capacity Data - returned in Big Endian format
+//
+
+typedef struct _READ_CAPACITY_DATA {
+    ULONG LogicalBlockAddress;
+    ULONG BytesPerBlock;
+} READ_CAPACITY_DATA, *PREAD_CAPACITY_DATA;
+
+
+//
+// Read Block Limits Data - returned in Big Endian format
+// This structure returns the maximum and minimum block
+// size for a TAPE device.
+//
+
+typedef struct _READ_BLOCK_LIMITS {
+    UCHAR Reserved;
+    UCHAR BlockMaximumSize[3];
+    UCHAR BlockMinimumSize[2];
+} READ_BLOCK_LIMITS_DATA, *PREAD_BLOCK_LIMITS_DATA;
+
+
+//
+// Mode data structures.
+//
+
+//
+// Define Mode parameter header.
+//
+
+typedef struct _MODE_PARAMETER_HEADER {
+    UCHAR ModeDataLength;
+    UCHAR MediumType;
+    UCHAR DeviceSpecificParameter;
+    UCHAR BlockDescriptorLength;
+}MODE_PARAMETER_HEADER, *PMODE_PARAMETER_HEADER;
+
+typedef struct _MODE_PARAMETER_HEADER10 {
+    UCHAR ModeDataLength[2];
+    UCHAR MediumType;
+    UCHAR DeviceSpecificParameter;
+    UCHAR Reserved[2];
+    UCHAR BlockDescriptorLength[2];
+}MODE_PARAMETER_HEADER10, *PMODE_PARAMETER_HEADER10;
+
+#define MODE_FD_SINGLE_SIDE     0x01
+#define MODE_FD_DOUBLE_SIDE     0x02
+#define MODE_FD_MAXIMUM_TYPE    0x1E
+#define MODE_DSP_FUA_SUPPORTED  0x10
+#define MODE_DSP_WRITE_PROTECT  0x80
+
+//
+// Define the mode parameter block.
+//
+
+typedef struct _MODE_PARAMETER_BLOCK {
+    UCHAR DensityCode;
+    UCHAR NumberOfBlocks[3];
+    UCHAR Reserved;
+    UCHAR BlockLength[3];
+}MODE_PARAMETER_BLOCK, *PMODE_PARAMETER_BLOCK;
+
+//
+// Define Disconnect-Reconnect page.
+//
+
+typedef struct _MODE_DISCONNECT_PAGE {
+    UCHAR PageCode : 6;
+    UCHAR Reserved : 1;
+    UCHAR PageSavable : 1;
+    UCHAR PageLength;
+    UCHAR BufferFullRatio;
+    UCHAR BufferEmptyRatio;
+    UCHAR BusInactivityLimit[2];
+    UCHAR BusDisconnectTime[2];
+    UCHAR BusConnectTime[2];
+    UCHAR MaximumBurstSize[2];
+    UCHAR DataTransferDisconnect : 2;
+    UCHAR Reserved2[3];
+}MODE_DISCONNECT_PAGE, *PMODE_DISCONNECT_PAGE;
+
+//
+// Define mode caching page.
+//
+
+typedef struct _MODE_CACHING_PAGE {
+    UCHAR PageCode : 6;
+    UCHAR Reserved : 1;
+    UCHAR PageSavable : 1;
+    UCHAR PageLength;
+    UCHAR ReadDisableCache : 1;
+    UCHAR MultiplicationFactor : 1;
+    UCHAR WriteCacheEnable : 1;
+    UCHAR Reserved2 : 5;
+    UCHAR WriteRetensionPriority : 4;
+    UCHAR ReadRetensionPriority : 4;
+    UCHAR DisablePrefetchTransfer[2];
+    UCHAR MinimumPrefetch[2];
+    UCHAR MaximumPrefetch[2];
+    UCHAR MaximumPrefetchCeiling[2];
+}MODE_CACHING_PAGE, *PMODE_CACHING_PAGE;
+
+//
+// Define mode flexible disk page.
+//
+
+typedef struct _MODE_FLEXIBLE_DISK_PAGE {
+    UCHAR PageCode : 6;
+    UCHAR Reserved : 1;
+    UCHAR PageSavable : 1;
+    UCHAR PageLength;
+    UCHAR TransferRate[2];
+    UCHAR NumberOfHeads;
+    UCHAR SectorsPerTrack;
+    UCHAR BytesPerSector[2];
+    UCHAR NumberOfCylinders[2];
+    UCHAR StartWritePrecom[2];
+    UCHAR StartReducedCurrent[2];
+    UCHAR StepRate[2];
+    UCHAR StepPluseWidth;
+    UCHAR HeadSettleDelay[2];
+    UCHAR MotorOnDelay;
+    UCHAR MotorOffDelay;
+    UCHAR Reserved2 : 5;
+    UCHAR MotorOnAsserted : 1;
+    UCHAR StartSectorNumber : 1;
+    UCHAR TrueReadySignal : 1;
+    UCHAR StepPlusePerCyclynder : 4;
+    UCHAR Reserved3 : 4;
+    UCHAR WriteCompenstation;
+    UCHAR HeadLoadDelay;
+    UCHAR HeadUnloadDelay;
+    UCHAR Pin2Usage : 4;
+    UCHAR Pin34Usage : 4;
+    UCHAR Pin1Usage : 4;
+    UCHAR Pin4Usage : 4;
+    UCHAR MediumRotationRate[2];
+    UCHAR Reserved4[2];
+}MODE_FLEXIBLE_DISK_PAGE, *PMODE_FLEXIBLE_DISK_PAGE;
+
+//
+// Define mode format page.
+//
+
+typedef struct _MODE_FORMAT_PAGE {
+    UCHAR PageCode : 6;
+    UCHAR Reserved : 1;
+    UCHAR PageSavable : 1;
+    UCHAR PageLength;
+    UCHAR TracksPerZone[2];
+    UCHAR AlternateSectorsPerZone[2];
+    UCHAR AlternateTracksPerZone[2];
+    UCHAR AlternateTracksPerLogicalUnit[2];
+    UCHAR SectorsPerTrack[2];
+    UCHAR BytesPerPhysicalSector[2];
+    UCHAR Interleave[2];
+    UCHAR TrackSkewFactor[2];
+    UCHAR CylinderSkewFactor[2];
+    UCHAR Reserved2 : 4;
+    UCHAR SurfaceFirst : 1;
+    UCHAR RemovableMedia : 1;
+    UCHAR HardSectorFormating : 1;
+    UCHAR SoftSectorFormating : 1;
+    UCHAR Reserved3[2];
+}MODE_FORMAT_PAGE, *PMODE_FORMAT_PAGE;
+
+//
+// Define rigid disk driver geometry page.
+//
+
+typedef struct _MODE_RIGID_GEOMETRY_PAGE {
+    UCHAR PageCode : 6;
+    UCHAR Reserved : 1;
+    UCHAR PageSavable : 1;
+    UCHAR PageLength;
+    UCHAR NumberOfCylinders[2];
+    UCHAR NumberOfHeads;
+    UCHAR StartWritePrecom[2];
+    UCHAR StartReducedCurrent[2];
+    UCHAR DriveStepRate[2];
+    UCHAR LandZoneCyclinder[2];
+    UCHAR RotationalPositionLock : 2;
+    UCHAR Reserved2 : 6;
+    UCHAR RotationOffset;
+    UCHAR Reserved3;
+    UCHAR RoataionRate[2];
+    UCHAR Reserved4[2];
+}MODE_RIGID_GEOMETRY_PAGE, *PMODE_RIGID_GEOMETRY_PAGE;
+
+//
+// Define read write recovery page
+//
+
+typedef struct _MODE_READ_WRITE_RECOVERY_PAGE {
+
+    UCHAR PageCode : 6;
+    UCHAR Reserved1 : 1;
+    UCHAR PSBit : 1;
+    UCHAR PageLength;
+    UCHAR DCRBit : 1;
+    UCHAR DTEBit : 1;
+    UCHAR PERBit : 1;
+    UCHAR EERBit : 1;
+    UCHAR RCBit : 1;
+    UCHAR TBBit : 1;
+    UCHAR ARRE : 1;
+    UCHAR AWRE : 1;
+    UCHAR ReadRetryCount;
+    UCHAR Reserved4[4];
+    UCHAR WriteRetryCount;
+    UCHAR Reserved5[3];
+
+} MODE_READ_WRITE_RECOVERY_PAGE, *PMODE_READ_WRITE_RECOVERY_PAGE;
+
+//
+// Define read recovery page - cdrom
+//
+
+typedef struct _MODE_READ_RECOVERY_PAGE {
+
+    UCHAR PageCode : 6;
+    UCHAR Reserved1 : 1;
+    UCHAR PSBit : 1;
+    UCHAR PageLength;
+    UCHAR DCRBit : 1;
+    UCHAR DTEBit : 1;
+    UCHAR PERBit : 1;
+    UCHAR Reserved2 : 1;
+    UCHAR RCBit : 1;
+    UCHAR TBBit : 1;
+    UCHAR Reserved3 : 2;
+    UCHAR ReadRetryCount;
+    UCHAR Reserved4[4];
+
+} MODE_READ_RECOVERY_PAGE, *PMODE_READ_RECOVERY_PAGE;
+
+//
+// Define CD-ROM Capabilities and Mechanical Status Page.
+//
+
+typedef struct _MODE_CAPABILITIES_PAGE2 {
+    UCHAR PageCode : 6;
+    UCHAR Reserved1 : 1;
+    UCHAR PSBit : 1;
+    UCHAR PageLength;
+    UCHAR Reserved2[2];
+    UCHAR Capabilities[4];
+    UCHAR MaximumSpeedSupported[2];
+    UCHAR Reserved3;
+    UCHAR NumberVolumeLevels;
+    UCHAR BufferSize[2];
+    UCHAR CurrentSpeed[2];
+    UCHAR Reserved4;
+    UCHAR Reserved5 : 1;
+    UCHAR DigitalOutput : 4;
+    UCHAR Reserved6 : 3;
+    UCHAR Reserved7[2];
+} MODE_CAPABILITIES_PAGE2, *PMODE_CAPABILITIES_PAGE2;
+
+//
+// Bit definitions of Capabilites and DigitalOutput
+//
+
+#define AUDIO_PLAY_SUPPORTED    0x01
+#define MODE2_FORM1_SUPPORTED   0x10
+#define MODE2_FORM2_SUPPORTED   0x20
+#define MULTI_SESSION_SUPPORTED 0x40
+
+#define READ_CD_SUPPORTED       0x01
+
+#define MEDIA_LOCKING_SUPPORTED 0x01
+#define CURRENT_LOCK_STATE      0x02
+#define SOFTWARE_EJECT_SUPPORT  0x08
+
+#define DISC_PRESENT_REPORTING 0x04
+
+//
+// Mode parameter list block descriptor -
+// set the block length for reading/writing
+//
+//
+
+#define MODE_BLOCK_DESC_LENGTH               8
+#define MODE_HEADER_LENGTH                   4
+#define MODE_HEADER_LENGTH10                 8
+
+typedef struct _MODE_PARM_READ_WRITE {
+
+   MODE_PARAMETER_HEADER  ParameterListHeader;  // List Header Format
+   MODE_PARAMETER_BLOCK   ParameterListBlock;   // List Block Descriptor
+
+} MODE_PARM_READ_WRITE_DATA, *PMODE_PARM_READ_WRITE_DATA;
+
+// end_ntminitape
+
+//
+// CDROM audio control (0x0E)
+//
+
+#define CDB_AUDIO_PAUSE 0
+#define CDB_AUDIO_RESUME 1
+
+#define CDB_DEVICE_START 0x11
+#define CDB_DEVICE_STOP 0x10
+
+#define CDB_EJECT_MEDIA 0x10
+#define CDB_LOAD_MEDIA 0x01
+
+#define CDB_SUBCHANNEL_HEADER      0x00
+#define CDB_SUBCHANNEL_BLOCK       0x01
+
+#define CDROM_AUDIO_CONTROL_PAGE   0x0E
+#define MODE_SELECT_IMMEDIATE      0x04
+#define MODE_SELECT_PFBIT          0x10
+
+#define CDB_USE_MSF                0x01
+
+typedef struct _PORT_OUTPUT {
+    UCHAR ChannelSelection;
+    UCHAR Volume;
+} PORT_OUTPUT, *PPORT_OUTPUT;
+
+typedef struct _AUDIO_OUTPUT {
+    UCHAR CodePage;
+    UCHAR ParameterLength;
+    UCHAR Immediate;
+    UCHAR Reserved[2];
+    UCHAR LbaFormat;
+    UCHAR LogicalBlocksPerSecond[2];
+    PORT_OUTPUT PortOutput[4];
+} AUDIO_OUTPUT, *PAUDIO_OUTPUT;
+
+//
+// Multisession CDROM
+//
+
+#define GET_LAST_SESSION 0x01
+#define GET_SESSION_DATA 0x02;
+
+
+/* Atapi 2.5 changer */
+
+typedef struct _MECHANICAL_STATUS_INFORMATION_HEADER
+{
+  UCHAR CurrentSlot : 5;
+  UCHAR ChangerState : 2;
+  UCHAR Fault : 1;
+  UCHAR Reserved : 5;
+  UCHAR MechanismState : 3;
+  UCHAR CurrentLogicalBlockAddress[3];
+  UCHAR NumberAvailableSlots;
+  UCHAR SlotTableLength[2];
+} MECHANICAL_STATUS_INFORMATION_HEADER, *PMECHANICAL_STATUS_INFORMATION_HEADER;
+
+typedef struct _SLOT_TABLE_INFORMATION
+{
+  UCHAR DiscChanged : 1;
+  UCHAR Reserved : 6;
+  UCHAR DiscPresent : 1;
+  UCHAR Reserved2[3];
+} SLOT_TABLE_INFORMATION, *PSLOT_TABLE_INFORMATION;
+
+typedef struct _MECHANICAL_STATUS
+{
+  MECHANICAL_STATUS_INFORMATION_HEADER MechanicalStatusHeader;
+  SLOT_TABLE_INFORMATION SlotTableInfo[1];
+} MECHANICAL_STATUS, *PMECHANICAL_STATUS;
+
+
+/* Tape definitions */
+
+typedef struct _TAPE_POSITION_DATA
+{
+  UCHAR Reserved1:2;
+  UCHAR BlockPositionUnsupported:1;
+  UCHAR Reserved2:3;
+  UCHAR EndOfPartition:1;
+  UCHAR BeginningOfPartition:1;
+  UCHAR PartitionNumber;
+  USHORT Reserved3;
+  UCHAR FirstBlock[4];
+  UCHAR LastBlock[4];
+  UCHAR Reserved4;
+  UCHAR NumberOfBlocks[3];
+  UCHAR NumberOfBytes[4];
+} TAPE_POSITION_DATA, *PTAPE_POSITION_DATA;
+
+/*
+ * This structure is used to convert little endian
+ * ULONGs to SCSI CDB 4 byte big endians values.
+ */
+
+typedef struct _FOUR_BYTE
+{
+  UCHAR Byte0;
+  UCHAR Byte1;
+  UCHAR Byte2;
+  UCHAR Byte3;
+} FOUR_BYTE, *PFOUR_BYTE;
+
+/*
+ * Byte reversing macro for converting
+ * between big- and little-endian formats
+ */
+
+#define REVERSE_BYTES(Destination, Source) \
+{ \
+  PFOUR_BYTE d = (PFOUR_BYTE)(Destination); \
+  PFOUR_BYTE s = (PFOUR_BYTE)(Source); \
+  d->Byte3 = s->Byte0; \
+  d->Byte2 = s->Byte1; \
+  d->Byte1 = s->Byte2; \
+  d->Byte0 = s->Byte3; \
+}
+
+
+/* This macro has the effect of Bit = log2(Data) */
+
+#define WHICH_BIT(Data, Bit) \
+{ \
+  for (Bit = 0; Bit < 32; Bit++) \
+    { \
+      if ((Data >> Bit) == 1) \
+        { \
+          break; \
+        } \
+    } \
+}
+
 
 #endif /* __STORAGE_INCLUDE_SCSI_H */
 
index c28db43..45cde47 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: srb.h,v 1.1 2001/07/21 07:29:53 ekohl Exp $
+/* $Id: srb.h,v 1.2 2002/01/14 01:44:19 ekohl Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
 #ifndef __STORAGE_INCLUDE_SRB_H
 #define __STORAGE_INCLUDE_SRB_H
 
+//
+// Define SCSI maximum configuration parameters.
+//
+
+#define SCSI_MAXIMUM_LOGICAL_UNITS 8
+#define SCSI_MAXIMUM_TARGETS_PER_BUS 32
+#define SCSI_MAXIMUM_BUSES 8
+#define SCSI_MINIMUM_PHYSICAL_BREAKS  16
+#define SCSI_MAXIMUM_PHYSICAL_BREAKS 255
+
+//
+// This constant is for backward compatibility.
+// This use to be the maximum number of targets supported.
+//
+
+#define SCSI_MAXIMUM_TARGETS 8
+
+// begin_ntminitape
+
+#define MAXIMUM_CDB_SIZE 12
+
+
 typedef PHYSICAL_ADDRESS SCSI_PHYSICAL_ADDRESS, *PSCSI_PHYSICAL_ADDRESS;
 
 
@@ -102,6 +124,119 @@ typedef struct _SCSI_REQUEST_BLOCK
 
 #define SCSI_REQUEST_BLOCK_SIZE sizeof(SCSI_REQUEST_BLOCK)
 
+//
+// SRB Functions
+//
+
+#define SRB_FUNCTION_EXECUTE_SCSI           0x00
+#define SRB_FUNCTION_CLAIM_DEVICE           0x01
+#define SRB_FUNCTION_IO_CONTROL             0x02
+#define SRB_FUNCTION_RECEIVE_EVENT          0x03
+#define SRB_FUNCTION_RELEASE_QUEUE          0x04
+#define SRB_FUNCTION_ATTACH_DEVICE          0x05
+#define SRB_FUNCTION_RELEASE_DEVICE         0x06
+#define SRB_FUNCTION_SHUTDOWN               0x07
+#define SRB_FUNCTION_FLUSH                  0x08
+#define SRB_FUNCTION_ABORT_COMMAND          0x10
+#define SRB_FUNCTION_RELEASE_RECOVERY       0x11
+#define SRB_FUNCTION_RESET_BUS              0x12
+#define SRB_FUNCTION_RESET_DEVICE           0x13
+#define SRB_FUNCTION_TERMINATE_IO           0x14
+#define SRB_FUNCTION_FLUSH_QUEUE            0x15
+#define SRB_FUNCTION_REMOVE_DEVICE          0x16
+
+//
+// SRB Status
+//
+
+#define SRB_STATUS_PENDING                  0x00
+#define SRB_STATUS_SUCCESS                  0x01
+#define SRB_STATUS_ABORTED                  0x02
+#define SRB_STATUS_ABORT_FAILED             0x03
+#define SRB_STATUS_ERROR                    0x04
+#define SRB_STATUS_BUSY                     0x05
+#define SRB_STATUS_INVALID_REQUEST          0x06
+#define SRB_STATUS_INVALID_PATH_ID          0x07
+#define SRB_STATUS_NO_DEVICE                0x08
+#define SRB_STATUS_TIMEOUT                  0x09
+#define SRB_STATUS_SELECTION_TIMEOUT        0x0A
+#define SRB_STATUS_COMMAND_TIMEOUT          0x0B
+#define SRB_STATUS_MESSAGE_REJECTED         0x0D
+#define SRB_STATUS_BUS_RESET                0x0E
+#define SRB_STATUS_PARITY_ERROR             0x0F
+#define SRB_STATUS_REQUEST_SENSE_FAILED     0x10
+#define SRB_STATUS_NO_HBA                   0x11
+#define SRB_STATUS_DATA_OVERRUN             0x12
+#define SRB_STATUS_UNEXPECTED_BUS_FREE      0x13
+#define SRB_STATUS_PHASE_SEQUENCE_FAILURE   0x14
+#define SRB_STATUS_BAD_SRB_BLOCK_LENGTH     0x15
+#define SRB_STATUS_REQUEST_FLUSHED          0x16
+#define SRB_STATUS_INVALID_LUN              0x20
+#define SRB_STATUS_INVALID_TARGET_ID        0x21
+#define SRB_STATUS_BAD_FUNCTION             0x22
+#define SRB_STATUS_ERROR_RECOVERY           0x23
+
+//
+// SRB Status Masks
+//
+
+#define SRB_STATUS_QUEUE_FROZEN             0x40
+#define SRB_STATUS_AUTOSENSE_VALID          0x80
+
+#define SRB_STATUS(Status) (Status & ~(SRB_STATUS_AUTOSENSE_VALID | SRB_STATUS_QUEUE_FROZEN))
+
+//
+// SRB Flag Bits
+//
+
+#define SRB_FLAGS_QUEUE_ACTION_ENABLE       0x00000002
+#define SRB_FLAGS_DISABLE_DISCONNECT        0x00000004
+#define SRB_FLAGS_DISABLE_SYNCH_TRANSFER    0x00000008
+#define SRB_FLAGS_BYPASS_FROZEN_QUEUE       0x00000010
+#define SRB_FLAGS_DISABLE_AUTOSENSE         0x00000020
+#define SRB_FLAGS_DATA_IN                   0x00000040
+#define SRB_FLAGS_DATA_OUT                  0x00000080
+#define SRB_FLAGS_NO_DATA_TRANSFER          0x00000000
+#define SRB_FLAGS_UNSPECIFIED_DIRECTION      (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)
+#define SRB_FLAGS_NO_QUEUE_FREEZE           0x00000100
+#define SRB_FLAGS_ADAPTER_CACHE_ENABLE      0x00000200
+#define SRB_FLAGS_IS_ACTIVE                 0x00010000
+#define SRB_FLAGS_ALLOCATED_FROM_ZONE       0x00020000
+#define SRB_FLAGS_SGLIST_FROM_POOL          0x00040000
+
+//
+// Queue Action
+//
+
+#define SRB_SIMPLE_TAG_REQUEST              0x20
+#define SRB_HEAD_OF_QUEUE_TAG_REQUEST       0x21
+#define SRB_ORDERED_QUEUE_TAG_REQUEST       0x22
+
+
+//
+// Port driver error codes
+//
+
+#define SP_BUS_PARITY_ERROR         0x0001
+#define SP_UNEXPECTED_DISCONNECT    0x0002
+#define SP_INVALID_RESELECTION      0x0003
+#define SP_BUS_TIME_OUT             0x0004
+#define SP_PROTOCOL_ERROR           0x0005
+#define SP_INTERNAL_ADAPTER_ERROR   0x0006
+#define SP_REQUEST_TIMEOUT          0x0007
+#define SP_IRQ_NOT_RESPONDING       0x0008
+#define SP_BAD_FW_WARNING           0x0009
+#define SP_BAD_FW_ERROR             0x000a
+
+//
+// Return values for SCSI_HW_FIND_ADAPTER.
+//
+
+#define SP_RETURN_NOT_FOUND     0
+#define SP_RETURN_FOUND         1
+#define SP_RETURN_ERROR         2
+#define SP_RETURN_BAD_CONFIG    3
+
 
 typedef enum _SCSI_NOTIFICATION_TYPE
 {
@@ -181,39 +316,25 @@ typedef struct _HW_INITIALIZATION_DATA
 /* FUNCTIONS ****************************************************************/
 
 VOID
-ScsiDebugPrint (
-       IN      ULONG   DebugPrintLevel,
-       IN      PCHAR   DebugMessage,
-       ...
-       );
+ScsiDebugPrint(IN ULONG DebugPrintLevel,
+              IN PCHAR DebugMessage,
+              ...);
 
-VOID
-STDCALL
-ScsiPortCompleteRequest (
-       IN      PVOID   HwDeviceExtension,
-       IN      UCHAR   PathId,
-       IN      UCHAR   TargetId,
-       IN      UCHAR   Lun,
-       IN      UCHAR   SrbStatus
-       );
+VOID STDCALL
+ScsiPortCompleteRequest(IN PVOID HwDeviceExtension,
+                       IN UCHAR PathId,
+                       IN UCHAR TargetId,
+                       IN UCHAR Lun,
+                       IN UCHAR SrbStatus);
 
-ULONG
-STDCALL
-ScsiPortConvertPhysicalAddressToUlong (
-       IN      SCSI_PHYSICAL_ADDRESS   Address
-       );
+ULONG STDCALL
+ScsiPortConvertPhysicalAddressToUlong(IN SCSI_PHYSICAL_ADDRESS Address);
 
-SCSI_PHYSICAL_ADDRESS
-STDCALL
-ScsiPortConvertUlongToPhysicalAddress (
-       IN      ULONG   UlongAddress
-       );
+SCSI_PHYSICAL_ADDRESS STDCALL
+ScsiPortConvertUlongToPhysicalAddress(IN ULONG UlongAddress);
 
-VOID
-STDCALL
-ScsiPortFlushDma (
-       IN      PVOID   HwDeviceExtension
-       );
+VOID STDCALL
+ScsiPortFlushDma(IN PVOID HwDeviceExtension);
 
 VOID
 STDCALL
@@ -272,23 +393,20 @@ ScsiPortGetSrb (
        IN      LONG    QueueTag
        );
 
-PVOID
-STDCALL
+PVOID STDCALL
 ScsiPortGetUncachedExtension (
        IN      PVOID                           HwDeviceExtension,
        IN      PPORT_CONFIGURATION_INFORMATION ConfigInfo,
        IN      ULONG                           NumberOfBytes
        );
 
-PVOID
-STDCALL
+PVOID STDCALL
 ScsiPortGetVirtualAddress (
        IN      PVOID                   HwDeviceExtension,
        IN      SCSI_PHYSICAL_ADDRESS   PhysicalAddress
        );
 
-ULONG
-STDCALL
+ULONG STDCALL
 ScsiPortInitialize (
        IN      PVOID                           Argument1,
        IN      PVOID                           Argument2,
@@ -296,8 +414,7 @@ ScsiPortInitialize (
        IN      PVOID                           HwContext
        );
 
-VOID
-STDCALL
+VOID STDCALL
 ScsiPortIoMapTransfer (
        IN      PVOID                   HwDeviceExtension,
        IN      PSCSI_REQUEST_BLOCK     Srb,
@@ -305,8 +422,7 @@ ScsiPortIoMapTransfer (
        IN      ULONG                   Length
        );
 
-VOID
-STDCALL
+VOID STDCALL
 ScsiPortLogError (
        IN      PVOID                   HwDeviceExtension,
        IN      PSCSI_REQUEST_BLOCK     Srb OPTIONAL,
@@ -317,38 +433,137 @@ ScsiPortLogError (
        IN      ULONG                   UniqueId
        );
 
-VOID
-STDCALL
-ScsiPortMoveMemory (
-       OUT     PVOID   Destination,
-       IN      PVOID   Source,
-       IN      ULONG   Length
-       );
+VOID STDCALL
+ScsiPortMoveMemory(OUT PVOID Destination,
+                  IN PVOID Source,
+                  IN ULONG Length);
 
 VOID
-ScsiPortNotification (
-       IN      SCSI_NOTIFICATION_TYPE  NotificationType,
-       IN      PVOID                   HwDeviceExtension,
-       ...
-       );
-
-UCHAR
-STDCALL
-ScsiPortReadPortUchar (
-       IN      PUCHAR  Port
-       );
-
-ULONG
-STDCALL
-ScsiPortReadPortUlong (
-       IN      PULONG  Port
-       );
-
-USHORT
-STDCALL
-ScsiPortReadPortUshort (
-       IN      PUSHORT Port
-       );
+ScsiPortNotification(IN SCSI_NOTIFICATION_TYPE NotificationType,
+                    IN PVOID HwDeviceExtension,
+                    ...);
+
+VOID STDCALL
+ScsiPortReadPortBufferUchar(IN PUCHAR Port,
+                           IN PUCHAR Value,
+                           IN ULONG Count);
+
+VOID STDCALL
+ScsiPortReadPortBufferUlong(IN PULONG Port,
+                           IN PULONG Value,
+                           IN ULONG Count);
+
+VOID STDCALL
+ScsiPortReadPortBufferUshort(IN PUSHORT Port,
+                            IN PUSHORT Value,
+                            IN ULONG Count);
+
+UCHAR STDCALL
+ScsiPortReadPortUchar(IN PUCHAR Port);
+
+ULONG STDCALL
+ScsiPortReadPortUlong(IN PULONG Port);
+
+USHORT STDCALL
+ScsiPortReadPortUshort(IN PUSHORT Port);
+
+VOID STDCALL
+ScsiPortReadRegisterBufferUchar(IN PUCHAR Register,
+                               IN PUCHAR Buffer,
+                               IN ULONG Count);
+
+VOID STDCALL
+ScsiPortReadRegisterBufferUlong(IN PULONG Register,
+                               IN PULONG Buffer,
+                               IN ULONG Count);
+
+VOID STDCALL
+ScsiPortReadRegisterBufferUshort(IN PUSHORT Register,
+                                IN PUSHORT Buffer,
+                                IN ULONG Count);
+
+UCHAR STDCALL
+ScsiPortReadRegisterUchar(IN PUCHAR Register);
+
+ULONG STDCALL
+ScsiPortReadRegisterUlong(IN PULONG Register);
+
+USHORT STDCALL
+ScsiPortReadRegisterUshort(IN PUSHORT Register);
+
+ULONG STDCALL
+ScsiPortSetBusDataByOffset(IN PVOID DeviceExtension,
+                          IN ULONG BusDataType,
+                          IN ULONG SystemIoBusNumber,
+                          IN ULONG SlotNumber,
+                          IN PVOID Buffer,
+                          IN ULONG Offset,
+                          IN ULONG Length);
+
+VOID STDCALL
+ScsiPortStallExecution(IN ULONG MicroSeconds);
+
+BOOLEAN STDCALL
+ScsiPortValidateRange(IN PVOID HwDeviceExtension,
+                     IN INTERFACE_TYPE BusType,
+                     IN ULONG SystemIoBusNumber,
+                     IN SCSI_PHYSICAL_ADDRESS IoAddress,
+                     IN ULONG NumberOfBytes,
+                     IN BOOLEAN InIoSpace);
+
+VOID STDCALL
+ScsiPortWritePortBufferUchar(IN PUCHAR Port,
+                            IN PUCHAR Buffer,
+                            IN ULONG Count);
+
+VOID STDCALL
+ScsiPortWritePortBufferUlong(IN PULONG Port,
+                            IN PULONG Buffer,
+                            IN ULONG Count);
+
+VOID STDCALL
+ScsiPortWritePortBufferUshort(IN PUSHORT Port,
+                             IN PUSHORT Value,
+                             IN ULONG Count);
+
+VOID STDCALL
+ScsiPortWritePortUchar(IN PUCHAR Port,
+                      IN UCHAR Value);
+
+VOID STDCALL
+ScsiPortWritePortUlong(IN PULONG Port,
+                      IN ULONG Value);
+
+VOID STDCALL
+ScsiPortWritePortUshort(IN PUSHORT Port,
+                       IN USHORT Value);
+
+VOID STDCALL
+ScsiPortWriteRegisterBufferUchar(IN PUCHAR Register,
+                                IN PUCHAR Buffer,
+                                IN ULONG Count);
+
+VOID STDCALL
+ScsiPortWriteRegisterBufferUlong(IN PULONG Register,
+                                IN PULONG Buffer,
+                                IN ULONG Count);
+
+VOID STDCALL
+ScsiPortWriteRegisterBufferUshort(IN PUSHORT Register,
+                                 IN PUSHORT Buffer,
+                                 IN ULONG Count);
+
+VOID STDCALL
+ScsiPortWriteRegisterUchar(IN PUCHAR Register,
+                          IN ULONG Value);
+
+VOID STDCALL
+ScsiPortWriteRegisterUlong(IN PULONG Register,
+                          IN ULONG Value);
+
+VOID STDCALL
+ScsiPortWriteRegisterUshort(IN PUSHORT Register,
+                           IN USHORT Value);
 
 #endif /* __STORAGE_INCLUDE_SRB_H */
 
index c5f711d..afc477b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: scsiport.c,v 1.1 2001/07/21 07:30:26 ekohl Exp $
+/* $Id: scsiport.c,v 1.2 2002/01/14 01:45:03 ekohl Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
 
 #define VERSION "0.0.1"
 
+
+static NTSTATUS STDCALL
+ScsiPortCreateClose(IN PDEVICE_OBJECT DeviceObject,
+                   IN PIRP Irp);
+
+
+
 //  -------------------------------------------------------  Public Interface
 
 //    DriverEntry
@@ -105,7 +112,11 @@ ScsiPortGetBusData(IN PVOID DeviceExtension,
                   IN PVOID Buffer,
                   IN ULONG Length)
 {
-  UNIMPLEMENTED;
+  return(HalGetBusData(BusDataType,
+                      SystemIoBusNumber,
+                      SlotNumber,
+                      Buffer,
+                      Length));
 }
 
 
@@ -202,6 +213,29 @@ ScsiPortInitialize(IN PVOID Argument1,
                   IN struct _HW_INITIALIZATION_DATA *HwInitializationData,
                   IN PVOID HwContext)
 {
+  PDRIVER_OBJECT DriverObject = (PDRIVER_OBJECT)Argument1;
+  PUNICODE_STRING RegistryPath = (PUNICODE_STRING)Argument2;
+
+  if ((HwInitializationData->HwInitialize == NULL) ||
+      (HwInitializationData->HwStartIo == NULL) ||
+      (HwInitializationData->HwInterrupt == NULL) ||
+      (HwInitializationData->HwFindAdapter == NULL) ||
+      (HwInitializationData->HwResetBus == NULL))
+    return(STATUS_INVALID_PARAMETER);
+
+//  DriverObject->DriverStartIo = HwInitializationData->HwStartIo;
+
+//  DriverObject->DriverStartIo = ScsiPortStartIo;
+  DriverObject->MajorFunction[IRP_MJ_CREATE] = ScsiPortCreateClose;
+  DriverObject->MajorFunction[IRP_MJ_CLOSE] = ScsiPortCreateClose;
+//  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = ScsiPortDeviceControl;
+//  DriverObject->MajorFunction[IRP_MJ_SCSI] = ScsiPortDispatch;
+
+//  DriverObject->MajorFunction[IRP_MJ_READ] = IDEDispatchReadWrite;
+//  DriverObject->MajorFunction[IRP_MJ_WRITE] = IDEDispatchReadWrite;
+//  DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = IDEDispatchQueryInformation;
+//  DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = IDEDispatchSetInformation;
+
   UNIMPLEMENTED;
   return(STATUS_SUCCESS);
 }
@@ -279,4 +313,20 @@ ScsiPortValidateRange(IN PVOID HwDeviceExtension,
   return(TRUE);
 }
 
+
+/* internal functions ******/
+
+
+static NTSTATUS STDCALL
+ScsiPortCreateClose(IN PDEVICE_OBJECT DeviceObject,
+                   IN PIRP Irp)
+{
+  Irp->IoStatus.Status = STATUS_SUCCESS;
+  Irp->IoStatus.Information = FILE_OPENED;
+  IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+  return STATUS_SUCCESS;
+}
+
+
 /* EOF */
index fe5e88e..659dd31 100644 (file)
@@ -1,4 +1,4 @@
-; $Id: scsiport.edf,v 1.3 2001/08/23 15:26:57 ekohl Exp $
+; $Id: scsiport.edf,v 1.4 2002/01/14 01:45:03 ekohl Exp $
 ;
 ; scsiport.def - export definition file for scsiport driver
 ;
@@ -38,7 +38,7 @@ ScsiPortSetDataBusByOffset=ScsiPortSetBusDataByOffset@28
 ScsiPortStallExecution=HAL.KeStallExecutionProcessor
 ScsiPortValidateRange=ScsiPortValidateRange@28
 ScsiPortWritePortUchar=HAL.WRITE_PORT_UCHAR
-ScsiPortWritePortUshort=HA.WRITE_PORT_USHORT
+ScsiPortWritePortUshort=HAL.WRITE_PORT_USHORT
 ScsiPortWritePortUlong=HAL.WRITE_PORT_ULONG
 ScsiPortWritePortBufferUchar=HAL.WRITE_PORT_BUFFER_UCHAR
 ScsiPortWritePortBufferUshort=HAL.WRITE_PORT_BUFFER_USHORT