]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/bootspec.h
hwdb: Add mapping for Xiaomi Mipad 2 bottom bezel capacitive buttons
[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
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
33BootEntryAddon* boot_entry_addon_free(BootEntryAddon *t);
34
7e87c7d9 35typedef struct BootEntry {
93f14ce2 36 BootEntryType type;
bb682057 37 bool reported_by_loader;
31f77657 38 char *id; /* This is the file basename (including extension!) */
15b82eec 39 char *id_old; /* Old-style ID, for deduplication purposes. */
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;
7e87c7d9
ZJS
50 char *kernel; /* linux is #defined to 1, yikes! */
51 char *efi;
52 char **initrd;
53 char *device_tree;
fdc5c042 54 char **device_tree_overlay;
7f5780ed
LP
55 unsigned tries_left;
56 unsigned tries_done;
7e87c7d9
ZJS
57} BootEntry;
58
7f5780ed
LP
59#define BOOT_ENTRY_INIT(t) \
60 { \
61 .type = (t), \
62 .tries_left = UINT_MAX, \
63 .tries_done = UINT_MAX, \
64 }
65
7e87c7d9
ZJS
66typedef struct BootConfig {
67 char *default_pattern;
7e87c7d9
ZJS
68
69 char *entry_oneshot;
70 char *entry_default;
a78e472d 71 char *entry_selected;
7e87c7d9
ZJS
72
73 BootEntry *entries;
74 size_t n_entries;
d412691a 75
01fd8411
EGE
76 BootEntryAddons global_addons;
77
7e87c7d9 78 ssize_t default_entry;
a78e472d 79 ssize_t selected_entry;
d486a0ea
LP
80
81 Set *inodes_seen;
7e87c7d9
ZJS
82} BootConfig;
83
f7a7a5e2
LP
84#define BOOT_CONFIG_NULL \
85 { \
86 .default_entry = -1, \
87 .selected_entry = -1, \
88 }
89
432ce537 90const char* boot_entry_type_to_string(BootEntryType);
4bc14b17 91const char* boot_entry_type_json_to_string(BootEntryType);
432ce537 92
3f8e42c0 93BootEntry* boot_config_find_entry(BootConfig *config, const char *id);
93f14ce2 94
8214758b 95static inline const BootEntry* boot_config_default_entry(const BootConfig *config) {
bb682057
LP
96 assert(config);
97
38bd74d6
LP
98 if (config->default_entry < 0)
99 return NULL;
100
d412691a 101 assert((size_t) config->default_entry < config->n_entries);
38bd74d6
LP
102 return config->entries + config->default_entry;
103}
104
7e87c7d9 105void boot_config_free(BootConfig *config);
d412691a 106
5ba1550f
ZJS
107int boot_loader_read_conf(BootConfig *config, FILE *file, const char *path);
108
a847b539
ZJS
109int boot_config_load_type1(
110 BootConfig *config,
111 FILE *f,
112 const char *root,
113 const char *dir,
114 const char *id);
115
5ba1550f 116int boot_config_finalize(BootConfig *config);
af9ae750
LP
117int boot_config_load(BootConfig *config, const char *esp_path, const char *xbootldr_path);
118int boot_config_load_auto(BootConfig *config, const char *override_esp_path, const char *override_xbootldr_path);
119int boot_config_augment_from_loader(BootConfig *config, char **list, bool only_auto);
64f05708 120
80a2381d 121int boot_config_select_special_entries(BootConfig *config, bool skip_efivars);
f7a7a5e2 122
64f05708 123static inline const char* boot_entry_title(const BootEntry *entry) {
bb682057
LP
124 assert(entry);
125
ec725c0c 126 return ASSERT_PTR(entry->show_title ?: entry->title ?: entry->id);
64f05708 127}
432ce537
ZJS
128
129int show_boot_entry(
130 const BootEntry *e,
01fd8411 131 const BootEntryAddons *global_addons,
432ce537
ZJS
132 bool show_as_default,
133 bool show_as_selected,
134 bool show_reported);
135int show_boot_entries(
136 const BootConfig *config,
137 JsonFormatFlags json_format);
7f5780ed
LP
138
139int boot_filename_extract_tries(const char *fname, char **ret_stripped, unsigned *ret_tries_left, unsigned *ret_tries_done);
f892954b
LP
140
141int boot_entry_to_json(const BootConfig *c, size_t i, JsonVariant **ret);