Exposing Your Driver as a Device File
Programs talk to drivers by opening a file under the device directory and reading, writing, or sending control commands to it. A miscellaneous device is the lightest way to create one: you state a name, implement a trait whose methods correspond to open, read, write, control and release, and a registration value creates the file when made and removes it when dropped. Each open produces a handle of your own type, so per-open state is ordinary owned Rust rather than a raw pointer stashed in a C structure. Without a device file your driver works but nothing in user space can ask it for anything.
Questions this Concept answers
- Why does each open of a Rust miscellaneous device produce a value of the driver's own type?
Writing a Linux Character Device Driver: File Operations, Registration, and /dev Nodes
A Linux character device driver exposes a piece of hardware or kernel functionality to user space as a file, implemented by defining a `file_operations` structure that maps standard file actions (ope…