ReactOS  0.4.15-dev-1201-gb2cf5a4
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_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 15 of file usbstor.c.

Function Documentation

◆ DriverEntry()

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

Definition at line 240 of file usbstor.c.

243 {
244 
245  DPRINT("********* USB Storage *********\n");
246 
247  //
248  // driver unload routine
249  //
251 
252  //
253  // add device function
254  //
256 
257  //
258  // driver start i/o routine
259  //
261 
262  //
263  // create / close
264  //
267 
268  //
269  // scsi pass through requests
270  //
272 
273  //
274  // irp dispatch read / write
275  //
278 
279  //
280  // scsi queue ioctl
281  //
283 
284  //
285  // pnp processing
286  //
288 
289  //
290  // power processing
291  //
293 
294  return STATUS_SUCCESS;
295 }
#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
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2262
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
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
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
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2268
NTSTATUS NTAPI USBSTOR_DispatchPower(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbstor.c:162
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2200
VOID NTAPI USBSTOR_Unload(PDRIVER_OBJECT DriverObject)
Definition: usbstor.c:65
#define IRP_MJ_READ
Definition: rdpdr.c:46
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2269
PDRIVER_STARTIO DriverStartIo
Definition: iotypes.h:2267
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
NTSTATUS NTAPI USBSTOR_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: usbstor.c:18
return STATUS_SUCCESS
Definition: btrfs.c:3014
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 22 of file usbstor.c.

25 {
28  PFDO_DEVICE_EXTENSION DeviceExtension;
29 
30  //
31  // lets create the device
32  //
34 
35  //
36  // check for success
37  //
38  if (!NT_SUCCESS(Status))
39  {
40  DPRINT1("USBSTOR_AddDevice: Failed to create FDO Status %x\n", Status);
41  return Status;
42  }
43 
44  //
45  // get device extension
46  //
47  DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
48  ASSERT(DeviceExtension);
49 
50  //
51  // zero device extension
52  //
53  RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
54 
55  //
56  // initialize device extension
57  //
58  DeviceExtension->Common.IsFDO = TRUE;
59  DeviceExtension->FunctionalDeviceObject = DeviceObject;
60  DeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
61  DeviceExtension->LowerDeviceObject = IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject);
62 
63  //
64  // init timer
65  //
67 
68  //
69  // did attaching fail
70  //
71  if (!DeviceExtension->LowerDeviceObject)
72  {
73  //
74  // device removed
75  //
77 
78  return STATUS_DEVICE_REMOVED;
79  }
80 
81  //
82  // set device flags
83  //
85 
86  //
87  // device is initialized
88  //
90 
91 
92  //
93  // done
94  //
95  return STATUS_SUCCESS;
96 }
#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
#define FALSE
Definition: types.h:117
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
#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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
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
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#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
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:147

◆ USBSTOR_DispatchClose()

NTSTATUS NTAPI USBSTOR_DispatchClose ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 110 of file usbstor.c.

113 {
114  //
115  // function always succeeds ;)
116  //
117  DPRINT("USBSTOR_DispatchClose\n");
118  Irp->IoStatus.Information = 0;
119  Irp->IoStatus.Status = STATUS_SUCCESS;
121  return STATUS_SUCCESS;
122 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define IO_NO_INCREMENT
Definition: iotypes.h:581
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ USBSTOR_DispatchDeviceControl()

NTSTATUS NTAPI USBSTOR_DispatchDeviceControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 127 of file usbstor.c.

130 {
132 
133  //
134  // handle requests
135  //
137 
138  //
139  // complete request
140  //
141  Irp->IoStatus.Status = Status;
143 
144  //
145  // done
146  //
147  return Status;
148 }
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define IoCompleteRequest
Definition: irp.c:1240
Status
Definition: gdiplustypes.h:24
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IO_NO_INCREMENT
Definition: iotypes.h:581
NTSTATUS USBSTOR_HandleDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: disk.c:417

◆ USBSTOR_DispatchPnp()

NTSTATUS NTAPI USBSTOR_DispatchPnp ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 180 of file usbstor.c.

183 {
184  PUSBSTOR_COMMON_DEVICE_EXTENSION DeviceExtension;
185 
186  //
187  // get common device extension
188  //
189  DeviceExtension = (PUSBSTOR_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
190 
191  //
192  // is it for the FDO
193  //
194  if (DeviceExtension->IsFDO)
195  {
196  //
197  // dispatch pnp request to fdo pnp handler
198  //
200  }
201  else
202  {
203  //
204  // dispatch request to pdo pnp handler
205  //
207  }
208 }
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS USBSTOR_FdoHandlePnp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: fdo.c:277
struct __COMMON_DEVICE_EXTENSION__ * PUSBSTOR_COMMON_DEVICE_EXTENSION
NTSTATUS USBSTOR_PdoHandlePnp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:511
if(!(yy_init))
Definition: macro.lex.yy.c:714
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464

◆ USBSTOR_DispatchPower()

NTSTATUS NTAPI USBSTOR_DispatchPower ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 212 of file usbstor.c.

215 {
216  PFDO_DEVICE_EXTENSION DeviceExtension;
217 
218  // get common device extension
219  DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
220 
221  if (DeviceExtension->Common.IsFDO)
222  {
225  return PoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
226  }
227  else
228  {
230  Irp->IoStatus.Status = STATUS_SUCCESS;
232  return STATUS_SUCCESS;
233  }
234 }
_In_ PIRP Irp
Definition: csq.h:116
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define IoCompleteRequest
Definition: irp.c:1240
if(!(yy_init))
Definition: macro.lex.yy.c:714
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:581
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ USBSTOR_DispatchReadWrite()

NTSTATUS NTAPI USBSTOR_DispatchReadWrite ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 165 of file usbstor.c.

168 {
169  //
170  // read write ioctl is not supported
171  //
172  Irp->IoStatus.Information = 0;
173  Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
176 }
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:581

◆ USBSTOR_DispatchScsi()

NTSTATUS NTAPI USBSTOR_DispatchScsi ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 153 of file usbstor.c.

156 {
157  //
158  // handle requests
159  //
161 }
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS USBSTOR_HandleInternalDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: disk.c:81
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464

◆ USBSTOR_Unload()

VOID NTAPI USBSTOR_Unload ( PDRIVER_OBJECT  DriverObject)

Definition at line 100 of file usbstor.c.

102 {
103  //
104  // no-op
105  //
106 }