ReactOS  0.4.15-dev-5455-g015cd25
cleanup.c File Reference
#include "vfat.h"
#include <debug.h>
Include dependency graph for cleanup.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static BOOLEAN VfatCleanupFile (PVFAT_IRP_CONTEXT IrpContext)
 
NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file cleanup.c.

Function Documentation

◆ VfatCleanup()

NTSTATUS VfatCleanup ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 176 of file cleanup.c.

178 {
180 
181  DPRINT("VfatCleanup(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
182 
183  if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
184  {
185  IrpContext->Irp->IoStatus.Information = 0;
186  return STATUS_SUCCESS;
187  }
188 
189  ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE);
190  Deleted = VfatCleanupFile(IrpContext);
191  if (!Deleted) ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
192 
193  IrpContext->Irp->IoStatus.Information = 0;
194  return STATUS_SUCCESS;
195 }
static BOOLEAN VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
Definition: cleanup.c:24
PDEVICE_EXTENSION DeviceExt
Definition: vfat.h:585
#define TRUE
Definition: types.h:120
IO_STATUS_BLOCK IoStatus
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
unsigned char BOOLEAN
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:412
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:18
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:584
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

Referenced by VfatDispatchRequest().

◆ VfatCleanupFile()

static BOOLEAN VfatCleanupFile ( PVFAT_IRP_CONTEXT  IrpContext)
static

Definition at line 24 of file cleanup.c.

