From c779dbd4c5779cfddfd4054601d996c15ae22ff4 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Mon, 15 Jan 2018 23:20:53 +0100 Subject: [PATCH] [NTOSKRNL] Implement CcIsThereDirtyData() --- ntoskrnl/cc/fs.c | 40 +++++++++++++++++++++++++++++++--- ntoskrnl/cc/view.c | 2 +- ntoskrnl/include/internal/cc.h | 1 + 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/ntoskrnl/cc/fs.c b/ntoskrnl/cc/fs.c index fb5f99aab26..d62e18dee0a 100644 --- a/ntoskrnl/cc/fs.c +++ b/ntoskrnl/cc/fs.c @@ -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; } /* diff --git a/ntoskrnl/cc/view.c b/ntoskrnl/cc/view.c index f38a028d9ba..0e37b77efca 100644 --- a/ntoskrnl/cc/view.c +++ b/ntoskrnl/cc/view.c @@ -41,7 +41,7 @@ /* GLOBALS *******************************************************************/ -static LIST_ENTRY DirtyVacbListHead; +LIST_ENTRY DirtyVacbListHead; static LIST_ENTRY VacbLruListHead; ULONG DirtyPageCount = 0; diff --git a/ntoskrnl/include/internal/cc.h b/ntoskrnl/include/internal/cc.h index 4f7c4823af3..58d2b15a507 100644 --- a/ntoskrnl/include/internal/cc.h +++ b/ntoskrnl/include/internal/cc.h @@ -40,6 +40,7 @@ // Global Cc Data // extern ULONG CcRosTraceLevel; +extern LIST_ENTRY DirtyVacbListHead; typedef struct _PF_SCENARIO_ID {