From: Lennart Poettering Date: Mon, 1 Jul 2024 09:54:21 +0000 (+0200) Subject: repart: add --list-devices switch for listing candidate block devices X-Git-Tag: v257-rc1~1007^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a37a13a02dcc227fec45f5d5529b3299a06cadd;p=thirdparty%2Fsystemd.git repart: add --list-devices switch for listing candidate block devices --- diff --git a/man/systemd-repart.xml b/man/systemd-repart.xml index 8f48081097b..bad3cf5ed28 100644 --- a/man/systemd-repart.xml +++ b/man/systemd-repart.xml @@ -19,7 +19,7 @@ systemd-repart systemd-repart.service - Automatically grow and add partitions + Automatically grow and add partitions, and generate disk images (DDIs). @@ -612,6 +612,16 @@ + + + + Show a list of candidate block devices this command may operate on. Specifically, + this enumerates block devices currently present that support partition tables, and shows their device + node paths along with any of their symlinks. + + + + diff --git a/src/partition/repart.c b/src/partition/repart.c index ab41769348d..9a5695d5621 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -18,6 +18,7 @@ #include "alloc-util.h" #include "blkid-util.h" +#include "blockdev-list.h" #include "blockdev-util.h" #include "btrfs-util.h" #include "build.h" @@ -6962,6 +6963,7 @@ static int help(void) { " --image-policy=POLICY\n" " Specify disk image dissection policy\n" " --definitions=DIR Find partition definitions in specified directory\n" + " --list-devices List candidate block devices to operate on\n" "\n%3$sVerity:%4$s\n" " --private-key=PATH|URI\n" " Private key to use when generating verity roothash\n" @@ -7062,6 +7064,7 @@ static int parse_argv(int argc, char *argv[]) { ARG_MAKE_DDI, ARG_GENERATE_FSTAB, ARG_GENERATE_CRYPTTAB, + ARG_LIST_DEVICES, }; static const struct option options[] = { @@ -7105,6 +7108,7 @@ static int parse_argv(int argc, char *argv[]) { { "make-ddi", required_argument, NULL, ARG_MAKE_DDI }, { "generate-fstab", required_argument, NULL, ARG_GENERATE_FSTAB }, { "generate-crypttab", required_argument, NULL, ARG_GENERATE_CRYPTTAB }, + { "list-devices", no_argument, NULL, ARG_LIST_DEVICES }, {} }; @@ -7496,6 +7500,13 @@ static int parse_argv(int argc, char *argv[]) { return r; break; + case ARG_LIST_DEVICES: + r = blockdev_list(BLOCKDEV_LIST_REQUIRE_PARTITION_SCANNING|BLOCKDEV_LIST_SHOW_SYMLINKS|BLOCKDEV_LIST_IGNORE_ZRAM); + if (r < 0) + return r; + + return 0; + case '?': return -EINVAL; diff --git a/test/units/TEST-58-REPART.sh b/test/units/TEST-58-REPART.sh index 77adce47bbc..2c69228d4e4 100755 --- a/test/units/TEST-58-REPART.sh +++ b/test/units/TEST-58-REPART.sh @@ -1308,6 +1308,10 @@ testcase_urandom() { [[ "$(sfdisk -q -l "$image" | grep -c "$image")" -eq 1 ]] } +testcase_list_devices() { + systemd-repart --list-devices +} + OFFLINE="yes" run_testcases