gpt-auto: add common parse_gpt_auto_root() parser
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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")) {
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user