ReactOS  0.4.13-dev-92-gf251225
dispatch.c
Go to the documentation of this file.
1 /*
2  * FFS File System Driver for Windows
3  *
4  * dipatch.c
5  *
6  * 2004.5.6 ~
7  *
8  * Lee Jae-Hong, http://www.pyrasis.com
9  *
10  * See License.txt
11  *
12  */
13 
14 #include "ntifs.h"
15 #include "ffsdrv.h"
16 
17 /* Globals */
18 
19 extern PFFS_GLOBAL FFSGlobal;
20 
21 
22 /* Definitions */
23 
24 #ifdef ALLOC_PRAGMA
25 #pragma alloc_text(PAGE, FFSQueueRequest)
26 #pragma alloc_text(PAGE, FFSDeQueueRequest)
27 #pragma alloc_text(PAGE, FFSDispatchRequest)
28 #pragma alloc_text(PAGE, FFSBuildRequest)
29 #endif
30 
31 
34  IN PFFS_IRP_CONTEXT IrpContext)
35 {
36  PAGED_CODE();
37 
38  ASSERT(IrpContext);
39 
40  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
41  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
42 
43  // IsSynchronous means we can block (so we don't requeue it)
44  IrpContext->IsSynchronous = TRUE;
45 
46  SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_REQUEUED);
47 
48  IoMarkIrpPending(IrpContext->Irp);
49 
51  &IrpContext->WorkQueueItem,
53  IrpContext);
54 
55  ExQueueWorkItem(&IrpContext->WorkQueueItem, CriticalWorkQueue);
56 
57  return STATUS_PENDING;
58 }
59 
60 
61 VOID NTAPI
64 {
65  PFFS_IRP_CONTEXT IrpContext;
66 
67  PAGED_CODE();
68 
69  IrpContext = (PFFS_IRP_CONTEXT) Context;
70 
71  ASSERT(IrpContext);
72 
73  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
74  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
75 
76  _SEH2_TRY
77  {
78  _SEH2_TRY
79  {
81 
82  if (!IrpContext->IsTopLevel)
83  {
85  }
86 
87  FFSDispatchRequest(IrpContext);
88  }
90  {
91  FFSExceptionHandler(IrpContext);
92  } _SEH2_END;
93  }
95  {
97 
99  } _SEH2_END;
100 }
101 
102 
103 NTSTATUS
105  IN PFFS_IRP_CONTEXT IrpContext)
106 {
107  PAGED_CODE();
108 
109  ASSERT(IrpContext);
110 
111  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
112  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
113 
114  switch (IrpContext->MajorFunction)
115  {
116  case IRP_MJ_CREATE:
117  return FFSCreate(IrpContext);
118 
119  case IRP_MJ_CLOSE:
120  return FFSClose(IrpContext);
121 
122  case IRP_MJ_READ:
123  return FFSRead(IrpContext);
124 
125 #if !FFS_READ_ONLY
126  case IRP_MJ_WRITE:
127  return FFSWrite(IrpContext);
128 #endif // !FFS_READ_ONLY
129 
131  return FFSFlush(IrpContext);
132 
134  return FFSQueryInformation(IrpContext);
135 
137  return FFSSetInformation(IrpContext);
138 
140  return FFSQueryVolumeInformation(IrpContext);
141 
142 #if !FFS_READ_ONLY
144  return FFSSetVolumeInformation(IrpContext);
145 #endif // !FFS_READ_ONLY
146 
148  return FFSDirectoryControl(IrpContext);
149 
151  return FFSFileSystemControl(IrpContext);
152 
154  return FFSDeviceControl(IrpContext);
155 
156  case IRP_MJ_LOCK_CONTROL:
157  return FFSLockControl(IrpContext);
158 
159  case IRP_MJ_CLEANUP:
160  return FFSCleanup(IrpContext);
161 
162  case IRP_MJ_SHUTDOWN:
163  return FFSShutDown(IrpContext);
164 
165 #if (_WIN32_WINNT >= 0x0500)
166  case IRP_MJ_PNP:
167  return FFSPnp(IrpContext);
168 #endif //(_WIN32_WINNT >= 0x0500)
169  default:
170  FFSPrint((DBG_ERROR, "FFSDispatchRequest: Unexpected major function: %xh\n",
171  IrpContext->MajorFunction));
172 
174 
176  }
177 }
178 
179 
183  PIRP Irp)
184 {
185  BOOLEAN AtIrqlPassiveLevel = FALSE;
186  BOOLEAN IsTopLevelIrp = FALSE;
187  PFFS_IRP_CONTEXT IrpContext = NULL;
189 
190  PAGED_CODE();
191 
192  _SEH2_TRY
193  {
194  _SEH2_TRY
195  {
196 #if DBG
198 #endif
199 
200  AtIrqlPassiveLevel = (KeGetCurrentIrql() == PASSIVE_LEVEL);
201 
202  if (AtIrqlPassiveLevel)
203  {
205  }
206 
207  if (!IoGetTopLevelIrp())
208  {
209  IsTopLevelIrp = TRUE;
211  }
212 
213  IrpContext = FFSAllocateIrpContext(DeviceObject, Irp);
214 
215  if (!IrpContext)
216  {
218  Irp->IoStatus.Status = Status;
219 
221  }
222  else
223  {
224  if ((IrpContext->MajorFunction == IRP_MJ_CREATE) &&
225  !AtIrqlPassiveLevel)
226  {
227  FFSBreakPoint();
228  }
229 
230  Status = FFSDispatchRequest(IrpContext);
231  }
232  }
234  {
235  Status = FFSExceptionHandler(IrpContext);
236  } _SEH2_END;
237  }
239  {
240  if (IsTopLevelIrp)
241  {
243  }
244 
245  if (AtIrqlPassiveLevel)
246  {
248  }
249  } _SEH2_END;
250 
251  return Status;
252 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
__drv_mustHoldCriticalRegion NTSTATUS FFSWrite(IN PFFS_IRP_CONTEXT IrpContext)
Definition: write.c:1487
__drv_mustHoldCriticalRegion NTSTATUS FFSQueryVolumeInformation(IN PFFS_IRP_CONTEXT IrpContext)
Definition: volinfo.c:32
#define IN
Definition: typedefs.h:38
__drv_mustHoldCriticalRegion NTSTATUS FFSSetVolumeInformation(IN PFFS_IRP_CONTEXT IrpContext)
Definition: volinfo.c:349
#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
NTSTATUS FFSExceptionHandler(IN PFFS_IRP_CONTEXT IrpContext)
Definition: except.c:117
#define FsRtlEnterFileSystem
#define IRP_MJ_FLUSH_BUFFERS
#define FsRtlExitFileSystem
#define IRP_MJ_SHUTDOWN
_In_ PIRP Irp
Definition: csq.h:116
UCHAR MajorFunction
Definition: ffsdrv.h:731
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_MJ_SET_VOLUME_INFORMATION
#define FFSCompleteRequest(Irp, bPrint, PriorityBoost)
Definition: ffsdrv.h:1049
Definition: ffsdrv.h:283
VOID FFSDbgPrintCall(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
#define PAGED_CODE()
Definition: video.h:57
__drv_mustHoldCriticalRegion NTSTATUS FFSPnp(IN PFFS_IRP_CONTEXT IrpContext)
_SEH2_TRY
Definition: create.c:4250
#define FFSBreakPoint()
Definition: ffsdrv.h:43
__drv_mustHoldCriticalRegion NTSTATUS FFSQueryInformation(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fileinfo.c:37
__drv_mustHoldCriticalRegion NTSTATUS FFSCreate(IN PFFS_IRP_CONTEXT IrpContext)
Definition: create.c:1835
NTSTATUS FFSDispatchRequest(IN PFFS_IRP_CONTEXT IrpContext)
Definition: dispatch.c:104
BOOLEAN IsTopLevel
Definition: ffsdrv.h:750
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
__drv_mustHoldCriticalRegion NTSTATUS FFSFileSystemControl(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:1645
struct _FFS_IRP_CONTEXT * PFFS_IRP_CONTEXT
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
__drv_mustHoldCriticalRegion NTSTATUS FFSShutDown(IN PFFS_IRP_CONTEXT IrpContext)
Definition: shutdown.c:31
__drv_mustHoldCriticalRegion NTSTATUS FFSDeviceControl(IN PFFS_IRP_CONTEXT IrpContext)
Definition: devctl.c:263
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
__drv_mustHoldCriticalRegion NTSTATUS FFSLockControl(IN PFFS_IRP_CONTEXT IrpContext)
Definition: lock.c:30
FFS_IDENTIFIER_TYPE Type
Definition: ffsdrv.h:294
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
ULONG Size
Definition: ffsdrv.h:295
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
__drv_mustHoldCriticalRegion PFFS_IRP_CONTEXT FFSAllocateIrpContext(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: memory.c:52
VOID NTAPI FFSDeQueueRequest(IN PVOID Context)
Definition: dispatch.c:62
NTSTATUS FFSExceptionFilter(IN PFFS_IRP_CONTEXT IrpContext, IN PEXCEPTION_POINTERS ExceptionPointer)
Definition: except.c:31
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_FILE_SYSTEM_CONTROL
NTSTATUS FFSQueueRequest(IN PFFS_IRP_CONTEXT IrpContext)
Definition: dispatch.c:33
PIRP NTAPI IoGetTopLevelIrp(VOID)
Definition: irp.c:1843
#define FSRTL_FSP_TOP_LEVEL_IRP
Definition: fsrtltypes.h:59
__drv_mustHoldCriticalRegion NTSTATUS FFSSetInformation(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fileinfo.c:551
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
__drv_mustHoldCriticalRegion NTSTATUS FFSCompleteIrpContext(IN PFFS_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:53
__drv_mustHoldCriticalRegion NTSTATUS FFSClose(IN PFFS_IRP_CONTEXT IrpContext)
Definition: close.c:32
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
__drv_mustHoldCriticalRegion NTSTATUS FFSRead(IN PFFS_IRP_CONTEXT IrpContext)
Definition: read.c:1068
#define DBG_ERROR
Definition: ffsdrv.h:1031
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:24
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
FFS_IDENTIFIER Identifier
Definition: ffsdrv.h:722
NTSTATUS NTAPI FFSBuildRequest(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatch.c:181
_SEH2_FINALLY
Definition: create.c:4395
#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
#define IRP_MJ_CLEANUP
__drv_mustHoldCriticalRegion NTSTATUS FFSCleanup(IN PFFS_IRP_CONTEXT IrpContext)
Definition: cleanup.c:30
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#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
IoMarkIrpPending(Irp)
PFFS_GLOBAL FFSGlobal
Definition: init.c:22
__drv_mustHoldCriticalRegion NTSTATUS FFSDirectoryControl(IN PFFS_IRP_CONTEXT IrpContext)
Definition: dirctl.c:1243
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
__drv_mustHoldCriticalRegion NTSTATUS FFSFlush(IN PFFS_IRP_CONTEXT IrpContext)
Definition: flush.c:169