]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkpr: prepare for _IOR() ioctls
authorStefan Hajnoczi <stefanha@redhat.com>
Wed, 17 Dec 2025 18:26:05 +0000 (13:26 -0500)
committerKarel Zak <kzak@redhat.com>
Mon, 12 Jan 2026 14:30:13 +0000 (15:30 +0100)
parse_pr_command() returns the ioctl command constant for a given
command or -1 when the command is unknown. Up until now all ioctl
command constants were positive, so the following check worked:

  if (command < 0)
      err(EXIT_FAILURE, _("unknown command"));

The top two bits of ioctl command constants encode the direction (_IO,
_IOR, _IOW, _IOWR). ioctl commands defined with _IOR have negative ioctl
command constants.

Explicitly check for -1 to differentiate "unknown command" from valid
ioctls commands. Later commits will add ioctl commands that use _IOR.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
sys-utils/blkpr.c

index 03ca9f7e5fd1e97851aa588d306bfdce88ca9a8a..c6b030def38f2ab82bcf10e5cc80ccc10063a742 100644 (file)
@@ -276,7 +276,7 @@ int main(int argc, char **argv)
                        break;
                case 'c':
                        command = parse_pr_command(optarg);
-                       if (command < 0)
+                       if (command == -1)
                                err(EXIT_FAILURE, _("unknown command"));
                        break;
                case 't':