ReactOS  0.4.15-dev-3177-gd6a0299
usbstor.c File Reference
#include "usbstor.h"
#include <debug.h>
Include dependency graph for usbstor.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI USBSTOR_AddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
 
VOID NTAPI USBSTOR_Unload (PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI USBSTOR_DispatchClose (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI USBSTOR_DispatchDeviceControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI USBSTOR_DispatchScsi (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI USBSTOR_DispatchReadWrite (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI USBSTOR_DispatchPnp (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI USBSTOR_DispatchSystemControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI USBSTOR_DispatchPower (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegPath)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file usbstor.c.

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegPath 
)

Definition at line 188 of file usbstor.c.

191 {
192 
193  DPRINT("********* USB Storage *********\n");
194 
195  DriverObject->DriverUnload = USBSTOR_Unload;
196  DriverObject->DriverExtension->AddDevice = USBSTOR_AddDevice;
197  DriverObject->DriverStartIo = USBSTOR_StartIo;
200  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = USBSTOR_DispatchDeviceControl; // scsi pass through requests
204  DriverObject->MajorFunction[IRP_MJ_PNP] = USBSTOR_DispatchPnp;
207 
208  return STATUS_SUCCESS;
209 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
NTSTATUS NTAPI USBSTOR_DispatchClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbstor.c:73
#define IRP_MJ_SCSI
NTSTATUS NTAPI USBSTOR_DispatchDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbstor.c:87
NTSTATUS NTAPI USBSTOR_DispatchReadWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbstor.c:110
NTSTATUS NTAPI USBSTOR_DispatchScsi(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbstor.c:101
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
VOID NTAPI USBSTOR_StartIo(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: queue.c:300
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
NTSTATUS NTAPI USBSTOR_DispatchSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbstor.c:143
NTSTATUS NTAPI USBSTOR_DispatchPower(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbstor.c:162
#define IRP_MJ_SYSTEM_CONTROL
VOID NTAPI USBSTOR_Unload(PDRIVER_OBJECT DriverObject)
Definition: usbstor.c:65
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
NTSTATUS NTAPI USBSTOR_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: usbstor.c:18
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
NTSTATUS NTAPI USBSTOR_DispatchPnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbstor.c:123
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

◆ USBSTOR_AddDevice()

NTSTATUS NTAPI USBSTOR_AddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 18 of file usbstor.c.

21 {
24  PFDO_DEVICE_EXTENSION DeviceExtension;
25 
27  if (!NT_SUCCESS(Status))
28  {
29  DPRINT1("USBSTOR_AddDevice: Failed to create FDO Status %x\n", Status);
30  return Status;
31  }
32 
33  DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
34  ASSERT(DeviceExtension);
35  RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
36 
37  // initialize device extension
38  DeviceExtension->Common.IsFDO = TRUE;
39  DeviceExtension->FunctionalDeviceObject = DeviceObject;
40  DeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
41  DeviceExtension->LowerDeviceObject = IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject);
42 
43  KeInitializeSpinLock(&DeviceExtension->CommonLock);
44 
46 
47  // did attaching fail
48  if (!DeviceExtension->LowerDeviceObject)
49  {
51 
52  return STATUS_DEVICE_REMOVED;
53  }
54 
56 
57  // device is initialized
59 
60  return STATUS_SUCCESS;
61 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
#define STATUS_DEVICE_REMOVED
Definition: ntstatus.h:809
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI IoInitializeTimer(IN PDEVICE_OBJECT DeviceObject, IN PIO_TIMER_ROUTINE TimerRoutine, IN PVOID Context)
Definition: iotimer.c:92
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
VOID NTAPI USBSTOR_TimerRoutine(PDEVICE_OBJECT DeviceObject, PVOID Context)
Definition: error.c:205
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define STATUS_SUCCESS
Definition: shellext.h:65
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:148

Referenced by DriverEntry().

◆ USBSTOR_DispatchClose()

NTSTATUS NTAPI USBSTOR_DispatchClose ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 73 of file usbstor.c.

76 {
77  // function always succeeds ;)
78  DPRINT("USBSTOR_DispatchClose\n");
79  Irp->IoStatus.Information = 0;
80  Irp->IoStatus.Status = STATUS_SUCCESS;
82  return STATUS_SUCCESS;
83 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

Referenced by DriverEntry().

◆ USBSTOR_DispatchDeviceControl()

NTSTATUS NTAPI USBSTOR_DispatchDeviceControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 87 of file usbstor.c.

90 {
92 
94  Irp->IoStatus.Status = Status;
96  return Status;
97 }
LONG NTSTATUS
Definition: precomp.h:26
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
Status
Definition: gdiplustypes.h:24
#define IO_NO_INCREMENT
Definition: iotypes.h:598
NTSTATUS USBSTOR_HandleDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: disk.c:413

Referenced by DriverEntry().

◆ USBSTOR_DispatchPnp()

NTSTATUS NTAPI USBSTOR_DispatchPnp ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 123 of file usbstor.c.

126 {
127  PUSBSTOR_COMMON_DEVICE_EXTENSION DeviceExtension;
128 
129  DeviceExtension = (PUSBSTOR_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
130 
131  if (DeviceExtension->IsFDO)
132  {
134  }
135  else
136  {
138  }
139 }
NTSTATUS USBSTOR_FdoHandlePnp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: fdo.c:277
if(dx==0 &&dy==0)
Definition: linetemp.h:174
struct __COMMON_DEVICE_EXTENSION__ * PUSBSTOR_COMMON_DEVICE_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS USBSTOR_PdoHandlePnp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:511

Referenced by DriverEntry().

◆ USBSTOR_DispatchPower()

NTSTATUS NTAPI USBSTOR_DispatchPower ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 162 of file usbstor.c.

165 {
166  PFDO_DEVICE_EXTENSION DeviceExtension;
167 
168  // get common device extension
169  DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
170 
171  if (DeviceExtension->Common.IsFDO)
172  {
175  return PoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
176  }
177  else
178  {
180  Irp->IoStatus.Status = STATUS_SUCCESS;
182  return STATUS_SUCCESS;
183  }
184 }
if(dx==0 &&dy==0)
Definition: linetemp.h:174
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:746
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by DriverEntry().

◆ USBSTOR_DispatchReadWrite()

NTSTATUS NTAPI USBSTOR_DispatchReadWrite ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 110 of file usbstor.c.

113 {
114  // read write ioctl is not supported
115  Irp->IoStatus.Information = 0;
116  Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
119 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by DriverEntry().

◆ USBSTOR_DispatchScsi()

NTSTATUS NTAPI USBSTOR_DispatchScsi ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 101 of file usbstor.c.

104 {
106 }
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS USBSTOR_HandleInternalDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: disk.c:81

Referenced by DriverEntry().

◆ USBSTOR_DispatchSystemControl()

NTSTATUS NTAPI USBSTOR_DispatchSystemControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 143 of file usbstor.c.

146 {
149 
150  if (DeviceExtension->IsFDO)
151  {
152  return IoCallDriver(((PFDO_DEVICE_EXTENSION)DeviceExtension)->LowerDeviceObject, Irp);
153  }
154  else
155  {
156  return IoCallDriver(((PPDO_DEVICE_EXTENSION)DeviceExtension)->LowerDeviceObject, Irp);
157  }
158 }
struct __COMMON_DEVICE_EXTENSION__ * PUSBSTOR_COMMON_DEVICE_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
_In_z_ PCCHAR _In_ PDEVICE_OBJECT LowerDeviceObject
Definition: classpnp.h:982
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421

Referenced by DriverEntry().

◆ USBSTOR_Unload()

VOID NTAPI USBSTOR_Unload ( PDRIVER_OBJECT  DriverObject)

Definition at line 65 of file usbstor.c.

67 {
68  // no-op
69 }

Referenced by DriverEntry().