Author: arty
Date: Sat Sep 6 14:27:10 2008
New Revision: 35999
URL:
http://svn.reactos.org/svn/reactos?rev=35999&view=rev
Log:
Overhaul CcCopyRead.
Modified:
branches/arty-newcc/ntoskrnl/cache/copysup.c
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] Sat Sep 6 14:27:10 2008
@@ -35,64 +35,66 @@
OUT PVOID Buffer,
OUT PIO_STATUS_BLOCK IoStatus)
{
- INT i, Count;
- PCHAR ReadBuf;
- ULONG ReadLen;
- PVOID Bcbs[CACHE_NUM_SECTIONS];
- PVOID ReadBuffers[CACHE_NUM_SECTIONS];
-
- DPRINT
- ("CcCopyRead(%x,%x,%d,%d,%x)\n",
- FileObject,
- FileOffset->LowPart,
- Length,
- Wait,
- Buffer);
-
- for (ReadLen = Length, i = 0;
- ReadLen > 0;
- ReadLen -= min(ReadLen, CACHE_STRIPE), i++)
- {
- if (!CcPinRead
- (FileObject,
- FileOffset,
- min(ReadLen, CACHE_STRIPE),
- Wait ? PIN_WAIT : PIN_IF_BCB,
- &Bcbs[i],
- &ReadBuffers[i]))
- {
- --i;
- while (i >= 0)
- CcUnpinData(Bcbs[i--]);
- IoStatus->Status = STATUS_UNSUCCESSFUL;
- IoStatus->Information = 0;
- DPRINT("Failed CcCopyRead\n");
- return FALSE;
- }
- }
-
- Count = i;
-
- DPRINT("Copying %d bytes for Read (%d buffers)\n", Length, Count);
- for (i = 0; i < Count; i++)
- {
- DPRINT(" %d: [#%02x:%x]\n", i, Bcbs[i], ReadBuffers[i]);
- }
-
- for (ReadBuf = (PCHAR)Buffer, ReadLen = Length, i = 0;
- ReadLen > 0;
- ReadBuf += CACHE_STRIPE, ReadLen -= min(ReadLen, CACHE_STRIPE), i++)
- RtlCopyMemory(ReadBuf, ReadBuffers[i], min(ReadLen, CACHE_STRIPE));
-
- for (i = 0; i < Count; i++)
- CcUnpinData(Bcbs[i]);
-
- IoStatus->Status = STATUS_SUCCESS;
- IoStatus->Information = Length;
-
- DPRINT("Done with CcCopyRead\n");
-
- return TRUE;
+ PCHAR ReadBuffer;
+ ULONG ReadLen;
+ PVOID Bcb;
+ PCHAR BufferTarget = (PCHAR)Buffer;
+ LARGE_INTEGER CacheOffset, EndOfExtent, NextOffset;
+
+ DPRINT
+ ("CcCopyRead(%x,%x,%d,%d,%x)\n",
+ FileObject,
+ FileOffset->LowPart,
+ Length,
+ Wait,
+ Buffer);
+
+ CacheOffset.QuadPart = FileOffset->QuadPart;
+ EndOfExtent.QuadPart = FileOffset->QuadPart + Length;
+
+ while (CacheOffset.QuadPart < EndOfExtent.QuadPart)
+ {
+ NextOffset.QuadPart = (CacheOffset.QuadPart + CACHE_STRIPE) & ~(CACHE_STRIPE-1);
+ ReadLen = EndOfExtent.QuadPart - CacheOffset.QuadPart;
+ if (CacheOffset.QuadPart + ReadLen > NextOffset.QuadPart)
+ {
+ ReadLen = NextOffset.QuadPart - CacheOffset.QuadPart;
+ }
+
+ DPRINT("Reading %d bytes in this go (at %08x%08x)\n", ReadLen,
CacheOffset.HighPart, CacheOffset.LowPart);
+
+ if (!CcPinRead
+ (FileObject,
+ &CacheOffset,
+ ReadLen,
+ Wait ? PIN_WAIT : PIN_IF_BCB,
+ &Bcb,
+ (PVOID*)&ReadBuffer))
+ {
+ IoStatus->Status = STATUS_UNSUCCESSFUL;
+ IoStatus->Information = 0;
+ DPRINT("Failed CcCopyRead\n");
+ return FALSE;
+ }
+
+ DPRINT("Copying %d bytes at %08x%08x\n", ReadLen, CacheOffset.HighPart,
CacheOffset.LowPart);
+ RtlCopyMemory
+ (BufferTarget,
+ ReadBuffer,
+ ReadLen);
+
+ BufferTarget += ReadLen;
+
+ CacheOffset = NextOffset;
+ CcUnpinData(Bcb);
+ }
+
+ IoStatus->Status = STATUS_SUCCESS;
+ IoStatus->Information = Length;
+
+ DPRINT("Done with CcCopyRead\n");
+
+ return TRUE;
}
VOID