Skip to content

Commit

Permalink
Fold filter_cfg_parts into enumerate_cfg_parts
Browse files Browse the repository at this point in the history
Now that we have strict boot-medium-first ordering in the volume list,
we can easily perform the config filtering already while enumerating.
Simplifies the code significantly.

Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
jan-kiszka committed Dec 9, 2024
1 parent 9eb8097 commit f8a342c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 50 deletions.
3 changes: 0 additions & 3 deletions env/fatvars.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ BG_STATUS load_config(BG_LOADER_PARAMS *bglp)
ERROR(L"Could not enumerate config partitions.\n");
goto lc_cleanup;
}

numHandles = filter_cfg_parts(config_volumes, numHandles);

if (numHandles > ENV_NUM_CONFIG_PARTS) {
ERROR(L"Too many config partitions found. Aborting.\n");
goto lc_cleanup;
Expand Down
60 changes: 14 additions & 46 deletions env/syspart.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

EFI_STATUS enumerate_cfg_parts(UINTN *config_volumes, UINTN *numHandles)
{
BOOLEAN use_envs_on_bootmedium_only = FALSE;
EFI_STATUS status;
UINTN rootCount = 0;

Expand All @@ -36,9 +37,16 @@ EFI_STATUS enumerate_cfg_parts(UINTN *config_volumes, UINTN *numHandles)
status = open_cfg_file(volumes[index].root, &fh,
EFI_FILE_MODE_READ);
if (status == EFI_SUCCESS) {
INFO(L"Config file found on volume %d.\n", index);
config_volumes[rootCount] = index;
rootCount++;
if (volumes[index].onbootmedium) {
use_envs_on_bootmedium_only = TRUE;
}
if (!use_envs_on_bootmedium_only || volumes[index].onbootmedium) {
INFO(L"Config file found on volume %d.\n", index);
config_volumes[rootCount] = index;
rootCount++;
} else {
WARNING(L"Ignoring config file found on volume %d.\n", index);
}
status = close_cfg_file(volumes[index].root, fh);
if (EFI_ERROR(status)) {
ERROR(L"Could not close config file on partition %d.\n",
Expand All @@ -47,49 +55,9 @@ EFI_STATUS enumerate_cfg_parts(UINTN *config_volumes, UINTN *numHandles)
}
}
*numHandles = rootCount;
if (use_envs_on_bootmedium_only) {
INFO(L"Booting with environments from boot medium only.\n");
}
INFO(L"%d config partitions detected.\n", rootCount);
return EFI_SUCCESS;
}

static VOID swap_uintn(UINTN *a, UINTN *b)
{
UINTN tmp;
tmp = *a;
*a = *b;
*b = tmp;
}

UINTN filter_cfg_parts(UINTN *config_volumes, UINTN numHandles)
{
BOOLEAN use_envs_on_bootmedium_only = FALSE;

INFO(L"Config filter: \n");
for (UINTN index = 0; index < numHandles; index++) {
VOLUME_DESC *v = &volumes[config_volumes[index]];

if (v->onbootmedium) {
use_envs_on_bootmedium_only = TRUE;
};
}

if (!use_envs_on_bootmedium_only) {
// nothing to do
return numHandles;
}

INFO(L"Booting with environments from boot medium only.\n");
UINTN num_sorted = 0;
for (UINTN j = 0; j < numHandles; j++) {
UINTN cvi = config_volumes[j];
VOLUME_DESC *v = &volumes[cvi];

if (v->onbootmedium) {
swap_uintn(&config_volumes[j],
&config_volumes[num_sorted++]);
} else {
WARNING(L"Ignoring config on volume #%d\n", cvi);
}
}

return num_sorted;
}
1 change: 0 additions & 1 deletion include/syspart.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@
(file)->Read((file), (len), (buffer))

EFI_STATUS enumerate_cfg_parts(UINTN *config_volumes, UINTN *maxHandles);
UINTN filter_cfg_parts(UINTN *config_volumes, UINTN maxHandles);

0 comments on commit f8a342c

Please sign in to comment.