libbtrfs/
ioctl.rs

1/* Note: on this file:
2 * this file is rust redefiniton of a ioctl header file. there are multiple ioctl header files in
3 * torvalds/linux as they can differ depending on architecture but this is a generic definition.
4 * The entire header file was not used only what was needed for _IO(R/W) macros.
5 * the ioctl.h file used can be found here:
6 * <https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/ioctl.h>
7 */
8
9
10
11/*
12 * The following is for compatibility across the various Linux
13 * platforms.  The generic ioctl numbering scheme doesn't really enforce
14 * a type field.  De facto, however, the top 8 bits of the lower 16
15 * bits are indeed used as a type field, so we might just as well make
16 * this explicit here.  Please be sure to use the decoding macros
17 * below from now on.
18 */
19const _IOC_NRBITS: u8   = 8;
20const _IOC_TYPEBITS: u8 = 8;
21
22
23const _IOC_SIZEBITS: u8 = 14;
24
25
26pub const _IOC_NRSHIFT: u64   = 0;
27pub const _IOC_TYPESHIFT: u64 = _IOC_NRSHIFT   + _IOC_NRBITS   as u64;
28pub const _IOC_SIZESHIFT: u64 = _IOC_TYPESHIFT + _IOC_TYPEBITS as u64;
29pub const _IOC_DIRSHIFT: u64  = _IOC_SIZESHIFT + _IOC_SIZEBITS as u64;
30
31
32pub const _IOC_NONE: u8  = 0;
33pub const _IOC_WRITE: u8 = 1;
34pub const _IOC_READ: u8  = 2;
35
36
37
38#[doc(hidden)]
39#[macro_export]
40macro_rules! _IOC {
41    ($dir: expr, $type: expr, $nr: expr, $size: expr) => {
42        (($dir as u64)  << $crate::ioctl::_IOC_DIRSHIFT) |
43        (($type as u64) << $crate::ioctl::_IOC_TYPESHIFT) |
44        (($nr)          << $crate::ioctl::_IOC_NRSHIFT) |
45        (($size as u64) << $crate::ioctl::_IOC_SIZESHIFT)
46    };
47}
48
49#[doc(hidden)]
50#[macro_export]
51macro_rules! _IOC_TYPECHECK {
52    ($t: ty) => {
53        std::mem::size_of::<$t>()
54    };
55}
56
57
58
59
60
61/*
62 * Used to create numbers.
63 *
64 * NOTE: _IOW means userland is writing and kernel is reading. _IOR
65 * means userland is reading and kernel is writing.
66 */
67#[doc(hidden)]
68#[macro_export(local_inner_macros)]
69macro_rules! _IO {
70    ($type: expr, $nr: expr) => {
71        _IOC!($crate::ioctl::_IOC_NONE, $type, $nr, 0)
72    };
73}
74
75#[doc(hidden)]
76#[macro_export(local_inner_macros)]
77macro_rules! _IOR {
78    ($type: expr, $nr: expr, $size: ty) => {
79        _IOC!($crate::ioctl::_IOC_READ, $type, $nr, _IOC_TYPECHECK!($size))
80    };
81}
82
83#[doc(hidden)]
84#[macro_export(local_inner_macros)]
85macro_rules! _IOW {
86    ($type: expr, $nr: expr, $size: ty) => {
87        _IOC!($crate::ioctl::_IOC_WRITE, $type, $nr, _IOC_TYPECHECK!($size))
88    };
89}
90
91#[doc(hidden)]
92#[macro_export(local_inner_macros)]
93macro_rules! _IOWR {
94    ($type: expr, $nr: expr, $size: ty) => {
95        _IOC!($crate::ioctl::_IOC_READ | $crate::ioctl::_IOC_WRITE, $type, $nr, _IOC_TYPECHECK!($size))
96    };
97}