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 PFILE_OBJECT FileObject
= IrpContext
->FileObject
;
29 DPRINT("VfatCleanupFile(DeviceExt %p, FileObject %p)\n",
30 IrpContext
->DeviceExt
, FileObject
);
32 /* FIXME: handle file/directory deletion here */
33 pFcb
= (PVFATFCB
)FileObject
->FsContext
;
35 return STATUS_SUCCESS
;
37 if (pFcb
->Flags
& FCB_IS_VOLUME
)
39 pFcb
->OpenHandleCount
--;
41 if (pFcb
->OpenHandleCount
!= 0)
43 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
48 if(!ExAcquireResourceExclusiveLite(&pFcb
->MainResource
,
49 (BOOLEAN
)(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
)))
51 return STATUS_PENDING
;
53 if(!ExAcquireResourceExclusiveLite(&pFcb
->PagingIoResource
,
54 (BOOLEAN
)(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
)))
56 ExReleaseResourceLite(&pFcb
->MainResource
);
57 return STATUS_PENDING
;
60 pFcb
->OpenHandleCount
--;
62 if (!(*pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
63 FsRtlAreThereCurrentFileLocks(&pFcb
->FileLock
))
65 /* remove all locks this process have on this file */
66 FsRtlFastUnlockAll(&pFcb
->FileLock
,
68 IoGetRequestorProcess(IrpContext
->Irp
),
72 if (pFcb
->Flags
& FCB_IS_DIRTY
)
74 VfatUpdateEntry (pFcb
);
77 if (pFcb
->Flags
& FCB_DELETE_PENDING
&&
78 pFcb
->OpenHandleCount
== 0)
80 PFILE_OBJECT tmpFileObject
;
81 tmpFileObject
= pFcb
->FileObject
;
82 if (tmpFileObject
!= NULL
)
84 pFcb
->FileObject
= NULL
;
85 CcUninitializeCacheMap(tmpFileObject
, NULL
, NULL
);
86 ObDereferenceObject(tmpFileObject
);
89 CcPurgeCacheSection(FileObject
->SectionObjectPointer
, NULL
, 0, FALSE
);
92 /* Uninitialize the cache (should be done even if caching was never initialized) */
93 CcUninitializeCacheMap(FileObject
, &pFcb
->RFCB
.FileSize
, NULL
);
95 if (pFcb
->OpenHandleCount
!= 0)
97 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
100 FileObject
->Flags
|= FO_CLEANUP_COMPLETE
;
102 ExReleaseResourceLite(&pFcb
->PagingIoResource
);
103 ExReleaseResourceLite(&pFcb
->MainResource
);
106 return STATUS_SUCCESS
;
110 * FUNCTION: Cleans up after a file has been closed.
114 PVFAT_IRP_CONTEXT IrpContext
)
118 DPRINT("VfatCleanup(DeviceObject %p, Irp %p)\n", IrpContext
->DeviceObject
, IrpContext
->Irp
);
120 if (IrpContext
->DeviceObject
== VfatGlobalData
->DeviceObject
)
122 Status
= STATUS_SUCCESS
;
126 if (!ExAcquireResourceExclusiveLite(&IrpContext
->DeviceExt
->DirResource
,
127 (BOOLEAN
)(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
)))
129 return VfatQueueRequest(IrpContext
);
132 Status
= VfatCleanupFile(IrpContext
);
134 ExReleaseResourceLite(&IrpContext
->DeviceExt
->DirResource
);
136 if (Status
== STATUS_PENDING
)
138 return VfatQueueRequest(IrpContext
);
142 IrpContext
->Irp
->IoStatus
.Status
= Status
;
143 IrpContext
->Irp
->IoStatus
.Information
= 0;
145 IoCompleteRequest(IrpContext
->Irp
, IO_NO_INCREMENT
);
146 VfatFreeIrpContext(IrpContext
);