Defining Control Commands for a Device File
Reading and writing bytes cannot express every request, so device files also accept numbered control commands with an optional argument structure. The number is not arbitrary: it packs a direction, a letter identifying the driver family, a sequence number and the size of the argument, so that a mismatched program and driver fail loudly instead of reading the wrong number of bytes. The kernel crate provides the same encoding helpers Rust-side, and your file type implements one method that matches on the command. Hand-rolled numbers in C are exactly how one driver's command silently means something else in another.
Questions this Concept answers
- Why is the size of the argument structure encoded into the command number itself?
IOCTL Device Driver Operations in Linux Kernel Driver Development
IOCTL (Input/Output Control) is a generic system-call mechanism that lets user-space applications send device-specific commands and data to a kernel device driver outside the normal read/write interf…