Skip to content

Commit

Permalink
Prioritize volumes on boot media
Browse files Browse the repository at this point in the history
This ensures that kernels are preferably loaded from the boot medium in
case there are multiple partitions with identical label names. For that
purpose, move all volumes on the boot medium to the front of the list.

As we are potentially reordering the list while building it, we need to
postpone its printing to the end when it is fully constructed.

Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
jan-kiszka committed Dec 9, 2024
1 parent 0fb31eb commit 3602b73
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ EFI_STATUS get_volumes(VOLUME_DESC **volumes, UINTN *count)
EFI_HANDLE *handles = NULL;
EFI_GUID sfspGuid = SIMPLE_FILE_SYSTEM_PROTOCOL;
UINTN handleCount = 0;
UINTN index, rootCount = 0;
UINTN index, rootCount = 0, bootCount = 0;

EFI_FILE_HANDLE tmp;

Expand All @@ -133,7 +133,6 @@ EFI_STATUS get_volumes(VOLUME_DESC **volumes, UINTN *count)

for (index = 0; index < handleCount; index++) {
EFI_FILE_IO_INTERFACE *fs = NULL;
CHAR16 *devpathstr;

status = BS->HandleProtocol(
handles[index], &sfspGuid, (VOID **)&fs);
Expand All @@ -155,29 +154,38 @@ EFI_STATUS get_volumes(VOLUME_DESC **volumes, UINTN *count)
ERROR(L"Could not get device path for config partition, skipping.\n");
continue;
}
devpathstr = DevicePathToStr(devpath);

UINTN target = rootCount;
BOOLEAN onbootmedium = IsOnBootMedium(devpath);

(*volumes)[rootCount].root = tmp;
(*volumes)[rootCount].devpath = devpath;
(*volumes)[rootCount].onbootmedium = onbootmedium;
(*volumes)[rootCount].fslabel =
get_volume_label((*volumes)[rootCount].root);
(*volumes)[rootCount].fscustomlabel =
get_volume_custom_label((*volumes)[rootCount].root);
INFO(L"Volume %d: ", rootCount);
if (onbootmedium) {
INFO(L"(On boot medium) ");
CopyMem(&(*volumes)[bootCount + 1], &(*volumes)[bootCount],
(rootCount - bootCount) * sizeof(VOLUME_DESC));
target = bootCount++;
}
INFO(L"%s, LABEL=%s, CLABEL=%s\n",
devpathstr, (*volumes)[rootCount].fslabel,
(*volumes)[rootCount].fscustomlabel);

FreePool(devpathstr);
(*volumes)[target].root = tmp;
(*volumes)[target].devpath = devpath;
(*volumes)[target].onbootmedium = onbootmedium;
(*volumes)[target].fslabel =
get_volume_label((*volumes)[target].root);
(*volumes)[target].fscustomlabel =
get_volume_custom_label((*volumes)[target].root);

rootCount++;
}

for (index = 0; index < rootCount; index++) {
INFO(L"Volume %d: ", index);
if ((*volumes)[index].onbootmedium) {
INFO(L"(On boot medium) ");
}
CHAR16 *devpathstr = DevicePathToStr((*volumes)[index].devpath);
INFO(L"%s, LABEL=%s, CLABEL=%s\n",
devpathstr, (*volumes)[index].fslabel,
(*volumes)[index].fscustomlabel);
FreePool(devpathstr);
}

*count = rootCount;
return EFI_SUCCESS;
}
Expand Down

0 comments on commit 3602b73

Please sign in to comment.