ReactOS  0.4.14-dev-77-gd9e7c48
devctl.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: devctl.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 _PREFAST_
22 IO_COMPLETION_ROUTINE RfsdDeviceControlCompletion;
23 #endif // _PREFAST_
24 
27  IN PIRP Irp,
28  IN PVOID Context);
29 
30 #ifdef ALLOC_PRAGMA
31 //#pragma alloc_text(PAGE, RfsdDeviceControlCompletion)
32 #pragma alloc_text(PAGE, RfsdDeviceControl)
33 #pragma alloc_text(PAGE, RfsdDeviceControlNormal)
34 #if RFSD_UNLOAD
35 #pragma alloc_text(PAGE, RfsdPrepareToUnload)
36 #endif
37 #endif
38 
41  IN PIRP Irp,
43 {
44  if (Irp->PendingReturned) {
46  }
47 
48  return STATUS_SUCCESS;
49 }
50 
53 {
57 
58  PRFSD_VCB Vcb;
59 
60  PIRP Irp;
62  PIO_STACK_LOCATION NextIrpSp;
63 
65 
66  PAGED_CODE();
67 
68  _SEH2_TRY {
69 
70  ASSERT(IrpContext != NULL);
71 
72  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
73  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
74 
76 
77  DeviceObject = IrpContext->DeviceObject;
78 
82  }
83 
84  Irp = IrpContext->Irp;
86 
87  Vcb = (PRFSD_VCB) IrpSp->FileObject->FsContext;
88 
89  if (!((Vcb) && (Vcb->Identifier.Type == RFSDVCB) &&
90  (Vcb->Identifier.Size == sizeof(RFSD_VCB)))) {
93  }
94 
95  TargetDeviceObject = Vcb->TargetDeviceObject;
96 
97  //
98  // Pass on the IOCTL to the driver below
99  //
100 
102 
103  NextIrpSp = IoGetNextIrpStackLocation( Irp );
104  *NextIrpSp = *IrpSp;
105 
107  Irp,
109  NULL,
110  FALSE,
111  TRUE,
112  TRUE );
113 
115 
116  } _SEH2_FINALLY {
117 
118  if (!IrpContext->ExceptionInProgress) {
119  if (IrpContext) {
120  if (!CompleteRequest) {
121  IrpContext->Irp = NULL;
122  }
123 
124  RfsdCompleteIrpContext(IrpContext, Status);
125  }
126  }
127  } _SEH2_END;
128 
129  return Status;
130 }
131 
132 #if RFSD_UNLOAD
133 
135 NTSTATUS
137 {
140  BOOLEAN GlobalDataResourceAcquired = FALSE;
141 
142  PAGED_CODE();
143 
144  _SEH2_TRY {
145 
146  ASSERT(IrpContext != NULL);
147 
148  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
149  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
150 
151  DeviceObject = IrpContext->DeviceObject;
152 
155  _SEH2_LEAVE;
156  }
157 
160  TRUE );
161 
162  GlobalDataResourceAcquired = TRUE;
163 
165  RfsdPrint((DBG_ERROR, "RfsdPrepareUnload: Already ready to unload.\n"));
166 
168 
169  _SEH2_LEAVE;
170  }
171 
172  {
173  PRFSD_VCB Vcb;
174  PLIST_ENTRY ListEntry;
175 
176  ListEntry = RfsdGlobal->VcbList.Flink;
177 
178  while (ListEntry != &(RfsdGlobal->VcbList)) {
179 
180  Vcb = CONTAINING_RECORD(ListEntry, RFSD_VCB, Next);
181  ListEntry = ListEntry->Flink;
182 
183  if (Vcb && (!Vcb->ReferenceCount) &&
184  IsFlagOn(Vcb->Flags, VCB_DISMOUNT_PENDING)) {
187 
188  RfsdFreeVcb(Vcb);
189  }
190  }
191  }
192 
193  if (!IsListEmpty(&(RfsdGlobal->VcbList))) {
194 
195  RfsdPrint((DBG_ERROR, "RfsdPrepareUnload: Mounted volumes exists.\n"));
196 
198 
199  _SEH2_LEAVE;
200  }
201 
203 
204 #ifdef _MSC_VER
205 #pragma prefast( suppress: 28175, "allowed to unload" )
206 #endif
208 
210 
211  RfsdPrint((DBG_INFO, "RfsdPrepareToUnload: Driver is ready to unload.\n"));
212 
214 
215  } _SEH2_FINALLY {
216 
217  if (GlobalDataResourceAcquired) {
221  );
222  }
223 
224  if (!IrpContext->ExceptionInProgress) {
225  RfsdCompleteIrpContext(IrpContext, Status);
226  }
227  } _SEH2_END;
228 
229  return Status;
230 }
231 
232 #endif
233 
235 NTSTATUS
237 {
238  PIRP Irp;
239  PIO_STACK_LOCATION IoStackLocation;
242 
243  PAGED_CODE();
244 
245  ASSERT(IrpContext);
246 
247  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
248  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
249 
250  Irp = IrpContext->Irp;
251 
252  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
253 
254  IoControlCode =
255  IoStackLocation->Parameters.DeviceIoControl.IoControlCode;
256 
257  switch (IoControlCode) {
258 
259 #if RFSD_UNLOAD
260  case IOCTL_PREPARE_TO_UNLOAD:
261  Status = RfsdPrepareToUnload(IrpContext);
262  break;
263 #endif
264  default:
265  Status = RfsdDeviceControlNormal(IrpContext);
266  }
267 
268  return Status;
269 }
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#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
_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
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1061
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
LIST_ENTRY VcbList
Definition: rfsd.h:410
Definition: rfsd.h:323
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define PAGED_CODE()
Definition: video.h:57
PDEVICE_OBJECT DeviceObject
Definition: rfsd.h:407
_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 RfsdDeviceControlNormal(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: devctl.c:52
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
VOID RfsdFreeVcb(IN PRFSD_VCB Vcb)
Definition: memory.c:1581
PRFSD_GLOBAL RfsdGlobal
Definition: init.c:17
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: rfsd.h:326
VOID RfsdRemoveVcb(PRFSD_VCB Vcb)
Definition: memory.c:1244
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
__drv_mustHoldCriticalRegion NTSTATUS RfsdDeviceControl(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: devctl.c:236
struct _RFSD_VCB * PRFSD_VCB
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
ULONG Flags
Definition: rfsd.h:431
if(!(yy_init))
Definition: macro.lex.yy.c:714
PDRIVER_OBJECT DriverObject
Definition: rfsd.h:404
#define Vcb
Definition: cdprocs.h:1425
NTSTATUS NTAPI RfsdDeviceControlCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: devctl.c:40
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
ERESOURCE Resource
Definition: rfsd.h:388
NTSTATUS NTAPI CompleteRequest(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: dispatch.c:19
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define VCB_DISMOUNT_PENDING
Definition: ext2fs.h:782
#define RfsdPrint(arg)
Definition: rfsd.h:1069
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
#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
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
NTSTATUS RfsdPrepareToUnload(IN PRFSD_IRP_CONTEXT IrpContext)
_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
VOID RfsdClearVpbFlag(IN PVPB Vpb, IN USHORT Flag)
Definition: fsctl.c:62
#define RFSD_UNLOAD_PENDING
Definition: rfsd.h:447
#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:2966
IoMarkIrpPending(Irp)
#define VPB_MOUNTED
Definition: iotypes.h:1764