]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/bootspec.h
hwdb: Add mapping for Xiaomi Mipad 2 bottom bezel capacitive buttons
[thirdparty/systemd.git] / src / shared / bootspec.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #pragma once
4
5 #include <errno.h>
6 #include <inttypes.h>
7 #include <stdbool.h>
8 #include <sys/types.h>
9
10 #include "json.h"
11 #include "set.h"
12 #include "string-util.h"
13
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) */
19 _BOOT_ENTRY_TYPE_MAX,
20 _BOOT_ENTRY_TYPE_INVALID = -EINVAL,
21 } BootEntryType;
22
23 typedef struct BootEntryAddon {
24 char *location;
25 char *cmdline;
26 } BootEntryAddon;
27
28 typedef struct BootEntryAddons {
29 BootEntryAddon *items;
30 size_t n_items;
31 } BootEntryAddons;
32
33 BootEntryAddon* boot_entry_addon_free(BootEntryAddon *t);
34
35 typedef struct BootEntry {
36 BootEntryType type;
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 */
42 char *title;
43 char *show_title;
44 char *sort_key;
45 char *version;
46 char *machine_id;
47 char *architecture;
48 char **options;
49 BootEntryAddons local_addons;
50 char *kernel; /* linux is #defined to 1, yikes! */
51 char *efi;
52 char **initrd;
53 char *device_tree;
54 char **device_tree_overlay;
55 unsigned tries_left;
56 unsigned tries_done;
57 } BootEntry;
58
59 #define BOOT_ENTRY_INIT(t) \
60 { \
61 .type = (t), \
62 .tries_left = UINT_MAX, \
63 .tries_done = UINT_MAX, \
64 }
65
66 typedef struct BootConfig {
67 char *default_pattern;
68
69 char *entry_oneshot;
70 char *entry_default;
71 char *entry_selected;
72
73 BootEntry *entries;
74 size_t n_entries;
75
76 BootEntryAddons global_addons;
77
78 ssize_t default_entry;
79 ssize_t selected_entry;
80
81 Set *inodes_seen;
82 } BootConfig;
83
84 #define BOOT_CONFIG_NULL \
85 { \
86 .default_entry = -1, \
87 .selected_entry = -1, \
88 }
89
90 const char* boot_entry_type_to_string(BootEntryType);
91 const char* boot_entry_type_json_to_string(BootEntryType);
92
93 BootEntry* boot_config_find_entry(BootConfig *config, const char *id);
94
95 static inline const BootEntry* boot_config_default_entry(const BootConfig *config) {
96 assert(config);
97
98 if (config->default_entry < 0)
99 return NULL;
100
101 assert((size_t) config->default_entry < config->n_entries);
102 return config->entries + config->default_entry;
103 }
104
105 void boot_config_free(BootConfig *config);
106
107 int boot_loader_read_conf(BootConfig *config, FILE *file, const char *path);
108
109 int boot_config_load_type1(
110 BootConfig *config,
111 FILE *f,
112 const char *root,
113 const char *dir,
114 const char *id);
115
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);
120
121 int boot_config_select_special_entries(BootConfig *config, bool skip_efivars);
122
123 static inline const char* boot_entry_title(const BootEntry *entry) {
124 assert(entry);
125
126 return ASSERT_PTR(entry->show_title ?: entry->title ?: entry->id);
127 }
128
129 int show_boot_entry(
130 const BootEntry *e,
131 const BootEntryAddons *global_addons,
132 bool show_as_default,
133 bool show_as_selected,
134 bool show_reported);
135 int show_boot_entries(
136 const BootConfig *config,
137 JsonFormatFlags json_format);
138
139 int boot_filename_extract_tries(const char *fname, char **ret_stripped, unsigned *ret_tries_left, unsigned *ret_tries_done);
140
141 int boot_entry_to_json(const BootConfig *c, size_t i, JsonVariant **ret);