Author: tkreuzer
Date: Mon Sep 10 20:53:39 2012
New Revision: 57267
URL:
http://svn.reactos.org/svn/reactos?rev=57267&view=rev
Log:
[FREELDR]
Stop using the FILESYSBUFFER. It's a 64 KB memory region statically set up int the
lower 1MB address space. This memory is rare and it doesn't make sense to put the
buffer there, since it's only used to copy the data from the DISKREADBUFFER (which
*must* be in the lower 1MB) to a temporary location to copy it to some other location
afterwards. It's replaced with temporary heap buffers and direct reads, where
possible. Also Don't read a full FAT cluster, when only a part of it is required.
Modified:
trunk/reactos/boot/freeldr/freeldr/fs/ext2.c
trunk/reactos/boot/freeldr/freeldr/fs/fat.c
trunk/reactos/boot/freeldr/freeldr/include/arch/arm/hardware.h
Modified: trunk/reactos/boot/freeldr/freeldr/fs/ext2.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/fs/ex…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/fs/ext2.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/fs/ext2.c [iso-8859-1] Mon Sep 10 20:53:39 2012
@@ -720,8 +720,9 @@
BOOLEAN Ext2ReadGroupDescriptors(VOID)
{
- ULONG GroupDescBlockCount;
- ULONG CurrentGroupDescBlock;
+ ULONG GroupDescBlockCount;
+ ULONG BlockNumber;
+ PUCHAR CurrentGroupDescBlock;
TRACE("Ext2ReadGroupDescriptors()\n");
@@ -751,14 +752,18 @@
}
// Now read the group descriptors
- for (CurrentGroupDescBlock=0; CurrentGroupDescBlock<GroupDescBlockCount;
CurrentGroupDescBlock++)
- {
- if (!Ext2ReadBlock(Ext2SuperBlock->first_data_block + 1 + CurrentGroupDescBlock,
(PVOID)FILESYSBUFFER))
+ CurrentGroupDescBlock = (PUCHAR)Ext2GroupDescriptors;
+ BlockNumber = Ext2SuperBlock->first_data_block + 1;
+
+ while (GroupDescBlockCount--)
+ {
+ if (!Ext2ReadBlock(BlockNumber, CurrentGroupDescBlock))
{
return FALSE;
}
- RtlCopyMemory((Ext2GroupDescriptors + (CurrentGroupDescBlock * Ext2BlockSizeInBytes)),
(PVOID)FILESYSBUFFER, Ext2BlockSizeInBytes);
+ BlockNumber++;
+ CurrentGroupDescBlock += Ext2BlockSizeInBytes;
}
return TRUE;
@@ -857,15 +862,20 @@
*/
BOOLEAN Ext2ReadPartialBlock(ULONG BlockNumber, ULONG StartingOffset, ULONG Length, PVOID
Buffer)
{
+ PVOID TempBuffer;
TRACE("Ext2ReadPartialBlock() BlockNumber = %d StartingOffset = %d Length = %d
Buffer = 0x%x\n", BlockNumber, StartingOffset, Length, Buffer);
- if (!Ext2ReadBlock(BlockNumber, (PVOID)FILESYSBUFFER))
- {
- return FALSE;
- }
-
- memcpy(Buffer, (PVOID)((ULONG_PTR)FILESYSBUFFER + StartingOffset), Length);
+ TempBuffer = HeapAllocate(FrLdrTempHeap, Ext2BlockSizeInBytes, '2TXE');
+
+ if (!Ext2ReadBlock(BlockNumber, TempBuffer))
+ {
+ return FALSE;
+ }
+
+ memcpy(Buffer, ((PUCHAR)TempBuffer + StartingOffset), Length);
+
+ HeapFree(FrLdrTempHeap, TempBuffer, '2TXE');
return TRUE;
}
@@ -902,6 +912,7 @@
ULONG InodeOffsetInBlock;
CHAR ErrorString[80];
EXT2_GROUP_DESC GroupDescriptor;
+ BOOLEAN Status;
TRACE("Ext2ReadInode() Inode = %d\n", Inode);
@@ -932,13 +943,14 @@
TRACE("InodeBlockNumber (after group desc correction) = %d\n",
InodeBlockNumber);
// Read the block
- if (!Ext2ReadBlock(InodeBlockNumber, (PVOID)FILESYSBUFFER))
- {
- return FALSE;
- }
-
- // Copy the data to their buffer
- RtlCopyMemory(InodeBuffer, (PVOID)((ULONG_PTR)FILESYSBUFFER + (InodeOffsetInBlock *
EXT2_INODE_SIZE(Ext2SuperBlock))), sizeof(EXT2_INODE));
+ Status = Ext2ReadPartialBlock(InodeBlockNumber,
+ (InodeOffsetInBlock *
EXT2_INODE_SIZE(Ext2SuperBlock)),
+ sizeof(EXT2_INODE),
+ InodeBuffer);
+ if (!Status)
+ {
+ return FALSE;
+ }
TRACE("Dumping inode information:\n");
TRACE("mode = 0x%x\n", InodeBuffer->mode);
@@ -1078,7 +1090,7 @@
BOOLEAN Ext2CopyIndirectBlockPointers(ULONG* BlockList, ULONG* CurrentBlockInList, ULONG
BlockCount, ULONG IndirectBlock)
{
- ULONG* BlockBuffer = (ULONG*)FILESYSBUFFER;
+ ULONG* BlockBuffer;
ULONG CurrentBlock;
ULONG BlockPointersPerBlock;
@@ -1086,6 +1098,14 @@
BlockPointersPerBlock = Ext2BlockSizeInBytes / sizeof(ULONG);
+ BlockBuffer = HeapAllocate(FrLdrTempHeap,
+ Ext2BlockSizeInBytes,
+ '2TXE');
+ if (!BlockBuffer)
+ {
+ return FALSE;
+ }
+
if (!Ext2ReadBlock(IndirectBlock, BlockBuffer))
{
return FALSE;
@@ -1096,6 +1116,8 @@
BlockList[(*CurrentBlockInList)] = BlockBuffer[CurrentBlock];
(*CurrentBlockInList)++;
}
+
+ HeapFree(FrLdrTempHeap, BlockBuffer, '2TXE');
return TRUE;
}
Modified: trunk/reactos/boot/freeldr/freeldr/fs/fat.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/fs/fa…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/fs/fat.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/fs/fat.c [iso-8859-1] Mon Sep 10 20:53:39 2012
@@ -904,8 +904,18 @@
UINT32 FatOffset;
UINT32 ThisFatSecNum;
UINT32 ThisFatEntOffset;
+ ULONG SectorCount;
+ PUCHAR ReadBuffer;
+ BOOLEAN status = TRUE;;
//TRACE("FatGetFatEntry() Retrieving FAT entry for cluster %d.\n", Cluster);
+
+ // We need a buffer for 2 secors
+ ReadBuffer = HeapAllocate(FrLdrTempHeap, 2 * Volume->BytesPerSector,
'xTAF');
+ if (!ReadBuffer)
+ {
+ return FALSE;
+ }
switch(Volume->FatType)
{
@@ -919,22 +929,23 @@
TRACE("ThisFatSecNum: %d\n", ThisFatSecNum);
TRACE("ThisFatEntOffset: %d\n", ThisFatEntOffset);
+
if (ThisFatEntOffset == (Volume->BytesPerSector - 1))
{
- if (!FatReadVolumeSectors(Volume, ThisFatSecNum, 2, (PVOID)FILESYSBUFFER))
- {
- return FALSE;
- }
+ SectorCount = 2;
}
else
{
- if (!FatReadVolumeSectors(Volume, ThisFatSecNum, 1, (PVOID)FILESYSBUFFER))
- {
- return FALSE;
- }
- }
-
- fat = *((USHORT *) ((ULONG_PTR)FILESYSBUFFER + ThisFatEntOffset));
+ SectorCount = 1;
+ }
+
+ if (!FatReadVolumeSectors(Volume, ThisFatSecNum, SectorCount, ReadBuffer))
+ {
+ status = FALSE;
+ break;
+ }
+
+ fat = *((USHORT *) (ReadBuffer + ThisFatEntOffset));
fat = SWAPW(fat);
if (Cluster & 0x0001)
fat = fat >> 4; /* Cluster number is ODD */
@@ -950,12 +961,13 @@
ThisFatSecNum = Volume->ActiveFatSectorStart + (FatOffset /
Volume->BytesPerSector);
ThisFatEntOffset = (FatOffset % Volume->BytesPerSector);
- if (!FatReadVolumeSectors(Volume, ThisFatSecNum, 1, (PVOID)FILESYSBUFFER))
- {
- return FALSE;
- }
-
- fat = *((USHORT *) ((ULONG_PTR)FILESYSBUFFER + ThisFatEntOffset));
+ if (!FatReadVolumeSectors(Volume, ThisFatSecNum, 1, ReadBuffer))
+ {
+ status = FALSE;
+ break;
+ }
+
+ fat = *((USHORT *) (ReadBuffer + ThisFatEntOffset));
fat = SWAPW(fat);
break;
@@ -967,24 +979,26 @@
ThisFatSecNum = Volume->ActiveFatSectorStart + (FatOffset /
Volume->BytesPerSector);
ThisFatEntOffset = (FatOffset % Volume->BytesPerSector);
- if (!FatReadVolumeSectors(Volume, ThisFatSecNum, 1, (PVOID)FILESYSBUFFER))
+ if (!FatReadVolumeSectors(Volume, ThisFatSecNum, 1, ReadBuffer))
{
return FALSE;
}
// Get the fat entry
- fat = (*((ULONG *) ((ULONG_PTR)FILESYSBUFFER + ThisFatEntOffset))) & 0x0FFFFFFF;
+ fat = (*((ULONG *) (ReadBuffer + ThisFatEntOffset))) & 0x0FFFFFFF;
fat = SWAPD(fat);
break;
default:
- TRACE("Unknown FAT type %d\n", Volume->FatType);
- return FALSE;
-
+ ERR("Unknown FAT type %d\n", Volume->FatType);
+ status = FALSE;
+ break;
}
//TRACE("FAT entry is 0x%x.\n", fat);
+
+ HeapFree(FrLdrTempHeap, ReadBuffer, 'xTAF');
*ClusterPointer = fat;
@@ -1106,12 +1120,10 @@
//
// Read cluster into memory
//
- if (!FatReadVolumeSectors(Volume, ClusterStartSector, Volume->SectorsPerCluster,
(PVOID)FILESYSBUFFER))
+ if (!FatReadVolumeSectors(Volume, ClusterStartSector, Volume->SectorsPerCluster,
Buffer))
{
return FALSE;
}
-
- memcpy(Buffer, (PVOID)FILESYSBUFFER, Volume->SectorsPerCluster *
Volume->BytesPerSector);
//
// Decrement count of clusters left to read
@@ -1152,19 +1164,39 @@
BOOLEAN FatReadPartialCluster(PFAT_VOLUME_INFO Volume, ULONG ClusterNumber, ULONG
StartingOffset, ULONG Length, PVOID Buffer)
{
ULONG ClusterStartSector;
+ ULONG SectorOffset, ReadSize, SectorCount;
+ PUCHAR ReadBuffer;
+ BOOLEAN status = FALSE;
//TRACE("FatReadPartialCluster() ClusterNumber = %d StartingOffset = %d Length = %d
Buffer = 0x%x\n", ClusterNumber, StartingOffset, Length, Buffer);
ClusterStartSector = ((ClusterNumber - 2) * Volume->SectorsPerCluster) +
Volume->DataSectorStart;
- if (!FatReadVolumeSectors(Volume, ClusterStartSector, Volume->SectorsPerCluster,
(PVOID)FILESYSBUFFER))
- {
- return FALSE;
- }
-
- memcpy(Buffer, (PVOID)((ULONG_PTR)FILESYSBUFFER + StartingOffset), Length);
-
- return TRUE;
+ // This is the offset of the data in sectors
+ SectorOffset = (StartingOffset / Volume->BytesPerSector);
+ StartingOffset %= Volume->BytesPerSector;
+
+ // Calculate how many sectors we need to read
+ SectorCount = (StartingOffset + Length + Volume->BytesPerSector - 1) /
Volume->BytesPerSector;
+
+ // Calculate rounded up read size
+ ReadSize = SectorCount * Volume->BytesPerSector;
+
+ ReadBuffer = HeapAllocate(FrLdrTempHeap, ReadSize, 'xTAF');
+ if (!ReadBuffer)
+ {
+ return FALSE;
+ }
+
+ if (FatReadVolumeSectors(Volume, ClusterStartSector + SectorOffset, SectorCount,
ReadBuffer))
+ {
+ memcpy(Buffer, ReadBuffer + StartingOffset, Length);
+ status = TRUE;
+ }
+
+ HeapFree(FrLdrTempHeap, ReadBuffer, 'xTAF');
+
+ return status;
}
/*
Modified: trunk/reactos/boot/freeldr/freeldr/include/arch/arm/hardware.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/arch/arm/hardware.h [iso-8859-1]
(original)
+++ trunk/reactos/boot/freeldr/freeldr/include/arch/arm/hardware.h [iso-8859-1] Mon Sep 10
20:53:39 2012
@@ -38,4 +38,3 @@
extern ULONG gDiskReadBuffer, gFileSysBuffer;
#define DISKREADBUFFER gDiskReadBuffer
-#define FILESYSBUFFER gFileSysBuffer