2005-08-14 22:27:15 +00:00
|
|
|
/*
|
2006-03-10 23:32:46 +00:00
|
|
|
* PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: drivers/usb/usbstor/usbstor.c
|
|
|
|
* PURPOSE: USB block storage device driver.
|
|
|
|
* PROGRAMMERS:
|
|
|
|
* James Tabor
|
2011-05-03 00:15:23 +00:00
|
|
|
Johannes Anderwald
|
2005-08-14 22:27:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#define INITGUID
|
|
|
|
#include "usbstor.h"
|
|
|
|
|
|
|
|
/* PUBLIC AND PRIVATE FUNCTIONS **********************************************/
|
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_AddDevice(
|
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PDEVICE_OBJECT PhysicalDeviceObject)
|
2005-08-14 22:27:15 +00:00
|
|
|
{
|
2011-05-03 00:15:23 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PFDO_DEVICE_EXTENSION DeviceExtension;
|
2005-08-14 22:27:15 +00:00
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
//
|
|
|
|
// lets create the device
|
|
|
|
//
|
2011-05-04 20:19:33 +00:00
|
|
|
Status = IoCreateDevice(DriverObject, sizeof(FDO_DEVICE_EXTENSION), 0, FILE_DEVICE_BUS_EXTENDER, FILE_AUTOGENERATED_DEVICE_NAME | FILE_DEVICE_SECURE_OPEN, FALSE, &DeviceObject);
|
2011-05-03 00:15:23 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// check for success
|
|
|
|
//
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("USBSTOR_AddDevice: Failed to create FDO Status %x\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// get device extension
|
|
|
|
//
|
|
|
|
DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
ASSERT(DeviceExtension);
|
|
|
|
|
|
|
|
//
|
|
|
|
// zero device extension
|
|
|
|
//
|
|
|
|
RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
|
|
|
|
|
|
|
|
//
|
|
|
|
// initialize device extension
|
|
|
|
//
|
|
|
|
DeviceExtension->Common.IsFDO = TRUE;
|
|
|
|
DeviceExtension->FunctionalDeviceObject = DeviceObject;
|
|
|
|
DeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
|
|
|
|
DeviceExtension->LowerDeviceObject = IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject);
|
|
|
|
|
|
|
|
//
|
|
|
|
// did attaching fail
|
|
|
|
//
|
|
|
|
if (!DeviceExtension->LowerDeviceObject)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// device removed
|
|
|
|
//
|
|
|
|
IoDeleteDevice(DeviceObject);
|
|
|
|
|
|
|
|
return STATUS_DEVICE_REMOVED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// set device flags
|
|
|
|
//
|
|
|
|
DeviceObject->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// device is initialized
|
|
|
|
//
|
|
|
|
DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
2006-06-04 21:34:02 +00:00
|
|
|
return STATUS_SUCCESS;
|
2005-08-14 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_Unload(
|
|
|
|
PDRIVER_OBJECT DriverObject)
|
2005-08-14 22:27:15 +00:00
|
|
|
{
|
2011-05-03 00:15:23 +00:00
|
|
|
//
|
|
|
|
// no-op
|
|
|
|
//
|
2005-08-14 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_DispatchClose(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
2005-08-14 22:27:15 +00:00
|
|
|
{
|
2011-05-03 00:15:23 +00:00
|
|
|
//
|
|
|
|
// function always succeeds ;)
|
|
|
|
//
|
2011-05-15 17:57:02 +00:00
|
|
|
DPRINT("USBSTOR_DispatchClose\n");
|
2006-06-04 21:34:02 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
2005-08-14 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_DispatchDeviceControl(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
2005-08-14 22:27:15 +00:00
|
|
|
{
|
2011-05-05 00:39:00 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
//
|
|
|
|
// handle requests
|
|
|
|
//
|
|
|
|
Status = USBSTOR_HandleDeviceControl(DeviceObject, Irp);
|
|
|
|
|
2011-05-06 16:25:01 +00:00
|
|
|
//
|
|
|
|
// complete request
|
|
|
|
//
|
2011-05-05 00:39:00 +00:00
|
|
|
Irp->IoStatus.Status = Status;
|
2011-05-03 00:15:23 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2011-05-06 16:25:01 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return Status;
|
2005-08-14 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_DispatchScsi(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
2005-08-14 22:27:15 +00:00
|
|
|
{
|
2011-05-05 00:39:00 +00:00
|
|
|
//
|
|
|
|
// handle requests
|
|
|
|
//
|
2011-05-11 03:49:15 +00:00
|
|
|
return USBSTOR_HandleInternalDeviceControl(DeviceObject, Irp);
|
2005-08-14 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_DispatchReadWrite(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
2005-08-14 22:27:15 +00:00
|
|
|
{
|
2011-05-03 00:15:23 +00:00
|
|
|
//
|
|
|
|
// read write ioctl is not supported
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2005-08-14 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_DispatchPnp(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
2005-08-14 22:27:15 +00:00
|
|
|
{
|
2011-05-05 00:39:00 +00:00
|
|
|
PUSBSTOR_COMMON_DEVICE_EXTENSION DeviceExtension;
|
2011-05-03 00:15:23 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get common device extension
|
|
|
|
//
|
2011-05-05 00:39:00 +00:00
|
|
|
DeviceExtension = (PUSBSTOR_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2011-05-03 00:15:23 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// is it for the FDO
|
|
|
|
//
|
|
|
|
if (DeviceExtension->IsFDO)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// dispatch pnp request to fdo pnp handler
|
|
|
|
//
|
|
|
|
return USBSTOR_FdoHandlePnp(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// dispatch request to pdo pnp handler
|
|
|
|
//
|
|
|
|
return USBSTOR_PdoHandlePnp(DeviceObject, Irp);
|
|
|
|
}
|
2005-08-14 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_DispatchPower(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
2005-08-14 22:27:15 +00:00
|
|
|
{
|
2011-05-03 00:15:23 +00:00
|
|
|
UNIMPLEMENTED
|
|
|
|
|
2006-06-04 21:34:02 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
2005-08-14 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
DriverEntry(
|
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PUNICODE_STRING RegPath)
|
2005-08-14 22:27:15 +00:00
|
|
|
{
|
2006-06-04 21:34:02 +00:00
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
DPRINT1("********* USB Storage *********\n");
|
|
|
|
|
|
|
|
//
|
|
|
|
// driver unload routine
|
|
|
|
//
|
|
|
|
DriverObject->DriverUnload = USBSTOR_Unload;
|
|
|
|
|
|
|
|
//
|
|
|
|
// add device function
|
|
|
|
//
|
|
|
|
DriverObject->DriverExtension->AddDevice = USBSTOR_AddDevice;
|
|
|
|
|
|
|
|
//
|
2011-05-14 18:09:00 +00:00
|
|
|
// driver start i/o routine
|
2011-05-03 00:15:23 +00:00
|
|
|
//
|
2011-05-14 18:09:00 +00:00
|
|
|
DriverObject->DriverStartIo = USBSTOR_StartIo;
|
2005-08-14 22:27:15 +00:00
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
//
|
|
|
|
// create / close
|
|
|
|
//
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CREATE] = USBSTOR_DispatchClose;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CLOSE] = USBSTOR_DispatchClose;
|
2005-08-14 22:27:15 +00:00
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
//
|
|
|
|
// scsi pass through requests
|
|
|
|
//
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = USBSTOR_DispatchDeviceControl;
|
2005-08-14 22:27:15 +00:00
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
//
|
|
|
|
// irp dispatch read / write
|
|
|
|
//
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_READ] = USBSTOR_DispatchReadWrite;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_WRITE] = USBSTOR_DispatchReadWrite;
|
2005-08-14 22:27:15 +00:00
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
//
|
|
|
|
// scsi queue ioctl
|
|
|
|
//
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_SCSI] = USBSTOR_DispatchScsi;
|
2005-08-14 22:27:15 +00:00
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
//
|
|
|
|
// pnp processing
|
|
|
|
//
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_PNP] = USBSTOR_DispatchPnp;
|
2005-08-14 22:27:15 +00:00
|
|
|
|
2011-05-03 00:15:23 +00:00
|
|
|
//
|
|
|
|
// power processing
|
|
|
|
//
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_POWER] = USBSTOR_DispatchPower;
|
2005-08-14 22:27:15 +00:00
|
|
|
|
2006-06-04 21:34:02 +00:00
|
|
|
return STATUS_SUCCESS;
|
2005-08-14 22:27:15 +00:00
|
|
|
}
|
|
|
|
|