]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/bootspec.h
shared/varlink: add missing terminator in json strings
[thirdparty/systemd.git] / src / shared / bootspec.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #pragma once
4
5 #include <inttypes.h>
6 #include <stdbool.h>
7 #include <sys/types.h>
8
9 #include "sd-id128.h"
10
11 #include "string-util.h"
12
13 typedef enum BootEntryType {
14 BOOT_ENTRY_CONF, /* Type #1 entries: *.conf files */
15 BOOT_ENTRY_UNIFIED, /* Type #2 entries: *.efi files */
16 BOOT_ENTRY_LOADER, /* Additional entries augmented from LoaderEntries EFI var */
17 _BOOT_ENTRY_MAX,
18 _BOOT_ENTRY_INVALID = -1,
19 } BootEntryType;
20
21 typedef struct BootEntry {
22 BootEntryType type;
23 char *id; /* This is the file basename without extension */
24 char *path; /* This is the full path to the drop-in file */
25 char *root; /* The root path in which the drop-in was found, i.e. to which 'kernel', 'efi' and 'initrd' are relative */
26 char *title;
27 char *show_title;
28 char *version;
29 char *machine_id;
30 char *architecture;
31 char **options;
32 char *kernel; /* linux is #defined to 1, yikes! */
33 char *efi;
34 char **initrd;
35 char *device_tree;
36 } BootEntry;
37
38 typedef struct BootConfig {
39 char *default_pattern;
40 char *timeout;
41 char *editor;
42 char *auto_entries;
43 char *auto_firmware;
44 char *console_mode;
45
46 char *entry_oneshot;
47 char *entry_default;
48
49 BootEntry *entries;
50 size_t n_entries;
51 ssize_t default_entry;
52 } BootConfig;
53
54 static inline bool boot_config_has_entry(BootConfig *config, const char *id) {
55 size_t j;
56
57 for (j = 0; j < config->n_entries; j++)
58 if (streq(config->entries[j].id, id))
59 return true;
60
61 return false;
62 }
63
64 static inline BootEntry* boot_config_default_entry(BootConfig *config) {
65 if (config->default_entry < 0)
66 return NULL;
67
68 return config->entries + config->default_entry;
69 }
70
71 void boot_config_free(BootConfig *config);
72 int boot_entries_load_config(const char *esp_path, const char *xbootldr_path, BootConfig *config);
73 int boot_entries_load_config_auto(const char *override_esp_path, const char *override_xbootldr_path, BootConfig *config);
74 #if ENABLE_EFI
75 int boot_entries_augment_from_loader(BootConfig *config, bool only_auto);
76 #else
77 static inline int boot_entries_augment_from_loader(BootConfig *config, bool only_auto) {
78 return -EOPNOTSUPP;
79 }
80 #endif
81
82 static inline const char* boot_entry_title(const BootEntry *entry) {
83 return entry->show_title ?: entry->title ?: entry->id;
84 }
85
86 int find_esp_and_warn(const char *path, bool unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid);
87 int find_xbootldr_and_warn(const char *path, bool unprivileged_mode, char **ret_path,sd_id128_t *ret_uuid);