[FASTFAT]
authorJérôme Gardou <jerome.gardou@reactos.org>
Fri, 31 Oct 2014 11:04:12 +0000 (11:04 +0000)
committerJérôme Gardou <jerome.gardou@reactos.org>
Fri, 31 Oct 2014 11:04:12 +0000 (11:04 +0000)
 - Fix renaming files in case the target file already exists.
 - Plug a few reference count leaks on FCBs.
CORE-8660 #comment fixed in r65140 #resolve
CORE-8633 #comment fixed in r65140 #resolve
CORE-4758 #comment fixed in r65140 #resolve

svn path=/trunk/; revision=65140

reactos/drivers/filesystems/fastfat/cleanup.c
reactos/drivers/filesystems/fastfat/create.c
reactos/drivers/filesystems/fastfat/finfo.c

index f9bde77..8bc68b8 100644 (file)
@@ -92,6 +92,7 @@ VfatCleanupFile(
                 pFcb->FileObject = NULL;
                 CcUninitializeCacheMap(tmpFileObject, NULL, NULL);
                 ObDereferenceObject(tmpFileObject);
+                vfatReleaseFCB(IrpContext->DeviceExt, pFcb);
             }
 
             CcPurgeCacheSection(FileObject->SectionObjectPointer, NULL, 0, FALSE);
index 6314c52..eda08cf 100644 (file)
@@ -365,7 +365,6 @@ VfatOpenFile(
         DPRINT("'%wZ'\n", &FileObject->RelatedFileObject->FileName);
 
         *ParentFcb = FileObject->RelatedFileObject->FsContext;
-        vfatGrabFCB(DeviceExt, *ParentFcb);
     }
     else
     {
index 7c08c1a..1dbe8f6 100644 (file)
@@ -396,30 +396,41 @@ vfatPrepareTargetForRename(
     /* If it exists */
     if (NT_SUCCESS(Status))
     {
+        DPRINT("Target file %wZ exists. FCB Flags %08x\n", NewName, TargetFcb->Flags);
         /* Check whether we are allowed to replace */
         if (ReplaceIfExists)
         {
             /* If that's a directory or a read-only file, we're not allowed */
-            if (vfatFCBIsDirectory(TargetFcb) || ((*TargetFcb->Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY));
+            if (vfatFCBIsDirectory(TargetFcb) || ((*TargetFcb->Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY))
             {
+                DPRINT("And this is a readonly file!\n");
                 vfatReleaseFCB(DeviceExt, *ParentFCB);
                 *ParentFCB = NULL;
                 vfatReleaseFCB(DeviceExt, TargetFcb);
                 return STATUS_OBJECT_NAME_COLLISION;
             }
 
-            /* Attempt to flush (might close the file) */
-            if (!MmFlushImageSection(TargetFcb->FileObject->SectionObjectPointer, MmFlushForDelete))
+
+            /* If we still have a file object, close it. */
+            if (TargetFcb->FileObject)
             {
-                vfatReleaseFCB(DeviceExt, *ParentFCB);
-                *ParentFCB = NULL;
-                vfatReleaseFCB(DeviceExt, TargetFcb);
-                return STATUS_ACCESS_DENIED;
+                if (!MmFlushImageSection(TargetFcb->FileObject->SectionObjectPointer, MmFlushForDelete))
+                {
+                    DPRINT("MmFlushImageSection failed.\n");
+                    vfatReleaseFCB(DeviceExt, *ParentFCB);
+                    *ParentFCB = NULL;
+                    vfatReleaseFCB(DeviceExt, TargetFcb);
+                    return STATUS_ACCESS_DENIED;
+                }
+
+                TargetFcb->FileObject->DeletePending = TRUE;
+                VfatCloseFile(DeviceExt, TargetFcb->FileObject);
             }
 
-            /* If we are, ensure the file isn't open by anyone! */
+            /* If we are here, ensure the file isn't open by anyone! */
             if (TargetFcb->OpenHandleCount != 0)
             {
+                DPRINT("There are still open handles for this file.\n");
                 vfatReleaseFCB(DeviceExt, *ParentFCB);
                 *ParentFCB = NULL;
                 vfatReleaseFCB(DeviceExt, TargetFcb);
@@ -427,10 +438,11 @@ vfatPrepareTargetForRename(
             }
 
             /* Effectively delete old file to allow renaming */
+            DPRINT("Effectively deleting the file.\n");
             VfatDelEntry(DeviceExt, TargetFcb, NULL);
-            vfatGrabFCB(DeviceExt, *ParentFCB);
             vfatReleaseFCB(DeviceExt, TargetFcb);
             *Deleted = TRUE;
+            return STATUS_SUCCESS;
         }
         else
         {