[FASTFAT]
authorPierre Schweitzer <pierre@reactos.org>
Sun, 26 Jun 2016 10:23:35 +0000 (10:23 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Sun, 26 Jun 2016 10:23:35 +0000 (10:23 +0000)
Don't allow renaming a directory if there are opened files in it.
The way we do it for now isn't fully optimal and could be really improved, but that's a first step in the right direction.
This should help getting rid of FAT volumes corruption.
This also fixes a few winetests it seems.

CORE-11426 #comment Patch that fixes bug 3 committed in r71674

svn path=/trunk/; revision=71674

reactos/drivers/filesystems/fastfat/finfo.c

index 83e691c..7ce51ee 100644 (file)
@@ -704,6 +704,27 @@ VfatSetRenameInformation(
     vfatSplitPathName(&NewName, &NewPath, &NewFile);
     DPRINT("New dir: %wZ, New file: %wZ\n", &NewPath, &NewFile);
 
+    /* FIXME: Do it in a more efficient way, like linking FCBs to their parent FCB so that we browse less FCBs
+     * Note: The FIXME is the way MS FastFAT seems to do it
+     */
+    if (vfatFCBIsDirectory(FCB))
+    {
+        PLIST_ENTRY Entry;
+        PVFATFCB VolFCB;
+
+        for (Entry = DeviceExt->FcbListHead.Flink; Entry != &DeviceExt->FcbListHead; Entry = Entry->Flink)
+        {
+            VolFCB = CONTAINING_RECORD(Entry, VFATFCB, FcbListEntry);
+            if (VolFCB->parentFcb == FCB && VolFCB->OpenHandleCount != 0)
+            {
+                DPRINT1("At least one children file opened! %wZ (%u, %u)\n", &VolFCB->PathNameU, VolFCB->RefCount, VolFCB->OpenHandleCount);
+                Status = STATUS_ACCESS_DENIED;
+                ASSERT(OldReferences == FCB->parentFcb->RefCount);
+                goto Cleanup;
+            }
+        }
+    }
+
     /* Are we working in place? */
     if (FsRtlAreNamesEqual(&SourcePath, &NewPath, TRUE, NULL))
     {