2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/fs/vfat/cleanup.c
5 * PURPOSE: VFAT Filesystem
6 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
9 /* INCLUDES *****************************************************************/
16 /* FUNCTIONS ****************************************************************/
19 * FUNCTION: Cleans up after a file has been closed.
24 PVFAT_IRP_CONTEXT IrpContext
)
29 PDEVICE_EXTENSION DeviceExt
= IrpContext
->DeviceExt
;
30 PFILE_OBJECT FileObject
= IrpContext
->FileObject
;
32 DPRINT("VfatCleanupFile(DeviceExt %p, FileObject %p)\n",
33 IrpContext
->DeviceExt
, FileObject
);
35 /* FIXME: handle file/directory deletion here */
36 pFcb
= (PVFATFCB
)FileObject
->FsContext
;
38 return STATUS_SUCCESS
;
40 IsVolume
= BooleanFlagOn(pFcb
->Flags
, FCB_IS_VOLUME
);
43 pFcb
->OpenHandleCount
--;
45 if (pFcb
->OpenHandleCount
!= 0)
47 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
52 if(!ExAcquireResourceExclusiveLite(&pFcb
->MainResource
,
53 BooleanFlagOn(IrpContext
->Flags
, IRPCONTEXT_CANWAIT
)))
55 return STATUS_PENDING
;
57 if(!ExAcquireResourceExclusiveLite(&pFcb
->PagingIoResource
,
58 BooleanFlagOn(IrpContext
->Flags
, IRPCONTEXT_CANWAIT
)))
60 ExReleaseResourceLite(&pFcb
->MainResource
);
61 return STATUS_PENDING
;
64 pCcb
= FileObject
->FsContext2
;
65 if (BooleanFlagOn(pCcb
->Flags
, CCB_DELETE_ON_CLOSE
))
67 pFcb
->Flags
|= FCB_DELETE_PENDING
;
70 /* Notify about the cleanup */
71 FsRtlNotifyCleanup(IrpContext
->DeviceExt
->NotifySync
,
72 &(IrpContext
->DeviceExt
->NotifyList
),
73 FileObject
->FsContext2
);
75 pFcb
->OpenHandleCount
--;
76 DeviceExt
->OpenHandleCount
--;
78 if (!vfatFCBIsDirectory(pFcb
) &&
79 FsRtlAreThereCurrentFileLocks(&pFcb
->FileLock
))
81 /* remove all locks this process have on this file */
82 FsRtlFastUnlockAll(&pFcb
->FileLock
,
84 IoGetRequestorProcess(IrpContext
->Irp
),
88 if (BooleanFlagOn(pFcb
->Flags
, FCB_IS_DIRTY
))
90 VfatUpdateEntry (pFcb
, vfatVolumeIsFatX(DeviceExt
));
93 if (BooleanFlagOn(pFcb
->Flags
, FCB_DELETE_PENDING
) &&
94 pFcb
->OpenHandleCount
== 0)
96 if (vfatFCBIsDirectory(pFcb
) &&
97 !VfatIsDirectoryEmpty(DeviceExt
, pFcb
))
99 pFcb
->Flags
&= ~FCB_DELETE_PENDING
;
103 PFILE_OBJECT tmpFileObject
;
104 tmpFileObject
= pFcb
->FileObject
;
105 if (tmpFileObject
!= NULL
)
107 pFcb
->FileObject
= NULL
;
108 CcUninitializeCacheMap(tmpFileObject
, NULL
, NULL
);
109 ObDereferenceObject(tmpFileObject
);
112 pFcb
->RFCB
.ValidDataLength
.QuadPart
= 0;
113 pFcb
->RFCB
.FileSize
.QuadPart
= 0;
114 pFcb
->RFCB
.AllocationSize
.QuadPart
= 0;
118 /* Uninitialize the cache (should be done even if caching was never initialized) */
119 CcUninitializeCacheMap(FileObject
, &pFcb
->RFCB
.FileSize
, NULL
);
121 if (BooleanFlagOn(pFcb
->Flags
, FCB_DELETE_PENDING
) &&
122 pFcb
->OpenHandleCount
== 0)
124 VfatDelEntry(DeviceExt
, pFcb
, NULL
);
126 FsRtlNotifyFullReportChange(DeviceExt
->NotifySync
,
127 &(DeviceExt
->NotifyList
),
128 (PSTRING
)&pFcb
->PathNameU
,
129 pFcb
->PathNameU
.Length
- pFcb
->LongNameU
.Length
,
132 vfatFCBIsDirectory(pFcb
) ?
133 FILE_NOTIFY_CHANGE_DIR_NAME
: FILE_NOTIFY_CHANGE_FILE_NAME
,
138 if (pFcb
->OpenHandleCount
!= 0)
140 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
143 FileObject
->Flags
|= FO_CLEANUP_COMPLETE
;
145 ExReleaseResourceLite(&pFcb
->PagingIoResource
);
146 ExReleaseResourceLite(&pFcb
->MainResource
);
149 #ifdef ENABLE_SWAPOUT
150 if (IsVolume
&& BooleanFlagOn(DeviceExt
->Flags
, VCB_DISMOUNT_PENDING
))
152 VfatCheckForDismount(DeviceExt
, FALSE
);
156 return STATUS_SUCCESS
;
160 * FUNCTION: Cleans up after a file has been closed.
164 PVFAT_IRP_CONTEXT IrpContext
)
168 DPRINT("VfatCleanup(DeviceObject %p, Irp %p)\n", IrpContext
->DeviceObject
, IrpContext
->Irp
);
170 if (IrpContext
->DeviceObject
== VfatGlobalData
->DeviceObject
)
172 IrpContext
->Irp
->IoStatus
.Information
= 0;
173 return STATUS_SUCCESS
;
176 if (!ExAcquireResourceExclusiveLite(&IrpContext
->DeviceExt
->DirResource
,
177 BooleanFlagOn(IrpContext
->Flags
, IRPCONTEXT_CANWAIT
)))
179 return VfatMarkIrpContextForQueue(IrpContext
);
182 Status
= VfatCleanupFile(IrpContext
);
184 ExReleaseResourceLite(&IrpContext
->DeviceExt
->DirResource
);
186 if (Status
== STATUS_PENDING
)
188 return VfatMarkIrpContextForQueue(IrpContext
);
191 IrpContext
->Irp
->IoStatus
.Information
= 0;