summaryrefslogtreecommitdiff
path: root/src/sys/ioctl
diff options
context:
space:
mode:
authorBryant Mairs <bryantmairs@google.com>2018-01-28 19:03:14 -0800
committerBryant Mairs <bryantmairs@google.com>2018-04-10 08:28:39 -0700
commit1a815f11473c1eb91a5613f8fe67d5e97975b3fc (patch)
tree28cd699f5d176443e35f91710e1068cc91dda9a9 /src/sys/ioctl
parentdb7574f676c2c0f90a48dde0c34a73e9549d955f (diff)
downloadnix-1a815f11473c1eb91a5613f8fe67d5e97975b3fc.zip
Implement equivalent for _IOWINT for FreeBSD-like targets
ioctls on FreeBSD and DragonflyBSD have a separate request code generation macro `_IOWINT` which is now exposed as `request_code_write_int`. `ioctl_write_int` is also fixed on these platforms to use this new request
Diffstat (limited to 'src/sys/ioctl')
-rw-r--r--src/sys/ioctl/bsd.rs11
-rw-r--r--src/sys/ioctl/mod.rs107
2 files changed, 84 insertions, 34 deletions
diff --git a/src/sys/ioctl/bsd.rs b/src/sys/ioctl/bsd.rs
index 922d32e8..b7c5345b 100644
--- a/src/sys/ioctl/bsd.rs
+++ b/src/sys/ioctl/bsd.rs
@@ -46,6 +46,17 @@ macro_rules! request_code_none {
($g:expr, $n:expr) => (ioc!($crate::sys::ioctl::VOID, $g, $n, 0))
}
+/// Generate an ioctl request code for a command that passes an integer
+///
+/// This is equivalent to the `_IOWINT()` macro exposed by the C ioctl API.
+///
+/// You should only use this macro directly if the `ioctl` you're working
+/// with is "bad" and you cannot use `ioctl_write_int!()` directly.
+#[macro_export]
+macro_rules! request_code_write_int {
+ ($g:expr, $n:expr) => (ioc!($crate::sys::ioctl::VOID, $g, $n, ::std::mem::size_of::<$crate::libc::c_int>()))
+}
+
/// Generate an ioctl request code for a command that reads.
///
/// This is equivalent to the `_IOR()` macro exposed by the C ioctl API.
diff --git a/src/sys/ioctl/mod.rs b/src/sys/ioctl/mod.rs
index c4ba39c8..9c76fe96 100644
--- a/src/sys/ioctl/mod.rs
+++ b/src/sys/ioctl/mod.rs
@@ -489,41 +489,80 @@ macro_rules! ioctl_write_ptr_bad {
)
}
-/// Generates a wrapper function for a ioctl that writes an integer to the kernel.
-///
-/// The arguments to this macro are:
-///
-/// * The function name
-/// * The ioctl identifier
-/// * The ioctl sequence number
-///
-/// The generated function has the following signature:
-///
-/// ```rust,ignore
-/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: libc::c_int) -> Result<libc::c_int>
-/// ```
-///
-/// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html).
-///
-/// # Example
-///
-/// ```
-/// # #[macro_use] extern crate nix;
-/// const HCI_IOC_MAGIC: u8 = b'k';
-/// const HCI_IOC_HCIDEVUP: u8 = 1;
-/// ioctl_write_int!(hci_dev_up, HCI_IOC_MAGIC, HCI_IOC_HCIDEVUP);
-/// # fn main() {}
-/// ```
-#[macro_export]
-macro_rules! ioctl_write_int {
- ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr) => (
- $(#[$attr])*
- pub unsafe fn $name(fd: $crate::libc::c_int,
- data: $crate::libc::c_int)
- -> $crate::Result<$crate::libc::c_int> {
- convert_ioctl_res!($crate::libc::ioctl(fd, request_code_write!($ioty, $nr, ::std::mem::size_of::<$crate::libc::c_int>()) as $crate::sys::ioctl::ioctl_num_type, data))
+cfg_if!{
+ if #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))] {
+ /// Generates a wrapper function for a ioctl that writes an integer to the kernel.
+ ///
+ /// The arguments to this macro are:
+ ///
+ /// * The function name
+ /// * The ioctl identifier
+ /// * The ioctl sequence number
+ ///
+ /// The generated function has the following signature:
+ ///
+ /// ```rust,ignore
+ /// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: libc::c_int) -> Result<libc::c_int>
+ /// ```
+ ///
+ /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html).
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// # #[macro_use] extern crate nix;
+ /// ioctl_write_int!(vt_activate, b'v', 4);
+ /// # fn main() {}
+ /// ```
+ #[macro_export]
+ macro_rules! ioctl_write_int {
+ ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr) => (
+ $(#[$attr])*
+ pub unsafe fn $name(fd: $crate::libc::c_int,
+ data: $crate::libc::c_int)
+ -> $crate::Result<$crate::libc::c_int> {
+ convert_ioctl_res!($crate::libc::ioctl(fd, request_code_write_int!($ioty, $nr) as $crate::sys::ioctl::ioctl_num_type, data))
+ }
+ )
}
- )
+ } else {
+ /// Generates a wrapper function for a ioctl that writes an integer to the kernel.
+ ///
+ /// The arguments to this macro are:
+ ///
+ /// * The function name
+ /// * The ioctl identifier
+ /// * The ioctl sequence number
+ ///
+ /// The generated function has the following signature:
+ ///
+ /// ```rust,ignore
+ /// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: libc::c_int) -> Result<libc::c_int>
+ /// ```
+ ///
+ /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html).
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// # #[macro_use] extern crate nix;
+ /// const HCI_IOC_MAGIC: u8 = b'k';
+ /// const HCI_IOC_HCIDEVUP: u8 = 1;
+ /// ioctl_write_int!(hci_dev_up, HCI_IOC_MAGIC, HCI_IOC_HCIDEVUP);
+ /// # fn main() {}
+ /// ```
+ #[macro_export]
+ macro_rules! ioctl_write_int {
+ ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr) => (
+ $(#[$attr])*
+ pub unsafe fn $name(fd: $crate::libc::c_int,
+ data: $crate::libc::c_int)
+ -> $crate::Result<$crate::libc::c_int> {
+ convert_ioctl_res!($crate::libc::ioctl(fd, request_code_write!($ioty, $nr, ::std::mem::size_of::<$crate::libc::c_int>()) as $crate::sys::ioctl::ioctl_num_type, data))
+ }
+ )
+ }
+ }
}
/// Generates a wrapper function for a "bad" ioctl that writes an integer to the kernel.