-/* $Id: cleanup.c,v 1.1 2001/03/07 13:44:40 ekohl 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.
*/
{
- DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
- DeviceExt, FileObject);
+ PVFATFCB pFcb;
+ PFILE_OBJECT FileObject = IrpContext->FileObject;
+
+ DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
+ IrpContext->DeviceExt, FileObject);
+
+ /* FIXME: handle file/directory deletion here */
+ pFcb = (PVFATFCB) FileObject->FsContext;
+ if (pFcb)
+ {
+ 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);
+ }
- /* FIXME: handle file/directory deletion here */
+ if (pFcb->Flags & FCB_IS_DIRTY)
+ {
+ VfatUpdateEntry (pFcb);
+ }
- return STATUS_SUCCESS;
+ 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 STDCALL
-VfatCleanup (PDEVICE_OBJECT DeviceObject, PIRP Irp)
+NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
/*
* FUNCTION: Cleans up after a file has been closed.
*/
{
- PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
- PFILE_OBJECT FileObject = Stack->FileObject;
- PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
NTSTATUS Status;
- DPRINT1("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 (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource,
+ (BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT)))
+ {
+ return VfatQueueRequest (IrpContext);
+ }
+
+ Status = VfatCleanupFile(IrpContext);
- Status = VfatCleanupFile(DeviceExtension, FileObject);
+ ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
- Irp->IoStatus.Status = Status;
- Irp->IoStatus.Information = 0;
+ByeBye:
+ IrpContext->Irp->IoStatus.Status = Status;
+ IrpContext->Irp->IoStatus.Information = 0;
- IoCompleteRequest (Irp, IO_NO_INCREMENT);
+ IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
+ VfatFreeIrpContext(IrpContext);
return (Status);
}