1use cfg_if::cfg_if;
2
3#[cfg(any(
5 target_os = "android",
6 target_os = "fuchsia",
7 target_os = "cygwin",
8 target_env = "musl",
9 target_env = "ohos"
10))]
11#[doc(hidden)]
12pub type ioctl_num_type = ::libc::c_int;
13#[cfg(not(any(
14 target_os = "android",
15 target_os = "fuchsia",
16 target_os = "cygwin",
17 target_env = "musl",
18 target_env = "ohos"
19)))]
20#[doc(hidden)]
21pub type ioctl_num_type = ::libc::c_ulong;
22#[cfg(not(target_os = "cygwin"))]
24#[doc(hidden)]
25pub type ioctl_param_type = ::libc::c_ulong;
26
27#[doc(hidden)]
28pub const NRBITS: ioctl_num_type = 8;
29#[doc(hidden)]
30pub const TYPEBITS: ioctl_num_type = 8;
31
32cfg_if! {
33 if #[cfg(any(
34 target_arch = "mips",
35 target_arch = "mips32r6",
36 target_arch = "mips64",
37 target_arch = "mips64r6",
38 target_arch = "powerpc",
39 target_arch = "powerpc64",
40 target_arch = "sparc64"
41 ))] {
42 mod consts {
43 #[doc(hidden)]
44 pub const NONE: u8 = 1;
45 #[doc(hidden)]
46 pub const READ: u8 = 2;
47 #[doc(hidden)]
48 pub const WRITE: u8 = 4;
49 #[doc(hidden)]
50 pub const SIZEBITS: u8 = 13;
51 #[doc(hidden)]
52 pub const DIRBITS: u8 = 3;
53 }
54 } else {
55 mod consts {
57 #[doc(hidden)]
58 pub const NONE: u8 = 0;
59 #[doc(hidden)]
60 pub const READ: u8 = 2;
61 #[doc(hidden)]
62 pub const WRITE: u8 = 1;
63 #[doc(hidden)]
64 pub const SIZEBITS: u8 = 14;
65 #[doc(hidden)]
66 pub const DIRBITS: u8 = 2;
67 }
68 }
69}
70
71pub use self::consts::*;
72
73#[doc(hidden)]
74pub const NRSHIFT: ioctl_num_type = 0;
75#[doc(hidden)]
76pub const TYPESHIFT: ioctl_num_type = NRSHIFT + NRBITS as ioctl_num_type;
77#[doc(hidden)]
78pub const SIZESHIFT: ioctl_num_type = TYPESHIFT + TYPEBITS as ioctl_num_type;
79#[doc(hidden)]
80pub const DIRSHIFT: ioctl_num_type = SIZESHIFT + SIZEBITS as ioctl_num_type;
81
82#[doc(hidden)]
83pub const NRMASK: ioctl_num_type = (1 << NRBITS) - 1;
84#[doc(hidden)]
85pub const TYPEMASK: ioctl_num_type = (1 << TYPEBITS) - 1;
86#[doc(hidden)]
87pub const SIZEMASK: ioctl_num_type = (1 << SIZEBITS) - 1;
88#[doc(hidden)]
89pub const DIRMASK: ioctl_num_type = (1 << DIRBITS) - 1;
90
91#[macro_export]
93#[doc(hidden)]
94macro_rules! ioc {
95 ($dir:expr, $ty:expr, $nr:expr, $sz:expr) => {
96 (($dir as $crate::sys::ioctl::ioctl_num_type
97 & $crate::sys::ioctl::DIRMASK)
98 << $crate::sys::ioctl::DIRSHIFT)
99 | (($ty as $crate::sys::ioctl::ioctl_num_type
100 & $crate::sys::ioctl::TYPEMASK)
101 << $crate::sys::ioctl::TYPESHIFT)
102 | (($nr as $crate::sys::ioctl::ioctl_num_type
103 & $crate::sys::ioctl::NRMASK)
104 << $crate::sys::ioctl::NRSHIFT)
105 | (($sz as $crate::sys::ioctl::ioctl_num_type
106 & $crate::sys::ioctl::SIZEMASK)
107 << $crate::sys::ioctl::SIZESHIFT)
108 };
109}
110
111#[macro_export(local_inner_macros)]
127macro_rules! request_code_none {
128 ($ty:expr, $nr:expr) => {
129 ioc!($crate::sys::ioctl::NONE, $ty, $nr, 0)
130 };
131}
132
133#[macro_export(local_inner_macros)]
144macro_rules! request_code_read {
145 ($ty:expr, $nr:expr, $sz:expr) => {
146 ioc!($crate::sys::ioctl::READ, $ty, $nr, $sz)
147 };
148}
149
150#[macro_export(local_inner_macros)]
161macro_rules! request_code_write {
162 ($ty:expr, $nr:expr, $sz:expr) => {
163 ioc!($crate::sys::ioctl::WRITE, $ty, $nr, $sz)
164 };
165}
166
167#[macro_export(local_inner_macros)]
174macro_rules! request_code_readwrite {
175 ($ty:expr, $nr:expr, $sz:expr) => {
176 ioc!(
177 $crate::sys::ioctl::READ | $crate::sys::ioctl::WRITE,
178 $ty,
179 $nr,
180 $sz
181 )
182 };
183}