[freeldr] Accept to read blocks whose size is not a multiple of device sector size

svn path=/trunk/; revision=43113
This commit is contained in:
Hervé Poussineau 2009-09-22 19:32:35 +00:00
parent f03906b449
commit 16c6a54da7

View file

@ -2,6 +2,7 @@
* FreeLoader * FreeLoader
* *
* Copyright (C) 2003, 2004 Eric Kohl * Copyright (C) 2003, 2004 Eric Kohl
* Copyright (C) 2009 Hervé Poussineau
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -466,15 +467,16 @@ static LONG DiskRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG* Count)
{ {
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId); DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
UCHAR* Ptr = (UCHAR*)Buffer; UCHAR* Ptr = (UCHAR*)Buffer;
ULONG i; ULONG i, Length;
BOOLEAN ret; BOOLEAN ret;
*Count = 0; *Count = 0;
if (N & (Context->SectorSize - 1)) i = 0;
return EINVAL; while (N > 0)
for (i = 0; i < N / Context->SectorSize; i++)
{ {
Length = N;
if (Length > Context->SectorSize)
Length = Context->SectorSize;
ret = MachDiskReadLogicalSectors( ret = MachDiskReadLogicalSectors(
Context->DriveNumber, Context->DriveNumber,
Context->SectorNumber + Context->SectorOffset + i, Context->SectorNumber + Context->SectorOffset + i,
@ -482,11 +484,13 @@ static LONG DiskRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG* Count)
(PVOID)DISKREADBUFFER); (PVOID)DISKREADBUFFER);
if (!ret) if (!ret)
return EIO; return EIO;
RtlCopyMemory(Ptr, (PVOID)DISKREADBUFFER, Context->SectorSize); RtlCopyMemory(Ptr, (PVOID)DISKREADBUFFER, Length);
Ptr += Context->SectorSize; Ptr += Length;
*Count += Length;
N -= Length;
i++;
} }
*Count = N;
return ESUCCESS; return ESUCCESS;
} }