]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/bootspec.h
build(deps): bump github/codeql-action from 3.28.18 to 3.29.2
[thirdparty/systemd.git] / src / shared / bootspec.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
7e87c7d9
ZJS
2
3#pragma once
4
69a283c5 5#include "forward.h"
93f14ce2
LP
6
7typedef enum BootEntryType {
bb682057
LP
8 BOOT_ENTRY_CONF, /* Boot Loader Specification Type #1 entries: *.conf files */
9 BOOT_ENTRY_UNIFIED, /* Boot Loader Specification Type #2 entries: *.efi files */
10 BOOT_ENTRY_LOADER, /* Additional entries augmented from LoaderEntries EFI variable (regular entries) */
11 BOOT_ENTRY_LOADER_AUTO, /* Additional entries augmented from LoaderEntries EFI variable (special "automatic" entries) */
12 _BOOT_ENTRY_TYPE_MAX,
13 _BOOT_ENTRY_TYPE_INVALID = -EINVAL,
93f14ce2
LP
14} BootEntryType;
15
f2751d75
AV
16typedef enum BootEntrySource {
17 BOOT_ENTRY_ESP,
18 BOOT_ENTRY_XBOOTLDR,
19 _BOOT_ENTRY_SOURCE_MAX,
20 _BOOT_ENTRY_SOURCE_INVALID = -EINVAL,
21} BootEntrySource;
22
122650b4
EGE
23typedef struct BootEntryAddon {
24 char *location;
25 char *cmdline;
26} BootEntryAddon;
27
28typedef struct BootEntryAddons {
29 BootEntryAddon *items;
706ca67d 30 size_t n_items;
122650b4
EGE
31} BootEntryAddons;
32
7e87c7d9 33typedef struct BootEntry {
93f14ce2 34 BootEntryType type;
f2751d75 35 BootEntrySource source;
bb682057 36 bool reported_by_loader;
31f77657 37 char *id; /* This is the file basename (including extension!) */
15b82eec 38 char *id_old; /* Old-style ID, for deduplication purposes. */
59b3df9b 39 char *id_without_profile; /* id without profile suffixed */
43b736a8
LP
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 */
7e87c7d9 42 char *title;
64f05708 43 char *show_title;
20ec8f53 44 char *sort_key;
7e87c7d9
ZJS
45 char *version;
46 char *machine_id;
47 char *architecture;
48 char **options;
122650b4 49 BootEntryAddons local_addons;
f2751d75 50 const BootEntryAddons *global_addons; /* Backpointer into the BootConfig; we don't own this here */
7e87c7d9
ZJS
51 char *kernel; /* linux is #defined to 1, yikes! */
52 char *efi;
53 char **initrd;
54 char *device_tree;
fdc5c042 55 char **device_tree_overlay;
7f5780ed
LP
56 unsigned tries_left;
57 unsigned tries_done;
59b3df9b 58 unsigned profile;
7e87c7d9
ZJS
59} BootEntry;
60
f2751d75 61#define BOOT_ENTRY_INIT(t, s) \
7f5780ed
LP
62 { \
63 .type = (t), \
f2751d75 64 .source = (s), \
7f5780ed
LP
65 .tries_left = UINT_MAX, \
66 .tries_done = UINT_MAX, \
67 }
68
7e87c7d9
ZJS
69typedef struct BootConfig {
70 char *default_pattern;
7e87c7d9
ZJS
71
72 char *entry_oneshot;
73 char *entry_default;
a78e472d 74 char *entry_selected;
004e3e40 75 char *entry_sysfail;
7e87c7d9
ZJS
76
77 BootEntry *entries;
78 size_t n_entries;
d412691a 79
f2751d75 80 BootEntryAddons global_addons[_BOOT_ENTRY_SOURCE_MAX];
01fd8411 81
7e87c7d9 82 ssize_t default_entry;
a78e472d 83 ssize_t selected_entry;
d486a0ea
LP
84
85 Set *inodes_seen;
7e87c7d9
ZJS
86} BootConfig;
87
f7a7a5e2
LP
88#define BOOT_CONFIG_NULL \
89 { \
90 .default_entry = -1, \
91 .selected_entry = -1, \
92 }
93
9a1276e0
MY
94const char* boot_entry_type_to_string(BootEntryType) _const_;
95const char* boot_entry_type_json_to_string(BootEntryType) _const_;
432ce537 96
9a1276e0
MY
97const char* boot_entry_source_to_string(BootEntrySource) _const_;
98const char* boot_entry_source_json_to_string(BootEntrySource) _const_;
f2751d75 99
3f8e42c0 100BootEntry* boot_config_find_entry(BootConfig *config, const char *id);
93f14ce2 101
8214758b 102static inline const BootEntry* boot_config_default_entry(const BootConfig *config) {
bb682057
LP
103 assert(config);
104
38bd74d6
LP
105 if (config->default_entry < 0)
106 return NULL;
107
d412691a 108 assert((size_t) config->default_entry < config->n_entries);
38bd74d6
LP
109 return config->entries + config->default_entry;
110}
111
7e87c7d9 112void boot_config_free(BootConfig *config);
d412691a 113
5ba1550f
ZJS
114int boot_loader_read_conf(BootConfig *config, FILE *file, const char *path);
115
a847b539
ZJS
116int boot_config_load_type1(
117 BootConfig *config,
118 FILE *f,
119 const char *root,
f2751d75 120 const BootEntrySource source,
a847b539
ZJS
121 const char *dir,
122 const char *id);
123
5ba1550f 124int boot_config_finalize(BootConfig *config);
af9ae750
LP
125int boot_config_load(BootConfig *config, const char *esp_path, const char *xbootldr_path);
126int boot_config_load_auto(BootConfig *config, const char *override_esp_path, const char *override_xbootldr_path);
b52f095e 127int boot_config_augment_from_loader(BootConfig *config, char **list, bool auto_only);
64f05708 128
80a2381d 129int boot_config_select_special_entries(BootConfig *config, bool skip_efivars);
f7a7a5e2 130
64f05708 131static inline const char* boot_entry_title(const BootEntry *entry) {
bb682057 132 assert(entry);
ec725c0c 133 return ASSERT_PTR(entry->show_title ?: entry->title ?: entry->id);
64f05708 134}
432ce537
ZJS
135
136int show_boot_entry(
137 const BootEntry *e,
138 bool show_as_default,
139 bool show_as_selected,
140 bool show_reported);
141int show_boot_entries(
142 const BootConfig *config,
309a747f 143 sd_json_format_flags_t json_format);
7f5780ed
LP
144
145int boot_filename_extract_tries(const char *fname, char **ret_stripped, unsigned *ret_tries_left, unsigned *ret_tries_done);
f892954b 146
309a747f 147int boot_entry_to_json(const BootConfig *c, size_t i, sd_json_variant **ret);