From: Karel Zak Date: Thu, 13 May 2021 08:34:14 +0000 (+0200) Subject: blkdiscard: do not probe for signatures on --force X-Git-Tag: v2.37~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e304441936a6198864812063f9c52c2fb587fe94;p=thirdparty%2Futil-linux.git blkdiscard: do not probe for signatures on --force The command-line option --force is defined as "disable all checks", but the current code does not follow this idea. We need a way how to disable read from the device (for example for dm-integrity devices). Fixes: https://github.com/karelzak/util-linux/issues/1308 Signed-off-by: Karel Zak --- diff --git a/sys-utils/blkdiscard.c b/sys-utils/blkdiscard.c index 9fa5a4f828..38240e80d9 100644 --- a/sys-utils/blkdiscard.c +++ b/sys-utils/blkdiscard.c @@ -258,25 +258,28 @@ 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 - /* Check for existing signatures on the device */ - switch(probe_device(fd, path)) { - case 0: /* signature detected */ - /* - * Only require force in interactive mode to avoid - * breaking existing scripts - */ - if (!force && isatty(STDIN_FILENO)) { - errx(EXIT_FAILURE, - _("This is destructive operation, data will " \ - "be lost! Use the -f option to override.")); - } + if (force) warnx(_("Operation forced, data will be lost!")); - break; - case 1: /* no signature */ - break; - default: /* error */ - err(EXIT_FAILURE, _("failed to probe the device")); - break; + else { + /* Check for existing signatures on the device */ + switch(probe_device(fd, path)) { + case 0: /* signature detected */ + /* + * Only require force in interactive mode to avoid + * breaking existing scripts + */ + if (isatty(STDIN_FILENO)) { + errx(EXIT_FAILURE, + _("This is destructive operation, data will " \ + "be lost! Use the -f option to override.")); + } + break; + case 1: /* no signature */ + break; + default: /* error */ + err(EXIT_FAILURE, _("failed to probe the device")); + break; + } } #endif /* HAVE_LIBBLKID */