mirror of
https://github.com/systemd/systemd.git
synced 2026-08-12 22:17:19 +00:00
find-esp: introduce _full() flavour of ESP/XBOOTLDR discovery functions
These functions take so many return paramaters, and in many of our cases we don't actually needt them. Hence introduce _full() flavours of the funcs, and hide the params by default.
This commit is contained in:
committed by
Luca Boccassi
parent
e87303d511
commit
8a2c423870
@@ -107,11 +107,26 @@ static int acquire_path(void) {
|
||||
if (!strv_isempty(arg_path))
|
||||
return 0;
|
||||
|
||||
r = find_esp_and_warn(NULL, NULL, /* unprivileged_mode= */ false, &esp_path, NULL, NULL, NULL, NULL, &esp_devid);
|
||||
r = find_esp_and_warn_full(
|
||||
/* root= */ NULL,
|
||||
/* path= */ NULL,
|
||||
/* unprivileged_mode= */ false,
|
||||
&esp_path,
|
||||
/* ret_part= */ NULL,
|
||||
/* ret_pstart= */ NULL,
|
||||
/* ret_psize= */ NULL,
|
||||
/* ret_uuid= */ NULL,
|
||||
&esp_devid);
|
||||
if (r < 0 && r != -ENOKEY) /* ENOKEY means not found, and is the only error the function won't log about on its own */
|
||||
return r;
|
||||
|
||||
r = find_xbootldr_and_warn(NULL, NULL, /* unprivileged_mode= */ false, &xbootldr_path, NULL, &xbootldr_devid);
|
||||
r = find_xbootldr_and_warn_full(
|
||||
/* root= */ NULL,
|
||||
/* path= */ NULL,
|
||||
/* unprivileged_mode= */ false,
|
||||
&xbootldr_path,
|
||||
/* ret_uuid= */ NULL,
|
||||
&xbootldr_devid);
|
||||
if (r < 0 && r != -ENOKEY)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -2062,7 +2062,7 @@ int vl_method_install(
|
||||
if (p.context.entry_token_type < 0)
|
||||
p.context.entry_token_type = BOOT_ENTRY_TOKEN_AUTO;
|
||||
|
||||
r = find_esp_and_warn_at(
|
||||
r = find_esp_and_warn_at_full(
|
||||
p.context.root_fd,
|
||||
/* path= */ NULL,
|
||||
/* unprivileged_mode= */ false,
|
||||
@@ -2081,9 +2081,7 @@ int vl_method_install(
|
||||
p.context.root_fd,
|
||||
/* path= */ NULL,
|
||||
/* unprivileged_mode= */ false,
|
||||
&p.context.xbootldr_path,
|
||||
/* ret_uuid= */ NULL,
|
||||
/* ret_devid= */ NULL);
|
||||
&p.context.xbootldr_path);
|
||||
if (r == -ENOKEY)
|
||||
log_debug_errno(r, "Didn't find an XBOOTLDR partition, using ESP as $BOOT.");
|
||||
else if (r < 0)
|
||||
|
||||
@@ -204,7 +204,7 @@ int install_random_seed(const char *esp) {
|
||||
int verb_random_seed(int argc, char *argv[], void *userdata) {
|
||||
int r;
|
||||
|
||||
r = find_esp_and_warn(arg_root, arg_esp_path, false, &arg_esp_path, NULL, NULL, NULL, NULL, NULL);
|
||||
r = find_esp_and_warn(arg_root, arg_esp_path, /* unprivileged_mode= */ false, &arg_esp_path);
|
||||
if (r == -ENOKEY) {
|
||||
/* find_esp_and_warn() doesn't warn about ENOKEY, so let's do that on our own */
|
||||
if (arg_graceful() == ARG_GRACEFUL_NO)
|
||||
|
||||
@@ -117,7 +117,7 @@ int acquire_esp(
|
||||
* we simply eat up the error here, so that --list and --status work too, without noise about
|
||||
* this). */
|
||||
|
||||
r = find_esp_and_warn(arg_root, arg_esp_path, unprivileged_mode, &np, ret_part, ret_pstart, ret_psize, ret_uuid, ret_devid);
|
||||
r = find_esp_and_warn_full(arg_root, arg_esp_path, unprivileged_mode, &np, ret_part, ret_pstart, ret_psize, ret_uuid, ret_devid);
|
||||
if (r == -ENOKEY) {
|
||||
if (graceful)
|
||||
return log_full_errno(arg_quiet ? LOG_DEBUG : LOG_INFO, r,
|
||||
@@ -144,7 +144,7 @@ int acquire_xbootldr(
|
||||
char *np;
|
||||
int r;
|
||||
|
||||
r = find_xbootldr_and_warn(arg_root, arg_xbootldr_path, unprivileged_mode, &np, ret_uuid, ret_devid);
|
||||
r = find_xbootldr_and_warn_full(arg_root, arg_xbootldr_path, unprivileged_mode, &np, ret_uuid, ret_devid);
|
||||
if (r == -ENOKEY || path_equal(np, arg_esp_path)) {
|
||||
log_debug("Didn't find an XBOOTLDR partition, using the ESP as $BOOT.");
|
||||
arg_xbootldr_path = mfree(arg_xbootldr_path);
|
||||
|
||||
@@ -570,9 +570,7 @@ static int context_acquire_xbootldr(Context *c) {
|
||||
/* rfd= */ c->rfd,
|
||||
/* path= */ arg_xbootldr_path,
|
||||
/* unprivileged_mode= */ -1,
|
||||
/* ret_path= */ &c->boot_root,
|
||||
/* ret_uuid= */ NULL,
|
||||
/* ret_devid= */ NULL);
|
||||
/* ret_path= */ &c->boot_root);
|
||||
if (r == -ENOKEY) {
|
||||
log_debug_errno(r, "Couldn't find an XBOOTLDR partition.");
|
||||
return 0;
|
||||
@@ -596,12 +594,7 @@ static int context_acquire_esp(Context *c) {
|
||||
/* rfd= */ c->rfd,
|
||||
/* path= */ arg_esp_path,
|
||||
/* unprivileged_mode= */ -1,
|
||||
/* ret_path= */ &c->boot_root,
|
||||
/* ret_part= */ NULL,
|
||||
/* ret_pstart= */ NULL,
|
||||
/* ret_psize= */ NULL,
|
||||
/* ret_uuid= */ NULL,
|
||||
/* ret_devid= */ NULL);
|
||||
/* ret_path= */ &c->boot_root);
|
||||
if (r == -ENOKEY) {
|
||||
log_debug_errno(r, "Couldn't find EFI system partition, ignoring.");
|
||||
return 0;
|
||||
|
||||
@@ -1587,11 +1587,26 @@ int boot_config_load_auto(
|
||||
"Failed to determine whether /run/boot-loader-entries/ exists: %m");
|
||||
}
|
||||
|
||||
r = find_esp_and_warn(NULL, override_esp_path, /* unprivileged_mode= */ false, &esp_where, NULL, NULL, NULL, NULL, &esp_devid);
|
||||
r = find_esp_and_warn_full(
|
||||
/* root= */ NULL,
|
||||
override_esp_path,
|
||||
/* unprivileged_mode= */ false,
|
||||
&esp_where,
|
||||
/* ret_part= */ NULL,
|
||||
/* ret_pstart= */ NULL,
|
||||
/* ret_psize= */ NULL,
|
||||
/* ret_uuid= */ NULL,
|
||||
&esp_devid);
|
||||
if (r < 0) /* we don't log about ENOKEY here, but propagate it, leaving it to the caller to log */
|
||||
return r;
|
||||
|
||||
r = find_xbootldr_and_warn(NULL, override_xbootldr_path, /* unprivileged_mode= */ false, &xbootldr_where, NULL, &xbootldr_devid);
|
||||
r = find_xbootldr_and_warn_full(
|
||||
/* root= */ NULL,
|
||||
override_xbootldr_path,
|
||||
/* unprivileged_mode= */ false,
|
||||
&xbootldr_where,
|
||||
/* ret_uuid= */ NULL,
|
||||
&xbootldr_devid);
|
||||
if (r < 0 && r != -ENOKEY)
|
||||
return r; /* It's fine if the XBOOTLDR partition doesn't exist, hence we ignore ENOKEY here */
|
||||
|
||||
|
||||
@@ -1689,9 +1689,7 @@ int get_global_boot_credentials_path(char **ret) {
|
||||
/* root= */ NULL,
|
||||
/* path= */ NULL,
|
||||
/* unprivileged_mode= */ false,
|
||||
&path,
|
||||
/* ret_uuid= */ NULL,
|
||||
/* ret_devid= */ NULL);
|
||||
&path);
|
||||
if (r < 0) {
|
||||
if (r != -ENOKEY)
|
||||
return log_error_errno(r, "Failed to find XBOOTLDR partition: %m");
|
||||
@@ -1700,12 +1698,7 @@ int get_global_boot_credentials_path(char **ret) {
|
||||
/* root= */ NULL,
|
||||
/* path= */ NULL,
|
||||
/* unprivileged_mode= */ false,
|
||||
&path,
|
||||
/* ret_part= */ NULL,
|
||||
/* ret_pstart= */ NULL,
|
||||
/* ret_psize= */ NULL,
|
||||
/* ret_uuid= */ NULL,
|
||||
/* ret_devid= */ NULL);
|
||||
&path);
|
||||
if (r < 0) {
|
||||
if (r != -ENOKEY)
|
||||
return log_error_errno(r, "Failed to find ESP partition: %m");
|
||||
|
||||
@@ -429,7 +429,7 @@ finish:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int find_esp_and_warn_at(
|
||||
int find_esp_and_warn_at_full(
|
||||
int rfd,
|
||||
const char *path,
|
||||
int unprivileged_mode,
|
||||
@@ -509,7 +509,7 @@ int find_esp_and_warn_at(
|
||||
return -ENOKEY;
|
||||
}
|
||||
|
||||
int find_esp_and_warn(
|
||||
int find_esp_and_warn_full(
|
||||
const char *root,
|
||||
const char *path,
|
||||
int unprivileged_mode,
|
||||
@@ -536,7 +536,7 @@ int find_esp_and_warn(
|
||||
return -errno;
|
||||
}
|
||||
|
||||
r = find_esp_and_warn_at(
|
||||
r = find_esp_and_warn_at_full(
|
||||
rfd,
|
||||
path,
|
||||
unprivileged_mode,
|
||||
@@ -792,7 +792,7 @@ finish:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int find_xbootldr_and_warn_at(
|
||||
int find_xbootldr_and_warn_at_full(
|
||||
int rfd,
|
||||
const char *path,
|
||||
int unprivileged_mode,
|
||||
@@ -853,7 +853,7 @@ int find_xbootldr_and_warn_at(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int find_xbootldr_and_warn(
|
||||
int find_xbootldr_and_warn_full(
|
||||
const char *root,
|
||||
const char *path,
|
||||
int unprivileged_mode,
|
||||
@@ -875,7 +875,7 @@ int find_xbootldr_and_warn(
|
||||
return -errno;
|
||||
}
|
||||
|
||||
r = find_xbootldr_and_warn_at(
|
||||
r = find_xbootldr_and_warn_at_full(
|
||||
rfd,
|
||||
path,
|
||||
unprivileged_mode,
|
||||
|
||||
@@ -4,8 +4,22 @@
|
||||
|
||||
#include "shared-forward.h"
|
||||
|
||||
int find_esp_and_warn_at(int rfd, const char *path, int unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid, dev_t *ret_devid);
|
||||
int find_esp_and_warn(const char *root, const char *path, int unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid, dev_t *ret_devid);
|
||||
int find_esp_and_warn_at_full(int rfd, const char *path, int unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid, dev_t *ret_devid);
|
||||
int find_esp_and_warn_full(const char *root, const char *path, int unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid, dev_t *ret_devid);
|
||||
|
||||
int find_xbootldr_and_warn_at(int rfd, const char *path, int unprivileged_mode, char **ret_path, sd_id128_t *ret_uuid, dev_t *ret_devid);
|
||||
int find_xbootldr_and_warn(const char *root, const char *path, int unprivileged_mode, char **ret_path, sd_id128_t *ret_uuid, dev_t *ret_devid);
|
||||
static inline int find_esp_and_warn_at(int rfd, const char *path, int unprivileged_mode, char **ret_path) {
|
||||
return find_esp_and_warn_at_full(rfd, path, unprivileged_mode, ret_path, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
static inline int find_esp_and_warn(const char *root, const char *path, int unprivileged_mode, char **ret_path) {
|
||||
return find_esp_and_warn_full(root, path, unprivileged_mode, ret_path, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
int find_xbootldr_and_warn_at_full(int rfd, const char *path, int unprivileged_mode, char **ret_path, sd_id128_t *ret_uuid, dev_t *ret_devid);
|
||||
int find_xbootldr_and_warn_full(const char *root, const char *path, int unprivileged_mode, char **ret_path, sd_id128_t *ret_uuid, dev_t *ret_devid);
|
||||
|
||||
static inline int find_xbootldr_and_warn_at(int rfd, const char *path, int unprivileged_mode, char **ret_path) {
|
||||
return find_xbootldr_and_warn_at_full(rfd, path, unprivileged_mode, ret_path, NULL, NULL);
|
||||
}
|
||||
static inline int find_xbootldr_and_warn(const char *root, const char *path, int unprivileged_mode, char **ret_path) {
|
||||
return find_xbootldr_and_warn_full(root, path, unprivileged_mode, ret_path, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -852,9 +852,9 @@ int resource_resolve_path(
|
||||
} else { /* boot, esp, or xbootldr */
|
||||
r = 0;
|
||||
if (IN_SET(rr->path_relative_to, PATH_RELATIVE_TO_BOOT, PATH_RELATIVE_TO_XBOOTLDR))
|
||||
r = find_xbootldr_and_warn(root, NULL, /* unprivileged_mode= */ -1, &relative_to, NULL, NULL);
|
||||
r = find_xbootldr_and_warn(root, /* path= */ NULL, /* unprivileged_mode= */ -1, &relative_to);
|
||||
if (r == -ENOKEY || rr->path_relative_to == PATH_RELATIVE_TO_ESP)
|
||||
r = find_esp_and_warn(root, NULL, -1, &relative_to, NULL, NULL, NULL, NULL, NULL);
|
||||
r = find_esp_and_warn(root, /* path= */ NULL, /* unprivileged_mode= */ -1, &relative_to);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to resolve $BOOT: %m");
|
||||
log_debug("Resolved $BOOT to '%s'", relative_to);
|
||||
|
||||
Reference in New Issue
Block a user