Author: pschweitzer
Date: Tue Dec 28 21:34:54 2010
New Revision: 50203
URL:
http://svn.reactos.org/svn/reactos?rev=50203&view=rev
Log:
[NTOSKRNL]
Hoovering part 2...
Modified:
trunk/reactos/ntoskrnl/cc/copy.c
Modified: trunk/reactos/ntoskrnl/cc/copy.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cc/copy.c?rev=502…
==============================================================================
--- trunk/reactos/ntoskrnl/cc/copy.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/cc/copy.c [iso-8859-1] Tue Dec 28 21:34:54 2010
@@ -186,62 +186,69 @@
NTAPI
ReadCacheSegment(PCACHE_SEGMENT CacheSeg)
{
- ULONG Size;
- PMDL Mdl;
- NTSTATUS Status;
- LARGE_INTEGER SegOffset;
- IO_STATUS_BLOCK IoStatus;
- KEVENT Event;
-
- SegOffset.QuadPart = CacheSeg->FileOffset;
- Size = (ULONG)(CacheSeg->Bcb->AllocationSize.QuadPart -
CacheSeg->FileOffset);
- if (Size > CacheSeg->Bcb->CacheSegmentSize)
- {
- Size = CacheSeg->Bcb->CacheSegmentSize;
- }
- Mdl = IoAllocateMdl(CacheSeg->BaseAddress, Size, FALSE, FALSE, NULL);
- MmBuildMdlForNonPagedPool(Mdl);
- Mdl->MdlFlags |= MDL_IO_PAGE_READ;
- KeInitializeEvent(&Event, NotificationEvent, FALSE);
- Status = IoPageRead(CacheSeg->Bcb->FileObject, Mdl, &SegOffset, & Event,
&IoStatus);
- if (Status == STATUS_PENDING)
- {
- KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
- Status = IoStatus.Status;
- }
-
- IoFreeMdl(Mdl);
-
- if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
- {
- DPRINT1("IoPageRead failed, Status %x\n", Status);
- return Status;
- }
- if (CacheSeg->Bcb->CacheSegmentSize > Size)
- {
- memset ((char*)CacheSeg->BaseAddress + Size, 0,
+ ULONG Size;
+ PMDL Mdl;
+ NTSTATUS Status;
+ LARGE_INTEGER SegOffset;
+ IO_STATUS_BLOCK IoStatus;
+ KEVENT Event;
+
+ SegOffset.QuadPart = CacheSeg->FileOffset;
+ Size = (ULONG)(CacheSeg->Bcb->AllocationSize.QuadPart -
CacheSeg->FileOffset);
+ if (Size > CacheSeg->Bcb->CacheSegmentSize)
+ {
+ Size = CacheSeg->Bcb->CacheSegmentSize;
+ }
+
+ Mdl = IoAllocateMdl(CacheSeg->BaseAddress, Size, FALSE, FALSE, NULL);
+ if (!Mdl)
+ {
+ return STATUS_INSUFFICIANT_RESOURCES;
+ }
+ MmBuildMdlForNonPagedPool(Mdl);
+ Mdl->MdlFlags |= MDL_IO_PAGE_READ;
+ KeInitializeEvent(&Event, NotificationEvent, FALSE);
+ Status = IoPageRead(CacheSeg->Bcb->FileObject, Mdl, &SegOffset, &Event,
&IoStatus);
+ if (Status == STATUS_PENDING)
+ {
+ KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
+ Status = IoStatus.Status;
+ }
+
+ IoFreeMdl(Mdl);
+
+ if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
+ {
+ DPRINT1("IoPageRead failed, Status %x\n", Status);
+ return Status;
+ }
+
+ if (CacheSeg->Bcb->CacheSegmentSize > Size)
+ {
+ RtlZeroMemory((char*)CacheSeg->BaseAddress + Size,
CacheSeg->Bcb->CacheSegmentSize - Size);
}
- return STATUS_SUCCESS;
+
+ return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
WriteCacheSegment(PCACHE_SEGMENT CacheSeg)
{
- ULONG Size;
- PMDL Mdl;
- NTSTATUS Status;
- IO_STATUS_BLOCK IoStatus;
- LARGE_INTEGER SegOffset;
- KEVENT Event;
-
- CacheSeg->Dirty = FALSE;
- SegOffset.QuadPart = CacheSeg->FileOffset;
- Size = (ULONG)(CacheSeg->Bcb->AllocationSize.QuadPart -
CacheSeg->FileOffset);
- if (Size > CacheSeg->Bcb->CacheSegmentSize)
- {
- Size = CacheSeg->Bcb->CacheSegmentSize;
+ ULONG Size;
+ PMDL Mdl;
+ NTSTATUS Status;
+ IO_STATUS_BLOCK IoStatus;
+ LARGE_INTEGER SegOffset;
+ KEVENT Event;
+
+ CacheSeg->Dirty = FALSE;
+ SegOffset.QuadPart = CacheSeg->FileOffset;
+ Size = (ULONG)(CacheSeg->Bcb->AllocationSize.QuadPart -
CacheSeg->FileOffset);
+ if (Size > CacheSeg->Bcb->CacheSegmentSize)
+ {
+ Size = CacheSeg->Bcb->CacheSegmentSize;
}
//
// Nonpaged pool PDEs in ReactOS must actually be synchronized between the
@@ -254,24 +261,30 @@
MmGetPfnForProcess(NULL, (PVOID)((ULONG_PTR)CacheSeg->BaseAddress + (i
<< PAGE_SHIFT)));
} while (++i < (Size >> PAGE_SHIFT));
}
- Mdl = IoAllocateMdl(CacheSeg->BaseAddress, Size, FALSE, FALSE, NULL);
- MmBuildMdlForNonPagedPool(Mdl);
- Mdl->MdlFlags |= MDL_IO_PAGE_READ;
- KeInitializeEvent(&Event, NotificationEvent, FALSE);
- Status = IoSynchronousPageWrite(CacheSeg->Bcb->FileObject, Mdl, &SegOffset,
&Event, &IoStatus);
- if (Status == STATUS_PENDING)
- {
- KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
- Status = IoStatus.Status;
- }
- IoFreeMdl(Mdl);
- if (!NT_SUCCESS(Status) && (Status != STATUS_END_OF_FILE))
- {
- DPRINT1("IoPageWrite failed, Status %x\n", Status);
- CacheSeg->Dirty = TRUE;
- return(Status);
- }
- return(STATUS_SUCCESS);
+
+ Mdl = IoAllocateMdl(CacheSeg->BaseAddress, Size, FALSE, FALSE, NULL);
+ if (!Mdl)
+ {
+ return STATUS_INSUFFICIANT_RESOURCES;
+ }
+ MmBuildMdlForNonPagedPool(Mdl);
+ Mdl->MdlFlags |= MDL_IO_PAGE_READ;
+ KeInitializeEvent(&Event, NotificationEvent, FALSE);
+ Status = IoSynchronousPageWrite(CacheSeg->Bcb->FileObject, Mdl, &SegOffset,
&Event, &IoStatus);
+ if (Status == STATUS_PENDING)
+ {
+ KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
+ Status = IoStatus.Status;
+ }
+ IoFreeMdl(Mdl);
+ if (!NT_SUCCESS(Status) && (Status != STATUS_END_OF_FILE))
+ {
+ DPRINT1("IoPageWrite failed, Status %x\n", Status);
+ CacheSeg->Dirty = TRUE;
+ return Status;
+ }
+
+ return STATUS_SUCCESS;
}