Author: tkreuzer
Date: Tue Sep 11 21:15:39 2012
New Revision: 57283
URL:
http://svn.reactos.org/svn/reactos?rev=57283&view=rev
Log:
[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.
Modified:
trunk/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c [iso-8859-1] Tue Sep 11 21:15:39
2012
@@ -114,31 +114,45 @@
{
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
UCHAR* Ptr = (UCHAR*)Buffer;
- ULONG i, Length;
+ ULONG Length, TotalSectors, MaxSectors, ReadSectors;
BOOLEAN ret;
-
- *Count = 0;
- i = 0;
- while (N > 0)
- {
- Length = N;
- if (Length > Context->SectorSize)
- Length = Context->SectorSize;
+ ULONGLONG SectorOffset;
+
+ TotalSectors = (N + Context->SectorSize - 1) / Context->SectorSize;
+ MaxSectors = DISKREADBUFFER_SIZE / Context->SectorSize;
+ SectorOffset = Context->SectorNumber + Context->SectorOffset;
+
+ ret = 1;
+
+ while (TotalSectors)
+ {
+ 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++;
- }
-
- return ESUCCESS;
+ SectorOffset += ReadSectors;
+ TotalSectors -= ReadSectors;
+ }
+
+ *Count = Ptr - (UCHAR *)Buffer;
+
+ return (!ret) ? EIO : ESUCCESS;
}
static LONG DiskSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)