Author: jgardou
Date: Sun Oct 30 00:58:21 2011
New Revision: 54273
URL:
http://svn.reactos.org/svn/reactos?rev=54273&view=rev
Log:
[CDFS]
- Read all blocks at once for misaligned read.
Modified:
trunk/reactos/drivers/filesystems/cdfs/rw.c
Modified: trunk/reactos/drivers/filesystems/cdfs/rw.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/cdfs/r…
==============================================================================
--- trunk/reactos/drivers/filesystems/cdfs/rw.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/cdfs/rw.c [iso-8859-1] Sun Oct 30 00:58:21 2011
@@ -55,6 +55,7 @@
{
NTSTATUS Status = STATUS_SUCCESS;
PFCB Fcb;
+ ULONG ToRead = Length;
DPRINT("CdfsReadFile(ReadOffset %lu Length %lu)\n", ReadOffset, Length);
@@ -67,6 +68,9 @@
if (ReadOffset >= Fcb->Entry.DataLengthL)
return(STATUS_END_OF_FILE);
+
+ if (ReadOffset + Length > Fcb->Entry.DataLengthL)
+ ToRead = Fcb->Entry.DataLengthL - ReadOffset;
DPRINT("Reading %d bytes at %d\n", Length, ReadOffset);
@@ -77,9 +81,6 @@
CC_FILE_SIZES FileSizes;
DPRINT("Using cache\n");
-
- if (ReadOffset + Length > Fcb->Entry.DataLengthL)
- Length = Fcb->Entry.DataLengthL - ReadOffset;
if (FileObject->PrivateCacheMap == NULL)
{
@@ -101,79 +102,56 @@
FileOffset.QuadPart = (LONGLONG)ReadOffset;
CcCopyRead(FileObject,
&FileOffset,
- Length,
+ ToRead,
TRUE,
Buffer,
&IoStatus);
*LengthRead = IoStatus.Information;
- return(IoStatus.Status);
- }
-
- if ((ReadOffset % BLOCKSIZE) != 0 || (Length % BLOCKSIZE) != 0)
- {
- /* Then we need to do a partial or misaligned read ... */
- PCHAR PageBuf = ExAllocatePool(NonPagedPool, BLOCKSIZE);
- PCHAR TargetRead = (PCHAR)Buffer;
- ULONG ActualReadOffset, EndOfExtent, ReadLen;
-
- if (!PageBuf)
- {
- return STATUS_NO_MEMORY;
- }
-
- ActualReadOffset = ROUND_DOWN(ReadOffset, BLOCKSIZE);
- EndOfExtent = ReadOffset + Length;
-
- while (ActualReadOffset < EndOfExtent)
- {
- Status = CdfsReadSectors
- (DeviceExt->StorageDevice,
- Fcb->Entry.ExtentLocationL + (ActualReadOffset / BLOCKSIZE),
- 1,
- (PVOID)PageBuf,
- FALSE);
-
- if (!NT_SUCCESS(Status))
- break;
-
- ReadLen = BLOCKSIZE - (ReadOffset - ActualReadOffset);
- if (ReadLen > EndOfExtent - ReadOffset)
+ Status = IoStatus.Status;
+ }
+ else
+ {
+ ULONG ActualReadOffset = ROUND_DOWN(ReadOffset, BLOCKSIZE);
+ ULONG nBlocks = (ROUND_UP(ReadOffset + ToRead, BLOCKSIZE) - ActualReadOffset) /
BLOCKSIZE;
+ PUCHAR PageBuf;
+ BOOLEAN bFreeBuffer = FALSE;
+ if ((ReadOffset % BLOCKSIZE) != 0 || (ToRead % BLOCKSIZE) != 0)
+ {
+ PageBuf = ExAllocatePool(NonPagedPool, nBlocks * BLOCKSIZE);
+ if (!PageBuf)
{
- ReadLen = EndOfExtent - ReadOffset;
+ return STATUS_NO_MEMORY;
}
- DPRINT("Copying %d bytes.\n", ReadLen);
- RtlCopyMemory(TargetRead, PageBuf + (ReadOffset - ActualReadOffset),
ReadLen);
-
- ActualReadOffset += BLOCKSIZE;
- TargetRead += ReadLen;
- ReadOffset += ReadLen;
- }
-
- ExFreePool(PageBuf);
- }
- else
- {
- if (ReadOffset + Length > ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE))
- Length = ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE) - ReadOffset;
-
+ bFreeBuffer = TRUE;
+ }
+ else
+ {
+ PageBuf = Buffer;
+ }
Status = CdfsReadSectors(DeviceExt->StorageDevice,
- Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE),
- Length / BLOCKSIZE,
- Buffer,
+ Fcb->Entry.ExtentLocationL + (ActualReadOffset / BLOCKSIZE),
+ nBlocks,
+ (PVOID)PageBuf,
FALSE);
- if (NT_SUCCESS(Status))
- {
- *LengthRead = Length;
- if (Length + ReadOffset > Fcb->Entry.DataLengthL)
+
+ if(NT_SUCCESS(Status))
+ {
+ *LengthRead = ToRead;
+ if(bFreeBuffer)
{
- memset(Buffer + Fcb->Entry.DataLengthL - ReadOffset,
- 0,
- Length + ReadOffset - Fcb->Entry.DataLengthL);
+ /* Copy what we've got */
+ RtlCopyMemory(Buffer, PageBuf + (ReadOffset - ActualReadOffset),
ToRead);
}
- }
- }
-
+ /* Zero out the rest */
+ if(ToRead != Length)
+ RtlZeroMemory(Buffer + ToRead, Length - ToRead);
+ }
+
+ if(bFreeBuffer)
+ ExFreePool(PageBuf);
+ }
+
return Status;
}