From fa92d9580010070405d4b0e7abd8d387bd66f294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sat, 4 Oct 2025 16:30:30 +0200 Subject: [PATCH] [FREELDR] Use the new volume size mechanism when loading a storage volume as a RamDisk (#8423) CORE-14603 The differentiation between a regular file loaded as a RamDisk and a storage device volume, is done by invoking `ArcGetFileInformation()` and looking at the `Information.Type` value. --- boot/freeldr/freeldr/disk/ramdisk.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/boot/freeldr/freeldr/disk/ramdisk.c b/boot/freeldr/freeldr/disk/ramdisk.c index 827dd42827b..bbd7c075ed2 100644 --- a/boot/freeldr/freeldr/disk/ramdisk.c +++ b/boot/freeldr/freeldr/disk/ramdisk.c @@ -129,7 +129,7 @@ RamDiskLoadVirtualFile( if (Status != ESUCCESS) return Status; - /* Get the file size */ + /* Get the file or device size */ Status = ArcGetFileInformation(RamFileId, &Information); if (Status != ESUCCESS) { @@ -141,6 +141,18 @@ RamDiskLoadVirtualFile( Information.EndingAddress.QuadPart -= Information.StartingAddress.QuadPart; Information.StartingAddress.QuadPart = 0ULL; + /* If we are actually opening a RAW device, retrieve instead its usable volume size */ + if (Information.FileNameLength == 0 && Information.FileName[0] == ANSI_NULL && + (Information.Type == DiskPeripheral || Information.Type == FloppyDiskPeripheral)) + { + ULONGLONG VolumeSize; + Status = FsGetVolumeSize(RamFileId, &VolumeSize); + if (Status != ESUCCESS) + ERR("Couldn't retrieve volume size on device '%s', falling back to RAW size\n", FileName); + else + Information.EndingAddress.QuadPart = VolumeSize; + } + TRACE("RAMDISK size: %I64u (High: %lu ; Low: %lu)\n", Information.EndingAddress.QuadPart, Information.EndingAddress.HighPart,