repart: add --list-devices switch for listing candidate block devices

This commit is contained in:
Lennart Poettering
2024-07-01 16:39:40 +02:00
parent e742c99999
commit 3a37a13a02
3 changed files with 26 additions and 1 deletions
+11 -1
View File
@@ -19,7 +19,7 @@
<refnamediv>
<refname>systemd-repart</refname>
<refname>systemd-repart.service</refname>
<refpurpose>Automatically grow and add partitions</refpurpose>
<refpurpose>Automatically grow and add partitions, and generate disk images (DDIs).</refpurpose>
</refnamediv>
<refsynopsisdiv>
@@ -612,6 +612,16 @@
<xi:include href="version-info.xml" xpointer="v256"/></listitem>
</varlistentry>
<varlistentry>
<term><option>--list-devices</option></term>
<listitem><para>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.</para>
<xi:include href="version-info.xml" xpointer="v257"/></listitem>
</varlistentry>
<xi:include href="standard-options.xml" xpointer="help" />
<xi:include href="standard-options.xml" xpointer="version" />
<xi:include href="standard-options.xml" xpointer="no-pager" />
+11
View File
@@ -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;
+4
View File
@@ -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