Skip to content

Commit 33b3e42

Browse files
committed
Merge #670
670: Improve ioctl docs r=asomers Integrates suggestions and comments made in #641. Basically we hid a lot of the internal workings of things and also revised the docs to make it more clear the exact API that `nix` is exposing. There is a small amount of code cleanup I did in the macros. I also fixed the `bad` version of the `ioctl!` macro and also added a `bad none` version for use with no-data, hardcoded-number `ioctl`s. Would appreciate any and all feedback. Please especially fetch this code locally and generate the pretty docs for it (`cargo doc --no-deps --open`) so you can see what our users will see. Closes #641. Closes #573. cc @cmr @roblabla
2 parents 07e6c2f + 4525567 commit 33b3e42

File tree

9 files changed

+546
-202
lines changed

9 files changed

+546
-202
lines changed

CHANGELOG.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2424
and nix::Error::UnsupportedOperation}`
2525
([#614](https://github.com/nix-rust/nix/pull/614))
2626
- Added `cfmakeraw`, `cfsetspeed`, and `tcgetsid`. ([#527](https://github.com/nix-rust/nix/pull/527))
27+
- Added "bad none", "bad write_ptr", "bad write_int", and "bad readwrite" variants to the `ioctl!`
28+
macro. ([#670](https://github.com/nix-rust/nix/pull/670))
2729

2830
### Changed
29-
- Changed `ioctl!(write ...)` to take argument by value instead as pointer.
30-
If you need a pointer as argument, use `ioctl!(write buf ...)`.
31-
([#626](https://github.com/nix-rust/nix/pull/626))
31+
- Changed `ioctl!(write ...)` into `ioctl!(write_ptr ...)` and `ioctl!(write_int ..)` variants
32+
to more clearly separate those use cases. ([#670](https://github.com/nix-rust/nix/pull/670))
3233
- Marked `sys::mman::{ mmap, munmap, madvise, munlock, msync }` as unsafe.
3334
([#559](https://github.com/nix-rust/nix/pull/559))
3435
- Minimum supported Rust version is now 1.13.
@@ -48,13 +49,21 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4849
- Revised the termios API including additional tests and documentation and exposed it on iOS. ([#527](https://github.com/nix-rust/nix/pull/527))
4950
- `eventfd`, `signalfd`, and `pwritev`/`preadv` functionality is now included by default for all
5051
supported platforms. ([#681](https://github.com/nix-rust/nix/pull/561))
52+
- The `ioctl!` macro's plain variants has been replaced with "bad read" to be consistent with
53+
other variants. The generated functions also have more strict types for their arguments. The
54+
"*_buf" variants also now calculate total array size and take slice references for improved type
55+
safety. The documentation has also been dramatically improved.
56+
([#670](https://github.com/nix-rust/nix/pull/670))
5157

5258
### Removed
5359
- Removed `io::Error` from `nix::Error` and the conversion from `nix::Error` to `Errno`
5460
([#614](https://github.com/nix-rust/nix/pull/614))
5561
- All feature flags have been removed in favor of conditional compilation on supported platforms.
5662
`execvpe` is no longer supported, but this was already broken and will be added back in the next
5763
release. ([#681](https://github.com/nix-rust/nix/pull/561))
64+
- Removed `ioc_*` functions and many helper constants and macros within the `ioctl` module. These
65+
should always have been private and only the `ioctl!` should be used in public code.
66+
([#670](https://github.com/nix-rust/nix/pull/670))
5867

5968
### Fixed
6069
- Fixed multiple issues compiling under different archetectures and OSes.
@@ -73,6 +82,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
7382
([#623](https://github.com/nix-rust/nix/pull/623))
7483
- Multiple constants related to the termios API have now been properly defined for
7584
all supported platforms. ([#527](https://github.com/nix-rust/nix/pull/527))
85+
- `ioctl!` macro now supports working with non-int datatypes and properly supports all platforms.
86+
([#670](https://github.com/nix-rust/nix/pull/670))
7687

7788
## [0.8.1] 2017-04-16
7889

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ pub mod libc {
3131
pub use self::libc::*;
3232
}
3333

34-
pub use libc::{c_int, c_void};
3534
pub use errno::Errno;
3635

3736
pub mod errno;
@@ -96,7 +95,7 @@ pub enum Error {
9695
/// The operation involved a conversion to Rust's native String type, which failed because the
9796
/// string did not contain all valid UTF-8.
9897
InvalidUtf8,
99-
/// The operation is not supported by Nix, in this instance either use the libc bindings or
98+
/// The operation is not supported by Nix, in this instance either use the libc bindings or
10099
/// consult the module documentation to see if there is a more appropriate interface available.
101100
UnsupportedOperation,
102101
}

src/sys/aio.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'a> AioCb<'a> {
9494
/// be prioritized at the process's priority level minus `prio`
9595
/// * `sigev_notify` Determines how you will be notified of event
9696
/// completion.
97-
pub fn from_fd(fd: RawFd, prio: ::c_int,
97+
pub fn from_fd(fd: RawFd, prio: libc::c_int,
9898
sigev_notify: SigevNotify) -> AioCb<'a> {
9999
let mut a = AioCb::common_init(fd, prio, sigev_notify);
100100
a.aio_offset = 0;
@@ -118,13 +118,13 @@ impl<'a> AioCb<'a> {
118118
/// * `opcode` This field is only used for `lio_listio`. It determines
119119
/// which operation to use for this individual aiocb
120120
pub fn from_mut_slice(fd: RawFd, offs: off_t, buf: &'a mut [u8],
121-
prio: ::c_int, sigev_notify: SigevNotify,
121+
prio: libc::c_int, sigev_notify: SigevNotify,
122122
opcode: LioOpcode) -> AioCb<'a> {
123123
let mut a = AioCb::common_init(fd, prio, sigev_notify);
124124
a.aio_offset = offs;
125125
a.aio_nbytes = buf.len() as size_t;
126126
a.aio_buf = buf.as_ptr() as *mut c_void;
127-
a.aio_lio_opcode = opcode as ::c_int;
127+
a.aio_lio_opcode = opcode as libc::c_int;
128128

129129
let aiocb = AioCb { aiocb: a, mutable: true, in_progress: false,
130130
keeper: Keeper::phantom(PhantomData)};
@@ -146,13 +146,13 @@ impl<'a> AioCb<'a> {
146146
/// * `opcode` This field is only used for `lio_listio`. It determines
147147
/// which operation to use for this individual aiocb
148148
pub fn from_boxed_slice(fd: RawFd, offs: off_t, buf: Rc<Box<[u8]>>,
149-
prio: ::c_int, sigev_notify: SigevNotify,
149+
prio: libc::c_int, sigev_notify: SigevNotify,
150150
opcode: LioOpcode) -> AioCb<'a> {
151151
let mut a = AioCb::common_init(fd, prio, sigev_notify);
152152
a.aio_offset = offs;
153153
a.aio_nbytes = buf.len() as size_t;
154154
a.aio_buf = buf.as_ptr() as *mut c_void;
155-
a.aio_lio_opcode = opcode as ::c_int;
155+
a.aio_lio_opcode = opcode as libc::c_int;
156156

157157
let aiocb = AioCb{ aiocb: a, mutable: true, in_progress: false,
158158
keeper: Keeper::boxed(buf)};
@@ -173,7 +173,7 @@ impl<'a> AioCb<'a> {
173173
// AioCb, and they must all be the same type. We're basically stuck with
174174
// using an unsafe function, since aio (as designed in C) is an unsafe API.
175175
pub fn from_slice(fd: RawFd, offs: off_t, buf: &'a [u8],
176-
prio: ::c_int, sigev_notify: SigevNotify,
176+
prio: libc::c_int, sigev_notify: SigevNotify,
177177
opcode: LioOpcode) -> AioCb {
178178
let mut a = AioCb::common_init(fd, prio, sigev_notify);
179179
a.aio_offset = offs;
@@ -183,14 +183,14 @@ impl<'a> AioCb<'a> {
183183
// it.
184184
a.aio_buf = buf.as_ptr() as *mut c_void;
185185
assert!(opcode != LioOpcode::LIO_READ, "Can't read into an immutable buffer");
186-
a.aio_lio_opcode = opcode as ::c_int;
186+
a.aio_lio_opcode = opcode as libc::c_int;
187187

188188
let aiocb = AioCb { aiocb: a, mutable: false, in_progress: false,
189189
keeper: Keeper::none};
190190
aiocb
191191
}
192192

193-
fn common_init(fd: RawFd, prio: ::c_int,
193+
fn common_init(fd: RawFd, prio: libc::c_int,
194194
sigev_notify: SigevNotify) -> libc::aiocb {
195195
// Use mem::zeroed instead of explicitly zeroing each field, because the
196196
// number and name of reserved fields is OS-dependent. On some OSes,
@@ -235,7 +235,7 @@ impl<'a> AioCb<'a> {
235235
pub fn fsync(&mut self, mode: AioFsyncMode) -> Result<()> {
236236
let p: *mut libc::aiocb = &mut self.aiocb;
237237
self.in_progress = true;
238-
Errno::result(unsafe { libc::aio_fsync(mode as ::c_int, p) }).map(drop)
238+
Errno::result(unsafe { libc::aio_fsync(mode as libc::c_int, p) }).map(drop)
239239
}
240240

241241
/// Asynchronously reads from a file descriptor into a buffer

src/sys/event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct KEvent {
2121
#[cfg(any(target_os = "openbsd", target_os = "freebsd",
2222
target_os = "dragonfly", target_os = "macos",
2323
target_os = "ios"))]
24-
type type_of_udata = *mut ::c_void;
24+
type type_of_udata = *mut libc::c_void;
2525
#[cfg(any(target_os = "openbsd", target_os = "freebsd",
2626
target_os = "dragonfly", target_os = "macos",
2727
target_os = "ios"))]
@@ -127,7 +127,7 @@ libc_bitflags!(
127127
#[cfg(any(target_os = "macos", target_os = "ios"))]
128128
NOTE_EXITSTATUS,
129129
NOTE_EXTEND,
130-
#[cfg(any(target_os = "macos",
130+
#[cfg(any(target_os = "macos",
131131
target_os = "ios",
132132
target_os = "freebsd",
133133
target_os = "dragonfly"))]

0 commit comments

Comments
 (0)