-/* $Id: cleanup.c,v 1.10 2003/01/25 15:55:07 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 ****************************************************************/
* FUNCTION: Cleans up after a file has been closed.
*/
{
- PVFATCCB pCcb;
PVFATFCB pFcb;
- PDEVICE_EXTENSION DeviceExt = IrpContext->DeviceExt;
PFILE_OBJECT FileObject = IrpContext->FileObject;
-
+
DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
- DeviceExt, FileObject);
-
+ IrpContext->DeviceExt, FileObject);
+
/* FIXME: handle file/directory deletion here */
- pCcb = (PVFATCCB) (FileObject->FsContext2);
- if (pCcb == NULL)
+ pFcb = (PVFATFCB) FileObject->FsContext;
+ if (pFcb)
{
- return STATUS_SUCCESS;
+ 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);
+ }
}
- pFcb = pCcb->pFcb;
-
- if (!(pFcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY) &&
- FsRtlAreThereCurrentFileLocks(&pFcb->FileLock))
- {
- /* remove all locks this process have on this file */
- FsRtlFastUnlockAll(&pFcb->FileLock,
- FileObject,
- IoGetRequestorProcess(IrpContext->Irp),
- NULL
- );
- }
-
- /* Uninitialize file cache if initialized for this file object. */
- if (pFcb->RFCB.Bcb != NULL)
- {
- CcRosReleaseFileCache (FileObject, pFcb->RFCB.Bcb);
- }
-
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);