[NTOSKRNL] Implement CcIsThereDirtyData()
authorPierre Schweitzer <pierre@reactos.org>
Mon, 15 Jan 2018 22:20:53 +0000 (23:20 +0100)
committerPierre Schweitzer <pierre@reactos.org>
Mon, 15 Jan 2018 22:20:53 +0000 (23:20 +0100)
ntoskrnl/cc/fs.c
ntoskrnl/cc/view.c
ntoskrnl/include/internal/cc.h

index fb5f99a..d62e18d 100644 (file)
@@ -111,17 +111,51 @@ CcInitializeCacheMap (
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 BOOLEAN
 NTAPI
 CcIsThereDirtyData (
     IN PVPB Vpb)
 {
+    PROS_VACB Vacb;
+    PLIST_ENTRY Entry;
+    /* Assume no dirty data */
+    BOOLEAN Dirty = FALSE;
+
     CCTRACE(CC_API_DEBUG, "Vpb=%p\n", Vpb);
 
-    UNIMPLEMENTED;
-    return FALSE;
+    KeAcquireGuardedMutex(&ViewLock);
+
+    /* Browse dirty VACBs */
+    for (Entry = DirtyVacbListHead.Flink; Entry != &DirtyVacbListHead; Entry = Entry->Flink)
+    {
+        Vacb = CONTAINING_RECORD(Entry, ROS_VACB, DirtyVacbListEntry);
+        /* Look for these associated with our volume */
+        if (Vacb->SharedCacheMap->FileObject->Vpb != Vpb)
+        {
+            continue;
+        }
+
+        /* From now on, we are associated with our VPB */
+
+        /* Temporary files are not counted as dirty */
+        if (BooleanFlagOn(Vacb->SharedCacheMap->FileObject->Flags, FO_TEMPORARY_FILE))
+        {
+            continue;
+        }
+
+        /* A single dirty VACB is enough to have dirty data */
+        if (Vacb->Dirty)
+        {
+            Dirty = TRUE;
+            break;
+        }
+    }
+
+    KeReleaseGuardedMutex(&ViewLock);
+
+    return Dirty;
 }
 
 /*
index f38a028..0e37b77 100644 (file)
@@ -41,7 +41,7 @@
 
 /* GLOBALS *******************************************************************/
 
-static LIST_ENTRY DirtyVacbListHead;
+LIST_ENTRY DirtyVacbListHead;
 static LIST_ENTRY VacbLruListHead;
 ULONG DirtyPageCount = 0;
 
index 4f7c482..58d2b15 100644 (file)
@@ -40,6 +40,7 @@
 // Global Cc Data
 //
 extern ULONG CcRosTraceLevel;
+extern LIST_ENTRY DirtyVacbListHead;
 
 typedef struct _PF_SCENARIO_ID
 {