Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Ioctl::opcode a method instead of a constant #1286

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

coolreader18
Copy link

@coolreader18 coolreader18 commented Jan 23, 2025

This lets the Ioctl trait be compatible with ioctls that take a runtime length value, e.g. these evdev ioctls from input.h:

#define EVIOCGNAME(len)		_IOC(_IOC_READ, 'E', 0x06, len)		/* get device name */
#define EVIOCGPHYS(len)		_IOC(_IOC_READ, 'E', 0x07, len)		/* get physical location */
#define EVIOCGUNIQ(len)		_IOC(_IOC_READ, 'E', 0x08, len)		/* get unique identifier */
#define EVIOCGPROP(len)		_IOC(_IOC_READ, 'E', 0x09, len)		/* get device properties */

These generally specify the length of the passed buffer, so that the driver can copy data into userspace (à la read()). rg 'len\)\s*_IO' /usr/include gives 26 results on my system, so they're not rare, and it'd be great to be able to use the Ioctl trait to wrap them.

Prior art: nix::ioctl_read_buf!()

@sunfishcode
Copy link
Member

This looks reasonable to me. @notgull do you have any thoughts on Ioctl's OPCODE changing to opcode()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants