ReactOS  0.4.14-dev-41-g31d7680
cleanup.c File Reference
#include "ntifs.h"
#include "ffsdrv.h"
Include dependency graph for cleanup.c:

Go to the source code of this file.

Functions

__drv_mustHoldCriticalRegion NTSTATUS FFSCleanup (IN PFFS_IRP_CONTEXT IrpContext)
 

Variables

PFFS_GLOBAL FFSGlobal
 

Function Documentation

◆ FFSCleanup()

Definition at line 30 of file cleanup.c.

32 {
35  PFFS_VCB Vcb = 0;
36  BOOLEAN VcbResourceAcquired = FALSE;
38  PFFS_FCB Fcb = 0;
39  BOOLEAN FcbResourceAcquired = FALSE;
40  BOOLEAN FcbPagingIoAcquired = FALSE;
41  PFFS_CCB Ccb;
42  PIRP Irp;
43 
44  PAGED_CODE();
45 
46  _SEH2_TRY
47  {
48  ASSERT(IrpContext != NULL);
49 
50  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
51  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
52 
53  DeviceObject = IrpContext->DeviceObject;
54 
56  {
59  }
60 
62 
63  ASSERT(Vcb != NULL);
64 
65  ASSERT((Vcb->Identifier.Type == FFSVCB) &&
66  (Vcb->Identifier.Size == sizeof(FFS_VCB)));
67 
68  if (!IsFlagOn(Vcb->Flags, VCB_INITIALIZED))
69  {
72  }
73 
74 #ifdef _MSC_VER
75 #pragma prefast( suppress: 28137, "by design" )
76 #endif
78  &Vcb->MainResource,
79  IrpContext->IsSynchronous))
80  {
83  }
84 
85  VcbResourceAcquired = TRUE;
86 
87  FileObject = IrpContext->FileObject;
88 
89  Fcb = (PFFS_FCB)FileObject->FsContext;
90 
91  if (!Fcb)
92  {
95  }
96 
97  if (Fcb->Identifier.Type == FFSVCB)
98  {
99  if (IsFlagOn(Vcb->Flags, VCB_VOLUME_LOCKED) &&
100  (Vcb->LockFile == FileObject))
101  {
103  Vcb->LockFile = NULL;
104 
106  }
107 
108  Vcb->OpenHandleCount--;
109 
110  if (!Vcb->OpenHandleCount)
111  {
112  IoRemoveShareAccess(FileObject, &Vcb->ShareAccess);
113  }
114 
116  _SEH2_LEAVE;
117  }
118 
119  ASSERT((Fcb->Identifier.Type == FFSFCB) &&
120  (Fcb->Identifier.Size == sizeof(FFS_FCB)));
121 
122 /*
123  if (!IsFlagOn(Vcb->Flags, VCB_READ_ONLY) &&
124  !IsFlagOn(Fcb->Flags, FCB_PAGE_FILE))
125 */
126  {
127 #ifdef _MSC_VER
128 #pragma prefast( suppress: 28137, "by design" )
129 #endif
131  &Fcb->MainResource,
132  IrpContext->IsSynchronous))
133  {
135  _SEH2_LEAVE;
136  }
137 
138  FcbResourceAcquired = TRUE;
139  }
140 
141  Ccb = (PFFS_CCB)FileObject->FsContext2;
142 
143  if (!Ccb)
144  {
146  _SEH2_LEAVE;
147  }
148 
150  {
151  if (IsFlagOn(FileObject->Flags, FO_FILE_MODIFIED) &&
152  IsFlagOn(Vcb->Flags, VCB_FLOPPY_DISK) &&
153  !IsFlagOn(Vcb->Flags, VCB_WRITE_PROTECTED))
154  {
156  }
157 
158  _SEH2_LEAVE;
159  }
160 
161  ASSERT((Ccb->Identifier.Type == FFSCCB) &&
162  (Ccb->Identifier.Size == sizeof(FFS_CCB)));
163  Irp = IrpContext->Irp;
164 
165  Fcb->OpenHandleCount--;
166 
167  if (!IsFlagOn(FileObject->Flags, FO_CACHE_SUPPORTED))
168  {
169  Fcb->NonCachedOpenCount--;
170  }
171 
172  Vcb->OpenFileHandleCount--;
173 
175  {
177 
178  if (IsDirectory(Fcb))
179  {
181  Vcb->NotifySync,
182  &Vcb->NotifyList,
183  Fcb,
184  NULL,
185  FALSE,
186  FALSE,
187  0,
188  NULL,
189  NULL,
190  NULL);
191  }
192  }
193 
194  if (IsDirectory(Fcb))
195  {
197  Vcb->NotifySync,
198  &Vcb->NotifyList,
199  Ccb);
200  }
201  else
202  {
203  //
204  // Drop any byte range locks this process may have on the file.
205  //
207  &Fcb->FileLockAnchor,
208  FileObject,
210  NULL);
211 
212  //
213  // If there are no byte range locks owned by other processes on the
214  // file the fast I/O read/write functions doesn't have to check for
215  // locks so we set IsFastIoPossible to FastIoIsPossible again.
216  //
217  if (!FsRtlGetNextFileLock(&Fcb->FileLockAnchor, TRUE))
218  {
219  if (Fcb->Header.IsFastIoPossible != FastIoIsPossible)
220  {
221  FFSPrint((
222  DBG_INFO, ": %-16.16s %-31s %s\n",
224  "FastIoIsPossible",
225  Fcb->AnsiFileName.Buffer));
226 
227  Fcb->Header.IsFastIoPossible = FastIoIsPossible;
228  }
229  }
230  }
231 
232  if (IsFlagOn(FileObject->Flags, FO_CACHE_SUPPORTED) &&
233  (Fcb->NonCachedOpenCount != 0) &&
234  (Fcb->NonCachedOpenCount == Fcb->ReferenceCount) &&
235  (Fcb->SectionObject.DataSectionObject != NULL))
236  {
237 
238  if(!IsFlagOn(Vcb->Flags, VCB_READ_ONLY) &&
239  !IsFlagOn(Vcb->Flags, VCB_WRITE_PROTECTED))
240  {
241  CcFlushCache(&Fcb->SectionObject, NULL, 0, NULL);
242  }
243 
246 
247  CcPurgeCacheSection(&Fcb->SectionObject,
248  NULL,
249  0,
250  FALSE);
251  }
252 
253 #if !FFS_READ_ONLY
254  if (Fcb->OpenHandleCount == 0)
255  {
257  {
258  BOOLEAN bDeleted = FALSE;
259 
260  //
261  // Have to delete this file...
262  //
263 #ifdef _MSC_VER
264 #pragma prefast( suppress: 28137, "by design" )
265 #endif
268  IrpContext->IsSynchronous))
269  {
271  _SEH2_LEAVE;
272  }
273 
274  FcbPagingIoAcquired = TRUE;
275 
276  bDeleted = FFSDeleteFile(IrpContext, Vcb, Fcb);
277 
278  if (bDeleted)
279  {
280  if (IsDirectory(Fcb))
281  {
282  FFSNotifyReportChange(IrpContext, Vcb, Fcb,
285  }
286  else
287  {
288  FFSNotifyReportChange(IrpContext, Vcb, Fcb,
291  }
292  }
293 
294  if (FcbPagingIoAcquired)
295  {
299 
300  FcbPagingIoAcquired = FALSE;
301  }
302 
303 /*
304  if (bDeleted)
305  {
306  FFSPurgeFile(Fcb, FALSE);
307  }
308 */
309  }
310  }
311 #endif // !FFS_READ_ONLY
312 
313  if (!IsDirectory(Fcb) && FileObject->PrivateCacheMap)
314  {
315  FFSPrint((DBG_INFO, "FFSCleanup: CcUninitializeCacheMap is called for %s.\n",
316  Fcb->AnsiFileName.Buffer));
317 
319  FileObject,
320  (PLARGE_INTEGER)(&(Fcb->Header.FileSize)),
321  NULL);
322  }
323 
324  if (!Fcb->OpenHandleCount)
325  {
327  }
328 
329  FFSPrint((DBG_INFO, "FFSCleanup: OpenCount: %u ReferCount: %u %s\n",
330  Fcb->OpenHandleCount, Fcb->ReferenceCount, Fcb->AnsiFileName.Buffer));
331 
333 
334  if (FileObject)
335  {
337  }
338  }
339 
341  {
342 
343  if (FcbPagingIoAcquired)
344  {
348  }
349 
350  if (FcbResourceAcquired)
351  {
353  &Fcb->MainResource,
355  }
356 
357  if (VcbResourceAcquired)
358  {
360  &Vcb->MainResource,
362  }
363 
364  if (!IrpContext->ExceptionInProgress)
365  {
366  if (Status == STATUS_PENDING)
367  {
368  FFSQueueRequest(IrpContext);
369  }
370  else
371  {
372  IrpContext->Irp->IoStatus.Status = Status;
373 
374  FFSCompleteIrpContext(IrpContext, Status);
375  }
376  }
377  } _SEH2_END;
378 
379  return Status;
380 }
PFFS_GLOBAL FFSGlobal
Definition: init.c:22
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
NTSTATUS FFSQueueRequest(IN PFFS_IRP_CONTEXT IrpContext)
Definition: dispatch.c:33
PEPROCESS NTAPI IoGetRequestorProcess(IN PIRP Irp)
Definition: irp.c:1782
Definition: ffsdrv.h:281
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
#define TRUE
Definition: types.h:120
__drv_mustHoldCriticalRegion BOOLEAN FFSDeleteFile(PFFS_IRP_CONTEXT IrpContext, PFFS_VCB Vcb, PFFS_FCB Fcb)
Definition: fileinfo.c:1653
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
LONG NTSTATUS
Definition: precomp.h:26
VOID FFSClearVpbFlag(IN PVPB Vpb, IN USHORT Flag)
Definition: fsctl.c:69
Definition: ffsdrv.h:283
#define FILE_NOTIFY_CHANGE_FILE_NAME
struct _FFS_FCB * PFFS_FCB
#define FILE_NOTIFY_CHANGE_DIR_NAME
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3477
#define FCB_DELETE_PENDING
Definition: ext2fs.h:879
PDEVICE_OBJECT DeviceObject
Definition: ffsdrv.h:371
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define FCB_DELETE_ON_CLOSE
Definition: ffsdrv.h:633
NTSTATUS FFSFlushFile(IN PFFS_FCB Fcb)
Definition: flush.c:133
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:1745
NTFSIDENTIFIER Identifier
Definition: ntfs.h:511
#define VPB_LOCKED
Definition: iotypes.h:1765
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
Definition: ffsdrv.h:282
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ACTION_REMOVED
struct _FFS_VCB * PFFS_VCB
#define FFSGetCurrentProcessName()
Definition: ffsdrv.h:1070
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PFILE_LOCK_INFO NTAPI FsRtlGetNextFileLock(IN PFILE_LOCK FileLock, IN BOOLEAN Restart)
Definition: filelock.c:259
ULONG OpenHandleCount
Definition: ntfs.h:533
SHARE_ACCESS ShareAccess
Definition: cdstruc.h:1015
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define STATUS_PENDING
Definition: ntstatus.h:82
#define Vcb
Definition: cdprocs.h:1425
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1738
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG Flags
Definition: ntfs.h:532
#define VCB_WRITE_PROTECTED
Definition: ext2fs.h:796
__drv_mustHoldCriticalRegion NTSTATUS FFSCompleteIrpContext(IN PFFS_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:53
_Must_inspect_result_ _In_ PFLT_INSTANCE _Out_ PBOOLEAN IsDirectory
Definition: fltkernel.h:1139
ULONG Type
Definition: ntfs.h:95
Definition: ffsdrv.h:280
_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:524
#define VCB_READ_ONLY
Definition: ext2fs.h:795
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
Status
Definition: gdiplustypes.h:24
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
struct _FFS_CCB * PFFS_CCB
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:1747
_SEH2_FINALLY
Definition: create.c:4395
#define VCB_VOLUME_LOCKED
Definition: ext2fs.h:780
VOID FFSNotifyReportChange(IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN PFFS_FCB Fcb, IN ULONG Filter, IN ULONG Action)
Definition: dirctl.c:1201
ERESOURCE PagingIoResource
Definition: ntfs.h:523
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define DBG_INFO
Definition: ffsdrv.h:1034
#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:2966
ULONG Size
Definition: ntfs.h:96

Referenced by FFSDispatchRequest().

Variable Documentation

◆ FFSGlobal

PFFS_GLOBAL FFSGlobal

Definition at line 22 of file init.c.

Referenced by FFSCleanup().