--- /dev/null
+/*
+ * 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;
+}
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;
}
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
//
// 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);
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
#include <usbdlib.h>
#include <stdio.h>
#include <wdmguid.h>
-
+#include <classpnp.h>
#define USB_STOR_TAG 'sbsu'
#define USB_MAXCHILDREN (16)
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
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
//
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);