From 8f6da8d78a28b0072ee2bac071e5a6df751b0eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Sun, 4 May 2025 21:13:46 +0200 Subject: [PATCH] [FREELDR] Fix RamDisk size determination; add some traces (#8399) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CORE-14603 CORE-9023 The RamDisk path specified with `/RDPATH=` can be a path to a block device, like a disk partition, or the current boot disk (a ReactOS specific feature added in commit 9b70d4380c), instead of being only a file (as with Windows' NTLDR). In this case, the `StartingAddress` and `EndingAddress` returned by `ArcGetFileInformation()` are, per the specs, the start and end positions of the partition as byte offsets from the start of the disk. Therefore, the size of the partition is `== EndingAddress - StartingAddress`. + Add diagnostic traces in `RamDiskLoadVirtualFile()` and `RamDiskInitialize()`. Co-authored-by: Hermès Bélusca-Maïto --- boot/freeldr/freeldr/disk/ramdisk.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/boot/freeldr/freeldr/disk/ramdisk.c b/boot/freeldr/freeldr/disk/ramdisk.c index 2d111d885d9..e080a7e4000 100644 --- a/boot/freeldr/freeldr/disk/ramdisk.c +++ b/boot/freeldr/freeldr/disk/ramdisk.c @@ -12,6 +12,9 @@ #include #include "../ntldr/ntldropts.h" +#include +DBG_DEFAULT_CHANNEL(DISK); + /* GLOBALS ********************************************************************/ PVOID gInitRamDiskBase = NULL; @@ -119,6 +122,8 @@ RamDiskLoadVirtualFile( UiDrawProgressBarCenter("Loading RamDisk..."); /* Try opening the Ramdisk file */ + TRACE("RamDiskLoadVirtualFile: Opening '%s', '%s'\n", + FileName, DefaultPath ? DefaultPath : "n/a"); Status = FsOpenFile(FileName, DefaultPath, OpenReadOnly, &RamFileId); if (Status != ESUCCESS) return Status; @@ -130,16 +135,24 @@ RamDiskLoadVirtualFile( ArcClose(RamFileId); return Status; } + /* NOTE: For partitions, StartingAddress/EndingAddress are the start/end + * positions of the partition as byte offsets from the start of the disk */ + Information.EndingAddress.QuadPart -= Information.StartingAddress.QuadPart; + Information.StartingAddress.QuadPart = 0ULL; + + TRACE("RAMDISK size: %I64u (High: %lu ; Low: %lu)\n", + Information.EndingAddress.QuadPart, + Information.EndingAddress.HighPart, + Information.EndingAddress.LowPart); /* FIXME: For now, limit RAM disks to 4GB */ - if (Information.EndingAddress.HighPart != 0) + if (Information.EndingAddress.HighPart != 0) // (RamDiskFileSize >= 0x100000000ULL) { ArcClose(RamFileId); UiMessageBox("RAM disk too big."); return ENOMEM; } RamDiskFileSize = Information.EndingAddress.QuadPart; - ASSERT(RamDiskFileSize < 0x100000000); // See FIXME above. /* Allocate memory for it */ ChunkSize = 8 * 1024 * 1024; @@ -208,6 +221,11 @@ RamDiskInitialize( IN PCSTR LoadOptions OPTIONAL, IN PCSTR DefaultPath OPTIONAL) { + TRACE("RamDiskInitialize(%s, '%s', '%s')\n", + InitRamDisk ? "INIT" : "REGULAR", + LoadOptions ? LoadOptions : "n/a", + DefaultPath ? DefaultPath : "n/a"); + /* Reset the RAMDISK device */ if ((RamDiskBase != gInitRamDiskBase) && (RamDiskFileSize != gInitRamDiskSize) &&