2018-06-14 12:50:49 +02:00
/* SPDX-License-Identifier: LGPL-2.1+ */
2017-10-17 18:23:16 +02:00
# pragma once
2018-06-22 11:38:43 +02:00
# include <inttypes.h>
# include <stdbool.h>
# include <sys/types.h>
# include "sd-id128.h"
2017-10-17 18:23:16 +02:00
2019-03-01 18:35:26 +01: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 {
2019-03-01 18:35:26 +01:00
BootEntryType type ;
2018-09-26 08:35:12 +02:00
char * id ; /* This is the file basename without extension */
2019-01-28 17:57:41 +01:00
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 ;
2018-01-28 17:06:22 +01:00
char * auto_entries ;
char * auto_firmware ;
2017-12-16 22:52:05 -02:00
char * console_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 ;
2019-03-01 18:35:26 +01:00
static inline bool boot_config_has_entry ( BootConfig * config , const char * id ) {
size_t j ;
for ( j = 0 ; j < config - > n_entries ; j + + )
if ( streq ( config - > entries [ j ] . id , id ) )
return true ;
return false ;
}
2019-03-04 18:02:30 +01:00
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 ) ;
2019-01-28 18:56:53 +01:00
int boot_entries_load_config ( const char * esp_path , const char * xbootldr_path , BootConfig * config ) ;
2019-03-04 17:52:17 +01:00
int boot_entries_load_config_auto ( const char * override_esp_path , const char * override_xbootldr_path , BootConfig * config ) ;
2019-03-01 18:35:26 +01:00
int boot_entries_augment_from_loader ( BootConfig * config , bool only_auto ) ;
2017-10-20 17:58:13 +02:00
static inline const char * boot_entry_title ( const BootEntry * entry ) {
2018-06-22 12:18:43 +02:00
return entry - > show_title ? : entry - > title ? : entry - > id ;
2017-10-20 17:58:13 +02:00
}
2017-10-20 18:31:34 +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 ) ;
2019-01-23 14:19:40 +01:00
int find_xbootldr_and_warn ( const char * path , bool unprivileged_mode , char * * ret_path , sd_id128_t * ret_uuid ) ;