ioctl-opt
raw JSON → 1.3.1 verified Fri May 01 auth: no python
A library providing functions to compute the opt argument for fcntl.ioctl. It helps encode ioctl request codes, supporting type, number, direction, and size. Current version: 1.3.1. Release cadence: infrequent, as needed.
pip install ioctl-opt Common errors
error ImportError: No module named 'ioctl-opt' ↓
cause Using hyphen in import statement instead of underscore.
fix
Change import to 'from ioctl_opt import ...'.
error TypeError: IOC() missing 2 required positional arguments: 'size' and 'number' ↓
cause Incorrect number of arguments passed to IOC or incorrect function signature understanding.
fix
Check documentation: IOC(direction, type, number, size). Use IOR/IOW/IOWR for simpler signatures.
Warnings
gotcha The library name on PyPI is 'ioctl-opt', but the Python import path uses an underscore: 'ioctl_opt'. Many users mistakenly try 'import ioctl_opt' as 'import ioctl-opt', which fails. ↓
fix Use 'from ioctl_opt import ...' not 'import ioctl-opt'.
deprecated The function 'IOC' with direction argument may be deprecated in future versions; prefer using IOR, IOW, IOWR for clear direction. ↓
fix Use IOR, IOW, IOWR for read, write, read-write respectively.
Imports
- IOC
from ioctl_opt import IOC - IOR
from ioctl_opt import IOR - IOW
from ioctl_opt import IOW - IOWR
from ioctl_opt import IOWR
Quickstart
from ioctl_opt import IOC, IOR, IOW, IOWR
# Define ioctl numbers
type_num = ord('t') # example 't'
number = 1
size = 256
# Create ioctl request codes
read_ioctl = IOR(type_num, number, size)
write_ioctl = IOW(type_num, number, size)
rdwr_ioctl = IOWR(type_num, number, size)
custom = IOC(0, type_num, number, size) # direction 0 (none)
print(f"IOR: {read_ioctl:#x}")
print(f"IOW: {write_ioctl:#x}")
print(f"IOWR: {rdwr_ioctl:#x}")