Author: pschweitzer
Date: Sat Aug  6 12:25:47 2016
New Revision: 72136

URL: http://svn.reactos.org/svn/reactos?rev=72136&view=rev
Log:
[FASTFAT]
Properly check for opened handles in subdirectories when we're about to rename 
a directory.
This helps reducing corruption where some renaming operations were allowed 
whereas they shouldn't have been.

CORE-11377
CORE-11426

Modified:
    trunk/reactos/drivers/filesystems/fastfat/finfo.c

Modified: trunk/reactos/drivers/filesystems/fastfat/finfo.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fastfat/finfo.c?rev=72136&r1=72135&r2=72136&view=diff
==============================================================================
--- trunk/reactos/drivers/filesystems/fastfat/finfo.c   [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/fastfat/finfo.c   [iso-8859-1] Sat Aug  6 
12:25:47 2016
@@ -458,6 +458,35 @@
     return Status;
 }
 
+static
+BOOLEAN
+IsThereAChildOpened(PVFATFCB FCB)
+{
+    PLIST_ENTRY Entry;
+    PVFATFCB VolFCB;
+
+    for (Entry = FCB->ParentListHead.Flink; Entry != &FCB->ParentListHead; 
Entry = Entry->Flink)
+    {
+        VolFCB = CONTAINING_RECORD(Entry, VFATFCB, ParentListEntry);
+        if (VolFCB->OpenHandleCount != 0)
+        {
+            ASSERT(VolFCB->parentFcb == FCB);
+            DPRINT1("At least one children file opened! %wZ (%u, %u)\n", 
&VolFCB->PathNameU, VolFCB->RefCount, VolFCB->OpenHandleCount);
+            return TRUE;
+        }
+
+        if (vfatFCBIsDirectory(VolFCB) && 
!IsListEmpty(&VolFCB->ParentListHead))
+        {
+            if (IsThereAChildOpened(VolFCB))
+            {
+                return TRUE;
+            }
+        }
+    }
+
+    return FALSE;
+}
+
 /*
  * FUNCTION: Set the file name information
  */
@@ -706,20 +735,11 @@
 
     if (vfatFCBIsDirectory(FCB) && !IsListEmpty(&FCB->ParentListHead))
     {
-        PLIST_ENTRY Entry;
-        PVFATFCB VolFCB;
-
-        for (Entry = FCB->ParentListHead.Flink; Entry != &FCB->ParentListHead; 
Entry = Entry->Flink)
-        {
-            VolFCB = CONTAINING_RECORD(Entry, VFATFCB, ParentListEntry);
-            if (VolFCB->OpenHandleCount != 0)
-            {
-                ASSERT(VolFCB->parentFCB == FCB);
-                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;
-            }
+        if (IsThereAChildOpened(FCB))
+        {
+            Status = STATUS_ACCESS_DENIED;
+            ASSERT(OldReferences == FCB->parentFcb->RefCount);
+            goto Cleanup;
         }
     }
 


Reply via email to