[PATCH v2 1/3] blkpr: prepare for _IOR() ioctls
Stefan Hajnoczi <[email protected]> Wed, 17 Dec 2025 13:26:05 -0500
| Newsgroups | org.kernel.vger.util-linux |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]>
---
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