Removed use of intermediate buffering when reading from the cache

svn path=/trunk/; revision=1503
This commit is contained in:
David Welch 2001-01-13 12:40:21 +00:00
parent e371c33d76
commit d2b9b6d912

View file

@ -1,5 +1,5 @@
/* $Id: rw.c,v 1.15 2001/01/12 21:00:08 dwelch Exp $ /* $Id: rw.c,v 1.16 2001/01/13 12:40:21 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -270,7 +270,9 @@ VfatReadCluster(PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster, ULONG FirstCluster,
PULONG CurrentCluster, PULONG CurrentCluster,
PVOID Destination, PVOID Destination,
ULONG Cached) ULONG Cached,
ULONG InternalOffset,
ULONG InternalLength)
{ {
ULONG BytesPerCluster; ULONG BytesPerCluster;
BOOLEAN Valid; BOOLEAN Valid;
@ -310,7 +312,7 @@ VfatReadCluster(PDEVICE_EXTENSION DeviceExt,
/* /*
* Copy the data from the cache to the caller * Copy the data from the cache to the caller
*/ */
memcpy(Destination, BaseAddress, BytesPerCluster); memcpy(Destination, BaseAddress + InternalOffset, InternalLength);
CcReleaseCacheSegment(Fcb->RFCB.Bcb, CacheSeg, TRUE); CcReleaseCacheSegment(Fcb->RFCB.Bcb, CacheSeg, TRUE);
Status = NextCluster(DeviceExt, FirstCluster, CurrentCluster); Status = NextCluster(DeviceExt, FirstCluster, CurrentCluster);
@ -381,7 +383,7 @@ VfatReadCluster(PDEVICE_EXTENSION DeviceExt,
/* /*
* Copy the data from the cache to the caller * Copy the data from the cache to the caller
*/ */
memcpy(Destination, BaseAddress + InternalOffset, BytesPerCluster); memcpy(Destination, BaseAddress + InternalOffset, InternalLength);
CcReleaseCacheSegment(Fcb->RFCB.Bcb, CacheSeg, TRUE); CcReleaseCacheSegment(Fcb->RFCB.Bcb, CacheSeg, TRUE);
} }
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
@ -398,10 +400,9 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
ULONG CurrentCluster; ULONG CurrentCluster;
ULONG FirstCluster; ULONG FirstCluster;
PVFATFCB Fcb; PVFATFCB Fcb;
PVOID Temp;
ULONG TempLength;
ULONG ChunkSize; ULONG ChunkSize;
NTSTATUS Status; NTSTATUS Status;
ULONG TempLength;
/* PRECONDITION */ /* PRECONDITION */
assert (DeviceExt != NULL); assert (DeviceExt != NULL);
@ -445,15 +446,6 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
*LengthRead = 0; *LengthRead = 0;
/*
* Allocate a buffer to hold partial clusters
*/
Temp = ExAllocatePool (NonPagedPool, ChunkSize);
if (!Temp)
{
return(STATUS_NO_MEMORY);
}
/* /*
* Find the cluster to start the read from * Find the cluster to start the read from
* FIXME: Optimize by remembering the last cluster read and using if * FIXME: Optimize by remembering the last cluster read and using if
@ -472,12 +464,11 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
*/ */
if ((ReadOffset % ChunkSize) != 0) if ((ReadOffset % ChunkSize) != 0)
{ {
TempLength = min (Length, ChunkSize - (ReadOffset % ChunkSize));
VfatReadCluster(DeviceExt, Fcb, VfatReadCluster(DeviceExt, Fcb,
ROUND_DOWN(ReadOffset, ChunkSize), ROUND_DOWN(ReadOffset, ChunkSize),
FirstCluster, &CurrentCluster, Temp, 1); FirstCluster, &CurrentCluster, Buffer, 1,
TempLength = min (Length, ChunkSize - (ReadOffset % ChunkSize)); ReadOffset % ChunkSize, TempLength);
memcpy (Buffer, Temp + ReadOffset % ChunkSize, TempLength);
(*LengthRead) = (*LengthRead) + TempLength; (*LengthRead) = (*LengthRead) + TempLength;
Length = Length - TempLength; Length = Length - TempLength;
@ -488,10 +479,9 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
while (Length >= ChunkSize) while (Length >= ChunkSize)
{ {
VfatReadCluster(DeviceExt, Fcb, ReadOffset, VfatReadCluster(DeviceExt, Fcb, ReadOffset,
FirstCluster, &CurrentCluster, Buffer, 1); FirstCluster, &CurrentCluster, Buffer, 1, 0, ChunkSize);
if (CurrentCluster == 0xffffffff) if (CurrentCluster == 0xffffffff)
{ {
ExFreePool (Temp);
return (STATUS_SUCCESS); return (STATUS_SUCCESS);
} }
@ -500,15 +490,12 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
Length = Length - ChunkSize; Length = Length - ChunkSize;
ReadOffset = ReadOffset + ChunkSize; ReadOffset = ReadOffset + ChunkSize;
} }
if (Length > 0) if (Length > 0)
{ {
VfatReadCluster(DeviceExt, Fcb, ReadOffset, VfatReadCluster(DeviceExt, Fcb, ReadOffset,
FirstCluster, &CurrentCluster, Temp, 1); FirstCluster, &CurrentCluster, Buffer, 1, 0, Length);
(*LengthRead) = (*LengthRead) + Length; (*LengthRead) = (*LengthRead) + Length;
memcpy (Buffer, Temp, Length);
} }
ExFreePool (Temp);
return (STATUS_SUCCESS); return (STATUS_SUCCESS);
} }