[NTOSKRNL] When initializing file cache, also allocate a private cache map if needed.
authorPierre Schweitzer <pierre@reactos.org>
Wed, 7 Feb 2018 22:18:54 +0000 (23:18 +0100)
committerPierre Schweitzer <pierre@reactos.org>
Wed, 7 Feb 2018 22:18:54 +0000 (23:18 +0100)
Not used yet.

ntoskrnl/cc/fs.c
ntoskrnl/cc/view.c
ntoskrnl/include/internal/cc.h

index 38c9ae5..fddf760 100644 (file)
@@ -346,6 +346,25 @@ CcUninitializeCacheMap (
                             FALSE);
     }
 
+    /* Closing the handle, so kill the private cache map */
+    if (FileObject->SectionObjectPointer->SharedCacheMap != NULL &&
+        FileObject->PrivateCacheMap != NULL)
+    {
+        PPRIVATE_CACHE_MAP PrivateMap;
+
+        PrivateMap = FileObject->PrivateCacheMap;
+        SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
+
+        /* Remove it from the file */
+        KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &OldIrql);
+        RemoveEntryList(&PrivateMap->PrivateLinks);
+        KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, OldIrql);
+
+        /* And free it */
+        FileObject->PrivateCacheMap = NULL;
+        ExFreePoolWithTag(PrivateMap, 'cPcC');
+    }
+
     Status = CcRosReleaseFileCache(FileObject);
     if (UninitializeCompleteEvent)
     {
index 1b4468c..145eb0d 100644 (file)
@@ -1209,17 +1209,19 @@ CcRosInitializeFileCache (
  * FUNCTION: Initializes a shared cache map for a file object
  */
 {
+    KIRQL OldIrql;
+    BOOLEAN Allocated;
     PROS_SHARED_CACHE_MAP SharedCacheMap;
 
     SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
     DPRINT("CcRosInitializeFileCache(FileObject 0x%p, SharedCacheMap 0x%p)\n",
            FileObject, SharedCacheMap);
 
+    Allocated = FALSE;
     KeAcquireGuardedMutex(&ViewLock);
     if (SharedCacheMap == NULL)
     {
-        KIRQL OldIrql;
-
+        Allocated = TRUE;
         SharedCacheMap = ExAllocateFromNPagedLookasideList(&SharedCacheMapLookasideList);
         if (SharedCacheMap == NULL)
         {
@@ -1239,6 +1241,7 @@ CcRosInitializeFileCache (
         SharedCacheMap->PinAccess = PinAccess;
         SharedCacheMap->DirtyPageThreshold = 0;
         SharedCacheMap->DirtyPages = 0;
+        InitializeListHead(&SharedCacheMap->PrivateList);
         KeInitializeSpinLock(&SharedCacheMap->CacheMapLock);
         InitializeListHead(&SharedCacheMap->CacheMapVacbListHead);
         FileObject->SectionObjectPointer->SharedCacheMap = SharedCacheMap;
@@ -1249,7 +1252,40 @@ CcRosInitializeFileCache (
     }
     if (FileObject->PrivateCacheMap == NULL)
     {
-        FileObject->PrivateCacheMap = SharedCacheMap;
+        PPRIVATE_CACHE_MAP PrivateMap;
+
+        /* Allocate the private cache map for this handle */
+        PrivateMap = ExAllocatePoolWithTag(NonPagedPool, sizeof(PRIVATE_CACHE_MAP), 'cPcC');
+        if (PrivateMap == NULL)
+        {
+            /* If we also allocated the shared cache map for this file, kill it */
+            if (Allocated)
+            {
+                KeAcquireSpinLock(&iSharedCacheMapLock, &OldIrql);
+                RemoveEntryList(&SharedCacheMap->SharedCacheMapLinks);
+                KeReleaseSpinLock(&iSharedCacheMapLock, OldIrql);
+
+                FileObject->SectionObjectPointer->SharedCacheMap = NULL;
+                ObDereferenceObject(FileObject);
+                ExFreeToNPagedLookasideList(&SharedCacheMapLookasideList, SharedCacheMap);
+            }
+
+            KeReleaseGuardedMutex(&ViewLock);
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
+
+        /* Initialize it */
+        RtlZeroMemory(PrivateMap, sizeof(PRIVATE_CACHE_MAP));
+        PrivateMap->NodeTypeCode = NODE_TYPE_PRIVATE_MAP;
+        PrivateMap->ReadAheadMask = 0xFFF;
+        PrivateMap->FileObject = FileObject;
+
+        /* Link it to the file */
+        KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &OldIrql);
+        InsertTailList(&SharedCacheMap->PrivateList, &PrivateMap->PrivateLinks);
+        KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, OldIrql);
+
+        FileObject->PrivateCacheMap = PrivateMap;
         SharedCacheMap->OpenCount++;
     }
     KeReleaseGuardedMutex(&ViewLock);
index f78e9c0..9679255 100644 (file)
@@ -163,6 +163,7 @@ typedef struct _ROS_SHARED_CACHE_MAP
     BOOLEAN PinAccess;
     PCACHE_MANAGER_CALLBACKS Callbacks;
     PVOID LazyWriteContext;
+    LIST_ENTRY PrivateList;
     KSPIN_LOCK CacheMapLock;
     ULONG OpenCount;
     ULONG DirtyPages;
@@ -255,6 +256,7 @@ typedef struct _WORK_QUEUE_ENTRY
 extern LAZY_WRITER LazyWriter;
 
 #define NODE_TYPE_DEFERRED_WRITE 0x02FC
+#define NODE_TYPE_PRIVATE_MAP    0x02FE
 
 VOID
 NTAPI