https://git.reactos.org/?p=reactos.git;a=commitdiff;h=90f96663087a9bde17c30…
commit 90f96663087a9bde17c300a3143d55609dd2c6a4
Author: Hervé Poussineau <hpoussin(a)reactos.org>
AuthorDate: Sat Jan 30 11:01:19 2021 +0100
Commit: Hervé Poussineau <hpoussin(a)reactos.org>
CommitDate: Thu Feb 4 11:15:47 2021 +0100
[FREELDR] In PXE, do not cache the current file
We can already restart reading the whole file if seeking backward,
and there is currently no more use case of backward seek.
By doing so, we gain 1MB of memory when using PXE.
---
boot/freeldr/freeldr/lib/fs/pxe.c | 31 ++-----------------------------
1 file changed, 2 insertions(+), 29 deletions(-)
diff --git a/boot/freeldr/freeldr/lib/fs/pxe.c b/boot/freeldr/freeldr/lib/fs/pxe.c
index da6135edb91..87d06b75e2c 100644
--- a/boot/freeldr/freeldr/lib/fs/pxe.c
+++ b/boot/freeldr/freeldr/lib/fs/pxe.c
@@ -32,7 +32,6 @@ static ULONG _FileSize = 0;
static ULONG _FilePosition = 0;
static ULONG _PacketPosition = 0;
static UCHAR _Packet[1024]; // Should be a value which can be transferred well in one
packet over the network
-static UCHAR* _CachedFile = NULL;
static ULONG _CachedLength = 0;
static PPXE
@@ -127,11 +126,6 @@ static ARC_STATUS PxeClose(ULONG FileId)
return EIO;
_OpenFile = NO_FILE;
- if (_CachedFile)
- {
- FrLdrTempFree(_CachedFile, TAG_PXE_FILE);
- _CachedFile = NULL;
- }
return ESUCCESS;
}
@@ -186,11 +180,6 @@ static ARC_STATUS PxeOpen(CHAR* Path, OPENMODE OpenMode, ULONG*
FileId)
}
_FileSize = sizeData.FileSize;
- if (_FileSize < 1024 * 1024)
- {
- _CachedFile = FrLdrTempAlloc(_FileSize, TAG_PXE_FILE);
- // Don't check for allocation failure, we support _CachedFile == NULL
- }
_CachedLength = 0;
RtlZeroMemory(&openData, sizeof(openData));
@@ -199,14 +188,7 @@ static ARC_STATUS PxeOpen(CHAR* Path, OPENMODE OpenMode, ULONG*
FileId)
openData.PacketSize = sizeof(_Packet);
if (!CallPxe(PXENV_TFTP_OPEN, &openData))
- {
- if (_CachedFile)
- {
- FrLdrTempFree(_CachedFile, TAG_PXE_FILE);
- _CachedFile = NULL;
- }
return ENOENT;
- }
_FilePosition = 0;
_PacketPosition = 0;
@@ -236,10 +218,7 @@ static ARC_STATUS PxeRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG*
Count)
i = N;
else
i = _CachedLength - _FilePosition;
- if (_CachedFile)
- RtlCopyMemory(Buffer, _CachedFile + _FilePosition, i);
- else
- RtlCopyMemory(Buffer, _Packet + _FilePosition - _PacketPosition, i);
+ RtlCopyMemory(Buffer, _Packet + _FilePosition - _PacketPosition, i);
_FilePosition += i;
Buffer = (UCHAR*)Buffer + i;
*Count += i;
@@ -249,8 +228,6 @@ static ARC_STATUS PxeRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG*
Count)
if (!CallPxe(PXENV_TFTP_READ, &readData))
return EIO;
- if (_CachedFile)
- RtlCopyMemory(_CachedFile + _CachedLength, _Packet, readData.BufferSize);
_PacketPosition = _CachedLength;
_CachedLength += readData.BufferSize;
}
@@ -268,7 +245,7 @@ static ARC_STATUS PxeSeek(ULONG FileId, LARGE_INTEGER* Position,
SEEKMODE SeekMo
if (Position->HighPart != 0 || SeekMode != SeekAbsolute)
return EINVAL;
- if (!_CachedFile && Position->LowPart < _FilePosition)
+ if (Position->LowPart < _FilePosition)
{
// Close and reopen the file to go to position 0
if (PxeClose(FileId) != ESUCCESS)
@@ -286,10 +263,6 @@ static ARC_STATUS PxeSeek(ULONG FileId, LARGE_INTEGER* Position,
SEEKMODE SeekMo
{
if (!CallPxe(PXENV_TFTP_READ, &readData))
return EIO;
- if (_CachedFile)
- {
- RtlCopyMemory(_CachedFile + _CachedLength, _Packet, readData.BufferSize);
- }
_PacketPosition = _CachedLength;
_CachedLength += readData.BufferSize;
}