ReactOS  0.4.13-dev-961-g238ea69
close.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: close.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, RfsdClose)
23 #pragma alloc_text(PAGE, RfsdQueueCloseRequest)
24 #pragma alloc_text(PAGE, RfsdDeQueueCloseRequest)
25 #endif
26 
30 {
33  PRFSD_VCB Vcb = 0;
34  BOOLEAN VcbResourceAcquired = FALSE;
36  PRFSD_FCB Fcb = 0;
37  BOOLEAN FcbResourceAcquired = FALSE;
38  PRFSD_CCB Ccb;
39  BOOLEAN FreeVcb = FALSE;
40 
41  PAGED_CODE();
42 
43  _SEH2_TRY
44  {
45  ASSERT(IrpContext != NULL);
46 
47  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
48  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
49 
50  DeviceObject = IrpContext->DeviceObject;
51 
53  {
56  }
57 
59 
60  ASSERT(Vcb != NULL);
61 
62  ASSERT((Vcb->Identifier.Type == RFSDVCB) &&
63  (Vcb->Identifier.Size == sizeof(RFSD_VCB)));
64 
66 
67 #ifdef _MSC_VER
68 #pragma prefast( suppress: 28137, "by design" )
69 #endif
71  &Vcb->MainResource,
72  IrpContext->IsSynchronous )) {
73  RfsdPrint((DBG_INFO, "RfsdClose: PENDING ... Vcb: %xh/%xh\n",
74  Vcb->OpenFileHandleCount, Vcb->ReferenceCount));
75 
78  }
79 
80  VcbResourceAcquired = TRUE;
81 
82  FileObject = IrpContext->FileObject;
83 
84  if (IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_DELAY_CLOSE)) {
85  Fcb = IrpContext->Fcb;
86  Ccb = IrpContext->Ccb;
87  } else {
88  Fcb = (PRFSD_FCB) FileObject->FsContext;
89 
90  if (!Fcb)
91  {
94  }
95 
96  ASSERT(Fcb != NULL);
97 
98  Ccb = (PRFSD_CCB) FileObject->FsContext2;
99  }
100 
101  if (Fcb->Identifier.Type == RFSDVCB) {
102 
103  Vcb->ReferenceCount--;
104 
105  if (!Vcb->ReferenceCount && FlagOn(Vcb->Flags, VCB_DISMOUNT_PENDING))
106  {
107  FreeVcb = TRUE;
108  }
109 
110  if (Ccb) {
111  RfsdFreeCcb(Ccb);
112 
113  if (FileObject) {
114  FileObject->FsContext2 = Ccb = NULL;
115  }
116  }
117 
119 
120  _SEH2_LEAVE;
121  }
122 
123  if (Fcb->Identifier.Type != RFSDFCB || Fcb->Identifier.Size != sizeof(RFSD_FCB)) {
124 
125 #if DBG
126  RfsdPrint((DBG_ERROR, "RfsdClose: Strange IRP_MJ_CLOSE by system!\n"));
129  TRUE );
130 
131  RfsdGlobal->IRPCloseCount++;
132 
136 #endif
137  _SEH2_LEAVE;
138  }
139 
140  ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
141  (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
142 
143 /*
144  if ( (!IsFlagOn(Vcb->Flags, VCB_READ_ONLY)) &&
145  (!IsFlagOn(Fcb->Flags, FCB_PAGE_FILE)) )
146 */
147  {
148 #ifdef _MSC_VER
149 #pragma prefast( suppress: 28137, "by design" )
150 #endif
152  &Fcb->MainResource,
153  IrpContext->IsSynchronous )) {
155  _SEH2_LEAVE;
156  }
157 
158  FcbResourceAcquired = TRUE;
159  }
160 
161  if (!Ccb) {
163  _SEH2_LEAVE;
164  }
165 
166  ASSERT((Ccb->Identifier.Type == RFSDCCB) &&
167  (Ccb->Identifier.Size == sizeof(RFSD_CCB)));
168 
169  Fcb->ReferenceCount--;
170  Vcb->ReferenceCount--;
171 
172  if (!Vcb->ReferenceCount && IsFlagOn(Vcb->Flags, VCB_DISMOUNT_PENDING)) {
173  FreeVcb = TRUE;
174  }
175 
176  RfsdPrint((DBG_INFO, "RfsdClose: OpenHandleCount: %u ReferenceCount: %u %s\n",
177  Fcb->OpenHandleCount, Fcb->ReferenceCount, Fcb->AnsiFileName.Buffer ));
178 
179  if (Ccb) {
180 
181  RfsdFreeCcb(Ccb);
182 
183  if (FileObject) {
184  FileObject->FsContext2 = Ccb = NULL;
185  }
186  }
187 
188  if (!Fcb->ReferenceCount) {
189  //
190  // Remove Fcb from Vcb->FcbList ...
191  //
192 
193  RemoveEntryList(&Fcb->Next);
194 
195  RfsdFreeFcb(Fcb);
196 
197  FcbResourceAcquired = FALSE;
198  }
199 
201 
202  } _SEH2_FINALLY {
203 
204  if (FcbResourceAcquired) {
206  &Fcb->MainResource,
208  }
209 
210  if (VcbResourceAcquired) {
212  &Vcb->MainResource,
214  }
215 
216  if (!IrpContext->ExceptionInProgress) {
217  if (Status == STATUS_PENDING) {
218 
219  RfsdQueueCloseRequest(IrpContext);
220 /*
221 
222  Status = STATUS_SUCCESS;
223 
224  if (IrpContext->Irp != NULL)
225  {
226  IrpContext->Irp->IoStatus.Status = Status;
227 
228  RfsdCompleteRequest(
229  IrpContext->Irp,
230  !IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_REQUEUED),
231  (CCHAR)
232  (NT_SUCCESS(Status) ? IO_DISK_INCREMENT : IO_NO_INCREMENT)
233  );
234 
235  IrpContext->Irp = NULL;
236  }
237 */
238  } else {
239 
240  RfsdCompleteIrpContext(IrpContext, Status);
241 
242  if (FreeVcb) {
243 
245  &RfsdGlobal->Resource, TRUE );
246 
248 
250 
254 
255  RfsdFreeVcb(Vcb);
256  }
257  }
258  }
259  } _SEH2_END;
260 
261  return Status;
262 }
263 
264 VOID
266 {
267  PAGED_CODE();
268 
269  ASSERT(IrpContext);
270 
271  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
272  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
273 
274  if (!IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_DELAY_CLOSE)) {
275  SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_DELAY_CLOSE);
276 
277  IrpContext->Fcb = (PRFSD_FCB) IrpContext->FileObject->FsContext;
278  IrpContext->Ccb = (PRFSD_CCB) IrpContext->FileObject->FsContext2;
279 
280  IrpContext->FileObject = NULL;
281  }
282 
283  // IsSynchronous means we can block (so we don't requeue it)
284  IrpContext->IsSynchronous = TRUE;
285 
287  &IrpContext->WorkQueueItem,
289  IrpContext);
290 
291  ExQueueWorkItem(&IrpContext->WorkQueueItem, CriticalWorkQueue);
292 }
293 
294 VOID NTAPI
296 {
297  PRFSD_IRP_CONTEXT IrpContext;
298 
299  PAGED_CODE();
300 
301  IrpContext = (PRFSD_IRP_CONTEXT) Context;
302 
303  ASSERT(IrpContext);
304 
305  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
306  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
307 
308  _SEH2_TRY {
309 
310  _SEH2_TRY {
311 
313  RfsdClose(IrpContext);
314 
316 
317  RfsdExceptionHandler(IrpContext);
318  } _SEH2_END;
319 
320  } _SEH2_FINALLY {
321 
323  } _SEH2_END;
324 }
struct _RFSD_CCB * PRFSD_CCB
NTSTATUS RfsdExceptionHandler(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: except.c:103
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define IN
Definition: typedefs.h:38
#define IsMounted(Vcb)
Definition: ext2fs.h:803
NTSTATUS RfsdCompleteIrpContext(IN PRFSD_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: memory.c:160
#define TRUE
Definition: types.h:120
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
#define FsRtlEnterFileSystem
#define __drv_mustHoldCriticalRegion
Definition: ffsdrv.h:34
#define FsRtlExitFileSystem
__drv_mustHoldCriticalRegion NTSTATUS RfsdClose(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: close.c:29
VOID RfsdFreeFcb(IN PRFSD_FCB Fcb)
Definition: memory.c:541
PRFSD_GLOBAL RfsdGlobal
Definition: init.c:17
LONG NTSTATUS
Definition: precomp.h:26
Definition: rfsd.h:323
#define PAGED_CODE()
Definition: video.h:57
PDEVICE_OBJECT DeviceObject
Definition: rfsd.h:407
_SEH2_TRY
Definition: create.c:4250
#define IRP_CONTEXT_FLAG_DELAY_CLOSE
Definition: ext2fs.h:1087
Definition: rfsd.h:324
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
struct _RFSD_FCB * PRFSD_FCB
NTFSIDENTIFIER Identifier
Definition: ntfs.h:511
VOID RfsdQueueCloseRequest(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: close.c:265
ERESOURCE CountResource
Definition: rfsd.h:391
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
VOID RfsdFreeVcb(IN PRFSD_VCB Vcb)
Definition: memory.c:1581
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
NTSTATUS RfsdExceptionFilter(IN PRFSD_IRP_CONTEXT IrpContext, IN PEXCEPTION_POINTERS ExceptionPointer)
Definition: except.c:27
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
RFSD_IDENTIFIER_TYPE Type
Definition: rfsd.h:336
Definition: rfsd.h:326
VOID RfsdRemoveVcb(PRFSD_VCB Vcb)
Definition: memory.c:1244
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
struct _RFSD_VCB * PRFSD_VCB
ULONG OpenHandleCount
Definition: ntfs.h:533
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define STATUS_PENDING
Definition: ntstatus.h:82
#define Vcb
Definition: cdprocs.h:1425
RFSD_IDENTIFIER Identifier
Definition: rfsd.h:755
ERESOURCE Resource
Definition: rfsd.h:388
VOID NTAPI RfsdDeQueueCloseRequest(IN PVOID Context)
Definition: close.c:295
* PFILE_OBJECT
Definition: iotypes.h:1954
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define VCB_DISMOUNT_PENDING
Definition: ext2fs.h:782
#define RfsdPrint(arg)
Definition: rfsd.h:1069
ULONG Type
Definition: ntfs.h:95
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define DBG_ERROR
Definition: ffsdrv.h:1031
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
struct _RFSD_IRP_CONTEXT * PRFSD_IRP_CONTEXT
ERESOURCE MainResource
Definition: ntfs.h:524
Definition: rfsd.h:325
Status
Definition: gdiplustypes.h:24
struct _FCB::@691::@694 Fcb
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
_SEH2_FINALLY
Definition: create.c:4395
VOID RfsdFreeCcb(IN PRFSD_CCB Ccb)
Definition: memory.c:661
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
ULONG Size
Definition: rfsd.h:337
#define DBG_INFO
Definition: ffsdrv.h:1034
VOID RfsdClearVpbFlag(IN PVPB Vpb, IN USHORT Flag)
Definition: fsctl.c:62
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_LEAVE
Definition: filesup.c:20
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2777
#define VPB_MOUNTED
Definition: iotypes.h:1763
ULONG Size
Definition: ntfs.h:96