update for HEAD-2003021201
[reactos.git] / drivers / fs / vfat / cleanup.c
index 7d65a10..8ab965b 100644 (file)
 /* 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;
+  PDEVICE_EXTENSION DeviceExt = IrpContext->DeviceExt;
+  PFILE_OBJECT FileObject = IrpContext->FileObject;
   
   DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
         DeviceExt, FileObject);
@@ -39,17 +40,22 @@ VfatCleanupFile(PDEVICE_EXTENSION DeviceExt,
     }
   pFcb = pCcb->pFcb;
 
-  if (FileObject->FileName.Buffer)
+  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)
     {
-      if (pFcb->Flags & FCB_UPDATE_DIRENTRY)
-       {
-         VfatUpdateEntry (DeviceExt, FileObject);
-         pFcb->Flags &= ~FCB_UPDATE_DIRENTRY;
-       }
+      CcRosReleaseFileCache (FileObject, pFcb->RFCB.Bcb);
     }
-
-  /* Uninitialize the file cache. */
-  CcRosReleaseFileCache (FileObject, pFcb->RFCB.Bcb);
   
   return STATUS_SUCCESS;
 }
@@ -74,7 +80,7 @@ NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
      return VfatQueueRequest (IrpContext);
    }
 
-   Status = VfatCleanupFile(IrpContext->DeviceExt, IrpContext->FileObject);
+   Status = VfatCleanupFile(IrpContext);
 
    ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);