[FREELDR]

Finally commit the patch to improve freeldr disk performance by Carlo Bramini.
Obviously someone wants to read 0 bytes and that should not fail.

svn path=/trunk/; revision=57283
This commit is contained in:
Timo Kreuzer 2012-09-11 21:15:39 +00:00
parent f9201cb0dd
commit a466b50b71

View file

@ -114,31 +114,45 @@ static LONG DiskRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG* Count)
{
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
UCHAR* Ptr = (UCHAR*)Buffer;
ULONG i, Length;
ULONG Length, TotalSectors, MaxSectors, ReadSectors;
BOOLEAN ret;
ULONGLONG SectorOffset;
*Count = 0;
i = 0;
while (N > 0)
TotalSectors = (N + Context->SectorSize - 1) / Context->SectorSize;
MaxSectors = DISKREADBUFFER_SIZE / Context->SectorSize;
SectorOffset = Context->SectorNumber + Context->SectorOffset;
ret = 1;
while (TotalSectors)
{
Length = N;
if (Length > Context->SectorSize)
Length = Context->SectorSize;
ReadSectors = TotalSectors;
if (ReadSectors > MaxSectors)
ReadSectors = MaxSectors;
ret = MachDiskReadLogicalSectors(
Context->DriveNumber,
Context->SectorNumber + Context->SectorOffset + i,
1,
SectorOffset,
ReadSectors,
(PVOID)DISKREADBUFFER);
if (!ret)
return EIO;
break;
Length = ReadSectors * Context->SectorSize;
if (Length > N)
Length = N;
RtlCopyMemory(Ptr, (PVOID)DISKREADBUFFER, Length);
Ptr += Length;
*Count += Length;
N -= Length;
i++;
SectorOffset += ReadSectors;
TotalSectors -= ReadSectors;
}
return ESUCCESS;
*Count = Ptr - (UCHAR *)Buffer;
return (!ret) ? EIO : ESUCCESS;
}
static LONG DiskSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)