]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ | |
2 | ||
3 | #pragma once | |
4 | ||
5 | #include "forward.h" | |
6 | ||
7 | typedef enum BootEntryType { | |
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, | |
14 | } BootEntryType; | |
15 | ||
16 | typedef enum BootEntrySource { | |
17 | BOOT_ENTRY_ESP, | |
18 | BOOT_ENTRY_XBOOTLDR, | |
19 | _BOOT_ENTRY_SOURCE_MAX, | |
20 | _BOOT_ENTRY_SOURCE_INVALID = -EINVAL, | |
21 | } BootEntrySource; | |
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 | typedef struct BootEntry { | |
34 | BootEntryType type; | |
35 | BootEntrySource source; | |
36 | bool reported_by_loader; | |
37 | char *id; /* This is the file basename (including extension!) */ | |
38 | char *id_old; /* Old-style ID, for deduplication purposes. */ | |
39 | char *id_without_profile; /* id without profile suffixed */ | |
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 | const BootEntryAddons *global_addons; /* Backpointer into the BootConfig; we don't own this here */ | |
51 | char *kernel; /* linux is #defined to 1, yikes! */ | |
52 | char *efi; | |
53 | char **initrd; | |
54 | char *device_tree; | |
55 | char **device_tree_overlay; | |
56 | unsigned tries_left; | |
57 | unsigned tries_done; | |
58 | unsigned profile; | |
59 | } BootEntry; | |
60 | ||
61 | #define BOOT_ENTRY_INIT(t, s) \ | |
62 | { \ | |
63 | .type = (t), \ | |
64 | .source = (s), \ | |
65 | .tries_left = UINT_MAX, \ | |
66 | .tries_done = UINT_MAX, \ | |
67 | } | |
68 | ||
69 | typedef struct BootConfig { | |
70 | char *default_pattern; | |
71 | ||
72 | char *entry_oneshot; | |
73 | char *entry_default; | |
74 | char *entry_selected; | |
75 | char *entry_sysfail; | |
76 | ||
77 | BootEntry *entries; | |
78 | size_t n_entries; | |
79 | ||
80 | BootEntryAddons global_addons[_BOOT_ENTRY_SOURCE_MAX]; | |
81 | ||
82 | ssize_t default_entry; | |
83 | ssize_t selected_entry; | |
84 | ||
85 | Set *inodes_seen; | |
86 | } BootConfig; | |
87 | ||
88 | #define BOOT_CONFIG_NULL \ | |
89 | { \ | |
90 | .default_entry = -1, \ | |
91 | .selected_entry = -1, \ | |
92 | } | |
93 | ||
94 | const char* boot_entry_type_to_string(BootEntryType) _const_; | |
95 | const char* boot_entry_type_json_to_string(BootEntryType) _const_; | |
96 | ||
97 | const char* boot_entry_source_to_string(BootEntrySource) _const_; | |
98 | const char* boot_entry_source_json_to_string(BootEntrySource) _const_; | |
99 | ||
100 | BootEntry* boot_config_find_entry(BootConfig *config, const char *id); | |
101 | ||
102 | static inline const BootEntry* boot_config_default_entry(const BootConfig *config) { | |
103 | assert(config); | |
104 | ||
105 | if (config->default_entry < 0) | |
106 | return NULL; | |
107 | ||
108 | assert((size_t) config->default_entry < config->n_entries); | |
109 | return config->entries + config->default_entry; | |
110 | } | |
111 | ||
112 | void boot_config_free(BootConfig *config); | |
113 | ||
114 | int boot_loader_read_conf(BootConfig *config, FILE *file, const char *path); | |
115 | ||
116 | int boot_config_load_type1( | |
117 | BootConfig *config, | |
118 | FILE *f, | |
119 | const char *root, | |
120 | const BootEntrySource source, | |
121 | const char *dir, | |
122 | const char *id); | |
123 | ||
124 | int boot_config_finalize(BootConfig *config); | |
125 | int boot_config_load(BootConfig *config, const char *esp_path, const char *xbootldr_path); | |
126 | int boot_config_load_auto(BootConfig *config, const char *override_esp_path, const char *override_xbootldr_path); | |
127 | int boot_config_augment_from_loader(BootConfig *config, char **list, bool auto_only); | |
128 | ||
129 | int boot_config_select_special_entries(BootConfig *config, bool skip_efivars); | |
130 | ||
131 | static inline const char* boot_entry_title(const BootEntry *entry) { | |
132 | assert(entry); | |
133 | return ASSERT_PTR(entry->show_title ?: entry->title ?: entry->id); | |
134 | } | |
135 | ||
136 | int show_boot_entry( | |
137 | const BootEntry *e, | |
138 | bool show_as_default, | |
139 | bool show_as_selected, | |
140 | bool show_reported); | |
141 | int show_boot_entries( | |
142 | const BootConfig *config, | |
143 | sd_json_format_flags_t json_format); | |
144 | ||
145 | int boot_filename_extract_tries(const char *fname, char **ret_stripped, unsigned *ret_tries_left, unsigned *ret_tries_done); | |
146 | ||
147 | int boot_entry_to_json(const BootConfig *c, size_t i, sd_json_variant **ret); |