mkfs-util: turn quiet/discard to a flags field
Add a new `MakeFilesystemFlags` enum and use it to replace the existing `quiet` and `discard` booleans on `make_filesystem()`. Update the callers. While we're doing that, consolidate some duplicated logic in systemd-repart. Signed-off-by: Allison Karlitskaya <allison.karlitskaya@redhat.com>
This commit is contained in:
+14
-15
@@ -322,8 +322,7 @@ int make_filesystem(
|
||||
const char *label,
|
||||
const char *root,
|
||||
sd_id128_t uuid,
|
||||
bool discard,
|
||||
bool quiet,
|
||||
MakeFileSystemFlags flags,
|
||||
uint64_t sector_size,
|
||||
char *compression,
|
||||
char *compression_level,
|
||||
@@ -424,7 +423,7 @@ int make_filesystem(
|
||||
"-U", vol_id,
|
||||
"-I", "256",
|
||||
"-m", "0",
|
||||
"-E", discard ? "discard,lazy_itable_init=1" : "nodiscard,lazy_itable_init=1",
|
||||
"-E", FLAGS_SET(flags, MKFS_DISCARD) ? "discard,lazy_itable_init=1" : "nodiscard,lazy_itable_init=1",
|
||||
"-b", "4096",
|
||||
"-T", "default");
|
||||
if (!argv)
|
||||
@@ -433,7 +432,7 @@ int make_filesystem(
|
||||
if (root && strv_extend_many(&argv, "-d", root) < 0)
|
||||
return log_oom();
|
||||
|
||||
if (quiet && strv_extend(&argv, "-q") < 0)
|
||||
if (FLAGS_SET(flags, MKFS_QUIET) && strv_extend(&argv, "-q") < 0)
|
||||
return log_oom();
|
||||
|
||||
if (strv_extend(&argv, node) < 0)
|
||||
@@ -454,13 +453,13 @@ int make_filesystem(
|
||||
if (!argv)
|
||||
return log_oom();
|
||||
|
||||
if (!discard && strv_extend(&argv, "--nodiscard") < 0)
|
||||
if (!FLAGS_SET(flags, MKFS_DISCARD) && strv_extend(&argv, "--nodiscard") < 0)
|
||||
return log_oom();
|
||||
|
||||
if (root && strv_extend_many(&argv, "-r", root) < 0)
|
||||
return log_oom();
|
||||
|
||||
if (quiet && strv_extend(&argv, "-q") < 0)
|
||||
if (FLAGS_SET(flags, MKFS_QUIET) && strv_extend(&argv, "-q") < 0)
|
||||
return log_oom();
|
||||
|
||||
if (compression) {
|
||||
@@ -479,7 +478,7 @@ int make_filesystem(
|
||||
|
||||
/* mkfs.btrfs unconditionally warns about several settings changing from v5.15 onwards which
|
||||
* isn't silenced by "-q", so let's redirect stdout to /dev/null as well. */
|
||||
if (quiet)
|
||||
if (FLAGS_SET(flags, MKFS_QUIET))
|
||||
stdio_fds[1] = -EBADF;
|
||||
|
||||
/* mkfs.btrfs expects a sector size of at least 4k bytes. */
|
||||
@@ -495,11 +494,11 @@ int make_filesystem(
|
||||
"-f", /* force override, without this it doesn't seem to want to write to an empty partition */
|
||||
"-l", label,
|
||||
"-U", vol_id,
|
||||
"-t", one_zero(discard));
|
||||
"-t", one_zero(FLAGS_SET(flags, MKFS_DISCARD)));
|
||||
if (!argv)
|
||||
return log_oom();
|
||||
|
||||
if (quiet && strv_extend(&argv, "-q") < 0)
|
||||
if (FLAGS_SET(flags, MKFS_QUIET) && strv_extend(&argv, "-q") < 0)
|
||||
return log_oom();
|
||||
|
||||
if (sector_size > 0) {
|
||||
@@ -525,7 +524,7 @@ int make_filesystem(
|
||||
if (!argv)
|
||||
return log_oom();
|
||||
|
||||
if (!discard && strv_extend(&argv, "-K") < 0)
|
||||
if (!FLAGS_SET(flags, MKFS_DISCARD) && strv_extend(&argv, "-K") < 0)
|
||||
return log_oom();
|
||||
|
||||
if (root) {
|
||||
@@ -557,7 +556,7 @@ int make_filesystem(
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
if (quiet && strv_extend(&argv, "-q") < 0)
|
||||
if (FLAGS_SET(flags, MKFS_QUIET) && strv_extend(&argv, "-q") < 0)
|
||||
return log_oom();
|
||||
|
||||
if (strv_extend(&argv, node) < 0)
|
||||
@@ -584,7 +583,7 @@ int make_filesystem(
|
||||
return log_oom();
|
||||
|
||||
/* mkfs.vfat does not have a --quiet option so let's redirect stdout to /dev/null instead. */
|
||||
if (quiet)
|
||||
if (FLAGS_SET(flags, MKFS_QUIET))
|
||||
stdio_fds[1] = -EBADF;
|
||||
|
||||
} else if (streq(fstype, "swap")) {
|
||||
@@ -597,7 +596,7 @@ int make_filesystem(
|
||||
if (!argv)
|
||||
return log_oom();
|
||||
|
||||
if (quiet)
|
||||
if (FLAGS_SET(flags, MKFS_QUIET))
|
||||
stdio_fds[1] = -EBADF;
|
||||
|
||||
} else if (streq(fstype, "squashfs")) {
|
||||
@@ -617,7 +616,7 @@ int make_filesystem(
|
||||
}
|
||||
|
||||
/* mksquashfs -quiet option is pretty new so let's redirect stdout to /dev/null instead. */
|
||||
if (quiet)
|
||||
if (FLAGS_SET(flags, MKFS_QUIET))
|
||||
stdio_fds[1] = -EBADF;
|
||||
|
||||
} else if (streq(fstype, "erofs")) {
|
||||
@@ -626,7 +625,7 @@ int make_filesystem(
|
||||
if (!argv)
|
||||
return log_oom();
|
||||
|
||||
if (quiet && strv_extend(&argv, "--quiet") < 0)
|
||||
if (FLAGS_SET(flags, MKFS_QUIET) && strv_extend(&argv, "--quiet") < 0)
|
||||
return log_oom();
|
||||
|
||||
if (compression) {
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
|
||||
#include "forward.h"
|
||||
|
||||
typedef enum MakeFilesystemFlags {
|
||||
MKFS_QUIET = 1 << 0, /* Suppress mkfs command output */
|
||||
MKFS_DISCARD = 1 << 1, /* Enable 'discard' mode on the filesystem */
|
||||
} MakeFileSystemFlags;
|
||||
|
||||
int mkfs_exists(const char *fstype);
|
||||
|
||||
int mkfs_supports_root_option(const char *fstype);
|
||||
@@ -15,8 +20,7 @@ int make_filesystem(
|
||||
const char *label,
|
||||
const char *root,
|
||||
sd_id128_t uuid,
|
||||
bool discard,
|
||||
bool quiet,
|
||||
MakeFileSystemFlags flags,
|
||||
uint64_t sector_size,
|
||||
char *compression,
|
||||
char *compression_level,
|
||||
|
||||
Reference in New Issue
Block a user