From: Lennart Poettering Date: Mon, 3 Mar 2025 13:35:29 +0000 (+0100) Subject: gpt-auto: add common parse_gpt_auto_root() parser X-Git-Tag: v258-rc1~1176^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=14ab9aafc25da13db39354690ac7981b35c6fb64;p=thirdparty%2Fsystemd.git gpt-auto: add common parse_gpt_auto_root() parser --- diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 7e85d476e4d..7e84be499d7 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -1119,7 +1119,7 @@ static bool validate_root_or_usr_mount_source(const char *what, const char *swit return false; } - if (STR_IN_SET(what, "gpt-auto", "gpt-auto-force")) { + if (parse_gpt_auto_root(what) > 0) { /* This is handled by gpt-auto-generator */ log_debug("Skipping %s directory handling, as gpt-auto was requested.", switch_name); return false; diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 6c2fbe17815..c6727523f00 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -38,16 +38,9 @@ #include "unit-name.h" #include "virt.h" -typedef enum GptAutoRoot { - GPT_AUTO_ROOT_UNSPECIFIED, /* no root= specified */ - GPT_AUTO_ROOT_OFF, /* root= set to something else */ - GPT_AUTO_ROOT_ON, /* root= set explicitly to "gpt-auto" */ - GPT_AUTO_ROOT_FORCE, /* root= set explicitly to "gpt-auto-force" → ignores factory reset mode */ -} GptAutoRoot; - static const char *arg_dest = NULL; static bool arg_enabled = true; -static GptAutoRoot arg_auto_root = GPT_AUTO_ROOT_UNSPECIFIED; +static GptAutoRoot arg_auto_root = _GPT_AUTO_ROOT_INVALID; static bool arg_swap_enabled = true; static char *arg_root_fstype = NULL; static char *arg_root_options = NULL; @@ -697,7 +690,7 @@ static int add_root_mount(void) { return 0; /* Neither explicitly enabled nor disabled? Then decide based on the EFI partition variables to be set */ - if (arg_auto_root == GPT_AUTO_ROOT_UNSPECIFIED) { + if (arg_auto_root < 0) { if (!is_efi_boot()) { log_debug("Not an EFI boot, not creating root mount."); return 0; @@ -948,16 +941,8 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat /* Disable root disk logic if there's a root= value specified (unless it happens to be * "gpt-auto" or "gpt-auto-force") */ - if (streq(value, "gpt-auto")) { - arg_auto_root = GPT_AUTO_ROOT_ON; - log_debug("Enabling root partition auto-detection (respecting factory reset mode), root= is explicitly set to 'gpt-auto'."); - } else if (streq(value, "gpt-auto-force")) { - arg_auto_root = GPT_AUTO_ROOT_FORCE; - log_debug("Enabling root partition auto-detection (ignoring factory reset mode), root= is explicitly set to 'gpt-auto-force'."); - } else { - arg_auto_root = GPT_AUTO_ROOT_OFF; - log_debug("Disabling root partition auto-detection, root= is neither unset, nor set to 'gpt-auto' or 'gpt-auto-force'."); - } + arg_auto_root = parse_gpt_auto_root(value); + assert(arg_auto_root >= 0); } else if (streq(key, "roothash")) { diff --git a/src/shared/generator.c b/src/shared/generator.c index 9d7246fe02c..f2997c1b167 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -1030,3 +1030,22 @@ bool generator_soft_rebooted(void) { return (cached = (u > 0)); } + +GptAutoRoot parse_gpt_auto_root(const char *value) { + assert(value); + + /* Parses the 'gpt-auto'/'gpt-auto-root' parameters to root= */ + + if (streq(value, "gpt-auto")) { + log_debug("Enabling root partition auto-detection (respecting factory reset mode), root= is explicitly set to 'gpt-auto'."); + return GPT_AUTO_ROOT_ON; + } + + if (streq(value, "gpt-auto-force")) { + log_debug("Enabling root partition auto-detection (ignoring factory reset mode), root= is explicitly set to 'gpt-auto-force'."); + return GPT_AUTO_ROOT_FORCE; + } + + log_debug("Disabling root partition auto-detection, root= is neither unset, nor set to 'gpt-auto' or 'gpt-auto-force'."); + return GPT_AUTO_ROOT_OFF; +} diff --git a/src/shared/generator.h b/src/shared/generator.h index 5879e34ea25..4738fe90afc 100644 --- a/src/shared/generator.h +++ b/src/shared/generator.h @@ -3,6 +3,7 @@ #include +#include "errno-list.h" #include "macro.h" #include "main-func.h" @@ -114,3 +115,13 @@ bool generator_soft_rebooted(void); argv[argc == 4 ? 3 : 1]), \ exit_failure_if_negative, \ exit_failure_if_negative) + +typedef enum GptAutoRoot { + GPT_AUTO_ROOT_OFF = 0, /* root= set to something else */ + GPT_AUTO_ROOT_ON, /* root= set explicitly to "gpt-auto" */ + GPT_AUTO_ROOT_FORCE, /* root= set explicitly to "gpt-auto-force" → ignores factory reset mode */ + _GPT_AUTO_ROOT_MAX, + _GPT_AUTO_ROOT_INVALID = -EINVAL, +} GptAutoRoot; + +GptAutoRoot parse_gpt_auto_root(const char *value);