ReactOS  0.4.14-dev-323-g6fe6a88
pnp.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: pnp.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 #define DBG_PNP DBG_USER
22 
23 #ifdef _PREFAST_
24 IO_COMPLETION_ROUTINE RfsdPnpCompletionRoutine;
25 #endif // _PREFAST_
26 
30  IN PIRP Irp,
31  IN PVOID Contxt );
32 
33 #ifdef ALLOC_PRAGMA
34 #pragma alloc_text(PAGE, RfsdPnp)
35 #pragma alloc_text(PAGE, RfsdPnpQueryRemove)
36 #pragma alloc_text(PAGE, RfsdPnpRemove)
37 #pragma alloc_text(PAGE, RfsdPnpCancelRemove)
38 #pragma alloc_text(PAGE, RfsdPnpSurpriseRemove)
39 #endif
40 
41 /* FUNCTIONS *************************************************************/
42 
43 #if (_WIN32_WINNT >= 0x0500)
44 
48  IN PIRP Irp,
49  IN PVOID Contxt
50  )
51 {
52  PKEVENT Event = (PKEVENT) Contxt;
53 
54  KeSetEvent( Event, 0, FALSE );
55 
57 
59  UNREFERENCED_PARAMETER( Contxt );
60 }
61 
64 RfsdPnp (IN PRFSD_IRP_CONTEXT IrpContext)
65 {
67  PIRP Irp;
69  PRFSD_VCB Vcb = 0;
71 
72  PAGED_CODE();
73 
74  _SEH2_TRY {
75 
76  ASSERT(IrpContext);
77 
78  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
79  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
80 
81  DeviceObject = IrpContext->DeviceObject;
82 
84 
85  ASSERT(Vcb != NULL);
86 
87  if ( !((Vcb->Identifier.Type == RFSDVCB) &&
88  (Vcb->Identifier.Size == sizeof(RFSD_VCB)))) {
89  _SEH2_LEAVE; // Status = STATUS_INVALID_PARAMETER
90  }
91 
92  Irp = IrpContext->Irp;
94 
95  SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT);
96 
97  switch ( IrpSp->MinorFunction ) {
98 
100 
101  RfsdPrint((DBG_PNP, "RfsdPnp: RfsdPnpQueryRemove...\n"));
102  Status = RfsdPnpQueryRemove(IrpContext, Vcb);
103 
104  break;
105 
107 
108  RfsdPrint((DBG_PNP, "RfsdPnp: RfsdPnpRemove...\n"));
109  Status = RfsdPnpRemove(IrpContext, Vcb);
110  break;
111 
113 
114  RfsdPrint((DBG_PNP, "RfsdPnp: RfsdPnpCancelRemove...\n"));
115  Status = RfsdPnpCancelRemove(IrpContext, Vcb);
116  break;
117 
119 
120  RfsdPrint((DBG_PNP, "RfsdPnp: RfsdPnpSupriseRemove...\n"));
121  Status = RfsdPnpSurpriseRemove(IrpContext, Vcb);
122  break;
123 
124  default:
125  break;
126  }
127 
128  } _SEH2_FINALLY {
129 
130  if (!IrpContext->ExceptionInProgress) {
131  Irp = IrpContext->Irp;
132 
133  if (Irp) {
134 
135  //
136  // Here we need pass the IRP to the disk driver.
137  //
138 
140 
141  Status = IoCallDriver(Vcb->TargetDeviceObject, Irp);
142 
143  IrpContext->Irp = NULL;
144  }
145 
146  RfsdCompleteIrpContext(IrpContext, Status);
147  }
148  } _SEH2_END;
149 
150  return Status;
151 }
152 
154 NTSTATUS
156  PRFSD_IRP_CONTEXT IrpContext,
157  PRFSD_VCB Vcb
158  )
159 
160 {
162  KEVENT Event;
163  BOOLEAN bDeleted = FALSE;
164  BOOLEAN VcbAcquired = FALSE;
165 
166  PAGED_CODE();
167 
168  _SEH2_TRY {
169 
170  RfsdPrint((DBG_PNP, "RfsdPnpQueryRemove by RfsdPnp ...\n"));
171 
172  RfsdPrint((DBG_PNP, "RfsdPnpQueryRemove: RfsdFlushVolume ...\n"));
173 
174 #if (_WIN32_WINNT >= 0x0500)
176 #endif
177 
179  &Vcb->MainResource, TRUE );
180  VcbAcquired = TRUE;
181 
183 
185 
186  RfsdPrint((DBG_PNP, "RfsdPnpQueryRemove: RfsdLockVcb: Vcb=%xh FileObject=%xh ...\n",
187  Vcb, IrpContext->FileObject));
188  Status = RfsdLockVcb(Vcb, IrpContext->FileObject);
189 
190  RfsdPrint((DBG_PNP, "RfsdPnpQueryRemove: RfsdPurgeVolume ...\n"));
192 
193  if (!NT_SUCCESS(Status)) {
194  _SEH2_LEAVE;
195  }
196 
198  &Vcb->MainResource,
200  VcbAcquired = FALSE;
201 
203 
205  IoSetCompletionRoutine( IrpContext->Irp,
207  &Event,
208  TRUE,
209  TRUE,
210  TRUE );
211 
212  RfsdPrint((DBG_PNP, "RfsdPnpQueryRemove: Call lower level driver...\n"));
213  Status = IoCallDriver( Vcb->TargetDeviceObject,
214  IrpContext->Irp);
215 
216  if (Status == STATUS_PENDING) {
217 
219  Executive,
220  KernelMode,
221  FALSE,
222  NULL );
223 
224  Status = IrpContext->Irp->IoStatus.Status;
225  }
226 
227  if (NT_SUCCESS(Status)) {
228  RfsdPrint((DBG_PNP, "RfsdPnpQueryRemove: RfsdCheckDismount ...\n"));
229  bDeleted = RfsdCheckDismount(IrpContext, Vcb, TRUE);
230  RfsdPrint((DBG_PNP, "RfsdPnpQueryRemove: RfsdFlushVolume bDelted=%xh ...\n", bDeleted));
231  }
232 
233  ASSERT( !(NT_SUCCESS(Status) && !bDeleted));
234 
235  } _SEH2_FINALLY {
236 
237  if (VcbAcquired) {
239  &Vcb->MainResource,
241  }
242 
244  IrpContext->Irp, FALSE, (CCHAR)(NT_SUCCESS(Status)?
246 
247  IrpContext->Irp = NULL;
248  } _SEH2_END;
249 
250  return Status;
251 }
252 
254 NTSTATUS
256  PRFSD_IRP_CONTEXT IrpContext,
257  PRFSD_VCB Vcb )
258 {
260  KEVENT Event;
261  BOOLEAN bDeleted;
262 
263  PAGED_CODE();
264 
265  _SEH2_TRY {
266 
267  RfsdPrint((DBG_PNP, "RfsdPnpRemove by RfsdPnp ...\n"));
268 #if (_WIN32_WINNT >= 0x0500)
270 #endif
272  &Vcb->MainResource, TRUE );
273 
274  Status = RfsdLockVcb(Vcb, IrpContext->FileObject);
275 
277  &Vcb->MainResource,
279 
280  //
281  // Setup the Irp. We'll send it to the lower disk driver.
282  //
283 
285 
287  IoSetCompletionRoutine( IrpContext->Irp,
289  &Event,
290  TRUE,
291  TRUE,
292  TRUE );
293 
294  Status = IoCallDriver( Vcb->TargetDeviceObject,
295  IrpContext->Irp);
296 
297  if (Status == STATUS_PENDING) {
298 
300  Executive,
301  KernelMode,
302  FALSE,
303  NULL );
304 
305  Status = IrpContext->Irp->IoStatus.Status;
306  }
307 
309  &Vcb->MainResource, TRUE );
310 
312 
314  &Vcb->MainResource,
316 
317  bDeleted = RfsdCheckDismount(IrpContext, Vcb, TRUE);
318 
319  } _SEH2_FINALLY {
321  IrpContext->Irp, FALSE, (CCHAR)(NT_SUCCESS(Status)?
323 
324  IrpContext->Irp = NULL;
325  } _SEH2_END;
326 
327  return Status;
328 }
329 
331 NTSTATUS
333  PRFSD_IRP_CONTEXT IrpContext,
334  PRFSD_VCB Vcb )
335 {
337  KEVENT Event;
338  BOOLEAN bDeleted;
339 
340  PAGED_CODE();
341 
342  _SEH2_TRY {
343 
344  RfsdPrint((DBG_PNP, "RfsdPnpSupriseRemove by RfsdPnp ...\n"));
345 #if (_WIN32_WINNT >= 0x0500)
347 #endif
349  &Vcb->MainResource, TRUE );
350 
351  Status = RfsdLockVcb(Vcb, IrpContext->FileObject);
352 
354  &Vcb->MainResource,
356 
357  //
358  // Setup the Irp. We'll send it to the lower disk driver.
359  //
360 
362 
364  IoSetCompletionRoutine( IrpContext->Irp,
366  &Event,
367  TRUE,
368  TRUE,
369  TRUE );
370 
371  Status = IoCallDriver( Vcb->TargetDeviceObject,
372  IrpContext->Irp);
373 
374  if (Status == STATUS_PENDING) {
375 
377  Executive,
378  KernelMode,
379  FALSE,
380  NULL );
381 
382  Status = IrpContext->Irp->IoStatus.Status;
383  }
384 
386  &Vcb->MainResource, TRUE );
387 
389 
391  &Vcb->MainResource,
393 
394  bDeleted = RfsdCheckDismount(IrpContext, Vcb, TRUE);
395 
396  } _SEH2_FINALLY {
397 
399  IrpContext->Irp, FALSE, (CCHAR)(NT_SUCCESS(Status)?
401 
402  IrpContext->Irp = NULL;
403  } _SEH2_END;
404 
405  return Status;
406 }
407 
409 NTSTATUS
411  PRFSD_IRP_CONTEXT IrpContext,
412  PRFSD_VCB Vcb
413  )
414 {
416 
417  PAGED_CODE();
418 
419  RfsdPrint((DBG_PNP, "RfsdPnpCancelRemove by RfsdPnp ...\n"));
420 
422  &Vcb->MainResource, TRUE );
423 
424  Status = RfsdUnlockVcb(Vcb, IrpContext->FileObject);
425 
427  &Vcb->MainResource,
429 
430  IoSkipCurrentIrpStackLocation(IrpContext->Irp);
431 
432  Status = IoCallDriver(Vcb->TargetDeviceObject, IrpContext->Irp);
433 
434  IrpContext->Irp = NULL;
435 
436  return Status;
437 }
438 
439 #endif // (_WIN32_WINNT >= 0x0500)
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define IN
Definition: typedefs.h:38
NTSTATUS RfsdUnlockVcb(IN PRFSD_VCB Vcb, IN PFILE_OBJECT FileObject)
Definition: fsctl.c:225
NTSTATUS RfsdCompleteIrpContext(IN PRFSD_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: memory.c:160
#define TRUE
Definition: types.h:120
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1221
struct _KEVENT * PKEVENT
#define IRP_MN_REMOVE_DEVICE
#define __drv_mustHoldCriticalRegion
Definition: ffsdrv.h:34
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS RfsdFlushVolume(IN PRFSD_VCB Vcb, BOOLEAN bShutDown)
Definition: flush.c:97
NTSTATUS RfsdFlushFiles(IN PRFSD_VCB Vcb, BOOLEAN bShutDown)
Definition: flush.c:51
__drv_mustHoldCriticalRegion NTSTATUS RfsdPnpSurpriseRemove(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb)
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
Definition: rfsd.h:323
__drv_mustHoldCriticalRegion NTSTATUS RfsdPnpRemove(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb)
#define PAGED_CODE()
Definition: video.h:57
PFILE_OBJECT FileObject
Definition: rfsd.h:774
_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
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
#define IO_DISK_INCREMENT
Definition: iotypes.h:568
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define IRP_MN_QUERY_REMOVE_DEVICE
__drv_mustHoldCriticalRegion NTSTATUS RfsdPurgeVolume(IN PRFSD_VCB Vcb, IN BOOLEAN FlushBeforePurge)
Definition: fsctl.c:1085
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: rfsd.h:326
#define DBG_PNP
Definition: pnp.c:21
struct _RFSD_VCB * PRFSD_VCB
NTSTATUS NTAPI CcWaitForCurrentLazyWriterActivity(VOID)
Definition: lazyrite.c:30
__drv_mustHoldCriticalRegion NTSTATUS RfsdPnp(IN PRFSD_IRP_CONTEXT IrpContext)
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
char CCHAR
Definition: typedefs.h:50
#define Vcb
Definition: cdprocs.h:1425
NTSTATUS RfsdLockVcb(IN PRFSD_VCB Vcb, IN PFILE_OBJECT FileObject)
Definition: fsctl.c:104
NTSTATUS NTAPI RfsdPnpCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Contxt)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define RfsdPrint(arg)
Definition: rfsd.h:1069
Status
Definition: gdiplustypes.h:24
__drv_mustHoldCriticalRegion NTSTATUS RfsdPnpCancelRemove(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb)
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
_SEH2_END
Definition: create.c:4424
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
PRFSD_GLOBAL RfsdGlobal
Definition: init.c:17
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
_SEH2_FINALLY
Definition: create.c:4395
__drv_mustHoldCriticalRegion NTSTATUS RfsdPnpQueryRemove(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb)
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:566
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
BOOLEAN RfsdCheckDismount(IN PRFSD_IRP_CONTEXT IrpContext, IN PRFSD_VCB Vcb, IN BOOLEAN bForce)
Definition: fsctl.c:1010
#define _SEH2_LEAVE
Definition: filesup.c:20
#define RfsdCompleteRequest(Irp, bPrint, PriorityBoost)
Definition: rfsd.h:1072