ReactOS  0.4.13-dev-100-gc8611ae
cleanup.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: cleanup.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, RfsdCleanup)
23 #endif
24 
28 {
31  PRFSD_VCB Vcb = 0;
32  BOOLEAN VcbResourceAcquired = FALSE;
34  PRFSD_FCB Fcb = 0;
35  BOOLEAN FcbResourceAcquired = FALSE;
36  BOOLEAN FcbPagingIoAcquired = FALSE;
37  PRFSD_CCB Ccb;
38  PIRP Irp;
39 
40  PAGED_CODE();
41 
42  _SEH2_TRY {
43 
44  ASSERT(IrpContext != NULL);
45 
46  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
47  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
48 
49  DeviceObject = IrpContext->DeviceObject;
50 
54  }
55 
57 
58  ASSERT(Vcb != NULL);
59 
60  ASSERT((Vcb->Identifier.Type == RFSDVCB) &&
61  (Vcb->Identifier.Size == sizeof(RFSD_VCB)));
62 
63  if (!IsFlagOn(Vcb->Flags, VCB_INITIALIZED)) {
66  }
67 
68 #ifdef _MSC_VER
69 #pragma prefast( suppress: 28137, "by design" )
70 #endif
72  &Vcb->MainResource,
73  IrpContext->IsSynchronous
74  )) {
77  }
78 
79  VcbResourceAcquired = TRUE;
80 
81  FileObject = IrpContext->FileObject;
82 
83  Fcb = (PRFSD_FCB) FileObject->FsContext;
84 
85  if (!Fcb) {
88  }
89 
90  if (Fcb->Identifier.Type == RFSDVCB) {
91  if (IsFlagOn(Vcb->Flags, VCB_VOLUME_LOCKED) &&
92  (Vcb->LockFile == FileObject) ) {
94  Vcb->LockFile = NULL;
95 
97  }
98 
99  Vcb->OpenHandleCount--;
100 
101  if (!Vcb->OpenHandleCount) {
102  IoRemoveShareAccess(FileObject, &Vcb->ShareAccess);
103  }
104 
106  _SEH2_LEAVE;
107  }
108 
109  ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
110  (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
111 
112 /*
113  if ( !IsFlagOn(Vcb->Flags, VCB_READ_ONLY) &&
114  !IsFlagOn(Fcb->Flags, FCB_PAGE_FILE))
115 */
116  {
117 #ifdef _MSC_VER
118 #pragma prefast( suppress: 28137, "by design" )
119 #endif
121  &Fcb->MainResource,
122  IrpContext->IsSynchronous
123  ))
124  {
126  _SEH2_LEAVE;
127  }
128 
129  FcbResourceAcquired = TRUE;
130  }
131 
132  Ccb = (PRFSD_CCB) FileObject->FsContext2;
133 
134  if (!Ccb) {
136  _SEH2_LEAVE;
137  }
138 
139  if (IsFlagOn(FileObject->Flags, FO_CLEANUP_COMPLETE)) {
140  if ( IsFlagOn(FileObject->Flags, FO_FILE_MODIFIED) &&
141  IsFlagOn(Vcb->Flags, VCB_FLOPPY_DISK) &&
142  !IsFlagOn(Vcb->Flags, VCB_WRITE_PROTECTED) ) {
144  }
145  _SEH2_LEAVE;
146  }
147 
148  ASSERT((Ccb->Identifier.Type == RFSDCCB) &&
149  (Ccb->Identifier.Size == sizeof(RFSD_CCB)));
150  Irp = IrpContext->Irp;
151 
152  Fcb->OpenHandleCount--;
153 
154  if (!IsFlagOn(FileObject->Flags, FO_CACHE_SUPPORTED )) {
155  Fcb->NonCachedOpenCount--;
156  }
157 
158  Vcb->OpenFileHandleCount--;
159 
162 
163  if (IsDirectory(Fcb)) {
165  Vcb->NotifySync,
166  &Vcb->NotifyList,
167  Fcb,
168  NULL,
169  FALSE,
170  FALSE,
171  0,
172  NULL,
173  NULL,
174  NULL );
175  }
176  }
177 
178  if (IsDirectory(Fcb)) {
179 
181  Vcb->NotifySync,
182  &Vcb->NotifyList,
183  Ccb );
184 
185  } else {
186 
187  //
188  // Drop any byte range locks this process may have on the file.
189  //
190 
192  &Fcb->FileLockAnchor,
193  FileObject,
195  NULL );
196 
197  //
198  // If there are no byte range locks owned by other processes on the
199  // file the fast I/O read/write functions doesn't have to check for
200  // locks so we set IsFastIoPossible to FastIoIsPossible again.
201  //
202  if (!FsRtlGetNextFileLock(&Fcb->FileLockAnchor, TRUE)) {
203  if (Fcb->Header.IsFastIoPossible != FastIoIsPossible) {
204  RfsdPrint((
205  DBG_INFO, ": %-16.16s %-31s %s\n",
207  "FastIoIsPossible",
208  Fcb->AnsiFileName.Buffer
209  ));
210 
211  Fcb->Header.IsFastIoPossible = FastIoIsPossible;
212  }
213  }
214  }
215 
216  if ( IsFlagOn( FileObject->Flags, FO_CACHE_SUPPORTED) &&
217  (Fcb->NonCachedOpenCount != 0) &&
218  (Fcb->NonCachedOpenCount == Fcb->ReferenceCount) &&
219  (Fcb->SectionObject.DataSectionObject != NULL)) {
220 
221  if( !IsFlagOn(Vcb->Flags, VCB_READ_ONLY) &&
222  !IsFlagOn(Vcb->Flags, VCB_WRITE_PROTECTED)) {
223  CcFlushCache(&Fcb->SectionObject, NULL, 0, NULL);
224  }
225 
228 
229  CcPurgeCacheSection( &Fcb->SectionObject,
230  NULL,
231  0,
232  FALSE );
233  }
234 
235  if (Fcb->OpenHandleCount == 0) {
236 
238  //
239  // Have to delete this file...
240  //
241 
242 #ifdef _MSC_VER
243 #pragma prefast( suppress: 28137, "by design" )
244 #endif
247  IrpContext->IsSynchronous
248  )) {
250  _SEH2_LEAVE;
251  }
252 
253  FcbPagingIoAcquired = TRUE;
254 DbgBreak();
255 #if DISABLED
256  Status = RfsdDeleteFile(IrpContext, Vcb, Fcb);
257 
258  if (NT_SUCCESS(Status)) {
259  if (IsDirectory(Fcb)) {
260  RfsdNotifyReportChange( IrpContext, Vcb, Fcb,
263  } else {
264  RfsdNotifyReportChange( IrpContext, Vcb, Fcb,
267  }
268  }
269 #endif
270  if (CcIsFileCached(FileObject)) {
271 
273  (PCC_FILE_SIZES)(&(Fcb->Header.AllocationSize)));
275  }
276 
277  if (FcbPagingIoAcquired) {
281 
282  FcbPagingIoAcquired = FALSE;
283  }
284  }
285  }
286 
287  if (!IsDirectory(Fcb) && FileObject->PrivateCacheMap) {
288  RfsdPrint((DBG_INFO, "RfsdCleanup: CcUninitializeCacheMap is called for %s.\n",
289  Fcb->AnsiFileName.Buffer ));
290 
292  FileObject,
293  (PLARGE_INTEGER)(&(Fcb->Header.FileSize)),
294  NULL );
295  }
296 
297  if (!Fcb->OpenHandleCount) {
299  }
300 
301  RfsdPrint((DBG_INFO, "RfsdCleanup: OpenCount: %u ReferCount: %u %s\n",
302  Fcb->OpenHandleCount, Fcb->ReferenceCount, Fcb->AnsiFileName.Buffer ));
303 
305 
306  if (FileObject) {
308  }
309 
310  } _SEH2_FINALLY {
311 
312  if (FcbPagingIoAcquired) {
316  }
317 
318  if (FcbResourceAcquired) {
320  &Fcb->MainResource,
322  }
323 
324  if (VcbResourceAcquired) {
326  &Vcb->MainResource,
328  }
329 
330  if (!IrpContext->ExceptionInProgress) {
331  if (Status == STATUS_PENDING) {
332  RfsdQueueRequest(IrpContext);
333  } else {
334  IrpContext->Irp->IoStatus.Status = Status;
335  RfsdCompleteIrpContext(IrpContext, Status);
336  }
337  }
338  } _SEH2_END;
339 
340  return Status;
341 }
struct _RFSD_CCB * PRFSD_CCB
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
PEPROCESS NTAPI IoGetRequestorProcess(IN PIRP Irp)
Definition: irp.c:1782
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
#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
#define __drv_mustHoldCriticalRegion
Definition: ffsdrv.h:34
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:931
VOID NTAPI FsRtlNotifyFullChangeDirectory(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext, IN PSTRING FullDirectoryName, IN BOOLEAN WatchTree, IN BOOLEAN IgnoreBuffer, IN ULONG CompletionFilter, IN PIRP NotifyIrp, IN PCHECK_FOR_TRAVERSE_ACCESS TraverseCallback OPTIONAL, IN PSECURITY_SUBJECT_CONTEXT SubjectContext OPTIONAL)
Definition: notify.c:1458
_In_ PIRP Irp
Definition: csq.h:116
VOID RfsdNotifyReportChange(IN PRFSD_IRP_CONTEXT IrpContext, IN PRFSD_VCB Vcb, IN PRFSD_FCB Fcb, IN ULONG Filter, IN ULONG Action)
Definition: dirctl.c:745
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_NOTIFY_CHANGE_FILE_NAME
NTSTATUS RfsdFlushFile(IN PRFSD_FCB Fcb)
Definition: flush.c:119
NTSTATUS RfsdQueueRequest(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: dispatch.c:29
#define FILE_NOTIFY_CHANGE_DIR_NAME
Definition: rfsd.h:323
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3477
#define FCB_DELETE_PENDING
Definition: ext2fs.h:879
#define PAGED_CODE()
Definition: video.h:57
PDEVICE_OBJECT DeviceObject
Definition: rfsd.h:407
_SEH2_TRY
Definition: create.c:4250
#define FCB_DELETE_ON_CLOSE
Definition: ffsdrv.h:633
Definition: rfsd.h:324
VOID NTAPI FsRtlNotifyCleanup(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext)
Definition: notify.c:635
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define FO_FILE_MODIFIED
Definition: iotypes.h:1744
struct _RFSD_FCB * PRFSD_FCB
NTFSIDENTIFIER Identifier
Definition: ntfs.h:499
#define CcIsFileCached(FO)
#define VPB_LOCKED
Definition: iotypes.h:1764
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
PRFSD_GLOBAL RfsdGlobal
Definition: init.c:17
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ACTION_REMOVED
Definition: rfsd.h:326
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PFILE_LOCK_INFO NTAPI FsRtlGetNextFileLock(IN PFILE_LOCK FileLock, IN BOOLEAN Restart)
Definition: filelock.c:259
struct _RFSD_VCB * PRFSD_VCB
ULONG OpenHandleCount
Definition: ntfs.h:521
SHARE_ACCESS ShareAccess
Definition: cdstruc.h:1015
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define RfsdGetCurrentProcessName()
Definition: rfsd.h:1095
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS RfsdDeleteFile(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb, PRFSD_FCB Fcb)
Definition: fileinfo.c:1417
#define Vcb
Definition: cdprocs.h:1425
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1954
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1737
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG Flags
Definition: ntfs.h:520
#define VCB_WRITE_PROTECTED
Definition: ext2fs.h:796
_Must_inspect_result_ _In_ PFLT_INSTANCE _Out_ PBOOLEAN IsDirectory
Definition: fltkernel.h:1139
#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
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
Definition: filelock.c:1026
ERESOURCE MainResource
Definition: ntfs.h:512
#define VCB_READ_ONLY
Definition: ext2fs.h:795
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
Definition: rfsd.h:325
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
#define VCB_FLOPPY_DISK
Definition: ext2fs.h:797
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1746
VOID NTAPI CcSetFileSizes(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
Definition: fssup.c:354
_SEH2_FINALLY
Definition: create.c:4395
#define VCB_VOLUME_LOCKED
Definition: ext2fs.h:780
ERESOURCE PagingIoResource
Definition: ntfs.h:511
#define DbgBreak()
Definition: ext2fs.h:46
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 VCB_INITIALIZED
Definition: ext2fs.h:779
#define _SEH2_LEAVE
Definition: filesup.c:20
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2725
ULONG Size
Definition: ntfs.h:96
__drv_mustHoldCriticalRegion NTSTATUS RfsdCleanup(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: cleanup.c:27