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 (pFcb
->Flags
& FCB_IS_VOLUME
)
40 pFcb
->OpenHandleCount
--;
42 if (pFcb
->OpenHandleCount
!= 0)
44 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
49 if(!ExAcquireResourceExclusiveLite(&pFcb
->MainResource
,
50 (BOOLEAN
)(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
)))
52 return STATUS_PENDING
;
54 if(!ExAcquireResourceExclusiveLite(&pFcb
->PagingIoResource
,
55 (BOOLEAN
)(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 (!(*pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
70 FsRtlAreThereCurrentFileLocks(&pFcb
->FileLock
))
72 /* remove all locks this process have on this file */
73 FsRtlFastUnlockAll(&pFcb
->FileLock
,
75 IoGetRequestorProcess(IrpContext
->Irp
),
79 if (pFcb
->Flags
& FCB_IS_DIRTY
)
81 VfatUpdateEntry (pFcb
);
84 if (pFcb
->Flags
& FCB_DELETE_PENDING
&&
85 pFcb
->OpenHandleCount
== 0)
87 PFILE_OBJECT tmpFileObject
;
88 tmpFileObject
= pFcb
->FileObject
;
89 if (tmpFileObject
!= NULL
)
91 pFcb
->FileObject
= NULL
;
92 CcUninitializeCacheMap(tmpFileObject
, NULL
, NULL
);
93 ObDereferenceObject(tmpFileObject
);
96 CcPurgeCacheSection(FileObject
->SectionObjectPointer
, NULL
, 0, FALSE
);
99 /* Uninitialize the cache (should be done even if caching was never initialized) */
100 CcUninitializeCacheMap(FileObject
, &pFcb
->RFCB
.FileSize
, NULL
);
102 if (pFcb
->OpenHandleCount
!= 0)
104 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
107 FileObject
->Flags
|= FO_CLEANUP_COMPLETE
;
109 ExReleaseResourceLite(&pFcb
->PagingIoResource
);
110 ExReleaseResourceLite(&pFcb
->MainResource
);
113 #ifdef ENABLE_SWAPOUT
114 if (DeviceExt
->Flags
& VCB_DISMOUNT_PENDING
)
116 VfatCheckForDismount(DeviceExt
, FALSE
);
120 return STATUS_SUCCESS
;
124 * FUNCTION: Cleans up after a file has been closed.
128 PVFAT_IRP_CONTEXT IrpContext
)
132 DPRINT("VfatCleanup(DeviceObject %p, Irp %p)\n", IrpContext
->DeviceObject
, IrpContext
->Irp
);
134 if (IrpContext
->DeviceObject
== VfatGlobalData
->DeviceObject
)
136 Status
= STATUS_SUCCESS
;
140 if (!ExAcquireResourceExclusiveLite(&IrpContext
->DeviceExt
->DirResource
,
141 (BOOLEAN
)(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
)))
143 return VfatQueueRequest(IrpContext
);
146 Status
= VfatCleanupFile(IrpContext
);
148 ExReleaseResourceLite(&IrpContext
->DeviceExt
->DirResource
);
150 if (Status
== STATUS_PENDING
)
152 return VfatQueueRequest(IrpContext
);
156 IrpContext
->Irp
->IoStatus
.Status
= Status
;
157 IrpContext
->Irp
->IoStatus
.Information
= 0;
159 IoCompleteRequest(IrpContext
->Irp
, IO_NO_INCREMENT
);
160 VfatFreeIrpContext(IrpContext
);