diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-05-07 21:39:10 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-05-12 07:51:50 +0200 |
commit | 2bc161dddb9d355d81ca1d2126c94b9c18b9e3cf (patch) | |
tree | ae5db93def62ca474231fe3ef661b6d8d1b77c97 /src/shared/mkfs-util.c | |
parent | aaa27e2e21c04339914f26b7125789087eb51166 (diff) | |
download | systemd-2bc161dddb9d355d81ca1d2126c94b9c18b9e3cf.tar.gz |
mkfs-util: Add quiet argument to make_filesystem()
We default to quiet operation everywhere except for repart, where
we disable quiet and have the mkfs tools write to stdout.
We also make sure --quiet or equivalent is implemented for all mkfs
tools.
Diffstat (limited to 'src/shared/mkfs-util.c')
-rw-r--r-- | src/shared/mkfs-util.c | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/shared/mkfs-util.c b/src/shared/mkfs-util.c index 16d2fb651f..3d8c16b7b9 100644 --- a/src/shared/mkfs-util.c +++ b/src/shared/mkfs-util.c @@ -264,6 +264,7 @@ int make_filesystem( const char *root, sd_id128_t uuid, bool discard, + bool quiet, uint64_t sector_size, char * const *extra_mkfs_args) { @@ -355,7 +356,6 @@ int make_filesystem( /* When changing this conditional, also adjust the log statement below. */ if (STR_IN_SET(fstype, "ext2", "ext3", "ext4")) { argv = strv_new(mkfs, - "-q", "-L", label, "-U", vol_id, "-I", "256", @@ -368,9 +368,11 @@ int make_filesystem( if (root && strv_extend_strv(&argv, STRV_MAKE("-d", root), false) < 0) return log_oom(); + if (quiet && strv_extend(&argv, "-q") < 0) + return log_oom(); + } else if (streq(fstype, "btrfs")) { argv = strv_new(mkfs, - "-q", "-L", label, "-U", vol_id, node); @@ -383,9 +385,11 @@ int make_filesystem( if (root && strv_extend_strv(&argv, STRV_MAKE("-r", root), false) < 0) return log_oom(); + if (quiet && strv_extend(&argv, "-q") < 0) + return log_oom(); + } else if (streq(fstype, "f2fs")) { argv = strv_new(mkfs, - "-q", "-g", /* "default options" */ "-f", /* force override, without this it doesn't seem to want to write to an empty partition */ "-l", label, @@ -393,13 +397,15 @@ int make_filesystem( "-t", one_zero(discard), node); + if (quiet && strv_extend(&argv, "-q") < 0) + return log_oom(); + } else if (streq(fstype, "xfs")) { const char *j; j = strjoina("uuid=", vol_id); argv = strv_new(mkfs, - "-q", "-L", label, "-m", j, "-m", "reflink=1", @@ -427,6 +433,9 @@ int make_filesystem( return log_oom(); } + if (quiet && strv_extend(&argv, "-q") < 0) + return log_oom(); + } else if (streq(fstype, "vfat")) { argv = strv_new(mkfs, @@ -444,32 +453,40 @@ int make_filesystem( } /* mkfs.vfat does not have a --quiet option so let's redirect stdout to /dev/null instead. */ - stdio_fds[1] = -EBADF; + if (quiet) + stdio_fds[1] = -EBADF; - } else if (streq(fstype, "swap")) - /* TODO: add --quiet here if - * https://github.com/util-linux/util-linux/issues/1499 resolved. */ + } else if (streq(fstype, "swap")) { + /* TODO: add --quiet once util-linux v2.38 is available everywhere. */ argv = strv_new(mkfs, "-L", label, "-U", vol_id, node); - else if (streq(fstype, "squashfs")) { + if (quiet) + stdio_fds[1] = -EBADF; + + } else if (streq(fstype, "squashfs")) { argv = strv_new(mkfs, root, node, "-noappend"); /* mksquashfs -quiet option is pretty new so let's redirect stdout to /dev/null instead. */ - stdio_fds[1] = -EBADF; + if (quiet) + stdio_fds[1] = -EBADF; - } else if (streq(fstype, "erofs")) + } else if (streq(fstype, "erofs")) { argv = strv_new(mkfs, "-U", vol_id, node, root); - else + + if (quiet && strv_extend(&argv, "--quiet") < 0) + return log_oom(); + + } else /* Generic fallback for all other file systems */ argv = strv_new(mkfs, node); |