[USBSTOR]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Thu, 5 May 2011 00:39:00 +0000 (00:39 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Thu, 5 May 2011 00:39:00 +0000 (00:39 +0000)
- Rename common device extension, it conflicts with classpnp.h header structures
- Start implementing disk ioctls
- Implement SRB_FUNCTION_CLAIM_DEVICE, SRB_FUNCTION_RELEASE_DEVICE

svn path=/branches/usb-bringup/; revision=51585

drivers/usb/usbstor/CMakeLists.txt
drivers/usb/usbstor/disk.c [new file with mode: 0644]
drivers/usb/usbstor/usbstor.c
drivers/usb/usbstor/usbstor.h

index ff9315f..a6e0395 100644 (file)
@@ -3,7 +3,7 @@ add_definitions(-DDEBUG_MODE)
 
 include_directories(${REACTOS_SOURCE_DIR}/ntoskrnl/include)
 
-add_library(usbstor SHARED descriptor.c fdo.c misc.c pdo.c scsi.c usbstor.c usbstor.rc)
+add_library(usbstor SHARED descriptor.c disk.c fdo.c misc.c pdo.c scsi.c usbstor.c usbstor.rc)
 
 set_module_type(usbstor kernelmodedriver)
 add_importlibs(usbstor ntoskrnl hal usbd)
diff --git a/drivers/usb/usbstor/disk.c b/drivers/usb/usbstor/disk.c
new file mode 100644 (file)
index 0000000..16b40e2
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ * PROJECT:     ReactOS Universal Serial Bus Bulk Storage Driver
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        drivers/usb/usbstor/disk.c
+ * PURPOSE:     USB block storage device driver.
+ * PROGRAMMERS:
+ *              James Tabor
+ *              Michael Martin (michael.martin@reactos.org)
+ *              Johannes Anderwald (johannes.anderwald@reactos.org)
+ */
+
+#include "usbstor.h"
+
+NTSTATUS
+USBSTOR_HandleExecuteSCSI(
+    IN PDEVICE_OBJECT DeviceObject,
+    IN PIRP Irp,
+    IN OUT PSCSI_REQUEST_BLOCK Request,
+    IN PPDO_DEVICE_EXTENSION PDODeviceExtension)
+{
+    DPRINT1("USBSTOR_HandleExecuteSCSI\n");
+
+    DbgBreakPoint();
+
+    Request->SrbStatus = SRB_STATUS_ERROR;
+    return STATUS_NOT_SUPPORTED;
+}
+
+NTSTATUS
+USBSTOR_HandleInternalDeviceControl(
+    IN PDEVICE_OBJECT DeviceObject,
+    IN PIRP Irp)
+{
+    PIO_STACK_LOCATION IoStack;
+    PSCSI_REQUEST_BLOCK Request;
+    PPDO_DEVICE_EXTENSION PDODeviceExtension;
+    NTSTATUS Status;
+
+    //
+    // get current stack location
+    //
+    IoStack = IoGetCurrentIrpStackLocation(Irp);
+
+    //
+    // get request block
+    //
+    Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
+
+    //
+    // get device extension
+    //
+    PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+
+    //
+    // sanity check
+    //
+    ASSERT(Request);
+    ASSERT(PDODeviceExtension);
+
+    switch(Request->Function)
+    {
+        case SRB_FUNCTION_EXECUTE_SCSI:
+        {
+            DPRINT1("SRB_FUNCTION_EXECUTE_SCSI\n");
+            Status = USBSTOR_HandleExecuteSCSI(DeviceObject, Irp, Request, PDODeviceExtension);
+
+        }
+        case SRB_FUNCTION_RELEASE_DEVICE:
+        {
+            DPRINT1("SRB_FUNCTION_RELEASE_DEVICE\n");
+            //
+            // sanity check
+            //
+            ASSERT(PDODeviceExtension->Claimed == TRUE);
+
+            //
+            // release claim
+            //
+            PDODeviceExtension->Claimed = TRUE;
+            Status = STATUS_SUCCESS;
+            break;
+        }
+        case SRB_FUNCTION_CLAIM_DEVICE:
+        {
+            DPRINT1("SRB_FUNCTION_CLAIM_DEVICE\n");
+            //
+            // check if the device has been claimed
+            //
+            if (PDODeviceExtension->Claimed)
+            {
+                //
+                // device has already been claimed
+                //
+                Status = STATUS_DEVICE_BUSY;
+                Request->SrbStatus = SRB_STATUS_BUSY;
+                break;
+            }
+
+            //
+            // claim device
+            //
+            PDODeviceExtension->Claimed = TRUE;
+
+            //
+            // output device object
+            //
+            Request->DataBuffer = DeviceObject;
+
+            //
+            // completed successfully
+            //
+            Status = STATUS_SUCCESS;
+            break;
+        }
+        case SRB_FUNCTION_RELEASE_QUEUE:
+        {
+            DPRINT1("SRB_FUNCTION_RELEASE_QUEUE UNIMPLEMENTED\n");
+            Status = STATUS_NOT_IMPLEMENTED;
+            break;
+        }
+        case SRB_FUNCTION_FLUSH:
+        {
+            DPRINT1("SRB_FUNCTION_FLUSH UNIMPLEMENTED\n");
+            Status = STATUS_NOT_IMPLEMENTED;
+            break;
+        }
+        case SRB_FUNCTION_SET_LINK_TIMEOUT:
+        {
+            DPRINT1("SRB_FUNCTION_FLUSH UNIMPLEMENTED\n");
+            Status = STATUS_NOT_IMPLEMENTED;
+            break;
+        }
+        default:
+        {
+            //
+            // not supported
+            //
+            Status = STATUS_NOT_SUPPORTED;
+            Request->SrbStatus = SRB_STATUS_ERROR;
+        }
+    }
+
+    return Status;
+}
+
+NTSTATUS
+USBSTOR_HandleDeviceControl(
+    IN PDEVICE_OBJECT DeviceObject,
+    IN PIRP Irp)
+{
+    PIO_STACK_LOCATION IoStack;
+
+    //
+    // get current stack location
+    //
+    IoStack = IoGetCurrentIrpStackLocation(Irp);
+
+    DPRINT1("USBSTOR_HandleDeviceControl IoControl %x\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
+    DPRINT1("USBSTOR_HandleDeviceControl InputBufferLength %x\n", IoStack->Parameters.DeviceIoControl.InputBufferLength);
+    DPRINT1("USBSTOR_HandleDeviceControl OutputBufferLength %x\n", IoStack->Parameters.DeviceIoControl.OutputBufferLength);
+    DPRINT1("USBSTOR_HandleDeviceControl InputBuffer %x\n", IoStack->Parameters.DeviceIoControl.Type3InputBuffer);
+    DPRINT1("USBSTOR_HandleDeviceControl SystemBuffer %x\n", Irp->AssociatedIrp.SystemBuffer);
+    DPRINT1("USBSTOR_HandleDeviceControl UserBuffer %x\n", Irp->UserBuffer);
+    DPRINT1("USBSTOR_HandleDeviceControl MdlAddress %x\n", Irp->MdlAddress);
+
+    //IOCTL_STORAGE_QUERY_PROPERTY
+
+    return STATUS_NOT_SUPPORTED;
+}
index 7e47f15..1142d90 100644 (file)
@@ -134,11 +134,16 @@ USBSTOR_DispatchDeviceControl(
     PDEVICE_OBJECT DeviceObject,
     PIRP Irp)
 {
-    DPRINT1("USBSTOR_DispatchDeviceControl\n");
+    NTSTATUS Status;
+
+    //
+    // handle requests
+    //
+    Status = USBSTOR_HandleDeviceControl(DeviceObject, Irp);
+
     Irp->IoStatus.Information = 0;
-    Irp->IoStatus.Status = STATUS_SUCCESS;
+    Irp->IoStatus.Status = Status;
     IoCompleteRequest(Irp, IO_NO_INCREMENT);
-    return STATUS_SUCCESS;
 }
 
 
@@ -148,12 +153,17 @@ USBSTOR_DispatchScsi(
     PDEVICE_OBJECT DeviceObject,
     PIRP Irp)
 {
-    DPRINT1("USBSTOR_DispatchScsi\n");
+    NTSTATUS Status;
+
+    //
+    // handle requests
+    //
+    Status = USBSTOR_HandleInternalDeviceControl(DeviceObject, Irp);
 
     Irp->IoStatus.Information = 0;
-    Irp->IoStatus.Status = STATUS_SUCCESS;
+    Irp->IoStatus.Status = Status;
     IoCompleteRequest(Irp, IO_NO_INCREMENT);
-    return STATUS_SUCCESS;
+    return Status;
 }
 
 NTSTATUS
@@ -165,7 +175,6 @@ USBSTOR_DispatchReadWrite(
     //
     // read write ioctl is not supported
     //
-    DPRINT1("USBSTOR_DispatchReadWrite\n");
     Irp->IoStatus.Information = 0;
     Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
     IoCompleteRequest(Irp, IO_NO_INCREMENT);
@@ -178,12 +187,12 @@ USBSTOR_DispatchPnp(
     PDEVICE_OBJECT DeviceObject,
     PIRP Irp)
 {
-    PCOMMON_DEVICE_EXTENSION DeviceExtension;
+    PUSBSTOR_COMMON_DEVICE_EXTENSION DeviceExtension;
 
     //
     // get common device extension
     //
-    DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+    DeviceExtension = (PUSBSTOR_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 
     //
     // is it for the FDO
index 9821c39..b9e0e2e 100644 (file)
@@ -13,7 +13,7 @@
 #include <usbdlib.h>
 #include <stdio.h>
 #include <wdmguid.h>
-
+#include <classpnp.h>
 
 #define USB_STOR_TAG 'sbsu'
 #define USB_MAXCHILDREN              (16)
@@ -24,15 +24,15 @@ IoAttachDeviceToDeviceStackSafe(
   IN PDEVICE_OBJECT TargetDevice,
   OUT PDEVICE_OBJECT *AttachedToDeviceObject);
 
-typedef struct _COMMON_DEVICE_EXTENSION
+typedef struct __COMMON_DEVICE_EXTENSION__
 {
     BOOLEAN IsFDO;
 
-}COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
+}USBSTOR_COMMON_DEVICE_EXTENSION, *PUSBSTOR_COMMON_DEVICE_EXTENSION;
 
 typedef struct
 {
-    COMMON_DEVICE_EXTENSION Common;                                                      // common device extension
+    USBSTOR_COMMON_DEVICE_EXTENSION Common;                                                      // common device extension
 
     PDEVICE_OBJECT FunctionalDeviceObject;                                               // functional device object
     PDEVICE_OBJECT PhysicalDeviceObject;                                                 // physical device object
@@ -50,13 +50,13 @@ typedef struct
 
 typedef struct
 {
-    COMMON_DEVICE_EXTENSION Common;
+    USBSTOR_COMMON_DEVICE_EXTENSION Common;
     PDEVICE_OBJECT LowerDeviceObject;                                                    // points to FDO
     UCHAR LUN;                                                                           // lun id
     PVOID InquiryData;                                                                   // USB SCSI inquiry data
+    UCHAR Claimed;                                                                       // indicating if it has been claimed by upper driver
 }PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
 
-
 //
 // max lun command identifier
 //
@@ -213,3 +213,18 @@ USBSTOR_GetPipeHandles(
 NTSTATUS
 USBSTOR_SendInquiryCmd(
     IN PDEVICE_OBJECT DeviceObject);
+
+
+//---------------------------------------------------------------------
+//
+// disk.c routines
+//
+NTSTATUS
+USBSTOR_HandleInternalDeviceControl(
+    IN PDEVICE_OBJECT DeviceObject,
+    IN PIRP Irp);
+
+NTSTATUS
+USBSTOR_HandleDeviceControl(
+    IN PDEVICE_OBJECT DeviceObject,
+    IN PIRP Irp);