Systemd/src/shared/bootspec.h

87 lines
2.9 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: LGPL-2.1-or-later */
2017-10-17 18:23:16 +02:00
#pragma once
#include <inttypes.h>
#include <stdbool.h>
#include <sys/types.h>
#include "sd-id128.h"
2017-10-17 18:23:16 +02:00
#include "string-util.h"
typedef enum BootEntryType {
BOOT_ENTRY_CONF, /* Type #1 entries: *.conf files */
BOOT_ENTRY_UNIFIED, /* Type #2 entries: *.efi files */
BOOT_ENTRY_LOADER, /* Additional entries augmented from LoaderEntries EFI var */
_BOOT_ENTRY_MAX,
_BOOT_ENTRY_INVALID = -1,
} BootEntryType;
2017-10-17 18:23:16 +02:00
typedef struct BootEntry {
BootEntryType type;
char *id; /* This is the file basename without extension */
char *id_old; /* Old-style ID, for deduplication purposes. */
char *path; /* This is the full path to the drop-in file */
char *root; /* The root path in which the drop-in was found, i.e. to which 'kernel', 'efi' and 'initrd' are relative */
2017-10-17 18:23:16 +02:00
char *title;
2017-10-20 17:58:13 +02:00
char *show_title;
2017-10-17 18:23:16 +02:00
char *version;
char *machine_id;
char *architecture;
char **options;
char *kernel; /* linux is #defined to 1, yikes! */
char *efi;
char **initrd;
char *device_tree;
} BootEntry;
typedef struct BootConfig {
char *default_pattern;
char *timeout;
char *editor;
char *auto_entries;
char *auto_firmware;
char *console_mode;
char *random_seed_mode;
2017-10-17 18:23:16 +02:00
char *entry_oneshot;
char *entry_default;
BootEntry *entries;
size_t n_entries;
ssize_t default_entry;
} BootConfig;
static inline bool boot_config_has_entry(BootConfig *config, const char *id) {
size_t j;
for (j = 0; j < config->n_entries; j++) {
const char* entry_id_old = config->entries[j].id_old;
if (streq(config->entries[j].id, id) ||
(entry_id_old && streq(entry_id_old, id)))
return true;
}
return false;
}
static inline BootEntry* boot_config_default_entry(BootConfig *config) {
if (config->default_entry < 0)
return NULL;
return config->entries + config->default_entry;
}
2017-10-17 18:23:16 +02:00
void boot_config_free(BootConfig *config);
int boot_entries_load_config(const char *esp_path, const char *xbootldr_path, BootConfig *config);
int boot_entries_load_config_auto(const char *override_esp_path, const char *override_xbootldr_path, BootConfig *config);
int boot_entries_augment_from_loader(BootConfig *config, char **list, bool only_auto);
2017-10-20 17:58:13 +02:00
static inline const char* boot_entry_title(const BootEntry *entry) {
return entry->show_title ?: entry->title ?: entry->id;
2017-10-20 17:58:13 +02:00
}
efi: rework find_esp() error propagation/logging a bit This renames find_esp() to find_esp_and_warn() and tries to normalize its behaviour: 1. Change the error that is returned when we can't find the ESP to ENOKEY (from ENOENT). This way the error code can only mean one thing: that our search loop didn't find a good candidate. 2. Really log about all errors, except for ENOKEY and EACCES, and document the letter cases. 3. Normalize parameters to the call: separate out the path parameter in two: an input path and an output path. That way the memory management is clear: we will access the input parameter only for reading, and only write out the output parameter, using malloc() memory. Before the calling convention were quire surprising for internal API code, as the path parameter had to be malloc() memory and might and might not have changed. 4. Rename bootctl's find_esp_warn() to acquire_esp(), and make it a simple wrapper around find_esp_warn(), that basically just adds the friendly logging for the ENOKEY case. This rework removes double logging in a number of error cases, as we no longer log here in anything but ENOKEY, and leave that entirely to find_esp_warn(). 5. find_esp_and_warn() now takes a bool flag parameter "unprivileged_mode", which disables logging in the EACCES case, and skips privileged validation of the path. This makes the function less magic, and doesn't hide this internal silencing automatism from the caller anymore. With all that in place "bootctl list" and "bootctl status" work properly (or as good as they can) when I invoke the tools whithout privileges on my system where /boot is not world-readable
2017-12-11 22:04:46 +01:00
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);
int find_xbootldr_and_warn(const char *path, bool unprivileged_mode, char **ret_path,sd_id128_t *ret_uuid);