From 199989e168ee070849e1c13ad3c450093c3ad64d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 7 Jul 2025 15:52:17 +0200 Subject: [PATCH 1/5] bootspec: rename boot_entry_type_to_string() to boot_entry_type_description_to_string() This helper does not translate BootEntryType to a string matching the enum's value names, but instead returns a human readable descriptive string. Let's make it clearer what this, by including "description" in the name. --- src/shared/bootspec.c | 6 +++--- src/shared/bootspec.h | 2 +- src/vmspawn/vmspawn.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index bac00c5b3c..59ab33a19b 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -32,14 +32,14 @@ #include "strv.h" #include "uki.h" -static const char* const boot_entry_type_table[_BOOT_ENTRY_TYPE_MAX] = { +static const char* const boot_entry_type_description_table[_BOOT_ENTRY_TYPE_MAX] = { [BOOT_ENTRY_CONF] = "Boot Loader Specification Type #1 (.conf)", [BOOT_ENTRY_UNIFIED] = "Boot Loader Specification Type #2 (.efi)", [BOOT_ENTRY_LOADER] = "Reported by Boot Loader", [BOOT_ENTRY_LOADER_AUTO] = "Automatic", }; -DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_type, BootEntryType); +DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_type_description, BootEntryType); static const char* const boot_entry_type_json_table[_BOOT_ENTRY_TYPE_MAX] = { [BOOT_ENTRY_CONF] = "type1", @@ -1823,7 +1823,7 @@ int show_boot_entry( assert(e); printf(" type: %s\n", - boot_entry_type_to_string(e->type)); + boot_entry_type_description_to_string(e->type)); printf(" title: %s%s%s", ansi_highlight(), boot_entry_title(e), ansi_normal()); diff --git a/src/shared/bootspec.h b/src/shared/bootspec.h index e0c561808c..f73ca627c5 100644 --- a/src/shared/bootspec.h +++ b/src/shared/bootspec.h @@ -91,7 +91,7 @@ typedef struct BootConfig { .selected_entry = -1, \ } -const char* boot_entry_type_to_string(BootEntryType) _const_; +const char* boot_entry_type_description_to_string(BootEntryType) _const_; const char* boot_entry_type_json_to_string(BootEntryType) _const_; const char* boot_entry_source_to_string(BootEntrySource) _const_; diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index 49833ec49f..6a7a34d35b 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -1373,7 +1373,7 @@ static int discover_boot_entry(const char *root, char **ret_linux, char ***ret_i if (!boot_entry) return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Failed to discover any boot entries."); - log_debug("Discovered boot entry %s (%s)", boot_entry->id, boot_entry_type_to_string(boot_entry->type)); + log_debug("Discovered boot entry %s (%s)", boot_entry->id, boot_entry_type_description_to_string(boot_entry->type)); _cleanup_free_ char *linux_kernel = NULL; _cleanup_strv_free_ char **initrds = NULL; From a1c7aa6a95956f6827b250a9fec9d584077e2a37 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 7 Jul 2025 15:54:17 +0200 Subject: [PATCH 2/5] bootspec: include 'UKI' in descriptive name for type #2 I am pretty sure that "UKI" is the best known name for type #2 boot loader spec entries, hence we really should put it in the name. --- src/shared/bootspec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 59ab33a19b..5ccfbfbb82 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -34,7 +34,7 @@ static const char* const boot_entry_type_description_table[_BOOT_ENTRY_TYPE_MAX] = { [BOOT_ENTRY_CONF] = "Boot Loader Specification Type #1 (.conf)", - [BOOT_ENTRY_UNIFIED] = "Boot Loader Specification Type #2 (.efi)", + [BOOT_ENTRY_UNIFIED] = "Boot Loader Specification Type #2 (UKI, .efi)", [BOOT_ENTRY_LOADER] = "Reported by Boot Loader", [BOOT_ENTRY_LOADER_AUTO] = "Automatic", }; From 9880c7f103cde943a40aa9eec8e70c40708ecb45 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 7 Jul 2025 18:10:13 +0200 Subject: [PATCH 3/5] bootspec: rename BootEntryType values So we exposed different names for the entry types in JSON than we named our enum values. Which is very confusing. Let's unify that. Given that the JSON fields are externally visible let's stick to that naming, even though I think "unified" and "conf" would have been more descriptive. This ensures we follow our usual logic that the enum identifiers and the strings they map to use the same naming. --- src/shared/bootspec.c | 32 ++++++++++++++++---------------- src/shared/bootspec.h | 10 +++++----- src/vmspawn/vmspawn.c | 10 +++++----- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 5ccfbfbb82..6fdfdb3db9 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -33,22 +33,22 @@ #include "uki.h" static const char* const boot_entry_type_description_table[_BOOT_ENTRY_TYPE_MAX] = { - [BOOT_ENTRY_CONF] = "Boot Loader Specification Type #1 (.conf)", - [BOOT_ENTRY_UNIFIED] = "Boot Loader Specification Type #2 (UKI, .efi)", - [BOOT_ENTRY_LOADER] = "Reported by Boot Loader", - [BOOT_ENTRY_LOADER_AUTO] = "Automatic", + [BOOT_ENTRY_TYPE1] = "Boot Loader Specification Type #1 (.conf)", + [BOOT_ENTRY_TYPE2] = "Boot Loader Specification Type #2 (UKI, .efi)", + [BOOT_ENTRY_LOADER] = "Reported by Boot Loader", + [BOOT_ENTRY_AUTO] = "Automatic", }; DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_type_description, BootEntryType); -static const char* const boot_entry_type_json_table[_BOOT_ENTRY_TYPE_MAX] = { - [BOOT_ENTRY_CONF] = "type1", - [BOOT_ENTRY_UNIFIED] = "type2", - [BOOT_ENTRY_LOADER] = "loader", - [BOOT_ENTRY_LOADER_AUTO] = "auto", +static const char* const boot_entry_type_table[_BOOT_ENTRY_TYPE_MAX] = { + [BOOT_ENTRY_TYPE1] = "type1", + [BOOT_ENTRY_TYPE2] = "type2", + [BOOT_ENTRY_LOADER] = "loader", + [BOOT_ENTRY_AUTO] = "auto", }; -DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_type_json, BootEntryType); +DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_type, BootEntryType); static const char* const boot_entry_source_table[_BOOT_ENTRY_SOURCE_MAX] = { [BOOT_ENTRY_ESP] = "EFI System Partition", @@ -319,7 +319,7 @@ static int boot_entry_load_type1( const char *fname, BootEntry *ret) { - _cleanup_(boot_entry_free) BootEntry tmp = BOOT_ENTRY_INIT(BOOT_ENTRY_CONF, source); + _cleanup_(boot_entry_free) BootEntry tmp = BOOT_ENTRY_INIT(BOOT_ENTRY_TYPE1, source); char *c; int r; @@ -759,7 +759,7 @@ static int boot_entry_load_unified( if (r < 0) return log_error_errno(r, "Failed to extract file name from '%s': %m", path); - _cleanup_(boot_entry_free) BootEntry tmp = BOOT_ENTRY_INIT(BOOT_ENTRY_UNIFIED, source); + _cleanup_(boot_entry_free) BootEntry tmp = BOOT_ENTRY_INIT(BOOT_ENTRY_TYPE2, source); r = boot_filename_extract_tries(fname, &tmp.id, &tmp.tries_left, &tmp.tries_done); if (r < 0) @@ -1620,7 +1620,7 @@ int boot_config_augment_from_loader( return log_oom(); config->entries[config->n_entries++] = (BootEntry) { - .type = startswith(*i, "auto-") ? BOOT_ENTRY_LOADER_AUTO : BOOT_ENTRY_LOADER, + .type = startswith(*i, "auto-") ? BOOT_ENTRY_AUTO : BOOT_ENTRY_LOADER, .id = TAKE_PTR(c), .title = TAKE_PTR(t), .path = TAKE_PTR(p), @@ -1840,7 +1840,7 @@ int show_boot_entry( if (e->type == BOOT_ENTRY_LOADER) printf(" %s(reported/absent)%s", ansi_highlight_red(), ansi_normal()); - else if (!e->reported_by_loader && e->type != BOOT_ENTRY_LOADER_AUTO) + else if (!e->reported_by_loader && e->type != BOOT_ENTRY_AUTO) printf(" %s(not reported/new)%s", ansi_highlight_green(), ansi_normal()); } @@ -1867,7 +1867,7 @@ int show_boot_entry( /* Let's urlify the link to make it easy to view in an editor, but only if it is a text * file. Unified images are binary ELFs, and EFI variables are not pure text either. */ - if (e->type == BOOT_ENTRY_CONF) + if (e->type == BOOT_ENTRY_TYPE1) (void) terminal_urlify_path(e->path, text, &link); printf(" source: %s (on the %s)\n", @@ -1942,7 +1942,7 @@ int boot_entry_to_json(const BootConfig *c, size_t i, sd_json_variant **ret) { r = sd_json_variant_merge_objectbo( &v, - SD_JSON_BUILD_PAIR("type", SD_JSON_BUILD_STRING(boot_entry_type_json_to_string(e->type))), + SD_JSON_BUILD_PAIR("type", SD_JSON_BUILD_STRING(boot_entry_type_to_string(e->type))), SD_JSON_BUILD_PAIR("source", SD_JSON_BUILD_STRING(boot_entry_source_json_to_string(e->source))), SD_JSON_BUILD_PAIR_CONDITION(!!e->id, "id", SD_JSON_BUILD_STRING(e->id)), SD_JSON_BUILD_PAIR_CONDITION(!!e->path, "path", SD_JSON_BUILD_STRING(e->path)), diff --git a/src/shared/bootspec.h b/src/shared/bootspec.h index f73ca627c5..1ce7202d99 100644 --- a/src/shared/bootspec.h +++ b/src/shared/bootspec.h @@ -5,10 +5,10 @@ #include "forward.h" typedef enum BootEntryType { - BOOT_ENTRY_CONF, /* Boot Loader Specification Type #1 entries: *.conf files */ - BOOT_ENTRY_UNIFIED, /* Boot Loader Specification Type #2 entries: *.efi files */ - BOOT_ENTRY_LOADER, /* Additional entries augmented from LoaderEntries EFI variable (regular entries) */ - BOOT_ENTRY_LOADER_AUTO, /* Additional entries augmented from LoaderEntries EFI variable (special "automatic" entries) */ + BOOT_ENTRY_TYPE1, /* Boot Loader Specification Type #1 entries: *.conf files */ + BOOT_ENTRY_TYPE2, /* Boot Loader Specification Type #2 entries: *.efi files (UKIs) */ + BOOT_ENTRY_LOADER, /* Additional entries augmented from LoaderEntries EFI variable (regular entries) */ + BOOT_ENTRY_AUTO, /* Additional entries augmented from LoaderEntries EFI variable (special "automatic" entries) */ _BOOT_ENTRY_TYPE_MAX, _BOOT_ENTRY_TYPE_INVALID = -EINVAL, } BootEntryType; @@ -92,7 +92,7 @@ typedef struct BootConfig { } const char* boot_entry_type_description_to_string(BootEntryType) _const_; -const char* boot_entry_type_json_to_string(BootEntryType) _const_; +const char* boot_entry_type_to_string(BootEntryType) _const_; const char* boot_entry_source_to_string(BootEntrySource) _const_; const char* boot_entry_source_json_to_string(BootEntrySource) _const_; diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index 6a7a34d35b..0a3ac89255 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -1350,7 +1350,7 @@ static int discover_boot_entry(const char *root, char **ret_linux, char ***ret_i const BootEntry *boot_entry = boot_config_default_entry(&config); - if (boot_entry && !IN_SET(boot_entry->type, BOOT_ENTRY_UNIFIED, BOOT_ENTRY_CONF)) + if (boot_entry && !IN_SET(boot_entry->type, BOOT_ENTRY_TYPE1, BOOT_ENTRY_TYPE2)) boot_entry = NULL; /* If we cannot determine a default entry search for UKIs (Type #2 EFI Unified Kernel Images) @@ -1358,14 +1358,14 @@ static int discover_boot_entry(const char *root, char **ret_linux, char ***ret_i * https://uapi-group.org/specifications/specs/boot_loader_specification */ if (!boot_entry) FOREACH_ARRAY(entry, config.entries, config.n_entries) - if (entry->type == BOOT_ENTRY_UNIFIED) { + if (entry->type == BOOT_ENTRY_TYPE2) { /* UKI */ boot_entry = entry; break; } if (!boot_entry) FOREACH_ARRAY(entry, config.entries, config.n_entries) - if (entry->type == BOOT_ENTRY_CONF) { + if (entry->type == BOOT_ENTRY_TYPE1) { /* .conf */ boot_entry = entry; break; } @@ -1377,11 +1377,11 @@ static int discover_boot_entry(const char *root, char **ret_linux, char ***ret_i _cleanup_free_ char *linux_kernel = NULL; _cleanup_strv_free_ char **initrds = NULL; - if (boot_entry->type == BOOT_ENTRY_UNIFIED) { + if (boot_entry->type == BOOT_ENTRY_TYPE2) { /* UKI */ linux_kernel = path_join(boot_entry->root, boot_entry->kernel); if (!linux_kernel) return log_oom(); - } else if (boot_entry->type == BOOT_ENTRY_CONF) { + } else if (boot_entry->type == BOOT_ENTRY_TYPE1) { /* .conf */ linux_kernel = path_join(boot_entry->root, boot_entry->kernel); if (!linux_kernel) return log_oom(); From 2030922e2ddb0aed335c8c4202a0c86f36c4d31d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 7 Jul 2025 18:25:22 +0200 Subject: [PATCH 4/5] bootspec: rename boot_entry_source_to_string() to boot_entry_source_description_to_string() Similar to the previous changes, let's make clear this string table contains *descriptive*, i.e. meaningful human-readable strings. --- src/shared/bootspec.c | 6 +++--- src/shared/bootspec.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 6fdfdb3db9..30d566e529 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -50,12 +50,12 @@ static const char* const boot_entry_type_table[_BOOT_ENTRY_TYPE_MAX] = { DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_type, BootEntryType); -static const char* const boot_entry_source_table[_BOOT_ENTRY_SOURCE_MAX] = { +static const char* const boot_entry_source_description_table[_BOOT_ENTRY_SOURCE_MAX] = { [BOOT_ENTRY_ESP] = "EFI System Partition", [BOOT_ENTRY_XBOOTLDR] = "Extended Boot Loader Partition", }; -DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_source, BootEntrySource); +DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_source_description, BootEntrySource); static const char* const boot_entry_source_json_table[_BOOT_ENTRY_SOURCE_MAX] = { [BOOT_ENTRY_ESP] = "esp", @@ -1872,7 +1872,7 @@ int show_boot_entry( printf(" source: %s (on the %s)\n", link ?: text ?: e->path, - boot_entry_source_to_string(e->source)); + boot_entry_source_description_to_string(e->source)); } if (e->tries_left != UINT_MAX) { printf(" tries: %u left", e->tries_left); diff --git a/src/shared/bootspec.h b/src/shared/bootspec.h index 1ce7202d99..bf4ecb3347 100644 --- a/src/shared/bootspec.h +++ b/src/shared/bootspec.h @@ -94,7 +94,7 @@ typedef struct BootConfig { const char* boot_entry_type_description_to_string(BootEntryType) _const_; const char* boot_entry_type_to_string(BootEntryType) _const_; -const char* boot_entry_source_to_string(BootEntrySource) _const_; +const char* boot_entry_source_description_to_string(BootEntrySource) _const_; const char* boot_entry_source_json_to_string(BootEntrySource) _const_; BootEntry* boot_config_find_entry(BootConfig *config, const char *id); From 1e7ba4780d5e887788742430feafc768e5cc7e49 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 7 Jul 2025 18:26:59 +0200 Subject: [PATCH 5/5] bootspec: boot_entry_source_to_json_string() to boot_entry_source_to_string() As with the previous changes for BootEntryType, let's also clean up the naming for BootEntrySource. --- src/shared/bootspec.c | 6 +++--- src/shared/bootspec.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 30d566e529..7788d65516 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -57,12 +57,12 @@ static const char* const boot_entry_source_description_table[_BOOT_ENTRY_SOURCE_ DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_source_description, BootEntrySource); -static const char* const boot_entry_source_json_table[_BOOT_ENTRY_SOURCE_MAX] = { +static const char* const boot_entry_source_table[_BOOT_ENTRY_SOURCE_MAX] = { [BOOT_ENTRY_ESP] = "esp", [BOOT_ENTRY_XBOOTLDR] = "xbootldr", }; -DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_source_json, BootEntrySource); +DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_source, BootEntrySource); static void boot_entry_addons_done(BootEntryAddons *addons) { assert(addons); @@ -1943,7 +1943,7 @@ int boot_entry_to_json(const BootConfig *c, size_t i, sd_json_variant **ret) { r = sd_json_variant_merge_objectbo( &v, SD_JSON_BUILD_PAIR("type", SD_JSON_BUILD_STRING(boot_entry_type_to_string(e->type))), - SD_JSON_BUILD_PAIR("source", SD_JSON_BUILD_STRING(boot_entry_source_json_to_string(e->source))), + SD_JSON_BUILD_PAIR("source", SD_JSON_BUILD_STRING(boot_entry_source_to_string(e->source))), SD_JSON_BUILD_PAIR_CONDITION(!!e->id, "id", SD_JSON_BUILD_STRING(e->id)), SD_JSON_BUILD_PAIR_CONDITION(!!e->path, "path", SD_JSON_BUILD_STRING(e->path)), SD_JSON_BUILD_PAIR_CONDITION(!!e->root, "root", SD_JSON_BUILD_STRING(e->root)), diff --git a/src/shared/bootspec.h b/src/shared/bootspec.h index bf4ecb3347..dd192b4722 100644 --- a/src/shared/bootspec.h +++ b/src/shared/bootspec.h @@ -95,7 +95,7 @@ const char* boot_entry_type_description_to_string(BootEntryType) _const_; const char* boot_entry_type_to_string(BootEntryType) _const_; const char* boot_entry_source_description_to_string(BootEntrySource) _const_; -const char* boot_entry_source_json_to_string(BootEntrySource) _const_; +const char* boot_entry_source_to_string(BootEntrySource) _const_; BootEntry* boot_config_find_entry(BootConfig *config, const char *id);