Don't check the share access for directories.
[reactos.git] / reactos / drivers / fs / vfat / cleanup.c
index 465c1ff..c56f4fb 100644 (file)
@@ -1,59 +1,85 @@
-/* $Id: cleanup.c,v 1.8 2002/12/15 17:01:51 chorns 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;
-  
-  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;
+  PFILE_OBJECT FileObject = IrpContext->FileObject;
 
-  if (FileObject->FileName.Buffer)
-    {
-      if (pFcb->Flags & FCB_UPDATE_DIRENTRY)
-       {
-         VfatUpdateEntry (DeviceExt, FileObject);
-         pFcb->Flags &= ~FCB_UPDATE_DIRENTRY;
-       }
-    }
+  DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
+        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;
 }
 
@@ -64,20 +90,21 @@ NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
 {
    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);