1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
12 #include "string-util.h"
14 typedef enum BootEntryType
{
15 BOOT_ENTRY_CONF
, /* Boot Loader Specification Type #1 entries: *.conf files */
16 BOOT_ENTRY_UNIFIED
, /* Boot Loader Specification Type #2 entries: *.efi files */
17 BOOT_ENTRY_LOADER
, /* Additional entries augmented from LoaderEntries EFI variable (regular entries) */
18 BOOT_ENTRY_LOADER_AUTO
, /* Additional entries augmented from LoaderEntries EFI variable (special "automatic" entries) */
20 _BOOT_ENTRY_TYPE_INVALID
= -EINVAL
,
23 typedef struct BootEntryAddon
{
28 typedef struct BootEntryAddons
{
29 BootEntryAddon
*items
;
33 BootEntryAddon
* boot_entry_addon_free(BootEntryAddon
*t
);
35 typedef struct BootEntry
{
37 bool reported_by_loader
;
38 char *id
; /* This is the file basename (including extension!) */
39 char *id_old
; /* Old-style ID, for deduplication purposes. */
40 char *path
; /* This is the full path to the drop-in file */
41 char *root
; /* The root path in which the drop-in was found, i.e. to which 'kernel', 'efi' and 'initrd' are relative */
49 BootEntryAddons local_addons
;
50 char *kernel
; /* linux is #defined to 1, yikes! */
54 char **device_tree_overlay
;
59 #define BOOT_ENTRY_INIT(t) \
62 .tries_left = UINT_MAX, \
63 .tries_done = UINT_MAX, \
66 typedef struct BootConfig
{
67 char *default_pattern
;
76 BootEntryAddons global_addons
;
78 ssize_t default_entry
;
79 ssize_t selected_entry
;
84 #define BOOT_CONFIG_NULL \
86 .default_entry = -1, \
87 .selected_entry = -1, \
90 const char* boot_entry_type_to_string(BootEntryType
);
91 const char* boot_entry_type_json_to_string(BootEntryType
);
93 BootEntry
* boot_config_find_entry(BootConfig
*config
, const char *id
);
95 static inline const BootEntry
* boot_config_default_entry(const BootConfig
*config
) {
98 if (config
->default_entry
< 0)
101 assert((size_t) config
->default_entry
< config
->n_entries
);
102 return config
->entries
+ config
->default_entry
;
105 void boot_config_free(BootConfig
*config
);
107 int boot_loader_read_conf(BootConfig
*config
, FILE *file
, const char *path
);
109 int boot_config_load_type1(
116 int boot_config_finalize(BootConfig
*config
);
117 int boot_config_load(BootConfig
*config
, const char *esp_path
, const char *xbootldr_path
);
118 int boot_config_load_auto(BootConfig
*config
, const char *override_esp_path
, const char *override_xbootldr_path
);
119 int boot_config_augment_from_loader(BootConfig
*config
, char **list
, bool only_auto
);
121 int boot_config_select_special_entries(BootConfig
*config
, bool skip_efivars
);
123 static inline const char* boot_entry_title(const BootEntry
*entry
) {
126 return ASSERT_PTR(entry
->show_title
?: entry
->title
?: entry
->id
);
131 const BootEntryAddons
*global_addons
,
132 bool show_as_default
,
133 bool show_as_selected
,
135 int show_boot_entries(
136 const BootConfig
*config
,
137 JsonFormatFlags json_format
);
139 int boot_filename_extract_tries(const char *fname
, char **ret_stripped
, unsigned *ret_tries_left
, unsigned *ret_tries_done
);
141 int boot_entry_to_json(const BootConfig
*c
, size_t i
, JsonVariant
**ret
);