Skip to content

Commit aabe082

Browse files
emberianPaul Osborne
authored andcommitted
Update docs
1 parent 23332d6 commit aabe082

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

src/sys/ioctl/mod.rs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
//! Provide helpers for making ioctl system calls
22
//!
3-
//! # Overview of IOCTLs
3+
//! Currently supports Linux on all architectures. Other platforms welcome!
44
//!
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:
1016
//!
1117
//! * Provide read/write access to out-of-band data related
1218
//! to a device such as configuration (for instance, setting
@@ -18,40 +24,36 @@
1824
//! to the CDROM device.
1925
//! * Do whatever else the device driver creator thought made most sense.
2026
//!
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
2228
//! write calls in that regard.
2329
//!
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.
2537
//!
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.
2940
//!
30-
//! Typically, an ioctl takes 3 parameters as arguments:
41+
//! How do I get the magic numbers?
42+
//! ===============================
3143
//!
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.
3949
//!
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.
4952
//!
5053
//! # Interface Overview
5154
//!
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.
5557
//!
5658
//! The most common access patterns for ioctls are as follows:
5759
//!

0 commit comments

Comments
 (0)