Skip to content

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

Merged
sunfishcode merged 1 commit intobytecodealliance:mainfrom
coolreader18:ioctl-opcode-method
Jan 25, 2025
Merged

Make Ioctl::opcode a method instead of a constant#1286
sunfishcode merged 1 commit intobytecodealliance:mainfrom
coolreader18:ioctl-opcode-method

Conversation

@coolreader18
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Member

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

@notgull
Copy link
Copy Markdown
Contributor

notgull commented Jan 25, 2025

This should be fine. I mistakenly believed that the opcode was always a constant and that const evaluation could fill in what gaps there were.

@sunfishcode
Copy link
Copy Markdown
Member

Thanks!

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.

3 participants