Skip to content

Commit fa92d95

Browse files
committed
[FREELDR] Use the new volume size mechanism when loading a storage volume as a RamDisk (reactos#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.
1 parent 0ac0eb2 commit fa92d95

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

boot/freeldr/freeldr/disk/ramdisk.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ RamDiskLoadVirtualFile(
129129
if (Status != ESUCCESS)
130130
return Status;
131131

132-
/* Get the file size */
132+
/* Get the file or device size */
133133
Status = ArcGetFileInformation(RamFileId, &Information);
134134
if (Status != ESUCCESS)
135135
{
@@ -141,6 +141,18 @@ RamDiskLoadVirtualFile(
141141
Information.EndingAddress.QuadPart -= Information.StartingAddress.QuadPart;
142142
Information.StartingAddress.QuadPart = 0ULL;
143143

144+
/* If we are actually opening a RAW device, retrieve instead its usable volume size */
145+
if (Information.FileNameLength == 0 && Information.FileName[0] == ANSI_NULL &&
146+
(Information.Type == DiskPeripheral || Information.Type == FloppyDiskPeripheral))
147+
{
148+
ULONGLONG VolumeSize;
149+
Status = FsGetVolumeSize(RamFileId, &VolumeSize);
150+
if (Status != ESUCCESS)
151+
ERR("Couldn't retrieve volume size on device '%s', falling back to RAW size\n", FileName);
152+
else
153+
Information.EndingAddress.QuadPart = VolumeSize;
154+
}
155+
144156
TRACE("RAMDISK size: %I64u (High: %lu ; Low: %lu)\n",
145157
Information.EndingAddress.QuadPart,
146158
Information.EndingAddress.HighPart,

0 commit comments

Comments
 (0)