From: Lennart Poettering Date: Fri, 29 Sep 2023 14:09:50 +0000 (+0200) Subject: repart: rework --empty= handling a bit X-Git-Tag: v255-rc1~319^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=243dd1e9fac1277f4877a42a50b6dcedd0c8a725;p=thirdparty%2Fsystemd.git repart: rework --empty= handling a bit Introduce a new enum value EMPTY_UNSET to which arg_empty now is set initially. Only after we finished parsing the command line we'll now set this to EMPTY_REFUSE as before. This prepares ground for later changes, where we then can make different decisions after havig all input from the command line. As of now this doesn't change behaviour of systemd-repart, it just rearranges things a bit. --- diff --git a/src/partition/repart.c b/src/partition/repart.c index 9b564444048..8ba6a9cb05b 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -108,12 +108,13 @@ * waste 3K per partition, which is probably fine. */ static enum { + EMPTY_UNSET, /* no choice has been made yet */ EMPTY_REFUSE, /* refuse empty disks, never create a partition table */ EMPTY_ALLOW, /* allow empty disks, create partition table if necessary */ EMPTY_REQUIRE, /* require an empty disk, create a partition table */ EMPTY_FORCE, /* make disk empty, erase everything, create a partition table always */ EMPTY_CREATE, /* create disk as loopback file, create a partition table always */ -} arg_empty = EMPTY_REFUSE; +} arg_empty = EMPTY_UNSET; typedef enum FilterPartitionType { FILTER_PARTITIONS_NONE, @@ -2416,6 +2417,9 @@ static int context_load_partition_table(Context *context) { /* Always reinitiaize the disk, don't consider what there was on the disk before */ from_scratch = true; break; + + case EMPTY_UNSET: + assert_not_reached(); } if (from_scratch) { @@ -6481,7 +6485,9 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_EMPTY: - if (isempty(optarg) || streq(optarg, "refuse")) + if (isempty(optarg)) + arg_empty = EMPTY_UNSET; + else if (streq(optarg, "refuse")) arg_empty = EMPTY_REFUSE; else if (streq(optarg, "allow")) arg_empty = EMPTY_ALLOW; @@ -6795,6 +6801,9 @@ static int parse_argv(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Expected at most one argument, the path to the block device."); + if (arg_empty == EMPTY_UNSET) /* default to refuse mode, if not otherwise specified */ + arg_empty = EMPTY_REFUSE; + if (arg_factory_reset > 0 && IN_SET(arg_empty, EMPTY_FORCE, EMPTY_REQUIRE, EMPTY_CREATE)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Combination of --factory-reset=yes and --empty=force/--empty=require/--empty=create is invalid.");