From: Karel Zak Date: Wed, 7 Dec 2022 10:11:08 +0000 (+0100) Subject: blkdiscard: add --quiet X-Git-Tag: v2.39-rc1~386 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8edaa1e1237c4bd65561e96b90435a6c4b9c4784;p=thirdparty%2Futil-linux.git blkdiscard: add --quiet Addresses: https://github.com/util-linux/util-linux/issues/1941 Signed-off-by: Karel Zak --- diff --git a/sys-utils/blkdiscard.8.adoc b/sys-utils/blkdiscard.8.adoc index 8368743579..240693d1cd 100644 --- a/sys-utils/blkdiscard.8.adoc +++ b/sys-utils/blkdiscard.8.adoc @@ -40,6 +40,9 @@ The number of bytes to discard (counting from the starting point). The provided *-p*, *--step* _length_:: The number of bytes to discard within one iteration. The default is to discard all by one ioctl call. +*-q*, *--quiet*:: +Suppress warning messages. + *-s*, *--secure*:: Perform a secure discard. A secure discard is the same as a regular discard except that all copies of the discarded blocks that were possibly created by garbage collection must also be erased. This requires support from the device. diff --git a/sys-utils/blkdiscard.c b/sys-utils/blkdiscard.c index 38240e80d9..f1553b795a 100644 --- a/sys-utils/blkdiscard.c +++ b/sys-utils/blkdiscard.c @@ -66,6 +66,8 @@ enum { ACT_SECURE }; +static int quiet; + static void print_stats(int act, char *path, uint64_t stats[]) { switch (act) { @@ -96,6 +98,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -o, --offset offset in bytes to discard from\n"), out); fputs(_(" -l, --length length of bytes to discard from the offset\n"), out); fputs(_(" -p, --step size of the discard iterations within the offset\n"), out); + fputs(_(" -q, --quiet suppress warning messages\n"), out); fputs(_(" -s, --secure perform secure discard\n"), out); fputs(_(" -z, --zeroout zero-fill rather than discard\n"), out); fputs(_(" -v, --verbose print aligned length and offset\n"), out); @@ -134,12 +137,13 @@ static int probe_device(int fd, char *path) if (ret) goto out; - if (!blkid_probe_lookup_value(pr, "TYPE", &type, NULL)) { - warnx("%s contains existing file system (%s).",path ,type); - } else if (!blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL)) { - warnx("%s contains existing partition (%s).",path ,type); - } else { - warnx("%s contains existing signature.", path); + if (!quiet) { + if (!blkid_probe_lookup_value(pr, "TYPE", &type, NULL)) + warnx("%s contains existing file system (%s).",path ,type); + else if (!blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL)) + warnx("%s contains existing partition (%s).",path ,type); + else + warnx("%s contains existing signature.", path); } out: @@ -164,6 +168,7 @@ int main(int argc, char **argv) { "force", no_argument, NULL, 'f' }, { "length", required_argument, NULL, 'l' }, { "step", required_argument, NULL, 'p' }, + { "quiet", no_argument, NULL, 'q' }, { "secure", no_argument, NULL, 's' }, { "verbose", no_argument, NULL, 'v' }, { "zeroout", no_argument, NULL, 'z' }, @@ -179,7 +184,7 @@ int main(int argc, char **argv) range[1] = ULLONG_MAX; step = 0; - while ((c = getopt_long(argc, argv, "hfVsvo:l:p:z", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "hfVsvo:l:p:qz", longopts, NULL)) != -1) { switch(c) { case 'f': force = 1; @@ -196,6 +201,9 @@ int main(int argc, char **argv) step = strtosize_or_err(optarg, _("failed to parse step")); break; + case 'q': + quiet = 1; + break; case 's': act = ACT_SECURE; break; @@ -258,9 +266,10 @@ int main(int argc, char **argv) errx(EXIT_FAILURE, _("%s: length %" PRIu64 " is not aligned " "to sector size %i"), path, range[1], secsize); #ifdef HAVE_LIBBLKID - if (force) - warnx(_("Operation forced, data will be lost!")); - else { + if (force) { + if (!quiet) + warnx(_("Operation forced, data will be lost!")); + } else { /* Check for existing signatures on the device */ switch(probe_device(fd, path)) { case 0: /* signature detected */