-/* $Id: cleanup.c,v 1.9 2003/01/11 15:52:54 hbirr Exp $
- *
+/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
- * FILE: services/fs/vfat/cleanup.c
+ * FILE: drivers/fs/vfat/cleanup.c
* PURPOSE: VFAT Filesystem
* PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
+ * Hartmut Birr
*/
/* INCLUDES *****************************************************************/
-#include <ddk/ntddk.h>
-
#define NDEBUG
-#include <debug.h>
-
#include "vfat.h"
/* FUNCTIONS ****************************************************************/
static NTSTATUS
-VfatCleanupFile(PDEVICE_EXTENSION DeviceExt,
- PFILE_OBJECT FileObject)
+VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
/*
* FUNCTION: Cleans up after a file has been closed.
*/
{
- PVFATCCB pCcb;
PVFATFCB pFcb;
-
+ PFILE_OBJECT FileObject = IrpContext->FileObject;
+
DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
- DeviceExt, FileObject);
-
- /* FIXME: handle file/directory deletion here */
- pCcb = (PVFATCCB) (FileObject->FsContext2);
- if (pCcb == NULL)
- {
- return STATUS_SUCCESS;
- }
- pFcb = pCcb->pFcb;
+ IrpContext->DeviceExt, FileObject);
- /* Uninitialize file cache if initialized for this file object. */
- if (pFcb->RFCB.Bcb != NULL)
+ /* FIXME: handle file/directory deletion here */
+ pFcb = (PVFATFCB) FileObject->FsContext;
+ if (pFcb)
{
- CcRosReleaseFileCache (FileObject, pFcb->RFCB.Bcb);
+ if (!(*pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY) &&
+ FsRtlAreThereCurrentFileLocks(&pFcb->FileLock))
+ {
+ /* remove all locks this process have on this file */
+ FsRtlFastUnlockAll(&pFcb->FileLock,
+ FileObject,
+ IoGetRequestorProcess(IrpContext->Irp),
+ NULL);
+ }
+
+ if (pFcb->Flags & FCB_IS_DIRTY)
+ {
+ VfatUpdateEntry (pFcb);
+ }
+
+ if (pFcb->Flags & FCB_DELETE_PENDING &&
+ pFcb->OpenHandleCount == 1)
+ {
+ PFILE_OBJECT tmpFileObject;
+ tmpFileObject = pFcb->FileObject;
+ if (tmpFileObject != NULL)
+ {
+ pFcb->FileObject = NULL;
+#ifdef USE_ROS_CC_AND_FS
+ CcRosReleaseFileCache(tmpFileObject);
+#else
+ CcUninitializeCacheMap(tmpFileObject, NULL, NULL);
+#endif
+ ObDereferenceObject(tmpFileObject);
+ }
+
+#if 0
+ /* FIXME:
+ * CcPurgeCacheSection is unimplemented.
+ */
+ CcPurgeCacheSection(FileObject->SectionObjectPointer, NULL, 0, FALSE);
+#endif
+ }
+ /* Uninitialize file cache if. */
+#ifdef USE_ROS_CC_AND_FS
+ CcRosReleaseFileCache (FileObject);
+#else
+ CcUninitializeCacheMap (FileObject, NULL, NULL);
+#endif
+ pFcb->OpenHandleCount--;
+ if (!(*pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ IoRemoveShareAccess(FileObject, &pFcb->FCBShareAccess);
+ }
}
-
return STATUS_SUCCESS;
}
{
NTSTATUS Status;
- DPRINT("VfatCleanup(DeviceObject %x, Irp %x)\n", DeviceObject, Irp);
+ DPRINT("VfatCleanup(DeviceObject %x, Irp %x)\n", IrpContext->DeviceObject, IrpContext->Irp);
- if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
- {
- Status = STATUS_SUCCESS;
- goto ByeBye;
- }
+ if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
+ {
+ Status = STATUS_SUCCESS;
+ goto ByeBye;
+ }
- if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, IrpContext->Flags & IRPCONTEXT_CANWAIT))
- {
- return VfatQueueRequest (IrpContext);
- }
+ if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource,
+ (BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT)))
+ {
+ return VfatQueueRequest (IrpContext);
+ }
- Status = VfatCleanupFile(IrpContext->DeviceExt, IrpContext->FileObject);
+ Status = VfatCleanupFile(IrpContext);
ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);