]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkdiscard: do not probe for signatures on --force
authorKarel Zak <kzak@redhat.com>
Thu, 13 May 2021 08:34:14 +0000 (10:34 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 13 May 2021 08:34:14 +0000 (10:34 +0200)
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 <kzak@redhat.com>
sys-utils/blkdiscard.c

index 9fa5a4f82832801f1f5bd36c8a126c75a3d6e14f..38240e80d9fc598b0328ed5c46b84fe27d78bb9c 100644 (file)
@@ -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 */