https://git.reactos.org/?p=reactos.git;a=commitdiff;h=074e7e97fe140f0c9f627…
commit 074e7e97fe140f0c9f627378995784b2c8328349
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Wed Feb 7 23:18:54 2018 +0100
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Wed Feb 7 23:18:54 2018 +0100
[NTOSKRNL] When initializing file cache, also allocate a private cache map if needed.
Not used yet.
---
ntoskrnl/cc/fs.c | 19 +++++++++++++++++++
ntoskrnl/cc/view.c | 42 +++++++++++++++++++++++++++++++++++++++---
ntoskrnl/include/internal/cc.h | 2 ++
3 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/ntoskrnl/cc/fs.c b/ntoskrnl/cc/fs.c
index 38c9ae527c..fddf76079a 100644
--- a/ntoskrnl/cc/fs.c
+++ b/ntoskrnl/cc/fs.c
@@ -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)
{
diff --git a/ntoskrnl/cc/view.c b/ntoskrnl/cc/view.c
index 1b4468cd41..145eb0d908 100644
--- a/ntoskrnl/cc/view.c
+++ b/ntoskrnl/cc/view.c
@@ -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);
diff --git a/ntoskrnl/include/internal/cc.h b/ntoskrnl/include/internal/cc.h
index f78e9c0491..9679255697 100644
--- a/ntoskrnl/include/internal/cc.h
+++ b/ntoskrnl/include/internal/cc.h
@@ -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