26 {
27  PVFATFCB pFcb;
28  PVFATCCB pCcb;
29  BOOLEAN IsVolume;
30  PDEVICE_EXTENSION DeviceExt = IrpContext->DeviceExt;
31  PFILE_OBJECT FileObject = IrpContext->FileObject;
33 
34  DPRINT("VfatCleanupFile(DeviceExt %p, FileObject %p)\n",
35  IrpContext->DeviceExt, FileObject);
36 
37  /* FIXME: handle file/directory deletion here */
38  pFcb = (PVFATFCB)FileObject->FsContext;
39  if (!pFcb)
40  return FALSE;
41 
42  IsVolume = BooleanFlagOn(pFcb->Flags, FCB_IS_VOLUME);
43  if (IsVolume)
44  {
45  pFcb->OpenHandleCount--;
46  DeviceExt->OpenHandleCount--;
47 
48  if (pFcb->OpenHandleCount != 0)
49  {
51  }
52  }
53  else
54  {
57 
58  pCcb = FileObject->FsContext2;
60  {
61  pFcb->Flags |= FCB_DELETE_PENDING;
62  }
63 
64  /* Notify about the cleanup */
65  FsRtlNotifyCleanup(IrpContext->DeviceExt->NotifySync,
66  &(IrpContext->DeviceExt->NotifyList),
67  FileObject->FsContext2);
68 
69  pFcb->OpenHandleCount--;
70  DeviceExt->OpenHandleCount--;
71 
72  if (!vfatFCBIsDirectory(pFcb) &&
74  {
75  /* remove all locks this process have on this file */
77  FileObject,
78  IoGetRequestorProcess(IrpContext->Irp),
79  NULL);
80  }
81 
82  if (BooleanFlagOn(pFcb->Flags, FCB_IS_DIRTY))
83  {
84  VfatUpdateEntry (DeviceExt, pFcb);
85  }
86 
88  pFcb->OpenHandleCount == 0)
89  {
90  if (vfatFCBIsDirectory(pFcb) &&
91  !VfatIsDirectoryEmpty(DeviceExt, pFcb))
92  {
93  pFcb->Flags &= ~FCB_DELETE_PENDING;
94  }
95  else
96  {
97  PFILE_OBJECT tmpFileObject;
98  tmpFileObject = pFcb->FileObject;
99  if (tmpFileObject != NULL)
100  {
101  pFcb->FileObject = NULL;
102  CcUninitializeCacheMap(tmpFileObject, NULL, NULL);
104  ObDereferenceObject(tmpFileObject);
105  }
106 
107  pFcb->RFCB.ValidDataLength.QuadPart = 0;
108  pFcb->RFCB.FileSize.QuadPart = 0;
109  pFcb->RFCB.AllocationSize.QuadPart = 0;
110  }
111  }
112 
113  /* Uninitialize the cache (should be done even if caching was never initialized) */
115 
116  if (BooleanFlagOn(pFcb->Flags, FCB_DELETE_PENDING) &&
117  pFcb->OpenHandleCount == 0)
118  {
119  VfatDelEntry(DeviceExt, pFcb, NULL);
120 
121  vfatReportChange(DeviceExt,
122  pFcb,
123  (vfatFCBIsDirectory(pFcb) ?
126  }
127 
128  if (pFcb->OpenHandleCount != 0)
129  {
131  }
132 /* FIXME: causes FS corruption and breaks selfhosting/testbots and so on */
133 #if 0
134  /* If that's the last open handle we just closed, try to see whether
135  * we can delay close operation
136  */
139  {
140  /* This is only allowed if that's a directory with no open files
141  * OR if it's a file with no section opened
142  */
143  if ((vfatFCBIsDirectory(pFcb) && IsListEmpty(&pFcb->ParentListHead)) ||
144  (!vfatFCBIsDirectory(pFcb) && FileObject->SectionObjectPointer->DataSectionObject == NULL &&
145  FileObject->SectionObjectPointer->ImageSectionObject == NULL))
146  {
147  DPRINT("Delaying close of: %wZ\n", &pFcb->PathNameU);
149  }
150  }
151 #endif
152 
154 #ifdef KDBG
155  pFcb->Flags |= FCB_CLEANED_UP;
156 #endif
157 
160  }
161 
162 #ifdef ENABLE_SWAPOUT
163  if (IsVolume && BooleanFlagOn(DeviceExt->Flags, VCB_DISMOUNT_PENDING))
164  {
165  Deleted = VfatCheckForDismount(DeviceExt, TRUE);
166  }
167 #endif
168 
169  return Deleted;
170 }
PEPROCESS NTAPI IoGetRequestorProcess(IN PIRP Irp)
Definition: irp.c:1782
#define FCB_IS_DIRTY
Definition: vfat.h:438
#define CCB_DELETE_ON_CLOSE
Definition: ext2fs.h:1026
Definition: vfat.h:447
Definition: vfat.h:536
PDEVICE_EXTENSION DeviceExt
Definition: vfat.h:585
#define TRUE
Definition: types.h:120
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
FORCEINLINE BOOLEAN vfatFCBIsDirectory(PVFATFCB FCB)
Definition: vfat.h:637
#define FILE_NOTIFY_CHANGE_FILE_NAME
if(dx==0 &&dy==0)
Definition: linetemp.h:174
PFILE_OBJECT FileObject
Definition: vfat.h:591
#define FILE_NOTIFY_CHANGE_DIR_NAME
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3477
#define FCB_DELETE_PENDING
Definition: ext2fs.h:879
VOID NTAPI FsRtlNotifyCleanup(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext)
Definition: notify.c:659
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define FALSE
Definition: types.h:117
ULONG Flags
Definition: vfat.h:539
PFILE_OBJECT FileObject
Definition: vfat.h:499
ULONG Flags
Definition: vfat.h:496
SHARE_ACCESS FCBShareAccess
Definition: vfat.h:508
unsigned char BOOLEAN
#define FILE_ACTION_REMOVED
#define FsRtlAreThereCurrentFileLocks(FL)
Definition: fsrtlfuncs.h:1584
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
#define FCB_IS_PAGE_FILE
Definition: vfat.h:436
#define ObDereferenceObject
Definition: obfuncs.h:203
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1998
FSRTL_COMMON_FCB_HEADER RFCB
Definition: vfat.h:450
#define FCB_CACHE_INITIALIZED
Definition: ntfs.h:508
FILE_LOCK FileLock
Definition: vfat.h:520
#define FCB_IS_FAT
Definition: vfat.h:435
FORCEINLINE BOOLEAN VfatIsDirectoryEmpty(PDEVICE_EXTENSION DeviceExt, struct _VFATFCB *Fcb)
Definition: vfat.h:367
#define VCB_DISMOUNT_PENDING
Definition: ext2fs.h:782
LARGE_INTEGER AllocationSize
Definition: env_spec_w32.h:755
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
Definition: filelock.c:1025
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
struct _VFATFCB * PVFATFCB
#define FCB_DELAYED_CLOSE
Definition: vfat.h:439
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
ERESOURCE PagingIoResource
Definition: vfat.h:453
FORCEINLINE VOID vfatReportChange(IN PDEVICE_EXTENSION DeviceExt, IN PVFATFCB Fcb, IN ULONG FilterMatch, IN ULONG Action)
Definition: vfat.h:658
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
FORCEINLINE NTSTATUS VfatDelEntry(PDEVICE_EXTENSION DeviceExt, struct _VFATFCB *Fcb, struct _VFAT_MOVE_CONTEXT *MoveContext)
Definition: vfat.h:388
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1790
#define NULL
Definition: types.h:112
#define FCB_IS_VOLUME
Definition: ntfs.h:510
ERESOURCE MainResource
Definition: vfat.h:452
UNICODE_STRING PathNameU
Definition: vfat.h:472
NTSTATUS VfatUpdateEntry(IN PDEVICE_EXTENSION DeviceExt, IN PVFATFCB pFcb)
Definition: dirwr.c:115
#define DPRINT
Definition: sndvol32.h:71
ULONG OpenHandleCount
Definition: vfat.h:511
LARGE_INTEGER ValidDataLength
Definition: env_spec_w32.h:757
LIST_ENTRY ParentListHead
Definition: vfat.h:493
LONGLONG QuadPart
Definition: typedefs.h:114
BOOLEAN VfatCheckForDismount(IN PDEVICE_EXTENSION DeviceExt, IN BOOLEAN Force)
Definition: misc.c:495

Referenced by VfatCleanup().