https://git.reactos.org/?p=reactos.git;a=commitdiff;h=20fe42c9e92093996cbfafbc046ad037b0f07c0f

commit 20fe42c9e92093996cbfafbc046ad037b0f07c0f
Author:     Jérôme Gardou <[email protected]>
AuthorDate: Tue Jan 5 10:45:39 2021 +0100
Commit:     Jérôme Gardou <[email protected]>
CommitDate: Wed Feb 3 09:41:23 2021 +0100

    [NTOS:CC] Simplify CcFlushCache implementation
---
 ntoskrnl/cc/view.c | 90 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 50 insertions(+), 40 deletions(-)

diff --git a/ntoskrnl/cc/view.c b/ntoskrnl/cc/view.c
index 1bd86b2cab7..2aeb9df5b3b 100644
--- a/ntoskrnl/cc/view.c
+++ b/ntoskrnl/cc/view.c
@@ -899,63 +899,73 @@ CcFlushCache (
     OUT PIO_STATUS_BLOCK IoStatus)
 {
     PROS_SHARED_CACHE_MAP SharedCacheMap;
-    LARGE_INTEGER Offset;
-    LONGLONG RemainingLength;
-    PROS_VACB current;
+    LONGLONG FlushStart, FlushEnd;
     NTSTATUS Status;
 
     CCTRACE(CC_API_DEBUG, "SectionObjectPointers=%p FileOffset=0x%I64X 
Length=%lu\n",
         SectionObjectPointers, FileOffset ? FileOffset->QuadPart : 0LL, 
Length);
 
-    if (SectionObjectPointers && SectionObjectPointers->SharedCacheMap)
+    if (!SectionObjectPointers || !SectionObjectPointers->SharedCacheMap)
     {
-        SharedCacheMap = SectionObjectPointers->SharedCacheMap;
-        ASSERT(SharedCacheMap);
-        if (FileOffset)
-        {
-            Offset = *FileOffset;
-            RemainingLength = Length;
-        }
-        else
-        {
-            Offset.QuadPart = 0;
-            RemainingLength = SharedCacheMap->FileSize.QuadPart;
-        }
+        Status = STATUS_INVALID_PARAMETER;
+        goto quit;
+    }
 
-        if (IoStatus)
-        {
-            IoStatus->Status = STATUS_SUCCESS;
-            IoStatus->Information = 0;
-        }
+    SharedCacheMap = SectionObjectPointers->SharedCacheMap;
+    ASSERT(SharedCacheMap);
+    if (FileOffset)
+    {
+        FlushStart = FileOffset->QuadPart;
+        Status = RtlLongLongAdd(FlushStart, Length, &FlushEnd);
+        if (!NT_SUCCESS(Status))
+            goto quit;
+    }
+    else
+    {
+        FlushStart = 0;
+        FlushEnd = SharedCacheMap->FileSize.QuadPart;
+    }
+
+    Status = STATUS_SUCCESS;
+
+    if (IoStatus)
+    {
+        IoStatus->Information = 0;
+    }
 
-        while (RemainingLength > 0)
+    while (FlushStart < FlushEnd)
+    {
+        PROS_VACB vacb = CcRosLookupVacb(SharedCacheMap, FlushStart);
+
+        if (vacb != NULL)
         {
-            current = CcRosLookupVacb(SharedCacheMap, Offset.QuadPart);
-            if (current != NULL)
+            if (vacb->Dirty)
             {
-                if (current->Dirty)
+                Status = CcRosFlushVacb(vacb);
+                if (!NT_SUCCESS(Status))
                 {
-                    Status = CcRosFlushVacb(current);
-                    if (!NT_SUCCESS(Status) && IoStatus != NULL)
-                    {
-                        IoStatus->Status = Status;
-                    }
+                    goto quit;
                 }
-
-                CcRosReleaseVacb(SharedCacheMap, current, FALSE, FALSE);
             }
 
-            Offset.QuadPart += VACB_MAPPING_GRANULARITY;
-            RemainingLength -= min(RemainingLength, VACB_MAPPING_GRANULARITY);
+            CcRosReleaseVacb(SharedCacheMap, vacb, FALSE, FALSE);
+
+            if (IoStatus)
+                IoStatus->Information += VACB_MAPPING_GRANULARITY;
         }
-    }
-    else
-    {
-        if (IoStatus)
+
+        if (!NT_SUCCESS(RtlLongLongAdd(FlushStart, VACB_MAPPING_GRANULARITY, 
&FlushStart)))
         {
-            IoStatus->Status = STATUS_INVALID_PARAMETER;
+            /* We're at the end of file ! */
+            break;
         }
     }
+
+quit:
+    if (IoStatus)
+    {
+        IoStatus->Status = Status;
+    }
 }
 
 NTSTATUS
@@ -1188,7 +1198,7 @@ CcRosInitializeFileCache (
 
         FileObject->SectionObjectPointer->SharedCacheMap = SharedCacheMap;
 
-        // CcRosTraceCacheMap(SharedCacheMap, TRUE);
+        //CcRosTraceCacheMap(SharedCacheMap, TRUE);
     }
     else if (SharedCacheMap->Flags & SHARED_CACHE_MAP_IN_CREATION)
     {

Reply via email to