From 44d5b89d66418cfd245fb43405bf8610ba4795b2 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 4 Nov 2024 17:15:33 -0500 Subject: [PATCH] bootloader: Fetch and display the size of the partition, if possible. Fixes #19202. --- src/system/boot/loader/menu.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/system/boot/loader/menu.cpp b/src/system/boot/loader/menu.cpp index 687e28b43b..0d09dabd17 100644 --- a/src/system/boot/loader/menu.cpp +++ b/src/system/boot/loader/menu.cpp @@ -1190,6 +1190,21 @@ add_boot_volume_item(Menu* menu, Directory* volume, const char* name) volumeInfo.Unset(); } + // Display the size of this boot partition, if we can. + Partition* partition; + if (gRoot->GetPartitionFor(volume, &partition) == B_OK) { + float size = partition->Size() / (1024.0 * 1024.0); + const char* unit = "MiB"; + if (size > 1024.0) { + size /= 1024.0; + unit = "GiB"; + } + + char* newName = (char*)alloca(128); + snprintf(newName, 128, "%s (%f %s)", name, size, unit); + name = newName; + } + BootVolumeMenuItem* item = new(nothrow) BootVolumeMenuItem(name); menu->AddItem(item);