public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: util-linux@vger.kernel.org
Cc: kwolf@redhat.com, hare@suse.de, Karel Zak <kzak@redhat.com>,
	pizhenwei@bytedance.com, Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH v2 1/3] blkpr: prepare for _IOR() ioctls
Date: Wed, 17 Dec 2025 13:26:05 -0500	[thread overview]
Message-ID: <20251217182607.179232-2-stefanha@redhat.com> (raw)
In-Reply-To: <20251217182607.179232-1-stefanha@redhat.com>

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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys-utils/blkpr.c b/sys-utils/blkpr.c
index 03ca9f7e5..c6b030def 100644
--- a/sys-utils/blkpr.c
+++ b/sys-utils/blkpr.c
@@ -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':
-- 
2.52.0


  reply	other threads:[~2025-12-17 18:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-17 18:26 [PATCH v2 0/3] blkpr: add read-keys and read-reservations commands Stefan Hajnoczi
2025-12-17 18:26 ` Stefan Hajnoczi [this message]
2025-12-17 18:26 ` [PATCH v2 2/3] blkpr: add read-keys command Stefan Hajnoczi
2025-12-17 18:26 ` [PATCH v2 3/3] blkpr: add read-reservation command Stefan Hajnoczi
2026-01-14  9:30 ` [PATCH v2 0/3] blkpr: add read-keys and read-reservations commands Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251217182607.179232-2-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=hare@suse.de \
    --cc=kwolf@redhat.com \
    --cc=kzak@redhat.com \
    --cc=pizhenwei@bytedance.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox