ReactOS  0.4.14-dev-593-g1793dcc
dispatch.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: GNU GENERAL PUBLIC LICENSE VERSION 2
3  * PROJECT: ReiserFs file system driver for Windows NT/2000/XP/Vista.
4  * FILE: dispatch.c
5  * PURPOSE:
6  * PROGRAMMER: Mark Piper, Matt Wu, Bo BrantÚn.
7  * HOMEPAGE:
8  * UPDATE HISTORY:
9  */
10 
11 /* INCLUDES *****************************************************************/
12 
13 #include "rfsd.h"
14 
15 /* GLOBALS ***************************************************************/
16 
18 
19 /* DEFINITIONS *************************************************************/
20 
21 #ifdef ALLOC_PRAGMA
22 #pragma alloc_text(PAGE, RfsdQueueRequest)
23 #pragma alloc_text(PAGE, RfsdDeQueueRequest)
24 #pragma alloc_text(PAGE, RfsdDispatchRequest)
25 #pragma alloc_text(PAGE, RfsdBuildRequest)
26 #endif
27 
30 {
31  PAGED_CODE();
32 
33  ASSERT(IrpContext);
34 
35  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
36  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
37 
38  // IsSynchronous means we can block (so we don't requeue it)
39  IrpContext->IsSynchronous = TRUE;
40 
41  SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_REQUEUED);
42 
43  IoMarkIrpPending(IrpContext->Irp);
44 
46  &IrpContext->WorkQueueItem,
48  IrpContext );
49 
50  ExQueueWorkItem(&IrpContext->WorkQueueItem, CriticalWorkQueue);
51 
52  return STATUS_PENDING;
53 }
54 
55 VOID NTAPI
57 {
58  PRFSD_IRP_CONTEXT IrpContext;
59 
60  PAGED_CODE();
61 
62  IrpContext = (PRFSD_IRP_CONTEXT) Context;
63 
64  ASSERT(IrpContext);
65 
66  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
67  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
68 
69  _SEH2_TRY {
70 
71  _SEH2_TRY {
72 
74 
75  if (!IrpContext->IsTopLevel) {
76 
78  }
79 
80  RfsdDispatchRequest(IrpContext);
81 
83 
84  RfsdExceptionHandler(IrpContext);
85  } _SEH2_END;
86 
87  } _SEH2_FINALLY {
88 
90 
92  } _SEH2_END;
93 }
94 
98 {
99  PAGED_CODE();
100 
101  ASSERT(IrpContext);
102 
103  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
104  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
105 
106  switch (IrpContext->MajorFunction) {
107 
108  case IRP_MJ_CREATE:
109  return RfsdCreate(IrpContext);
110 
111  case IRP_MJ_CLOSE:
112  return RfsdClose(IrpContext);
113 
114  case IRP_MJ_READ:
115  return RfsdRead(IrpContext);
116 
117 #if !RFSD_READ_ONLY
118  case IRP_MJ_WRITE:
119  return RfsdWrite(IrpContext);
120 #endif // !RFSD_READ_ONLY
121 
123  return RfsdFlush(IrpContext);
124 
126  return RfsdQueryInformation(IrpContext);
127 
129  return RfsdSetInformation(IrpContext);
130 
132  return RfsdQueryVolumeInformation(IrpContext);
133 
134 #if !RFSD_READ_ONLY
136  return RfsdSetVolumeInformation(IrpContext);
137 #endif // !RFSD_READ_ONLY
138 
140  return RfsdDirectoryControl(IrpContext);
141 
143  return RfsdFileSystemControl(IrpContext);
144 
146  return RfsdDeviceControl(IrpContext);
147 
148  case IRP_MJ_LOCK_CONTROL:
149  return RfsdLockControl(IrpContext);
150 
151  case IRP_MJ_CLEANUP:
152  return RfsdCleanup(IrpContext);
153 
154  case IRP_MJ_SHUTDOWN:
155  return RfsdShutDown(IrpContext);
156 
157 #if (_WIN32_WINNT >= 0x0500)
158  case IRP_MJ_PNP:
159  return RfsdPnp(IrpContext);
160 #endif //(_WIN32_WINNT >= 0x0500)
161  default:
162  {
164 
165  RfsdPrint((DBG_ERROR, "RfsdDispatchRequest: Unexpected major function: %xh\n",
166  IrpContext->MajorFunction));
167 
168  RfsdCompleteIrpContext(IrpContext, DefaultRC);
169 
170  return DefaultRC;
171  }
172  }
173 }
174 
177 {
178  BOOLEAN AtIrqlPassiveLevel = FALSE;
179  BOOLEAN IsTopLevelIrp = FALSE;
180  PRFSD_IRP_CONTEXT IrpContext = NULL;
182 
183  PAGED_CODE();
184 
185  _SEH2_TRY {
186 
187  _SEH2_TRY {
188 
189 #if DBG
191 #endif
192 
193  AtIrqlPassiveLevel = (KeGetCurrentIrql() == PASSIVE_LEVEL);
194 
195  if (AtIrqlPassiveLevel) {
196 
198  }
199 
200  if (!IoGetTopLevelIrp()) {
201 
202  IsTopLevelIrp = TRUE;
204  }
205 
206  IrpContext = RfsdAllocateIrpContext(DeviceObject, Irp);
207 
208  if (!IrpContext) {
209 
211  Irp->IoStatus.Status = Status;
212 
214 
215  } else {
216 
217  if ((IrpContext->MajorFunction == IRP_MJ_CREATE) &&
218  !AtIrqlPassiveLevel) {
219 
220  DbgBreak();
221  }
222 
223  Status = RfsdDispatchRequest(IrpContext);
224  }
226 
227  Status = RfsdExceptionHandler(IrpContext);
228  } _SEH2_END;
229 
230  } _SEH2_FINALLY {
231 
232  if (IsTopLevelIrp) {
234  }
235 
236  if (AtIrqlPassiveLevel) {
238  }
239  } _SEH2_END;
240 
241  return Status;
242 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
NTSTATUS RfsdExceptionHandler(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: except.c:103
PRFSD_GLOBAL RfsdGlobal
Definition: init.c:17
#define IN
Definition: typedefs.h:38
NTSTATUS RfsdCompleteIrpContext(IN PRFSD_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: memory.c:160
#define TRUE
Definition: types.h:120
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define FsRtlEnterFileSystem
NTSTATUS NTAPI RfsdBuildRequest(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatch.c:176
BOOLEAN IsTopLevel
Definition: rfsd.h:783
#define IRP_MJ_FLUSH_BUFFERS
#define __drv_mustHoldCriticalRegion
Definition: ffsdrv.h:34
#define FsRtlExitFileSystem
NTSTATUS RfsdQueueRequest(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: dispatch.c:29
NTSTATUS RfsdClose(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: close.c:29
#define IRP_MJ_SHUTDOWN
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS RfsdSetVolumeInformation(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: volinfo.c:312
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_MJ_SET_VOLUME_INFORMATION
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
NTSTATUS RfsdSetInformation(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: fileinfo.c:457
NTSTATUS RfsdRead(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: read.c:894
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
NTSTATUS RfsdQueryVolumeInformation(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: volinfo.c:30
NTSTATUS RfsdExceptionFilter(IN PRFSD_IRP_CONTEXT IrpContext, IN PEXCEPTION_POINTERS ExceptionPointer)
Definition: except.c:27
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
RFSD_IDENTIFIER_TYPE Type
Definition: rfsd.h:336
UCHAR MajorFunction
Definition: rfsd.h:764
Definition: rfsd.h:326
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
NTSTATUS RfsdShutDown(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: shutdown.c:27
__drv_mustHoldCriticalRegion NTSTATUS RfsdPnp(IN PRFSD_IRP_CONTEXT IrpContext)
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
NTSTATUS RfsdDirectoryControl(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: dirctl.c:784
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID RfsdDbgPrintCall(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
#define IRP_MJ_FILE_SYSTEM_CONTROL
__drv_mustHoldCriticalRegion NTSTATUS RfsdDispatchRequest(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: dispatch.c:97
PIRP NTAPI IoGetTopLevelIrp(VOID)
Definition: irp.c:1843
RFSD_IDENTIFIER Identifier
Definition: rfsd.h:755
#define FSRTL_FSP_TOP_LEVEL_IRP
Definition: fsrtltypes.h:59
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define RfsdPrint(arg)
Definition: rfsd.h:1069
NTSTATUS RfsdCreate(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: create.c:1153
#define DBG_ERROR
Definition: ffsdrv.h:1031
NTSTATUS RfsdFlush(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: flush.c:153
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
struct _RFSD_IRP_CONTEXT * PRFSD_IRP_CONTEXT
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
NTSTATUS RfsdDeviceControl(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: devctl.c:236
_SEH2_FINALLY
Definition: create.c:4395
NTSTATUS RfsdCleanup(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: cleanup.c:27
#define IRP_CONTEXT_FLAG_REQUEUED
Definition: ext2fs.h:1085
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define IRP_MJ_READ
Definition: rdpdr.c:46
NTSTATUS RfsdQueryInformation(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: fileinfo.c:35
#define IRP_MJ_CLEANUP
NTSTATUS RfsdFileSystemControl(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: fsctl.c:1233
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define DbgBreak()
Definition: ext2fs.h:46
ULONG Size
Definition: rfsd.h:337
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
PRFSD_IRP_CONTEXT RfsdAllocateIrpContext(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: memory.c:48
IoMarkIrpPending(Irp)
NTSTATUS RfsdWrite(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: write.c:1358
NTSTATUS RfsdLockControl(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: lockctl.c:26
#define RfsdCompleteRequest(Irp, bPrint, PriorityBoost)
Definition: rfsd.h:1072
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
VOID NTAPI RfsdDeQueueRequest(IN PVOID Context)
Definition: dispatch.c:56