|
1 | 1 | //! Provide helpers for making ioctl system calls
|
2 | 2 | //!
|
3 |
| -//! # Overview of IOCTLs |
| 3 | +//! Currently supports Linux on all architectures. Other platforms welcome! |
4 | 4 | //!
|
5 |
| -//! The `ioctl` system call is a widely support system |
6 |
| -//! call on *nix systems providing access to functions |
7 |
| -//! and data that do not fit nicely into the standard |
8 |
| -//! read and write operations on a file itself. It is |
9 |
| -//! common to see ioctls used for the following purposes: |
| 5 | +//! This library is pretty low-level and messy. `ioctl` is not fun. |
| 6 | +//! |
| 7 | +//! What is an `ioctl`? |
| 8 | +//! =================== |
| 9 | +//! |
| 10 | +//! The `ioctl` syscall is the grab-bag syscall on POSIX systems. Don't want |
| 11 | +//! to add a new syscall? Make it an `ioctl`! `ioctl` refers to both the syscall, |
| 12 | +//! and the commands that can be send with it. `ioctl` stands for "IO control", |
| 13 | +//! and the commands are always sent to a file descriptor. |
| 14 | +//! |
| 15 | +//! It is common to see `ioctl`s used for the following purposes: |
10 | 16 | //!
|
11 | 17 | //! * Provide read/write access to out-of-band data related
|
12 | 18 | //! to a device such as configuration (for instance, setting
|
|
18 | 24 | //! to the CDROM device.
|
19 | 25 | //! * Do whatever else the device driver creator thought made most sense.
|
20 | 26 | //!
|
21 |
| -//! Ioctls are synchronous system calls and are similar to read and |
| 27 | +//! `ioctl`s are synchronous system calls and are similar to read and |
22 | 28 | //! write calls in that regard.
|
23 | 29 | //!
|
24 |
| -//! The prototype for the ioctl system call in libc is as follows: |
| 30 | +//! What does this module support? |
| 31 | +//! =============================== |
| 32 | +//! |
| 33 | +//! This library provides the `ioctl!` macro, for binding `ioctl`s. It also tries |
| 34 | +//! to bind every `ioctl` supported by the system with said macro, but |
| 35 | +//! some `ioctl`s requires some amount of manual work (usually by |
| 36 | +//! providing `struct` declaration) that this library does not support yet. |
25 | 37 | //!
|
26 |
| -//! ```c |
27 |
| -//! int ioctl(int fd, unsigned long request, ...); |
28 |
| -//! ``` |
| 38 | +//! Additionally, in `etc`, there are scripts for scraping system headers for |
| 39 | +//! `ioctl` definitions, and generating calls to `ioctl!` corresponding to them. |
29 | 40 | //!
|
30 |
| -//! Typically, an ioctl takes 3 parameters as arguments: |
| 41 | +//! How do I get the magic numbers? |
| 42 | +//! =============================== |
31 | 43 | //!
|
32 |
| -//! 1. An open file descriptor, `fd`. |
33 |
| -//! 2. An device-dependennt request code or operation. This request |
34 |
| -//! code is referred to as `op` in this module. |
35 |
| -//! 3. Either a pointer to a location in memory or an integer. This |
36 |
| -//! number of pointer may either be used by the kernel or written |
37 |
| -//! to by the kernel depending on how the operation is documented |
38 |
| -//! to work. |
| 44 | +//! For Linux, look at your system's headers. For example, `/usr/include/linxu/input.h` has a lot |
| 45 | +//! of lines defining macros which use `_IOR`, `_IOW`, `_IOC`, and `_IORW`. These macros |
| 46 | +//! correspond to the `ior!`, `iow!`, `ioc!`, and `iorw!` macros defined in this crate. |
| 47 | +//! Additionally, there is the `ioctl!` macro for creating a wrapper around `ioctl` that is |
| 48 | +//! somewhat more type-safe. |
39 | 49 | //!
|
40 |
| -//! The `op` request code is essentially an arbitrary integer having |
41 |
| -//! a device-driver specific meaning. Over time, it proved difficult |
42 |
| -//! for various driver implementors to use this field sanely, so a |
43 |
| -//! convention with macros was introduced to the Linux Kernel that |
44 |
| -//! is used by most newer drivers. See |
45 |
| -//! https://github.com/torvalds/linux/blob/master/Documentation/ioctl/ioctl-number.txt |
46 |
| -//! for additional details. The macros exposed by the kernel for |
47 |
| -//! consumers are implemented in this module and may be used to |
48 |
| -//! instead of calls like `_IOC`, `_IO`, `_IOR`, and `_IOW`. |
| 50 | +//! Most `ioctl`s have no or little documentation. You'll need to scrounge through |
| 51 | +//! the source to figure out what they do and how they should be used. |
49 | 52 | //!
|
50 | 53 | //! # Interface Overview
|
51 | 54 | //!
|
52 |
| -//! This ioctl module seeks to tame the ioctl beast by providing |
53 |
| -//! a set of safer (although not safe) functions |
54 |
| -//! implementing the most common ioctl access patterns. |
| 55 | +//! This ioctl module seeks to tame the ioctl beast by providing a set of safer (although not safe) |
| 56 | +//! functions implementing the most common ioctl access patterns. |
55 | 57 | //!
|
56 | 58 | //! The most common access patterns for ioctls are as follows:
|
57 | 59 | //!
|
|
0 commit comments