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
)
27 PDEVICE_EXTENSION DeviceExt
= IrpContext
->DeviceExt
;
28 PFILE_OBJECT FileObject
= IrpContext
->FileObject
;
30 DPRINT("VfatCleanupFile(DeviceExt %p, FileObject %p)\n",
31 IrpContext
->DeviceExt
, FileObject
);
33 /* FIXME: handle file/directory deletion here */
34 pFcb
= (PVFATFCB
)FileObject
->FsContext
;
36 return STATUS_SUCCESS
;
38 if (BooleanFlagOn(pFcb
->Flags
, FCB_IS_VOLUME
))
40 pFcb
->OpenHandleCount
--;
42 if (pFcb
->OpenHandleCount
!= 0)
44 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
49 if(!ExAcquireResourceExclusiveLite(&pFcb
->MainResource
,
50 BooleanFlagOn(IrpContext
->Flags
, IRPCONTEXT_CANWAIT
)))
52 return STATUS_PENDING
;
54 if(!ExAcquireResourceExclusiveLite(&pFcb
->PagingIoResource
,
55 BooleanFlagOn(IrpContext
->Flags
, IRPCONTEXT_CANWAIT
)))
57 ExReleaseResourceLite(&pFcb
->MainResource
);
58 return STATUS_PENDING
;
61 /* Notify about the cleanup */
62 FsRtlNotifyCleanup(IrpContext
->DeviceExt
->NotifySync
,
63 &(IrpContext
->DeviceExt
->NotifyList
),
64 FileObject
->FsContext2
);
66 pFcb
->OpenHandleCount
--;
67 DeviceExt
->OpenHandleCount
--;
69 if (!vfatFCBIsDirectory(pFcb
) &&
70 FsRtlAreThereCurrentFileLocks(&pFcb
->FileLock
))
72 /* remove all locks this process have on this file */
73 FsRtlFastUnlockAll(&pFcb
->FileLock
,
75 IoGetRequestorProcess(IrpContext
->Irp
),
79 if (BooleanFlagOn(pFcb
->Flags
, FCB_IS_DIRTY
))
81 VfatUpdateEntry (pFcb
, vfatVolumeIsFatX(DeviceExt
));
84 if (BooleanFlagOn(pFcb
->Flags
, FCB_DELETE_PENDING
) &&
85 pFcb
->OpenHandleCount
== 0)
87 if (vfatFCBIsDirectory(pFcb
) &&
88 !VfatIsDirectoryEmpty(DeviceExt
, pFcb
))
90 pFcb
->Flags
&= ~FCB_DELETE_PENDING
;
94 PFILE_OBJECT tmpFileObject
;
95 tmpFileObject
= pFcb
->FileObject
;
96 if (tmpFileObject
!= NULL
)
98 pFcb
->FileObject
= NULL
;
99 CcUninitializeCacheMap(tmpFileObject
, NULL
, NULL
);
100 ObDereferenceObject(tmpFileObject
);
103 pFcb
->RFCB
.ValidDataLength
.QuadPart
= 0;
104 pFcb
->RFCB
.FileSize
.QuadPart
= 0;
105 pFcb
->RFCB
.AllocationSize
.QuadPart
= 0;
109 /* Uninitialize the cache (should be done even if caching was never initialized) */
110 CcUninitializeCacheMap(FileObject
, &pFcb
->RFCB
.FileSize
, NULL
);
112 if (BooleanFlagOn(pFcb
->Flags
, FCB_DELETE_PENDING
) &&
113 pFcb
->OpenHandleCount
== 0)
115 VfatDelEntry(DeviceExt
, pFcb
, NULL
);
117 FsRtlNotifyFullReportChange(DeviceExt
->NotifySync
,
118 &(DeviceExt
->NotifyList
),
119 (PSTRING
)&pFcb
->PathNameU
,
120 pFcb
->PathNameU
.Length
- pFcb
->LongNameU
.Length
,
123 vfatFCBIsDirectory(pFcb
) ?
124 FILE_NOTIFY_CHANGE_DIR_NAME
: FILE_NOTIFY_CHANGE_FILE_NAME
,
129 if (pFcb
->OpenHandleCount
!= 0)
131 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
134 FileObject
->Flags
|= FO_CLEANUP_COMPLETE
;
136 ExReleaseResourceLite(&pFcb
->PagingIoResource
);
137 ExReleaseResourceLite(&pFcb
->MainResource
);
140 #ifdef ENABLE_SWAPOUT
141 if (BooleanFlagOn(DeviceExt
->Flags
, VCB_DISMOUNT_PENDING
))
143 VfatCheckForDismount(DeviceExt
, FALSE
);
147 return STATUS_SUCCESS
;
151 * FUNCTION: Cleans up after a file has been closed.
155 PVFAT_IRP_CONTEXT IrpContext
)
159 DPRINT("VfatCleanup(DeviceObject %p, Irp %p)\n", IrpContext
->DeviceObject
, IrpContext
->Irp
);
161 if (IrpContext
->DeviceObject
== VfatGlobalData
->DeviceObject
)
163 IrpContext
->Irp
->IoStatus
.Information
= 0;
164 return STATUS_SUCCESS
;
167 if (!ExAcquireResourceExclusiveLite(&IrpContext
->DeviceExt
->DirResource
,
168 BooleanFlagOn(IrpContext
->Flags
, IRPCONTEXT_CANWAIT
)))
170 return VfatMarkIrpContextForQueue(IrpContext
);
173 Status
= VfatCleanupFile(IrpContext
);
175 ExReleaseResourceLite(&IrpContext
->DeviceExt
->DirResource
);
177 if (Status
== STATUS_PENDING
)
179 return VfatMarkIrpContextForQueue(IrpContext
);
182 IrpContext
->Irp
->IoStatus
.Information
= 0;