]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/bootspec.h
Merge pull request #25608 from poettering/dissect-moar
[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
e94830c0 5#include <errno.h>
195b36cf
LP
6#include <inttypes.h>
7#include <stdbool.h>
8#include <sys/types.h>
9
432ce537 10#include "json.h"
d486a0ea 11#include "set.h"
93f14ce2
LP
12#include "string-util.h"
13
14typedef enum BootEntryType {
bb682057
LP
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) */
19 _BOOT_ENTRY_TYPE_MAX,
20 _BOOT_ENTRY_TYPE_INVALID = -EINVAL,
93f14ce2
LP
21} BootEntryType;
22
7e87c7d9 23typedef struct BootEntry {
93f14ce2 24 BootEntryType type;
bb682057 25 bool reported_by_loader;
31f77657 26 char *id; /* This is the file basename (including extension!) */
15b82eec 27 char *id_old; /* Old-style ID, for deduplication purposes. */
43b736a8
LP
28 char *path; /* This is the full path to the drop-in file */
29 char *root; /* The root path in which the drop-in was found, i.e. to which 'kernel', 'efi' and 'initrd' are relative */
7e87c7d9 30 char *title;
64f05708 31 char *show_title;
20ec8f53 32 char *sort_key;
7e87c7d9
ZJS
33 char *version;
34 char *machine_id;
35 char *architecture;
36 char **options;
37 char *kernel; /* linux is #defined to 1, yikes! */
38 char *efi;
39 char **initrd;
40 char *device_tree;
fdc5c042 41 char **device_tree_overlay;
7f5780ed
LP
42 unsigned tries_left;
43 unsigned tries_done;
7e87c7d9
ZJS
44} BootEntry;
45
7f5780ed
LP
46#define BOOT_ENTRY_INIT(t) \
47 { \
48 .type = (t), \
49 .tries_left = UINT_MAX, \
50 .tries_done = UINT_MAX, \
51 }
52
7e87c7d9
ZJS
53typedef struct BootConfig {
54 char *default_pattern;
55 char *timeout;
56 char *editor;
c1d4e298
JJ
57 char *auto_entries;
58 char *auto_firmware;
d37b0737 59 char *console_mode;
d403d8f0 60 char *beep;
7e87c7d9
ZJS
61
62 char *entry_oneshot;
63 char *entry_default;
a78e472d 64 char *entry_selected;
7e87c7d9
ZJS
65
66 BootEntry *entries;
67 size_t n_entries;
d412691a 68
7e87c7d9 69 ssize_t default_entry;
a78e472d 70 ssize_t selected_entry;
d486a0ea
LP
71
72 Set *inodes_seen;
7e87c7d9
ZJS
73} BootConfig;
74
f7a7a5e2
LP
75#define BOOT_CONFIG_NULL \
76 { \
77 .default_entry = -1, \
78 .selected_entry = -1, \
79 }
80
432ce537 81const char* boot_entry_type_to_string(BootEntryType);
4bc14b17 82const char* boot_entry_type_json_to_string(BootEntryType);
432ce537 83
3f8e42c0 84BootEntry* boot_config_find_entry(BootConfig *config, const char *id);
93f14ce2 85
8214758b 86static inline const BootEntry* boot_config_default_entry(const BootConfig *config) {
bb682057
LP
87 assert(config);
88
38bd74d6
LP
89 if (config->default_entry < 0)
90 return NULL;
91
d412691a 92 assert((size_t) config->default_entry < config->n_entries);
38bd74d6
LP
93 return config->entries + config->default_entry;
94}
95
7e87c7d9 96void boot_config_free(BootConfig *config);
d412691a 97
5ba1550f
ZJS
98int boot_loader_read_conf(BootConfig *config, FILE *file, const char *path);
99
a847b539
ZJS
100int boot_config_load_type1(
101 BootConfig *config,
102 FILE *f,
103 const char *root,
104 const char *dir,
105 const char *id);
106
5ba1550f 107int boot_config_finalize(BootConfig *config);
af9ae750
LP
108int boot_config_load(BootConfig *config, const char *esp_path, const char *xbootldr_path);
109int boot_config_load_auto(BootConfig *config, const char *override_esp_path, const char *override_xbootldr_path);
110int boot_config_augment_from_loader(BootConfig *config, char **list, bool only_auto);
64f05708 111
80a2381d 112int boot_config_select_special_entries(BootConfig *config, bool skip_efivars);
f7a7a5e2 113
64f05708 114static inline const char* boot_entry_title(const BootEntry *entry) {
bb682057
LP
115 assert(entry);
116
ec725c0c 117 return ASSERT_PTR(entry->show_title ?: entry->title ?: entry->id);
64f05708 118}
432ce537
ZJS
119
120int show_boot_entry(
121 const BootEntry *e,
122 bool show_as_default,
123 bool show_as_selected,
124 bool show_reported);
125int show_boot_entries(
126 const BootConfig *config,
127 JsonFormatFlags json_format);
7f5780ed
LP
128
129int boot_filename_extract_tries(const char *fname, char **ret_stripped, unsigned *ret_tries_left, unsigned *ret_tries_done);