From 103fbf8518d4fcf45e4fae2c5665a354309a4e17 Mon Sep 17 00:00:00 2001 From: Sir Richard Date: Tue, 5 Oct 2010 15:52:00 +0000 Subject: [PATCH] [NTOS]: When shutting down, call Cc to flush the dirty cached pages, otherwise these might've gotten lost (and lead to lost/corrupted data on disk). [NTOS]: Don't assume that CcFlushDirtyPages will run with APCs disabled. Go ahead and actually enter/leave a critical region (Acquire/ReleaseForLazyWrite depend on this). The guarded mutex does disable APCs, but it's released when the actual flush happens. svn path=/trunk/; revision=48998 --- reactos/ntoskrnl/cc/view.c | 2 ++ reactos/ntoskrnl/po/power.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/reactos/ntoskrnl/cc/view.c b/reactos/ntoskrnl/cc/view.c index 72e70c99f4e..fcdefc4d032 100644 --- a/reactos/ntoskrnl/cc/view.c +++ b/reactos/ntoskrnl/cc/view.c @@ -189,6 +189,7 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count) (*Count) = 0; + KeEnterCriticalRegion(); KeAcquireGuardedMutex(&ViewLock); WriteCount[0] = WriteCount[1]; @@ -278,6 +279,7 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count) } KeReleaseGuardedMutex(&ViewLock); + KeLeaveCriticalRegion(); DPRINT("CcRosFlushDirtyPages() finished\n"); return(STATUS_SUCCESS); diff --git a/reactos/ntoskrnl/po/power.c b/reactos/ntoskrnl/po/power.c index 971691fa765..a163b98bc48 100644 --- a/reactos/ntoskrnl/po/power.c +++ b/reactos/ntoskrnl/po/power.c @@ -659,6 +659,7 @@ NtSetSystemPowerState(IN POWER_ACTION SystemAction, KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(); POP_POWER_ACTION Action = {0}; NTSTATUS Status; + ULONG Dummy; /* Check for invalid parameter combinations */ if ((MinSystemState >= PowerSystemMaximum) || @@ -742,9 +743,12 @@ NtSetSystemPowerState(IN POWER_ACTION SystemAction, /* Check if we're still in an invalid status */ if (!NT_SUCCESS(Status)) break; + + /* Flush dirty cache pages */ + CcRosFlushDirtyPages(-1, &Dummy); /* Flush all volumes and the registry */ - DPRINT1("Flushing volumes\n"); + DPRINT1("Flushing volumes, cache flushed %d pages\n", Dummy); PopFlushVolumes(PopAction.Shutdown); /* Set IRP for drivers */