diff --git a/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c b/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c index 1eb5e84e950..926f5ef7164 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c @@ -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; + + TotalSectors = (N + Context->SectorSize - 1) / Context->SectorSize; + MaxSectors = 1;//DISKREADBUFFER_SIZE / Context->SectorSize; + SectorOffset = Context->SectorNumber + Context->SectorOffset; + + ret = 0; - *Count = 0; - i = 0; while (N > 0) { - 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)