[NTOS:CC] Restore read-ahead behaviour in CcCopyRead
authorJérôme Gardou <jerome.gardou@reactos.org>
Fri, 11 Dec 2020 13:31:08 +0000 (14:31 +0100)
committerJérôme Gardou <jerome.gardou@reactos.org>
Wed, 3 Feb 2021 08:41:22 +0000 (09:41 +0100)
ntoskrnl/cc/copy.c

index 315e9f1..3dd172f 100644 (file)
@@ -556,6 +556,27 @@ CcCopyRead (
     IoStatus->Status = STATUS_SUCCESS;
     IoStatus->Information = ReadLength;
 
+    /* If that was a successful sync read operation, let's handle read ahead */
+    if (Length == 0 && Wait)
+    {
+        PPRIVATE_CACHE_MAP PrivateCacheMap = FileObject->PrivateCacheMap;
+
+        /* If file isn't random access and next read may get us cross VACB boundary,
+         * schedule next read
+         */
+        if (!BooleanFlagOn(FileObject->Flags, FO_RANDOM_ACCESS) &&
+            (CurrentOffset - 1) / VACB_MAPPING_GRANULARITY != (CurrentOffset + ReadLength - 1) / VACB_MAPPING_GRANULARITY)
+        {
+            CcScheduleReadAhead(FileObject, FileOffset, ReadLength);
+        }
+
+        /* And update read history in private cache map */
+        PrivateCacheMap->FileOffset1.QuadPart = PrivateCacheMap->FileOffset2.QuadPart;
+        PrivateCacheMap->BeyondLastByte1.QuadPart = PrivateCacheMap->BeyondLastByte2.QuadPart;
+        PrivateCacheMap->FileOffset2.QuadPart = FileOffset->QuadPart;
+        PrivateCacheMap->BeyondLastByte2.QuadPart = FileOffset->QuadPart + ReadLength;
+    }
+
     return TRUE;
 }