Author: arty
Date: Mon Aug 18 06:01:17 2008
New Revision: 35426
URL:
http://svn.reactos.org/svn/reactos?rev=35426&view=rev
Log:
More WIP. Actually implement pinning and flushing, among other things.
VFAT still isn't writing. Figuring out why.
Modified:
branches/arty-newcc/ntoskrnl/cache/cachesub.c
branches/arty-newcc/ntoskrnl/cache/copysup.c
branches/arty-newcc/ntoskrnl/cache/fssup.c
branches/arty-newcc/ntoskrnl/cache/pinsup.c
branches/arty-newcc/ntoskrnl/include/internal/cc.h
branches/arty-newcc/ntoskrnl/mm/section.c
Modified: branches/arty-newcc/ntoskrnl/cache/cachesub.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/cache…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/cachesub.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/cachesub.c [iso-8859-1] Mon Aug 18 06:01:17 2008
@@ -37,7 +37,7 @@
NTSTATUS Status;
PIRP Irp = NULL;
KEVENT ReadWait;
- PDEVICE_OBJECT DeviceObject = MmGetDeviceObjectForFile(FileObject);
+ PDEVICE_OBJECT DeviceObject;
PIO_STACK_LOCATION IrpSp;
KIRQL OldIrql;
@@ -47,11 +47,11 @@
!MmIsCOWAddress(PsInitialSystemProcess, Buffer))
{
DPRINT1
- ("PAGING WRITE (FLUSH) File %wZ Offset %x Length %d\n",
- &FileObject->FileName,
+ ("PAGING WRITE (FLUSH) Offset %x Length %d\n",
FileOffset->u.LowPart,
Length);
+ DeviceObject = MmGetDeviceObjectForFile(FileObject);
MmSetCleanPage(PsInitialSystemProcess, Buffer);
KeLowerIrql(OldIrql);
@@ -185,8 +185,6 @@
LARGE_INTEGER ToWrite = *FileOffset;
IO_STATUS_BLOCK IOSB;
- DPRINT("CcFlushCache\n");
-
BOOLEAN Result = CcpMapData
((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap,
FileOffset,
@@ -200,20 +198,22 @@
BufStart = (PCHAR)PAGE_ROUND_DOWN(((ULONG_PTR)Buffer));
ToWrite.LowPart = PAGE_ROUND_DOWN(FileOffset->LowPart);
+ DPRINT
+ ("CcpSimpleWrite: [%wZ] %x:%d\n",
+ &Bcb->FileObject->FileName,
+ Buffer,
+ Bcb->Length);
+
for (BufPage = BufStart;
BufPage < BufStart + PAGE_ROUND_UP(Length);
BufPage += PAGE_SIZE)
{
- DPRINT
- ("CcpSimpleWrite: [%wZ] %x:%d\n",
- &Bcb->FileObject->FileName,
- Bcb->FileOffset.LowPart,
- Bcb->Length);
CcpSimpleWrite(Bcb->FileObject, &ToWrite, BufPage, &IOSB);
- DPRINT
- ("Page Write: %08x\n", IOSB.Status);
ToWrite.QuadPart += PAGE_SIZE;
}
+
+ DPRINT
+ ("Page Write: %08x\n", IOSB.Status);
CcUnpinData(Bcb);
@@ -227,7 +227,6 @@
IoStatus->Status = IOSB.Status;
IoStatus->Information = 0;
}
- DPRINT("CcFlushCache -> %08x\n", IOSB.Status);
}
// Always succeeds for us
Modified: branches/arty-newcc/ntoskrnl/cache/copysup.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/copys…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/copysup.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/copysup.c [iso-8859-1] Mon Aug 18 06:01:17 2008
@@ -153,7 +153,7 @@
Count = i;
- DPRINT("Copying %d bytes for Read\n", Length);
+ DPRINT("Copying %d bytes for Write\n", Length);
for (WriteBuf = (PCHAR)Buffer, WriteLen = Length, i = 0;
WriteLen > 0;
Modified: branches/arty-newcc/ntoskrnl/cache/fssup.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/fssup…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/fssup.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/fssup.c [iso-8859-1] Mon Aug 18 06:01:17 2008
@@ -59,6 +59,7 @@
KEBUGCHECK(0);
}
+#if 0
Status = PsCreateSystemThread
(&CcLazyWriteThreadHandle,
THREAD_ALL_ACCESS,
@@ -67,6 +68,7 @@
&CcLazyWriteThreadId,
(PKSTART_ROUTINE) CcpLazyWriteThread,
NULL);
+#endif
if (!NT_SUCCESS(Status))
{
@@ -101,12 +103,12 @@
IN PCACHE_MANAGER_CALLBACKS Callbacks,
IN PVOID LazyWriteContext)
{
- DPRINT("Initializing file object for %wZ\n", &FileObject->FileName);
- PNOCC_CACHE_MAP Map = ExAllocatePool(NonPagedPool, sizeof(NOCC_CACHE_MAP));
+ DPRINT("Initializing file object for %wZ\n",
&FileObject->FileName);
+ PNOCC_CACHE_MAP Map = ExAllocatePool(NonPagedPool, sizeof(NOCC_CACHE_MAP));
FileObject->SectionObjectPointer->SharedCacheMap = Map;
- Map->FileObject = FileObject;
- Map->NumberOfMaps = 0;
- InitializeListHead(&Map->AssociatedBcb);
+ Map->FileObject = FileObject;
+ Map->NumberOfMaps = 0;
+ InitializeListHead(&Map->AssociatedBcb);
return;
}
@@ -116,30 +118,52 @@
IN OPTIONAL PLARGE_INTEGER TruncateSize,
IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
{
- PNOCC_CACHE_MAP Map =
(PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
- PNOCC_BCB Bcb;
- PLIST_ENTRY Entry;
-
- DPRINT("Uninitializing file object for %wZ\n", &FileObject->FileName);
-
+ PNOCC_CACHE_MAP Map =
(PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
+ PNOCC_BCB Bcb;
+ PLIST_ENTRY Entry;
+ IO_STATUS_BLOCK IOSB;
+
+ DPRINT("Uninitializing file object for %wZ\n",
&FileObject->FileName);
+
ASSERT(UninitializeEvent == NULL);
- CcpLock();
-
- for (Entry =
((PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap)->AssociatedBcb.Flink;
- Entry !=
&((PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap)->AssociatedBcb;
- Entry = Entry->Flink)
- {
- Bcb = CONTAINING_RECORD(Entry, NOCC_BCB, ThisFileList);
- if (Bcb->RefCount == 1)
- {
- DPRINT("Unmapping #%x\n", Bcb - CcCacheSections);
- CcpDereferenceCache(Bcb - CcCacheSections);
- }
- }
- CcpUnlock();
-
- ExFreePool(Map);
-
+
+ for (Entry = Map->AssociatedBcb.Flink;
+ Entry != &Map->AssociatedBcb;
+ Entry = Entry->Flink)
+ {
+ Bcb = CONTAINING_RECORD(Entry, NOCC_BCB, ThisFileList);
+
+ if (!Bcb->Dirty) continue;
+
+ if (Bcb->RefCount == 1)
+ {
+ DPRINT("Flushing #%x\n", Bcb - CcCacheSections);
+ CcFlushCache
+ (Bcb->FileObject->SectionObjectPointer,
+ &Bcb->FileOffset,
+ Bcb->Length,
+ &IOSB);
+ }
+ }
+
+ CcpLock();
+
+ for (Entry = Map->AssociatedBcb.Flink;
+ Entry != &Map->AssociatedBcb;
+ Entry = Entry->Flink)
+ {
+ Bcb = CONTAINING_RECORD(Entry, NOCC_BCB, ThisFileList);
+ if (Bcb->RefCount == 1)
+ {
+ DPRINT("Unmapping #%x\n", Bcb - CcCacheSections);
+ CcpDereferenceCache(Bcb - CcCacheSections);
+ }
+ }
+
+ CcpUnlock();
+
+ ExFreePool(Map);
+
/* Clear the cache map */
FileObject->SectionObjectPointer->SharedCacheMap = NULL;
return TRUE;
Modified: branches/arty-newcc/ntoskrnl/cache/pinsup.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/pinsu…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/pinsup.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/pinsup.c [iso-8859-1] Mon Aug 18 06:01:17 2008
@@ -43,64 +43,80 @@
(PFILE_OBJECT FileObject,
PNOCC_BCB Bcb)
{
- PLIST_ENTRY Entry;
-
- for (Entry =
((PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap)->AssociatedBcb.Flink;
- Entry !=
&((PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap)->AssociatedBcb;
- Entry = Entry->Flink)
- {
- ASSERT(CONTAINING_RECORD(Entry, NOCC_BCB, ThisFileList) != Bcb);
- }
+ PLIST_ENTRY Entry;
+
+ for (Entry =
((PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap)->AssociatedBcb.Flink;
+ Entry !=
&((PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap)->AssociatedBcb;
+ Entry = Entry->Flink)
+ {
+ ASSERT(CONTAINING_RECORD(Entry, NOCC_BCB, ThisFileList) != Bcb);
+ }
}
VOID CcpLock()
{
+ KeAcquireGuardedMutex(&CcMutex);
+ //DPRINT("<<<---<<< CC In Mutex!\n");
+}
+
+NTSTATUS
+NTAPI
+CcpSimpleWrite
+(PFILE_OBJECT FileObject,
+ PLARGE_INTEGER FileOffset,
+ PVOID Buffer,
+ PIO_STATUS_BLOCK ReadStatus);
+
+VOID CcpPerformUnmapWork()
+{
+ NOCC_UNMAP_CHAIN WorkingOn;
+ IO_STATUS_BLOCK IoStatus;
+ ULONG NumElements;
+ PCHAR BufStart, BufPage;
+ LARGE_INTEGER ToWrite;
+
+ KeAcquireGuardedMutex(&CcMutex);
+ while (CcOutstandingDeletes > 0)
+ {
+ NumElements = InterlockedDecrement(&CcOutstandingDeletes);
+ DPRINT1("Unmapping %d ...\n", NumElements);
+ WorkingOn = CcUnmapChain[0];
+ RtlMoveMemory(&CcUnmapChain[0], &CcUnmapChain[1], NumElements *
sizeof(NOCC_UNMAP_CHAIN));
+ KeReleaseGuardedMutex(&CcMutex);
+
+ BufStart = (PCHAR)WorkingOn.Buffer;
+ ToWrite = WorkingOn.FileOffset;
+
+ for (BufPage = BufStart;
+ BufPage < BufStart + WorkingOn.Length;
+ BufPage += PAGE_SIZE)
+ {
+ CcpSimpleWrite(WorkingOn.FileObject, &ToWrite, BufPage, &IoStatus);
+ ToWrite.QuadPart += PAGE_SIZE;
+ }
+
+ MmUnmapViewInSystemSpace(WorkingOn.Buffer);
+ ObDereferenceObject(WorkingOn.SectionObject);
+ DPRINT1("Done unmapping\n");
KeAcquireGuardedMutex(&CcMutex);
- //DPRINT("<<<---<<< CC In Mutex!\n");
-}
-
-VOID CcpPerformUnmapWork()
-{
- NOCC_UNMAP_CHAIN WorkingOn;
- IO_STATUS_BLOCK IoStatus;
- ULONG NumElements;
-
- KeAcquireGuardedMutex(&CcMutex);
- while (CcOutstandingDeletes > 0)
- {
- NumElements = InterlockedDecrement(&CcOutstandingDeletes);
- DPRINT1("Unmapping %d ...\n", NumElements);
- WorkingOn = CcUnmapChain[0];
- RtlMoveMemory(&CcUnmapChain[0], &CcUnmapChain[1], NumElements *
sizeof(NOCC_UNMAP_CHAIN));
- KeReleaseGuardedMutex(&CcMutex);
- CcFlushCache
- (WorkingOn.FileObject->SectionObjectPointer,
- &WorkingOn.FileOffset,
- WorkingOn.Length,
- &IoStatus);
- DPRINT1("Status result from flush: %08x\n", IoStatus.Status);
- MmUnmapViewInSystemSpace(WorkingOn.Buffer);
- ObDereferenceObject(WorkingOn.SectionObject);
- DPRINT1("Done unmapping\n");
- KeAcquireGuardedMutex(&CcMutex);
- }
- KeReleaseGuardedMutex(&CcMutex);
+ }
+ KeReleaseGuardedMutex(&CcMutex);
}
VOID CcpUnlock()
{
- //DPRINT(">>>--->>> CC Exit Mutex!\n");
- KeReleaseGuardedMutex(&CcMutex);
+ //DPRINT(">>>--->>> CC Exit Mutex!\n");
+ KeReleaseGuardedMutex(&CcMutex);
}
VOID STDCALL
CcpUnmapThread(PVOID Unused)
{
- while (TRUE)
- {
- KeWaitForSingleObject(&CcDeleteEvent, UserRequest, KernelMode, FALSE, NULL);
- CcpPerformUnmapWork();
- }
+ while (TRUE)
+ {
+ KeWaitForSingleObject(&CcDeleteEvent, UserRequest, KernelMode, FALSE, NULL);
+ CcpPerformUnmapWork();
+ }
}
PDEVICE_OBJECT
@@ -109,50 +125,50 @@
VOID CcpUnmapSegment(ULONG Segment)
{
- PNOCC_BCB Bcb = &CcCacheSections[Segment];
- PNOCC_UNMAP_CHAIN UnmapWork = &CcUnmapChain[CcOutstandingDeletes];
-
- ASSERT(Bcb->RefCount > 0);
- DPRINT("CcpUnmapSegment(#%x)\n", Segment);
-
- InterlockedIncrement(&CcOutstandingDeletes);
- UnmapWork->Buffer = Bcb->BaseAddress;
- UnmapWork->SectionObject = Bcb->SectionObject;
- UnmapWork->FileObject = Bcb->FileObject;
- UnmapWork->FileOffset = Bcb->FileOffset;
- UnmapWork->Length = Bcb->Length;
- Bcb->BaseAddress = NULL;
- Bcb->Length = 0;
- Bcb->FileOffset.QuadPart = 0;
-
- KeSetEvent(&CcDeleteEvent, IO_DISK_INCREMENT, FALSE);
+ PNOCC_BCB Bcb = &CcCacheSections[Segment];
+ PNOCC_UNMAP_CHAIN UnmapWork = &CcUnmapChain[CcOutstandingDeletes];
+
+ ASSERT(Bcb->RefCount > 0);
+ DPRINT("CcpUnmapSegment(#%x)\n", Segment);
+
+ InterlockedIncrement(&CcOutstandingDeletes);
+ UnmapWork->Buffer = Bcb->BaseAddress;
+ UnmapWork->SectionObject = Bcb->SectionObject;
+ UnmapWork->FileObject = Bcb->FileObject;
+ UnmapWork->FileOffset = Bcb->FileOffset;
+ UnmapWork->Length = Bcb->Length;
+ Bcb->BaseAddress = NULL;
+ Bcb->Length = 0;
+ Bcb->FileOffset.QuadPart = 0;
+
+ KeSetEvent(&CcDeleteEvent, IO_DISK_INCREMENT, FALSE);
}
NTSTATUS CcpMapSegment(ULONG Start)
{
- PNOCC_BCB Bcb = &CcCacheSections[Start];
- ULONG ViewSize = CACHE_STRIPE;
- NTSTATUS Status;
-
- ASSERT(RtlTestBit(CcCacheBitmap, Start));
- DPRINT("CcpMapSegment(#%x)\n", Start);
-
- Status = MmMapViewInSystemSpaceAtOffset
- (Bcb->SectionObject,
- &Bcb->BaseAddress,
- &Bcb->FileOffset,
- &ViewSize);
-
- if (!NT_SUCCESS(Status))
- {
- DPRINT("Failed to map view in system space: %x\n", Status);
- return Status;
- }
-
- DPRINT("System view is at %x\n", Bcb->BaseAddress);
- Bcb->Length = ViewSize;
-
- return TRUE;
+ PNOCC_BCB Bcb = &CcCacheSections[Start];
+ ULONG ViewSize = CACHE_STRIPE;
+ NTSTATUS Status;
+
+ ASSERT(RtlTestBit(CcCacheBitmap, Start));
+ DPRINT("CcpMapSegment(#%x)\n", Start);
+
+ Status = MmMapViewInSystemSpaceAtOffset
+ (Bcb->SectionObject,
+ &Bcb->BaseAddress,
+ &Bcb->FileOffset,
+ &ViewSize);
+
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("Failed to map view in system space: %x\n", Status);
+ return Status;
+ }
+
+ DPRINT("System view is at %x\n", Bcb->BaseAddress);
+ Bcb->Length = ViewSize;
+
+ return TRUE;
}
NTSTATUS CcpAllocateSection
@@ -161,52 +177,52 @@
ULONG Protect,
PSECTION_OBJECT *Result)
{
- NTSTATUS Status;
- LARGE_INTEGER MaxSize;
-
- MaxSize.QuadPart = Length;
-
- Status = MmCreateSection
- ((PVOID*)Result,
- STANDARD_RIGHTS_REQUIRED,
- NULL,
- &MaxSize,
- Protect,
- SEC_RESERVE,
- NULL,
- FileObject);
-
- return Status;
+ NTSTATUS Status;
+ LARGE_INTEGER MaxSize;
+
+ MaxSize.QuadPart = Length;
+
+ Status = MmCreateSection
+ ((PVOID*)Result,
+ STANDARD_RIGHTS_REQUIRED,
+ NULL,
+ &MaxSize,
+ Protect,
+ SEC_RESERVE,
+ NULL,
+ FileObject);
+
+ return Status;
}
/* Must have acquired the mutex */
VOID CcpDereferenceCache(ULONG Start)
{
- PNOCC_BCB Bcb;
- PNOCC_CACHE_MAP Map;
-
- DPRINT("CcpDereferenceCache(#%x)\n", Start);
-
- Bcb = &CcCacheSections[Start];
- DPRINT("Dereference #%x (count %d)\n", Start, Bcb->RefCount);
- ASSERT(Bcb->FileObject);
- ASSERT(Bcb->SectionObject);
- ASSERT(Bcb->RefCount == 1);
-
- Map = (PNOCC_CACHE_MAP)Bcb->FileObject->SectionObjectPointer->SharedCacheMap;
- Map->NumberOfMaps--;
-
- DPRINT("Fully unreferencing Bcb #%x\n", Start);
- CcpUnmapSegment(Start);
-
- RemoveEntryList(&Bcb->ThisFileList);
-
- Bcb->FileObject = NULL;
- Bcb->SectionObject = NULL;
- Bcb->BaseAddress = NULL;
- Bcb->FileOffset.QuadPart = 0;
- Bcb->Length = 0;
- Bcb->RefCount = 0;
+ PNOCC_BCB Bcb;
+ PNOCC_CACHE_MAP Map;
+
+ DPRINT("CcpDereferenceCache(#%x)\n", Start);
+
+ Bcb = &CcCacheSections[Start];
+ DPRINT("Dereference #%x (count %d)\n", Start, Bcb->RefCount);
+ ASSERT(Bcb->FileObject);
+ ASSERT(Bcb->SectionObject);
+ ASSERT(Bcb->RefCount == 1);
+
+ Map =
(PNOCC_CACHE_MAP)Bcb->FileObject->SectionObjectPointer->SharedCacheMap;
+ Map->NumberOfMaps--;
+
+ DPRINT("Fully unreferencing Bcb #%x\n", Start);
+ CcpUnmapSegment(Start);
+
+ RemoveEntryList(&Bcb->ThisFileList);
+
+ Bcb->FileObject = NULL;
+ Bcb->SectionObject = NULL;
+ Bcb->BaseAddress = NULL;
+ Bcb->FileOffset.QuadPart = 0;
+ Bcb->Length = 0;
+ Bcb->RefCount = 0;
}
/* Needs mutex */
@@ -215,67 +231,67 @@
PSECTION_OBJECT SectionObject,
PLARGE_INTEGER FileOffset)
{
- ULONG i = INVALID_CACHE;
- PNOCC_CACHE_MAP Map;
- PNOCC_BCB Bcb;
-
- DPRINT("AllocateCacheSections: FileObject %x\n", FileObject);
-
- if (!FileObject->SectionObjectPointer)
- return INVALID_CACHE;
-
- Map = (PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
-
- if (!Map)
- return INVALID_CACHE;
-
- DPRINT("Allocating Cache Section (File already has %d sections)\n",
Map->NumberOfMaps);
-
- i = RtlFindClearBitsAndSet
- (CcCacheBitmap, 1, CcCacheClockHand);
- CcCacheClockHand = i + 1;
-
- if (i != INVALID_CACHE)
- {
- DPRINT("Setting up Bcb #%x\n", i);
-
- Bcb = &CcCacheSections[i];
-
- ASSERT(Bcb->RefCount < 2);
-
- if (Bcb->RefCount > 0)
- {
- CcpDereferenceCache(i);
- }
-
- ASSERT(!Bcb->RefCount);
-
- Bcb->RefCount = 1;
- DPRINT("Bcb #%x RefCount %d\n", Bcb - CcCacheSections, Bcb->RefCount);
- ObReferenceObject(SectionObject);
-
- Bcb->FileObject = FileObject;
- Bcb->SectionObject = SectionObject;
- Bcb->FileOffset = *FileOffset;
- Bcb->Length = CACHE_STRIPE;
- Map->NumberOfMaps++;
-
- InsertTailList(&Map->AssociatedBcb, &Bcb->ThisFileList);
-
- if (!RtlTestBit(CcCacheBitmap, i))
- {
- DPRINT("Somebody stoeled BCB #%x\n", i);
- }
- ASSERT(RtlTestBit(CcCacheBitmap, i));
-
- DPRINT("Allocated #%x\n", i);
- ASSERT(CcCacheSections[i].RefCount);
- }
- else
- {
- DPRINT("Failed to allocate cache segment\n");
- }
- return i;
+ ULONG i = INVALID_CACHE;
+ PNOCC_CACHE_MAP Map;
+ PNOCC_BCB Bcb;
+
+ DPRINT("AllocateCacheSections: FileObject %x\n", FileObject);
+
+ if (!FileObject->SectionObjectPointer)
+ return INVALID_CACHE;
+
+ Map = (PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
+
+ if (!Map)
+ return INVALID_CACHE;
+
+ DPRINT("Allocating Cache Section (File already has %d sections)\n",
Map->NumberOfMaps);
+
+ i = RtlFindClearBitsAndSet
+ (CcCacheBitmap, 1, CcCacheClockHand);
+ CcCacheClockHand = i + 1;
+
+ if (i != INVALID_CACHE)
+ {
+ DPRINT("Setting up Bcb #%x\n", i);
+
+ Bcb = &CcCacheSections[i];
+
+ ASSERT(Bcb->RefCount < 2);
+
+ if (Bcb->RefCount > 0)
+ {
+ CcpDereferenceCache(i);
+ }
+
+ ASSERT(!Bcb->RefCount);
+
+ Bcb->RefCount = 1;
+ DPRINT("Bcb #%x RefCount %d\n", Bcb - CcCacheSections, Bcb->RefCount);
+ ObReferenceObject(SectionObject);
+
+ Bcb->FileObject = FileObject;
+ Bcb->SectionObject = SectionObject;
+ Bcb->FileOffset = *FileOffset;
+ Bcb->Length = CACHE_STRIPE;
+ Map->NumberOfMaps++;
+
+ InsertTailList(&Map->AssociatedBcb, &Bcb->ThisFileList);
+
+ if (!RtlTestBit(CcCacheBitmap, i))
+ {
+ DPRINT("Somebody stoeled BCB #%x\n", i);
+ }
+ ASSERT(RtlTestBit(CcCacheBitmap, i));
+
+ DPRINT("Allocated #%x\n", i);
+ ASSERT(CcCacheSections[i].RefCount);
+ }
+ else
+ {
+ DPRINT("Failed to allocate cache segment\n");
+ }
+ return i;
}
/*
@@ -283,86 +299,86 @@
*/
ULONG CcpFindCacheFor(PNOCC_CACHE_MAP Map)
{
- if (!Map)
- return INVALID_CACHE;
- else
- {
- if (IsListEmpty(&Map->AssociatedBcb))
- return INVALID_CACHE;
- PNOCC_BCB Bcb = CONTAINING_RECORD
- (Map->AssociatedBcb.Flink,
- NOCC_BCB,
- ThisFileList);
- return Bcb - CcCacheSections;
- }
+ if (!Map)
+ return INVALID_CACHE;
+ else
+ {
+ if (IsListEmpty(&Map->AssociatedBcb))
+ return INVALID_CACHE;
+ PNOCC_BCB Bcb = CONTAINING_RECORD
+ (Map->AssociatedBcb.Flink,
+ NOCC_BCB,
+ ThisFileList);
+ return Bcb - CcCacheSections;
+ }
}
/* Must have acquired the mutex */
VOID CcpReferenceCache(ULONG Start)
{
- PNOCC_BCB Bcb;
- Bcb = &CcCacheSections[Start];
- ASSERT(Bcb->FileObject);
- ASSERT(Bcb->SectionObject);
- Bcb->RefCount++;
- RtlSetBit(CcCacheBitmap, Start);
+ PNOCC_BCB Bcb;
+ Bcb = &CcCacheSections[Start];
+ ASSERT(Bcb->FileObject);
+ ASSERT(Bcb->SectionObject);
+ Bcb->RefCount++;
+ RtlSetBit(CcCacheBitmap, Start);
}
VOID CcpMarkForExclusive(ULONG Start)
{
- PNOCC_BCB Bcb;
- Bcb = &CcCacheSections[Start];
- Bcb->ExclusiveWaiter++;
+ PNOCC_BCB Bcb;
+ Bcb = &CcCacheSections[Start];
+ Bcb->ExclusiveWaiter++;
}
/* Must not have the mutex */
VOID CcpReferenceCacheExclusive(ULONG Start)
{
- PNOCC_BCB Bcb = &CcCacheSections[Start];
-
- KeWaitForSingleObject(&Bcb->ExclusiveWait, Executive, KernelMode, FALSE, NULL);
- CcpLock();
- ASSERT(Bcb->ExclusiveWaiter);
- ASSERT(Bcb->FileObject);
- ASSERT(Bcb->SectionObject);
- Bcb->RefCount++;
- Bcb->Exclusive = TRUE;
- Bcb->ExclusiveWaiter--;
- RtlSetBit(CcCacheBitmap, Start);
- CcpUnlock();
+ PNOCC_BCB Bcb = &CcCacheSections[Start];
+
+ KeWaitForSingleObject(&Bcb->ExclusiveWait, Executive, KernelMode, FALSE,
NULL);
+ CcpLock();
+ ASSERT(Bcb->ExclusiveWaiter);
+ ASSERT(Bcb->FileObject);
+ ASSERT(Bcb->SectionObject);
+ Bcb->RefCount++;
+ Bcb->Exclusive = TRUE;
+ Bcb->ExclusiveWaiter--;
+ RtlSetBit(CcCacheBitmap, Start);
+ CcpUnlock();
}
/* Find a map that encompasses the target range */
/* Must have the mutex */
ULONG CcpFindMatchingMap(PNOCC_BCB Head, PLARGE_INTEGER FileOffset, ULONG Length)
{
- PLIST_ENTRY Entry;
-
- //DPRINT("Find Matching Map: %x:%x\n", FileOffset->LowPart, Length);
-
- if (FileOffset->QuadPart >= Head->FileOffset.QuadPart &&
- FileOffset->QuadPart + Length <= Head->FileOffset.QuadPart + Head->Length)
- {
- //DPRINT("Head matched\n");
- return Head - CcCacheSections;
- }
-
- for (Entry = Head->ThisFileList.Flink; Entry != &Head->ThisFileList; Entry =
Entry->Flink)
- {
- PNOCC_BCB Bcb = CONTAINING_RECORD(Entry, NOCC_BCB, ThisFileList);
- //DPRINT("This File: %x:%x\n", Bcb->FileOffset.LowPart, Bcb->Length);
- if (FileOffset->QuadPart >= Bcb->FileOffset.QuadPart &&
- FileOffset->QuadPart + Length <= Bcb->FileOffset.QuadPart + Bcb->Length)
- {
- //DPRINT("Found match at #%x\n", Bcb - CcCacheSections);
- return Bcb - CcCacheSections;
- }
- }
-
- //DPRINT("This region isn't mapped\n");
-
- return INVALID_CACHE;
+ PLIST_ENTRY Entry;
+
+ //DPRINT("Find Matching Map: %x:%x\n", FileOffset->LowPart, Length);
+
+ if (FileOffset->QuadPart >= Head->FileOffset.QuadPart &&
+ FileOffset->QuadPart + Length <= Head->FileOffset.QuadPart + Head->Length)
+ {
+ //DPRINT("Head matched\n");
+ return Head - CcCacheSections;
+ }
+
+ for (Entry = Head->ThisFileList.Flink; Entry != &Head->ThisFileList; Entry
= Entry->Flink)
+ {
+ PNOCC_BCB Bcb = CONTAINING_RECORD(Entry, NOCC_BCB, ThisFileList);
+ //DPRINT("This File: %x:%x\n", Bcb->FileOffset.LowPart, Bcb->Length);
+ if (FileOffset->QuadPart >= Bcb->FileOffset.QuadPart &&
+ FileOffset->QuadPart + Length <= Bcb->FileOffset.QuadPart +
Bcb->Length)
+ {
+ //DPRINT("Found match at #%x\n", Bcb - CcCacheSections);
+ return Bcb - CcCacheSections;
+ }
+ }
+
+ //DPRINT("This region isn't mapped\n");
+
+ return INVALID_CACHE;
}
BOOLEAN
@@ -375,130 +391,130 @@
OUT PVOID *BcbResult,
OUT PVOID *Buffer)
{
- BOOLEAN Success = FALSE;
- PFILE_OBJECT FileObject = Map->FileObject;
- /* Note: windows 2000 drivers treat this as a bool */
- BOOLEAN Wait = (Flags & MAP_WAIT) || (Flags == TRUE);
- LARGE_INTEGER Target;
- ULONG BcbHead;
- PNOCC_BCB Bcb = NULL;
- PSECTION_OBJECT SectionObject = NULL;
- NTSTATUS Status;
-
- DPRINT("CcMapData(F->%x,%x:%d)\n", Map, FileOffset->LowPart, Length);
-
- ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
-
- Target.QuadPart = CACHE_ROUND_DOWN(FileOffset->QuadPart);
-
- CcpLock();
-
- /* Find out if any range is a superset of what we want */
- BcbHead = CcpFindCacheFor(Map);
-
- /* No bcbs for this file */
- if (BcbHead != INVALID_CACHE)
- {
- /* Find an accomodating section */
- //DPRINT("Selected BCB #%x\n", BcbHead);
- Bcb = &CcCacheSections[BcbHead];
- SectionObject = Bcb->SectionObject;
- BcbHead = CcpFindMatchingMap(Bcb, FileOffset, Length);
-
- if (BcbHead == INVALID_CACHE)
- {
- if (!Wait)
- {
- CcpUnlock();
- //DPRINT("End\n");
- goto cleanup;
- }
- }
- else
- {
- Bcb = &CcCacheSections[BcbHead];
- Success = TRUE;
- *BcbResult = Bcb;
- *Buffer = ((PCHAR)Bcb->BaseAddress) + (int)(FileOffset->QuadPart -
Bcb->FileOffset.QuadPart);
- DPRINT
- ("Bcb #%x Buffer maps (%x) At %x Length %x (Getting %x:%x)\n",
- Bcb - CcCacheSections,
- Bcb->FileOffset.LowPart,
- Bcb->BaseAddress,
- Bcb->Length,
- *Buffer,
- Length);
- CcpUnlock();
- //DPRINT("w1n\n");
- goto cleanup;
- }
- }
-
- CcpUnlock();
-
- if (!SectionObject)
- {
- Status = CcpAllocateSection
- (FileObject,
- CACHE_STRIPE,
- PAGE_READWRITE,
- &SectionObject);
-
- if (!NT_SUCCESS(Status))
- {
- //DPRINT("End %08x\n", Status);
- goto cleanup;
- }
- }
-
- /* Returns a reference */
- do
- {
- CcpLock();
-
- BcbHead = CcpAllocateCacheSections
- (FileObject,
- SectionObject,
- &Target);
-
+ BOOLEAN Success = FALSE;
+ PFILE_OBJECT FileObject = Map->FileObject;
+ /* Note: windows 2000 drivers treat this as a bool */
+ BOOLEAN Wait = (Flags & MAP_WAIT) || (Flags == TRUE);
+ LARGE_INTEGER Target;
+ ULONG BcbHead;
+ PNOCC_BCB Bcb = NULL;
+ PSECTION_OBJECT SectionObject = NULL;
+ NTSTATUS Status;
+
+ DPRINT("CcMapData(F->%x,%x:%d)\n", Map, FileOffset->LowPart,
Length);
+
+ ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
+
+ Target.QuadPart = CACHE_ROUND_DOWN(FileOffset->QuadPart);
+
+ CcpLock();
+
+ /* Find out if any range is a superset of what we want */
+ BcbHead = CcpFindCacheFor(Map);
+
+ /* No bcbs for this file */
+ if (BcbHead != INVALID_CACHE)
+ {
+ /* Find an accomodating section */
+ //DPRINT("Selected BCB #%x\n", BcbHead);
+ Bcb = &CcCacheSections[BcbHead];
+ SectionObject = Bcb->SectionObject;
+ BcbHead = CcpFindMatchingMap(Bcb, FileOffset, Length);
+
+ if (BcbHead == INVALID_CACHE)
+ {
+ if (!Wait)
+ {
CcpUnlock();
- }
- while (BcbHead == INVALID_CACHE &&
- NT_SUCCESS
- (KeWaitForSingleObject
- (&CcDeleteEvent, UserRequest, KernelMode, FALSE, NULL)));
-
- if (BcbHead == INVALID_CACHE)
- {
//DPRINT("End\n");
goto cleanup;
- }
-
- //DPRINT("Selected BCB #%x\n", BcbHead);
- Bcb = &CcCacheSections[BcbHead];
- Status = CcpMapSegment(BcbHead);
-
- if (NT_SUCCESS(Status))
- {
- Success = TRUE;
- //DPRINT("w1n\n");
- *BcbResult = &CcCacheSections[BcbHead];
- *Buffer = ((PCHAR)Bcb->BaseAddress) + (int)(FileOffset->QuadPart -
Bcb->FileOffset.QuadPart);
- DPRINT
- ("Bcb #%x Buffer maps (%x) At %x Length %x (Getting %x:%x)\n",
- Bcb - CcCacheSections,
- Bcb->FileOffset.LowPart,
- Bcb->BaseAddress,
- Bcb->Length,
- *Buffer,
- Length);
- goto cleanup;
- }
-
- //DPRINT("TERM!\n");
+ }
+ }
+ else
+ {
+ Bcb = &CcCacheSections[BcbHead];
+ Success = TRUE;
+ *BcbResult = Bcb;
+ *Buffer = ((PCHAR)Bcb->BaseAddress) + (int)(FileOffset->QuadPart -
Bcb->FileOffset.QuadPart);
+ DPRINT
+ ("Bcb #%x Buffer maps (%x) At %x Length %x (Getting %x:%x)\n",
+ Bcb - CcCacheSections,
+ Bcb->FileOffset.LowPart,
+ Bcb->BaseAddress,
+ Bcb->Length,
+ *Buffer,
+ Length);
+ CcpUnlock();
+ //DPRINT("w1n\n");
+ goto cleanup;
+ }
+ }
+
+ CcpUnlock();
+
+ if (!SectionObject)
+ {
+ Status = CcpAllocateSection
+ (FileObject,
+ CACHE_STRIPE,
+ PAGE_READWRITE,
+ &SectionObject);
+
+ if (!NT_SUCCESS(Status))
+ {
+ //DPRINT("End %08x\n", Status);
+ goto cleanup;
+ }
+ }
+
+ /* Returns a reference */
+ do
+ {
+ CcpLock();
+
+ BcbHead = CcpAllocateCacheSections
+ (FileObject,
+ SectionObject,
+ &Target);
+
+ CcpUnlock();
+ }
+ while (BcbHead == INVALID_CACHE &&
+ NT_SUCCESS
+ (KeWaitForSingleObject
+ (&CcDeleteEvent, UserRequest, KernelMode, FALSE, NULL)));
+
+ if (BcbHead == INVALID_CACHE)
+ {
+ //DPRINT("End\n");
+ goto cleanup;
+ }
+
+ //DPRINT("Selected BCB #%x\n", BcbHead);
+ Bcb = &CcCacheSections[BcbHead];
+ Status = CcpMapSegment(BcbHead);
+
+ if (NT_SUCCESS(Status))
+ {
+ Success = TRUE;
+ //DPRINT("w1n\n");
+ *BcbResult = &CcCacheSections[BcbHead];
+ *Buffer = ((PCHAR)Bcb->BaseAddress) + (int)(FileOffset->QuadPart -
Bcb->FileOffset.QuadPart);
+ DPRINT
+ ("Bcb #%x Buffer maps (%x) At %x Length %x (Getting %x:%x)\n",
+ Bcb - CcCacheSections,
+ Bcb->FileOffset.LowPart,
+ Bcb->BaseAddress,
+ Bcb->Length,
+ *Buffer,
+ Length);
+ goto cleanup;
+ }
+
+ //DPRINT("TERM!\n");
cleanup:
- return Success;
+ return Success;
}
BOOLEAN
@@ -511,21 +527,21 @@
OUT PVOID *BcbResult,
OUT PVOID *Buffer)
{
- if (!(PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap)
- {
- PNOCC_CACHE_MAP Map = ExAllocatePool(NonPagedPool, sizeof(NOCC_CACHE_MAP));
- FileObject->SectionObjectPointer->SharedCacheMap = Map;
- Map->FileObject = FileObject;
- InitializeListHead(&Map->AssociatedBcb);
- }
-
- return CcpMapData
- ((PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap,
- FileOffset,
- Length,
- Flags,
- BcbResult,
- Buffer);
+ if (!(PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap)
+ {
+ PNOCC_CACHE_MAP Map = ExAllocatePool(NonPagedPool, sizeof(NOCC_CACHE_MAP));
+ FileObject->SectionObjectPointer->SharedCacheMap = Map;
+ Map->FileObject = FileObject;
+ InitializeListHead(&Map->AssociatedBcb);
+ }
+
+ return CcpMapData
+ ((PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap,
+ FileOffset,
+ Length,
+ Flags,
+ BcbResult,
+ Buffer);
}
BOOLEAN
@@ -536,31 +552,45 @@
IN ULONG Flags,
IN OUT PVOID *Bcb)
{
- BOOLEAN Wait = Flags & PIN_WAIT;
- BOOLEAN Exclusive = Flags & PIN_EXCLUSIVE;
- BOOLEAN Result;
- ULONG BcbHead;
- PVOID Buffer;
-
- Result = CcMapData(FileObject, FileOffset, Length, Wait ? MAP_WAIT : 0, Bcb,
&Buffer);
- BcbHead = ((PNOCC_BCB)*Bcb) - CcCacheSections;
-
- if (!Result) return FALSE;
-
- CcpLock();
- if (Exclusive)
- {
- DPRINT("Requesting #%x Exclusive\n", BcbHead);
- CcpMarkForExclusive(BcbHead);
- }
- else
- CcpReferenceCache(BcbHead);
- CcpUnlock();
-
- if (Exclusive)
- CcpReferenceCacheExclusive(BcbHead);
-
- return TRUE;
+ BOOLEAN Wait = Flags & PIN_WAIT;
+ BOOLEAN Exclusive = Flags & PIN_EXCLUSIVE;
+ BOOLEAN Result;
+ ULONG BcbHead;
+ PNOCC_BCB TheBcb;
+ PVOID Buffer;
+
+ Result = CcMapData(FileObject, FileOffset, Length, Wait ? MAP_WAIT : 0, Bcb,
&Buffer);
+
+ if (!Result) return FALSE;
+
+ TheBcb = (PNOCC_BCB)Bcb;
+ BcbHead = TheBcb - CcCacheSections;
+
+ CcpLock();
+ if (Exclusive)
+ {
+ DPRINT("Requesting #%x Exclusive\n", BcbHead);
+ CcpMarkForExclusive(BcbHead);
+ }
+ else
+ CcpReferenceCache(BcbHead);
+ CcpUnlock();
+
+ if (Exclusive)
+ CcpReferenceCacheExclusive(BcbHead);
+
+ if (!TheBcb->Pinned)
+ {
+ TheBcb->Pinned = IoAllocateMdl
+ (TheBcb->BaseAddress,
+ TheBcb->Length,
+ FALSE,
+ FALSE,
+ NULL);
+ MmProbeAndLockPages(TheBcb->Pinned, KernelMode, IoReadAccess);
+ }
+
+ return TRUE;
}
BOOLEAN
@@ -572,7 +602,24 @@
OUT PVOID *Bcb,
OUT PVOID *Buffer)
{
- return CcMapData(FileObject, FileOffset, Length, Flags, Bcb, Buffer);
+ BOOLEAN Result = CcMapData(FileObject, FileOffset, Length, Flags, Bcb, Buffer);
+
+ if (Result)
+ {
+ PNOCC_BCB TheBcb = (PNOCC_BCB)*Bcb;
+ if (!TheBcb->Pinned)
+ {
+ TheBcb->Pinned = IoAllocateMdl
+ (TheBcb->BaseAddress,
+ TheBcb->Length,
+ FALSE,
+ FALSE,
+ NULL);
+ MmProbeAndLockPages(TheBcb->Pinned, KernelMode, IoReadAccess);
+ }
+ }
+
+ return Result;
}
BOOLEAN
@@ -585,56 +632,73 @@
OUT PVOID *Bcb,
OUT PVOID *Buffer)
{
- BOOLEAN GotIt = CcPinMappedData
- (FileObject,
- FileOffset,
- Length,
- Flags,
- Bcb);
-
- PNOCC_BCB TheBcb = (PNOCC_BCB)*Bcb;
- ULONG Start = TheBcb - CcCacheSections;
-
- DPRINT("CcPreparePinWrite(#%x)\n", Start);
-
- if (GotIt)
- {
- CcCacheSections[Start].Dirty = TRUE;
- *Buffer = (PVOID)((PCHAR)TheBcb->BaseAddress + (FileOffset->QuadPart -
TheBcb->FileOffset.QuadPart));
- DPRINT("Returning Buffer: %x\n", *Buffer);
- }
-
- DPRINT("Done\n");
- return GotIt;
+ BOOLEAN GotIt = CcPinMappedData
+ (FileObject,
+ FileOffset,
+ Length,
+ Flags,
+ Bcb);
+
+ PNOCC_BCB TheBcb = (PNOCC_BCB)*Bcb;
+ ULONG Start = TheBcb - CcCacheSections;
+
+ DPRINT("CcPreparePinWrite(#%x)\n", Start);
+
+ if (GotIt)
+ {
+ CcCacheSections[Start].Dirty = TRUE;
+ *Buffer = (PVOID)((PCHAR)TheBcb->BaseAddress + (FileOffset->QuadPart -
TheBcb->FileOffset.QuadPart));
+ DPRINT("Returning Buffer: %x\n", *Buffer);
+ if (!TheBcb->Pinned)
+ {
+ TheBcb->Pinned = IoAllocateMdl
+ (TheBcb->BaseAddress,
+ TheBcb->Length,
+ FALSE,
+ FALSE,
+ NULL);
+ MmProbeAndLockPages(TheBcb->Pinned, KernelMode, IoReadAccess);
+ }
+ }
+
+ DPRINT("Done\n");
+ return GotIt;
}
VOID
NTAPI
CcUnpinData(IN PVOID Bcb)
{
- PNOCC_BCB RealBcb = (PNOCC_BCB)Bcb;
- ULONG Selected = RealBcb - CcCacheSections;
- DPRINT("CcUnpinData Bcb #%x (RefCount %d)\n", Selected,
RealBcb->RefCount);
- CcpLock();
- if (RealBcb->RefCount <= 2)
- {
- DPRINT("Unset allocation bit #%x\n", Selected);
- RtlClearBit(CcCacheBitmap, Selected);
- RealBcb->Exclusive = FALSE;
- if (RealBcb->ExclusiveWaiter)
- {
- DPRINT("Triggering exclusive waiter\n");
- KeSetEvent(&RealBcb->ExclusiveWait, IO_NO_INCREMENT, FALSE);
- }
- }
- if (RealBcb->RefCount > 1)
- {
- DPRINT("Removing one reference #%x\n", Selected);
- RealBcb->RefCount--;
- ASSERT(RealBcb->RefCount);
- }
- CcpUnlock();
- KeSetEvent(&CcDeleteEvent, IO_DISK_INCREMENT, FALSE);
+ PNOCC_BCB RealBcb = (PNOCC_BCB)Bcb;
+ ULONG Selected = RealBcb - CcCacheSections;
+ DPRINT("CcUnpinData Bcb #%x (RefCount %d)\n", Selected,
RealBcb->RefCount);
+ CcpLock();
+ if (RealBcb->RefCount <= 2)
+ {
+ if (RealBcb->Pinned)
+ {
+ DPRINT("Unpin (actually) the memory\n");
+ MmUnlockPages(RealBcb->Pinned);
+ IoFreeMdl(RealBcb->Pinned);
+ RealBcb->Pinned = NULL;
+ }
+ DPRINT("Unset allocation bit #%x\n", Selected);
+ RtlClearBit(CcCacheBitmap, Selected);
+ RealBcb->Exclusive = FALSE;
+ if (RealBcb->ExclusiveWaiter)
+ {
+ DPRINT("Triggering exclusive waiter\n");
+ KeSetEvent(&RealBcb->ExclusiveWait, IO_NO_INCREMENT, FALSE);
+ }
+ }
+ if (RealBcb->RefCount > 1)
+ {
+ DPRINT("Removing one reference #%x\n", Selected);
+ RealBcb->RefCount--;
+ ASSERT(RealBcb->RefCount);
+ }
+ CcpUnlock();
+ KeSetEvent(&CcDeleteEvent, IO_DISK_INCREMENT, FALSE);
}
VOID
@@ -642,11 +706,11 @@
CcSetBcbOwnerPointer(IN PVOID Bcb,
IN PVOID OwnerPointer)
{
- PNOCC_BCB RealBcb = (PNOCC_BCB)Bcb;
- CcpLock();
- CcpReferenceCache(RealBcb - CcCacheSections);
- RealBcb->OwnerPointer = OwnerPointer;
- CcpUnlock();
+ PNOCC_BCB RealBcb = (PNOCC_BCB)Bcb;
+ CcpLock();
+ CcpReferenceCache(RealBcb - CcCacheSections);
+ RealBcb->OwnerPointer = OwnerPointer;
+ CcpUnlock();
}
VOID
@@ -654,7 +718,7 @@
CcUnpinDataForThread(IN PVOID Bcb,
IN ERESOURCE_THREAD ResourceThreadId)
{
- CcUnpinData(Bcb);
+ CcUnpinData(Bcb);
}
/* EOF */
Modified: branches/arty-newcc/ntoskrnl/include/internal/cc.h
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/include/int…
==============================================================================
--- branches/arty-newcc/ntoskrnl/include/internal/cc.h [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/include/internal/cc.h [iso-8859-1] Mon Aug 18 06:01:17
2008
@@ -130,21 +130,22 @@
/* So we know the initial request that was made */
PFILE_OBJECT FileObject;
- PSECTION_OBJECT SectionObject;
- LARGE_INTEGER FileOffset;
- ULONG Length;
- PVOID BaseAddress;
- BOOLEAN Dirty;
- PVOID OwnerPointer;
-
- /* Reference counts */
- ULONG RefCount;
-
- LIST_ENTRY ThisFileList;
-
- KEVENT ExclusiveWait;
- BOOLEAN Exclusive;
- ULONG ExclusiveWaiter;
+ PSECTION_OBJECT SectionObject;
+ LARGE_INTEGER FileOffset;
+ ULONG Length;
+ PVOID BaseAddress;
+ BOOLEAN Dirty;
+ PVOID OwnerPointer;
+ PMDL Pinned;
+
+ /* Reference counts */
+ ULONG RefCount;
+
+ LIST_ENTRY ThisFileList;
+
+ KEVENT ExclusiveWait;
+ ULONG ExclusiveWaiter;
+ BOOLEAN Exclusive;
} NOCC_BCB, *PNOCC_BCB;
typedef struct _NOCC_CACHE_MAP
Modified: branches/arty-newcc/ntoskrnl/mm/section.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/section.…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] Mon Aug 18 06:01:17 2008
@@ -105,8 +105,8 @@
}
else
{
- return IoGetRelatedDeviceObject(FileObject);
- }
+ return IoGetRelatedDeviceObject(FileObject);
+ }
}
PFILE_OBJECT
@@ -229,13 +229,22 @@
NTSTATUS Status;
PIRP Irp = NULL;
KEVENT ReadWait;
- PDEVICE_OBJECT DeviceObject = MmGetDeviceObjectForFile(FileObject);
+ PDEVICE_OBJECT DeviceObject;
PIO_STACK_LOCATION IrpSp;
+ ASSERT(FileObject);
+ ASSERT(FileOffset);
+ ASSERT(Buffer);
+ ASSERT(ReadStatus);
+
+ DeviceObject = MmGetDeviceObjectForFile(FileObject);
+
+ ASSERT(DeviceObject);
+
DPRINT1
- ("PAGING WRITE File %wZ Offset %x Length %d\n",
- &FileObject->FileName,
- FileOffset->u.LowPart,
+ ("PAGING WRITE: FileObject %x Offset %x Length %d\n",
+ &FileObject,
+ FileOffset->LowPart,
Length);
KeInitializeEvent(&ReadWait, NotificationEvent, FALSE);
@@ -591,7 +600,6 @@
BOOLEAN PageOut)
{
ULONG Entry;
- BOOLEAN IsDirectMapped = FALSE;
Entry = MmGetPageEntrySectionSegment(Segment, Offset);
if (Entry == 0)
@@ -627,16 +635,6 @@
Page = PFN_FROM_SSE(Entry);
FileObject = Section->FileObject;
- if (FileObject != NULL &&
- !(Segment->Characteristics & IMAGE_SCN_MEM_SHARED))
- {
-
- if ((FileOffset.QuadPart % PAGE_SIZE) == 0 &&
- (Offset + PAGE_SIZE <= Segment->RawLength || !IsImageSection))
- {
- IsDirectMapped = TRUE;
- }
- }
SavedSwapEntry = MmGetSavedSwapEntryPage(Page);
if (SavedSwapEntry == 0)
@@ -657,10 +655,6 @@
else
{
MmSetPageEntrySectionSegment(Segment, Offset, 0);
- if (!IsDirectMapped)
- {
- MmReleasePageMemoryConsumer(MC_USER, Page);
- }
}
}
else
@@ -1542,7 +1536,6 @@
LARGE_INTEGER FileOffset;
NTSTATUS Status;
PFILE_OBJECT FileObject;
- BOOLEAN DirectMapped;
BOOLEAN IsImageSection;
PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
@@ -1561,22 +1554,6 @@
IsImageSection = Context.Section->AllocationAttributes & SEC_IMAGE ? TRUE :
FALSE;
FileObject = Context.Section->FileObject;
- DirectMapped = FALSE;
- if (FileObject != NULL &&
- !(Context.Segment->Characteristics & IMAGE_SCN_MEM_SHARED))
- {
- /*
- * If the file system is letting us go directly to the cache and the
- * memory area was mapped at an offset in the file which is page aligned
- * then note this is a direct mapped page.
- */
- if ((FileOffset.QuadPart % PAGE_SIZE) == 0 &&
- (Context.Offset + PAGE_SIZE <= Context.Segment->RawLength ||
!IsImageSection))
- {
- DirectMapped = TRUE;
- }
- }
-
/*
* This should never happen since mappings of physical memory are never
@@ -1616,14 +1593,6 @@
else
{
Context.Private = FALSE;
- }
-
- /*
- * Take an additional reference to the page or the cache segment.
- */
- if (!(DirectMapped && !Context.Private))
- {
- MmReferencePage(Page);
}
MmDeleteAllRmaps(Page, (PVOID)&Context, MmPageOutDeleteMapping);
@@ -1687,31 +1656,6 @@
MmspCompleteAndReleasePageOp(PageOp);
return(STATUS_SUCCESS);
}
- }
- else if (!Context.Private && DirectMapped)
- {
- if (SwapEntry != 0)
- {
- DPRINT1("Found a swapentry for a non private and direct mapped page
(address %x)\n",
- Address);
- KEBUGCHECK(0);
- }
- PageOp->Status = STATUS_SUCCESS;
- MmspCompleteAndReleasePageOp(PageOp);
- return(STATUS_SUCCESS);
- }
- else if (!Context.WasDirty && !DirectMapped && !Context.Private)
- {
- if (SwapEntry != 0)
- {
- DPRINT1("Found a swap entry for a non dirty, non private and not direct
mapped page (address %x)\n",
- Address);
- KEBUGCHECK(0);
- }
- MmReleasePageMemoryConsumer(MC_USER, Page);
- PageOp->Status = STATUS_SUCCESS;
- MmspCompleteAndReleasePageOp(PageOp);
- return(STATUS_SUCCESS);
}
else if (!Context.WasDirty && Context.Private && SwapEntry != 0)
{
@@ -1881,7 +1825,6 @@
BOOLEAN Private;
NTSTATUS Status;
PFILE_OBJECT FileObject;
- BOOLEAN DirectMapped;
BOOLEAN IsImageSection;
PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
@@ -1898,21 +1841,6 @@
IsImageSection = Section->AllocationAttributes & SEC_IMAGE ? TRUE : FALSE;
FileObject = Section->FileObject;
- DirectMapped = FALSE;
- if (FileObject != NULL &&
- !(Segment->Characteristics & IMAGE_SCN_MEM_SHARED))
- {
- /*
- * If the file system is letting us go directly to the cache and the
- * memory area was mapped at an offset in the file which is page aligned
- * then note this is a direct mapped page.
- */
- if (((Offset + Segment->FileOffset.QuadPart) % PAGE_SIZE) == 0 &&
- (Offset + PAGE_SIZE <= Segment->RawLength || !IsImageSection))
- {
- DirectMapped = TRUE;
- }
- }
/*
* This should never happen since mappings of physical memory are never
@@ -1957,39 +1885,6 @@
* Speculatively set all mappings of the page to clean.
*/
MmSetCleanAllRmaps(Page);
-
- /*
- * If this page was direct mapped from the cache then the cache manager
- * will take care of writing it back to disk.
- */
- if (DirectMapped && !Private)
- {
- LONG RemainingLength;
- NTSTATUS Status;
- LARGE_INTEGER FileOffset;
- IO_STATUS_BLOCK ReadStatus;
-
- FileOffset.QuadPart = Offset;
-
- RemainingLength = min(PAGE_SIZE, Segment->FileOffset.QuadPart + Segment->Length
- FileOffset.QuadPart);
- DPRINT("Writing no more than %d bytes\n", RemainingLength);
-
- if (RemainingLength > 0)
- {
- Status = MiSimpleWrite
- (Section->FileObject,
- &FileOffset,
- Address,
- RemainingLength,
- &ReadStatus);
- } else
- Status = STATUS_SUCCESS;
-
- PageOp->Status = Status;
- MmspCompleteAndReleasePageOp(PageOp);
-
- return(Status);
- }
/*
* If necessary, allocate an entry in the paging file for this page