mirror of
https://github.com/reactos/reactos.git
synced 2025-05-27 13:08:23 +00:00
Check if a uncached read is sector aligned, fail if is not.
svn path=/trunk/; revision=3915
This commit is contained in:
parent
5d8ab9ff70
commit
f9725d0888
1 changed files with 18 additions and 57 deletions
|
@ -16,7 +16,7 @@
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
/* $Id: rw.c,v 1.8 2002/11/20 21:55:25 ekohl Exp $
|
/* $Id: rw.c,v 1.9 2003/01/02 16:02:02 hbirr Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -76,19 +76,15 @@ CdfsReadFile(PDEVICE_EXTENSION DeviceExt,
|
||||||
if (ReadOffset >= Fcb->Entry.DataLengthL)
|
if (ReadOffset >= Fcb->Entry.DataLengthL)
|
||||||
return(STATUS_END_OF_FILE);
|
return(STATUS_END_OF_FILE);
|
||||||
|
|
||||||
if (ReadOffset + Length > Fcb->Entry.DataLengthL)
|
|
||||||
Length = Fcb->Entry.DataLengthL - ReadOffset;
|
|
||||||
|
|
||||||
DPRINT("Reading %d bytes at %d\n", Length, ReadOffset);
|
DPRINT("Reading %d bytes at %d\n", Length, ReadOffset);
|
||||||
|
|
||||||
if (Length == 0)
|
|
||||||
return(STATUS_UNSUCCESSFUL);
|
|
||||||
|
|
||||||
if (!(IrpFlags & (IRP_NOCACHE|IRP_PAGING_IO)))
|
if (!(IrpFlags & (IRP_NOCACHE|IRP_PAGING_IO)))
|
||||||
{
|
{
|
||||||
LARGE_INTEGER FileOffset;
|
LARGE_INTEGER FileOffset;
|
||||||
IO_STATUS_BLOCK IoStatus;
|
IO_STATUS_BLOCK IoStatus;
|
||||||
|
|
||||||
|
if (ReadOffset + Length > Fcb->Entry.DataLengthL)
|
||||||
|
Length = Fcb->Entry.DataLengthL - ReadOffset;
|
||||||
if (FileObject->PrivateCacheMap == NULL)
|
if (FileObject->PrivateCacheMap == NULL)
|
||||||
{
|
{
|
||||||
CcRosInitializeFileCache(FileObject, &Fcb->RFCB.Bcb, PAGE_SIZE);
|
CcRosInitializeFileCache(FileObject, &Fcb->RFCB.Bcb, PAGE_SIZE);
|
||||||
|
@ -106,60 +102,25 @@ CdfsReadFile(PDEVICE_EXTENSION DeviceExt,
|
||||||
return(IoStatus.Status);
|
return(IoStatus.Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ReadOffset % BLOCKSIZE) != 0)
|
if ((ReadOffset % BLOCKSIZE) != 0 || (Length % BLOCKSIZE) != 0)
|
||||||
{
|
{
|
||||||
TempLength = min(Length, BLOCKSIZE - (ReadOffset % BLOCKSIZE));
|
return STATUS_INVALID_PARAMETER;
|
||||||
TempBuffer = ExAllocatePool(NonPagedPool, BLOCKSIZE);
|
}
|
||||||
|
if (ReadOffset + Length > ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE))
|
||||||
|
Length = ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE) - ReadOffset;
|
||||||
|
|
||||||
Status = CdfsReadSectors(DeviceExt->StorageDevice,
|
Status = CdfsReadSectors(DeviceExt->StorageDevice,
|
||||||
Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE),
|
Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE),
|
||||||
1,
|
Length / BLOCKSIZE,
|
||||||
TempBuffer);
|
|
||||||
if (NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
memcpy(Buffer, TempBuffer + (ReadOffset % BLOCKSIZE), TempLength);
|
|
||||||
(*LengthRead) = (*LengthRead) + TempLength;
|
|
||||||
Length = Length - TempLength;
|
|
||||||
Buffer = Buffer + TempLength;
|
|
||||||
ReadOffset = ReadOffset + TempLength;
|
|
||||||
}
|
|
||||||
ExFreePool(TempBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINT("Status %lx\n", Status);
|
|
||||||
|
|
||||||
if ((Length / BLOCKSIZE) != 0 && NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
TempLength = ROUND_DOWN(Length, BLOCKSIZE);
|
|
||||||
Status = CdfsReadSectors(DeviceExt->StorageDevice,
|
|
||||||
Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE),
|
|
||||||
TempLength / BLOCKSIZE,
|
|
||||||
Buffer);
|
Buffer);
|
||||||
if (NT_SUCCESS(Status))
|
if (NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
(*LengthRead) = (*LengthRead) + TempLength;
|
*LengthRead = Length;
|
||||||
Length = Length - TempLength;
|
if (Length + ReadOffset > Fcb->Entry.DataLengthL)
|
||||||
Buffer = Buffer + TempLength;
|
|
||||||
ReadOffset = ReadOffset + TempLength;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINT("Status %lx\n", Status);
|
|
||||||
|
|
||||||
if (Length > 0 && NT_SUCCESS(Status))
|
|
||||||
{
|
{
|
||||||
TempBuffer = ExAllocatePool(NonPagedPool, BLOCKSIZE);
|
memset(Buffer + Fcb->Entry.DataLengthL - ReadOffset,
|
||||||
|
0, Length + ReadOffset - Fcb->Entry.DataLengthL);
|
||||||
Status = CdfsReadSectors(DeviceExt->StorageDevice,
|
|
||||||
Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE),
|
|
||||||
1,
|
|
||||||
TempBuffer);
|
|
||||||
if (NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
memcpy(Buffer, TempBuffer, Length);
|
|
||||||
(*LengthRead) = (*LengthRead) + Length;
|
|
||||||
}
|
}
|
||||||
ExFreePool(TempBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(Status);
|
return(Status);
|
||||||
|
|
Loading…
Reference in a new issue