ReactOS  0.4.14-dev-614-gbfd8a84
devctl.c
Go to the documentation of this file.
1 /*
2  * FFS File System Driver for Windows
3  *
4  * devctl.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 _PREFAST_
25 IO_COMPLETION_ROUTINE FFSDeviceControlCompletion;
26 #endif // _PREFAST_
27 
31  IN PIRP Irp,
32  IN PVOID Context);
33 
34 
35 #ifdef ALLOC_PRAGMA
36 #pragma alloc_text(PAGE, FFSDeviceControl)
37 #pragma alloc_text(PAGE, FFSDeviceControlNormal)
38 #if FFS_UNLOAD
39 #pragma alloc_text(PAGE, FFSPrepareToUnload)
40 #endif
41 #endif
42 
43 
47  IN PIRP Irp,
49 {
50  if (Irp->PendingReturned)
51  {
53  }
54 
55  return STATUS_SUCCESS;
56 }
57 
58 
62  IN PFFS_IRP_CONTEXT IrpContext)
63 {
67 
68  PFFS_VCB Vcb;
69 
70  PIRP Irp;
72  PIO_STACK_LOCATION NextIrpSp;
73 
75 
76  PAGED_CODE();
77 
78  _SEH2_TRY
79  {
80  ASSERT(IrpContext != NULL);
81 
82  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
83  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
84 
86 
87  DeviceObject = IrpContext->DeviceObject;
88 
90  {
92 
94  }
95 
96  Irp = IrpContext->Irp;
98 
99  Vcb = (PFFS_VCB)IrpSp->FileObject->FsContext;
100 
101  if (!((Vcb) && (Vcb->Identifier.Type == FFSVCB) &&
102  (Vcb->Identifier.Size == sizeof(FFS_VCB))
103  )
104  )
105  {
107  _SEH2_LEAVE;
108  }
109 
110  TargetDeviceObject = Vcb->TargetDeviceObject;
111 
112  //
113  // Pass on the IOCTL to the driver below
114  //
115 
117 
118  NextIrpSp = IoGetNextIrpStackLocation(Irp);
119  *NextIrpSp = *IrpSp;
120 
122  Irp,
124  NULL,
125  FALSE,
126  TRUE,
127  TRUE);
128 
130  }
131 
133  {
134  if (!IrpContext->ExceptionInProgress)
135  {
136  if (IrpContext)
137  {
138  if (!CompleteRequest)
139  {
140  IrpContext->Irp = NULL;
141  }
142 
143  FFSCompleteIrpContext(IrpContext, Status);
144  }
145  }
146  } _SEH2_END;
147 
148  return Status;
149 }
150 
151 
152 #if FFS_UNLOAD
153 
155 NTSTATUS
157  IN PFFS_IRP_CONTEXT IrpContext)
158 {
161  BOOLEAN GlobalDataResourceAcquired = FALSE;
162 
163  PAGED_CODE();
164 
165  _SEH2_TRY
166  {
167  ASSERT(IrpContext != NULL);
168 
169  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
170  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
171 
172  DeviceObject = IrpContext->DeviceObject;
173 
175  {
177  _SEH2_LEAVE;
178  }
179 
182  TRUE);
183 
184  GlobalDataResourceAcquired = TRUE;
185 
187  {
188  FFSPrint((DBG_ERROR, "FFSPrepareUnload: Already ready to unload.\n"));
189 
191 
192  _SEH2_LEAVE;
193  }
194 
195  {
196  PFFS_VCB Vcb;
197  PLIST_ENTRY ListEntry;
198 
199  ListEntry = FFSGlobal->VcbList.Flink;
200 
201  while (ListEntry != &(FFSGlobal->VcbList))
202  {
203  Vcb = CONTAINING_RECORD(ListEntry, FFS_VCB, Next);
204  ListEntry = ListEntry->Flink;
205 
206  if (Vcb && (!Vcb->ReferenceCount) &&
208  {
209  FFSRemoveVcb(Vcb);
211 
212  FFSFreeVcb(Vcb);
213  }
214  }
215  }
216 
217  if (!IsListEmpty(&(FFSGlobal->VcbList)))
218  {
219 
220  FFSPrint((DBG_ERROR, "FFSPrepareUnload: Mounted volumes exists.\n"));
221 
223 
224  _SEH2_LEAVE;
225  }
226 
228 
229 #ifdef _MSC_VER
230 #pragma prefast( suppress: 28175, "allowed to unload" )
231 #endif
233 
235 
236  FFSPrint((DBG_INFO, "FFSPrepareToUnload: Driver is ready to unload.\n"));
237 
239  }
241  {
242  if (GlobalDataResourceAcquired)
243  {
247  }
248 
249  if (!IrpContext->ExceptionInProgress)
250  {
251  FFSCompleteIrpContext(IrpContext, Status);
252  }
253  } _SEH2_END;
254 
255  return Status;
256 }
257 
258 #endif
259 
260 
262 NTSTATUS
264  IN PFFS_IRP_CONTEXT IrpContext)
265 {
266  PIRP Irp;
267  PIO_STACK_LOCATION IoStackLocation;
270 
271  PAGED_CODE();
272 
273  ASSERT(IrpContext);
274 
275  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
276  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
277 
278  Irp = IrpContext->Irp;
279 
280  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
281 
282  IoControlCode =
283  IoStackLocation->Parameters.DeviceIoControl.IoControlCode;
284 
285  switch (IoControlCode)
286  {
287 #if FFS_UNLOAD
288  case IOCTL_PREPARE_TO_UNLOAD:
289  Status = FFSPrepareToUnload(IrpContext);
290  break;
291 #endif
292 
294  Status = FFSSelectBSDPartition(IrpContext);
295  break;
296 
297  default:
298  Status = FFSDeviceControlNormal(IrpContext);
299  }
300 
301  return Status;
302 }
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define IN
Definition: typedefs.h:38
__drv_mustHoldCriticalRegion NTSTATUS FFSSelectBSDPartition(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:1610
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
#define __drv_mustHoldCriticalRegion
Definition: ffsdrv.h:34
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PFFS_GLOBAL FFSGlobal
Definition: init.c:22
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1061
LONG NTSTATUS
Definition: precomp.h:26
VOID FFSClearVpbFlag(IN PVPB Vpb, IN USHORT Flag)
Definition: fsctl.c:69
ULONG Flags
Definition: ffsdrv.h:395
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
Definition: ffsdrv.h:283
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
PDEVICE_OBJECT DeviceObject
Definition: ffsdrv.h:371
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
NTSTATUS NTAPI FFSDeviceControlCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: devctl.c:45
__drv_mustHoldCriticalRegion NTSTATUS FFSDeviceControlNormal(IN PFFS_IRP_CONTEXT IrpContext)
Definition: devctl.c:61
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
struct _FFS_VCB * PFFS_VCB
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
VOID FFSRemoveVcb(PFFS_VCB Vcb)
Definition: memory.c:1542
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define IOCTL_SELECT_BSD_PARTITION
Definition: ffsdrv.h:125
#define Vcb
Definition: cdprocs.h:1425
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
__drv_mustHoldCriticalRegion NTSTATUS FFSPrepareToUnload(IN PFFS_IRP_CONTEXT IrpContext)
NTSTATUS NTAPI CompleteRequest(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: dispatch.c:19
__drv_mustHoldCriticalRegion VOID FFSFreeVcb(IN PFFS_VCB Vcb)
Definition: memory.c:1886
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
__drv_mustHoldCriticalRegion NTSTATUS FFSCompleteIrpContext(IN PFFS_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:53
LIST_ENTRY VcbList
Definition: ffsdrv.h:374
#define VCB_DISMOUNT_PENDING
Definition: ext2fs.h:782
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
Definition: ffsdrv.h:280
#define DBG_ERROR
Definition: ffsdrv.h:1031
Definition: typedefs.h:117
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
ERESOURCE Resource
Definition: ffsdrv.h:352
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
static DRIVER_UNLOAD DriverUnload
Definition: kbdclass.c:17
_SEH2_FINALLY
Definition: create.c:4395
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define DBG_INFO
Definition: ffsdrv.h:1034
#define _SEH2_LEAVE
Definition: filesup.c:20
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IN OUT PVCB IN PDEVICE_OBJECT TargetDeviceObject
Definition: fatprocs.h:1664
return STATUS_SUCCESS
Definition: btrfs.c:2938
IoMarkIrpPending(Irp)
#define VPB_MOUNTED
Definition: iotypes.h:1764
PDRIVER_OBJECT DriverObject
Definition: ffsdrv.h:368
#define FFS_UNLOAD_PENDING
Definition: ffsdrv.h:404
__drv_mustHoldCriticalRegion NTSTATUS FFSDeviceControl(IN PFFS_IRP_CONTEXT IrpContext)
Definition: devctl.c:263