mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 09:25:10 +00:00
[USBSTOR]
- 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
This commit is contained in:
parent
dd5249b4b6
commit
c5af801a10
4 changed files with 209 additions and 16 deletions
|
@ -3,7 +3,7 @@ add_definitions(-DDEBUG_MODE)
|
||||||
|
|
||||||
include_directories(${REACTOS_SOURCE_DIR}/ntoskrnl/include)
|
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)
|
set_module_type(usbstor kernelmodedriver)
|
||||||
add_importlibs(usbstor ntoskrnl hal usbd)
|
add_importlibs(usbstor ntoskrnl hal usbd)
|
||||||
|
|
169
drivers/usb/usbstor/disk.c
Normal file
169
drivers/usb/usbstor/disk.c
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -134,11 +134,16 @@ USBSTOR_DispatchDeviceControl(
|
||||||
PDEVICE_OBJECT DeviceObject,
|
PDEVICE_OBJECT DeviceObject,
|
||||||
PIRP Irp)
|
PIRP Irp)
|
||||||
{
|
{
|
||||||
DPRINT1("USBSTOR_DispatchDeviceControl\n");
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// handle requests
|
||||||
|
//
|
||||||
|
Status = USBSTOR_HandleDeviceControl(DeviceObject, Irp);
|
||||||
|
|
||||||
Irp->IoStatus.Information = 0;
|
Irp->IoStatus.Information = 0;
|
||||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
Irp->IoStatus.Status = Status;
|
||||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||||
return STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,12 +153,17 @@ USBSTOR_DispatchScsi(
|
||||||
PDEVICE_OBJECT DeviceObject,
|
PDEVICE_OBJECT DeviceObject,
|
||||||
PIRP Irp)
|
PIRP Irp)
|
||||||
{
|
{
|
||||||
DPRINT1("USBSTOR_DispatchScsi\n");
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// handle requests
|
||||||
|
//
|
||||||
|
Status = USBSTOR_HandleInternalDeviceControl(DeviceObject, Irp);
|
||||||
|
|
||||||
Irp->IoStatus.Information = 0;
|
Irp->IoStatus.Information = 0;
|
||||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
Irp->IoStatus.Status = Status;
|
||||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||||
return STATUS_SUCCESS;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
|
@ -165,7 +175,6 @@ USBSTOR_DispatchReadWrite(
|
||||||
//
|
//
|
||||||
// read write ioctl is not supported
|
// read write ioctl is not supported
|
||||||
//
|
//
|
||||||
DPRINT1("USBSTOR_DispatchReadWrite\n");
|
|
||||||
Irp->IoStatus.Information = 0;
|
Irp->IoStatus.Information = 0;
|
||||||
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
||||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||||
|
@ -178,12 +187,12 @@ USBSTOR_DispatchPnp(
|
||||||
PDEVICE_OBJECT DeviceObject,
|
PDEVICE_OBJECT DeviceObject,
|
||||||
PIRP Irp)
|
PIRP Irp)
|
||||||
{
|
{
|
||||||
PCOMMON_DEVICE_EXTENSION DeviceExtension;
|
PUSBSTOR_COMMON_DEVICE_EXTENSION DeviceExtension;
|
||||||
|
|
||||||
//
|
//
|
||||||
// get common device extension
|
// get common device extension
|
||||||
//
|
//
|
||||||
DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
DeviceExtension = (PUSBSTOR_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||||
|
|
||||||
//
|
//
|
||||||
// is it for the FDO
|
// is it for the FDO
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include <usbdlib.h>
|
#include <usbdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <wdmguid.h>
|
#include <wdmguid.h>
|
||||||
|
#include <classpnp.h>
|
||||||
|
|
||||||
#define USB_STOR_TAG 'sbsu'
|
#define USB_STOR_TAG 'sbsu'
|
||||||
#define USB_MAXCHILDREN (16)
|
#define USB_MAXCHILDREN (16)
|
||||||
|
@ -24,15 +24,15 @@ IoAttachDeviceToDeviceStackSafe(
|
||||||
IN PDEVICE_OBJECT TargetDevice,
|
IN PDEVICE_OBJECT TargetDevice,
|
||||||
OUT PDEVICE_OBJECT *AttachedToDeviceObject);
|
OUT PDEVICE_OBJECT *AttachedToDeviceObject);
|
||||||
|
|
||||||
typedef struct _COMMON_DEVICE_EXTENSION
|
typedef struct __COMMON_DEVICE_EXTENSION__
|
||||||
{
|
{
|
||||||
BOOLEAN IsFDO;
|
BOOLEAN IsFDO;
|
||||||
|
|
||||||
}COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
|
}USBSTOR_COMMON_DEVICE_EXTENSION, *PUSBSTOR_COMMON_DEVICE_EXTENSION;
|
||||||
|
|
||||||
typedef struct
|
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 FunctionalDeviceObject; // functional device object
|
||||||
PDEVICE_OBJECT PhysicalDeviceObject; // physical device object
|
PDEVICE_OBJECT PhysicalDeviceObject; // physical device object
|
||||||
|
@ -50,13 +50,13 @@ typedef struct
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
COMMON_DEVICE_EXTENSION Common;
|
USBSTOR_COMMON_DEVICE_EXTENSION Common;
|
||||||
PDEVICE_OBJECT LowerDeviceObject; // points to FDO
|
PDEVICE_OBJECT LowerDeviceObject; // points to FDO
|
||||||
UCHAR LUN; // lun id
|
UCHAR LUN; // lun id
|
||||||
PVOID InquiryData; // USB SCSI inquiry data
|
PVOID InquiryData; // USB SCSI inquiry data
|
||||||
|
UCHAR Claimed; // indicating if it has been claimed by upper driver
|
||||||
}PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
|
}PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// max lun command identifier
|
// max lun command identifier
|
||||||
//
|
//
|
||||||
|
@ -213,3 +213,18 @@ USBSTOR_GetPipeHandles(
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
USBSTOR_SendInquiryCmd(
|
USBSTOR_SendInquiryCmd(
|
||||||
IN PDEVICE_OBJECT DeviceObject);
|
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);
|
||||||
|
|
Loading…
Reference in a new issue