Skip to content

Cleanup IOCTL definitions in linux_like tree #4418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,8 @@ fn test_android(target: &str) {
// sigval is a struct in Rust, but a union in C:
"sigval" => "union sigval".to_string(),

"Ioctl" => "int".to_string(),

// put `struct` in front of all structs:.
t if is_struct => format!("struct {t}"),

Expand Down
5 changes: 5 additions & 0 deletions libc-test/semver/android.txt
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ FF1
FFDLY
FF_CNT
FF_MAX
FICLONE
FICLONERANGE
FILE
FILENAME_MAX
FIOCLEX
Expand Down Expand Up @@ -750,6 +752,8 @@ IFF_DYNAMIC
IFF_LOOPBACK
IFF_MASTER
IFF_MULTICAST
IFF_NAPI
IFF_NAPI_FRAGS
IFF_NOARP
IFF_NOTRAILERS
IFF_NO_CARRIER
Expand Down Expand Up @@ -3321,6 +3325,7 @@ fgetpos
fgets
fgets_unlocked
fgetxattr
file_clone_range
fileno
flistxattr
flock
Expand Down
160 changes: 9 additions & 151 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

use crate::prelude::*;

cfg_if! {
if #[cfg(doc)] {
pub(crate) type Ioctl = c_int;
} else {
#[doc(hidden)]
pub type Ioctl = c_int;
}
}

pub type clock_t = c_long;
pub type time_t = c_long;
pub type suseconds_t = c_long;
Expand Down Expand Up @@ -337,19 +346,6 @@ s! {
pub dlpi_tls_data: *mut c_void,
}

// linux/filter.h
pub struct sock_filter {
pub code: crate::__u16,
pub jt: crate::__u8,
pub jf: crate::__u8,
pub k: crate::__u32,
}

pub struct sock_fprog {
pub len: c_ushort,
pub filter: *mut sock_filter,
}

// linux/seccomp.h
pub struct seccomp_data {
pub nr: c_int,
Expand Down Expand Up @@ -1656,27 +1652,6 @@ pub const FIONREAD: c_int = 0x541B;
pub const TIOCCONS: c_int = 0x541D;
pub const TIOCSBRK: c_int = 0x5427;
pub const TIOCCBRK: c_int = 0x5428;
cfg_if! {
if #[cfg(any(
target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm",
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "s390x"
))] {
pub const FICLONE: c_int = 0x40049409;
pub const FICLONERANGE: c_int = 0x4020940D;
} else if #[cfg(any(
target_arch = "mips",
target_arch = "mips64",
target_arch = "powerpc",
target_arch = "powerpc64"
))] {
pub const FICLONE: c_int = 0x80049409;
pub const FICLONERANGE: c_int = 0x8020940D;
}
}

pub const ST_RDONLY: c_ulong = 1;
pub const ST_NOSUID: c_ulong = 2;
Expand Down Expand Up @@ -1858,38 +1833,6 @@ pub const BLKIOOPT: c_int = 0x1279;
pub const BLKSSZGET: c_int = 0x1268;
pub const BLKPBSZGET: c_int = 0x127B;

cfg_if! {
// Those type are constructed using the _IOC macro
// DD-SS_SSSS_SSSS_SSSS-TTTT_TTTT-NNNN_NNNN
// where D stands for direction (either None (00), Read (01) or Write (11))
// where S stands for size (int, long, struct...)
// where T stands for type ('f','v','X'...)
// where N stands for NR (NumbeR)
if #[cfg(any(target_arch = "x86", target_arch = "arm"))] {
pub const FS_IOC_GETFLAGS: c_int = 0x80046601;
pub const FS_IOC_SETFLAGS: c_int = 0x40046602;
pub const FS_IOC_GETVERSION: c_int = 0x80047601;
pub const FS_IOC_SETVERSION: c_int = 0x40047602;
pub const FS_IOC32_GETFLAGS: c_int = 0x80046601;
pub const FS_IOC32_SETFLAGS: c_int = 0x40046602;
pub const FS_IOC32_GETVERSION: c_int = 0x80047601;
pub const FS_IOC32_SETVERSION: c_int = 0x40047602;
} else if #[cfg(any(
target_arch = "x86_64",
target_arch = "riscv64",
target_arch = "aarch64"
))] {
pub const FS_IOC_GETFLAGS: c_int = 0x80086601;
pub const FS_IOC_SETFLAGS: c_int = 0x40086602;
pub const FS_IOC_GETVERSION: c_int = 0x80087601;
pub const FS_IOC_SETVERSION: c_int = 0x40087602;
pub const FS_IOC32_GETFLAGS: c_int = 0x80046601;
pub const FS_IOC32_SETFLAGS: c_int = 0x40046602;
pub const FS_IOC32_GETVERSION: c_int = 0x80047601;
pub const FS_IOC32_SETVERSION: c_int = 0x40047602;
}
}

pub const EAI_AGAIN: c_int = 2;
pub const EAI_BADFLAGS: c_int = 3;
pub const EAI_FAIL: c_int = 4;
Expand Down Expand Up @@ -2624,65 +2567,6 @@ pub const SND_CNT: usize = SND_MAX as usize + 1;
pub const UINPUT_VERSION: c_uint = 5;
pub const UINPUT_MAX_NAME_SIZE: usize = 80;

// bionic/libc/kernel/uapi/linux/if_tun.h
pub const IFF_TUN: c_int = 0x0001;
pub const IFF_TAP: c_int = 0x0002;
pub const IFF_NAPI: c_int = 0x0010;
pub const IFF_NAPI_FRAGS: c_int = 0x0020;
pub const IFF_NO_CARRIER: c_int = 0x0040;
pub const IFF_NO_PI: c_int = 0x1000;
pub const IFF_ONE_QUEUE: c_int = 0x2000;
pub const IFF_VNET_HDR: c_int = 0x4000;
pub const IFF_TUN_EXCL: c_int = 0x8000;
pub const IFF_MULTI_QUEUE: c_int = 0x0100;
pub const IFF_ATTACH_QUEUE: c_int = 0x0200;
pub const IFF_DETACH_QUEUE: c_int = 0x0400;
pub const IFF_PERSIST: c_int = 0x0800;
pub const IFF_NOFILTER: c_int = 0x1000;
pub const TUN_TX_TIMESTAMP: c_int = 1;
// Features for GSO (TUNSETOFFLOAD)
pub const TUN_F_CSUM: c_uint = 0x01;
pub const TUN_F_TSO4: c_uint = 0x02;
pub const TUN_F_TSO6: c_uint = 0x04;
pub const TUN_F_TSO_ECN: c_uint = 0x08;
pub const TUN_F_UFO: c_uint = 0x10;
pub const TUN_F_USO4: c_uint = 0x20;
pub const TUN_F_USO6: c_uint = 0x40;
// Protocol info prepended to the packets (when IFF_NO_PI is not set)
pub const TUN_PKT_STRIP: c_int = 0x0001;
// Accept all multicast packets
pub const TUN_FLT_ALLMULTI: c_int = 0x0001;
// Ioctl operation codes
const T_TYPE: u32 = b'T' as u32;
pub const TUNSETNOCSUM: c_int = _IOW::<c_int>(T_TYPE, 200);
pub const TUNSETDEBUG: c_int = _IOW::<c_int>(T_TYPE, 201);
pub const TUNSETIFF: c_int = _IOW::<c_int>(T_TYPE, 202);
pub const TUNSETPERSIST: c_int = _IOW::<c_int>(T_TYPE, 203);
pub const TUNSETOWNER: c_int = _IOW::<c_int>(T_TYPE, 204);
pub const TUNSETLINK: c_int = _IOW::<c_int>(T_TYPE, 205);
pub const TUNSETGROUP: c_int = _IOW::<c_int>(T_TYPE, 206);
pub const TUNGETFEATURES: c_int = _IOR::<c_int>(T_TYPE, 207);
pub const TUNSETOFFLOAD: c_int = _IOW::<c_int>(T_TYPE, 208);
pub const TUNSETTXFILTER: c_int = _IOW::<c_int>(T_TYPE, 209);
pub const TUNGETIFF: c_int = _IOR::<c_int>(T_TYPE, 210);
pub const TUNGETSNDBUF: c_int = _IOR::<c_int>(T_TYPE, 211);
pub const TUNSETSNDBUF: c_int = _IOW::<c_int>(T_TYPE, 212);
pub const TUNATTACHFILTER: c_int = _IOW::<sock_fprog>(T_TYPE, 213);
pub const TUNDETACHFILTER: c_int = _IOW::<sock_fprog>(T_TYPE, 214);
pub const TUNGETVNETHDRSZ: c_int = _IOR::<c_int>(T_TYPE, 215);
pub const TUNSETVNETHDRSZ: c_int = _IOW::<c_int>(T_TYPE, 216);
pub const TUNSETQUEUE: c_int = _IOW::<c_int>(T_TYPE, 217);
pub const TUNSETIFINDEX: c_int = _IOW::<c_int>(T_TYPE, 218);
pub const TUNGETFILTER: c_int = _IOR::<sock_fprog>(T_TYPE, 219);
pub const TUNSETVNETLE: c_int = _IOW::<c_int>(T_TYPE, 220);
pub const TUNGETVNETLE: c_int = _IOR::<c_int>(T_TYPE, 221);
pub const TUNSETVNETBE: c_int = _IOW::<c_int>(T_TYPE, 222);
pub const TUNGETVNETBE: c_int = _IOR::<c_int>(T_TYPE, 223);
pub const TUNSETSTEERINGEBPF: c_int = _IOR::<c_int>(T_TYPE, 224);
pub const TUNSETFILTEREBPF: c_int = _IOR::<c_int>(T_TYPE, 225);
pub const TUNSETCARRIER: c_int = _IOW::<c_int>(T_TYPE, 226);
pub const TUNGETDEVNETNS: c_int = _IO(T_TYPE, 227);

// start android/platform/bionic/libc/kernel/uapi/linux/if_ether.h
// from https://android.googlesource.com/platform/bionic/+/HEAD/libc/kernel/uapi/linux/if_ether.h
pub const ETH_ALEN: c_int = 6;
Expand Down Expand Up @@ -3716,7 +3600,6 @@ extern "C" {
pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut crate::timezone) -> c_int;
pub fn mlock2(addr: *const c_void, len: size_t, flags: c_int) -> c_int;
pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
pub fn ioctl(fd: c_int, request: c_int, ...) -> c_int;
pub fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int;
pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int;
pub fn recvfrom(
Expand Down Expand Up @@ -4257,28 +4140,3 @@ impl siginfo_t {
self.sifields().sigchld.si_stime
}
}

/// Build an ioctl number for an argumentless ioctl.
pub const fn _IO(ty: u32, nr: u32) -> c_int {
super::_IOC(super::_IOC_NONE, ty, nr, 0) as c_int
}

/// Build an ioctl number for an read-only ioctl.
pub const fn _IOR<T>(ty: u32, nr: u32) -> c_int {
super::_IOC(super::_IOC_READ, ty, nr, mem::size_of::<T>()) as c_int
}

/// Build an ioctl number for an write-only ioctl.
pub const fn _IOW<T>(ty: u32, nr: u32) -> c_int {
super::_IOC(super::_IOC_WRITE, ty, nr, mem::size_of::<T>()) as c_int
}

/// Build an ioctl number for a read-write ioctl.
pub const fn _IOWR<T>(ty: u32, nr: u32) -> c_int {
super::_IOC(
super::_IOC_READ | super::_IOC_WRITE,
ty,
nr,
mem::size_of::<T>(),
) as c_int
}
46 changes: 1 addition & 45 deletions src/unix/linux_like/linux/arch/generic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::*;
use crate::{Ioctl, _IOR, _IOW};
use crate::Ioctl;

s! {
pub struct termios2 {
Expand Down Expand Up @@ -158,9 +158,6 @@ pub const SO_DEVMEM_LINEAR: c_int = 78;
pub const SO_DEVMEM_DMABUF: c_int = 79;
pub const SO_DEVMEM_DONTNEED: c_int = 80;

pub const FICLONE: Ioctl = _IOW::<c_int>(0x94, 9) as Ioctl;
pub const FICLONERANGE: Ioctl = _IOW::<crate::file_clone_range>(0x94, 13) as Ioctl;

// Defined in unix/linux_like/mod.rs
// pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP;
pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS;
Expand Down Expand Up @@ -251,47 +248,6 @@ pub const BLKIOMIN: Ioctl = 0x1278;
pub const BLKIOOPT: Ioctl = 0x1279;
pub const BLKSSZGET: Ioctl = 0x1268;
pub const BLKPBSZGET: Ioctl = 0x127B;
// linux/if_tun.h
pub const TUNSETNOCSUM: Ioctl = 0x400454c8;
pub const TUNSETDEBUG: Ioctl = 0x400454c9;
pub const TUNSETIFF: Ioctl = 0x400454ca;
pub const TUNSETPERSIST: Ioctl = 0x400454cb;
pub const TUNSETOWNER: Ioctl = 0x400454cc;
pub const TUNSETLINK: Ioctl = 0x400454cd;
pub const TUNSETGROUP: Ioctl = 0x400454ce;
pub const TUNGETFEATURES: Ioctl = 0x800454cf;
pub const TUNSETOFFLOAD: Ioctl = 0x400454d0;
pub const TUNSETTXFILTER: Ioctl = 0x400454d1;
pub const TUNGETIFF: Ioctl = 0x800454d2;
pub const TUNGETSNDBUF: Ioctl = 0x800454d3;
pub const TUNSETSNDBUF: Ioctl = 0x400454d4;
pub const TUNGETVNETHDRSZ: Ioctl = 0x800454d7;
pub const TUNSETVNETHDRSZ: Ioctl = 0x400454d8;
pub const TUNSETQUEUE: Ioctl = 0x400454d9;
pub const TUNSETIFINDEX: Ioctl = 0x400454da;
pub const TUNSETVNETLE: Ioctl = 0x400454dc;
pub const TUNGETVNETLE: Ioctl = 0x800454dd;
/* The TUNSETVNETBE and TUNGETVNETBE ioctls are for cross-endian support on
* little-endian hosts. Not all kernel configurations support them, but all
* configurations that support SET also support GET.
*/
pub const TUNSETVNETBE: Ioctl = 0x400454de;
pub const TUNGETVNETBE: Ioctl = 0x800454df;
pub const TUNSETSTEERINGEBPF: Ioctl = 0x800454e0;
pub const TUNSETFILTEREBPF: Ioctl = 0x800454e1;

pub const FS_IOC_GETFLAGS: Ioctl = _IOR::<c_long>('f' as u32, 1) as Ioctl;
pub const FS_IOC_SETFLAGS: Ioctl = _IOW::<c_long>('f' as u32, 2) as Ioctl;
pub const FS_IOC_GETVERSION: Ioctl = _IOR::<c_long>('v' as u32, 1) as Ioctl;
pub const FS_IOC_SETVERSION: Ioctl = _IOW::<c_long>('v' as u32, 2) as Ioctl;
pub const FS_IOC32_GETFLAGS: Ioctl = _IOR::<c_int>('f' as u32, 1) as Ioctl;
pub const FS_IOC32_SETFLAGS: Ioctl = _IOW::<c_int>('f' as u32, 2) as Ioctl;
pub const FS_IOC32_GETVERSION: Ioctl = _IOR::<c_int>('v' as u32, 1) as Ioctl;
pub const FS_IOC32_SETVERSION: Ioctl = _IOW::<c_int>('v' as u32, 2) as Ioctl;

pub const TUNATTACHFILTER: Ioctl = _IOW::<crate::sock_fprog>('T' as u32, 213) as Ioctl;
pub const TUNDETACHFILTER: Ioctl = _IOW::<crate::sock_fprog>('T' as u32, 214) as Ioctl;
pub const TUNGETFILTER: Ioctl = _IOR::<crate::sock_fprog>('T' as u32, 219) as Ioctl;

cfg_if! {
if #[cfg(any(target_arch = "arm", target_arch = "s390x"))] {
Expand Down
65 changes: 0 additions & 65 deletions src/unix/linux_like/linux/arch/mips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ pub const SO_DEVMEM_LINEAR: c_int = 78;
pub const SO_DEVMEM_DMABUF: c_int = 79;
pub const SO_DEVMEM_DONTNEED: c_int = 80;

pub const FICLONE: c_ulong = 0x80049409;
pub const FICLONERANGE: c_ulong = 0x8020940D;

// Defined in unix/linux_like/mod.rs
// pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP;
pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS;
Expand Down Expand Up @@ -223,68 +220,6 @@ pub const BLKIOMIN: Ioctl = 0x20001278;
pub const BLKIOOPT: Ioctl = 0x20001279;
pub const BLKSSZGET: Ioctl = 0x20001268;
pub const BLKPBSZGET: Ioctl = 0x2000127B;
// linux/if_tun.h
pub const TUNSETNOCSUM: Ioctl = 0x800454c8;
pub const TUNSETDEBUG: Ioctl = 0x800454c9;
pub const TUNSETIFF: Ioctl = 0x800454ca;
pub const TUNSETPERSIST: Ioctl = 0x800454cb;
pub const TUNSETOWNER: Ioctl = 0x800454cc;
pub const TUNSETLINK: Ioctl = 0x800454cd;
pub const TUNSETGROUP: Ioctl = 0x800454ce;
pub const TUNGETFEATURES: Ioctl = 0x400454cf;
pub const TUNSETOFFLOAD: Ioctl = 0x800454d0;
pub const TUNSETTXFILTER: Ioctl = 0x800454d1;
pub const TUNGETIFF: Ioctl = 0x400454d2;
pub const TUNGETSNDBUF: Ioctl = 0x400454d3;
pub const TUNSETSNDBUF: Ioctl = 0x800454d4;
pub const TUNGETVNETHDRSZ: Ioctl = 0x400454d7;
pub const TUNSETVNETHDRSZ: Ioctl = 0x800454d8;
pub const TUNSETQUEUE: Ioctl = 0x800454d9;
pub const TUNSETIFINDEX: Ioctl = 0x800454da;
pub const TUNSETVNETLE: Ioctl = 0x800454dc;
pub const TUNGETVNETLE: Ioctl = 0x400454dd;
/* The TUNSETVNETBE and TUNGETVNETBE ioctls are for cross-endian support on
* little-endian hosts. Not all kernel configurations support them, but all
* configurations that support SET also support GET.
*/
pub const TUNSETVNETBE: Ioctl = 0x800454de;
pub const TUNGETVNETBE: Ioctl = 0x400454df;
pub const TUNSETSTEERINGEBPF: Ioctl = 0x400454e0;
pub const TUNSETFILTEREBPF: Ioctl = 0x400454e1;

cfg_if! {
// Those type are constructed using the _IOC macro
// DD-SS_SSSS_SSSS_SSSS-TTTT_TTTT-NNNN_NNNN
// where D stands for direction (either None (00), Read (01) or Write (11))
// where S stands for size (int, long, struct...)
// where T stands for type ('f','v','X'...)
// where N stands for NR (NumbeR)
if #[cfg(any(target_arch = "mips", target_arch = "mips32r6"))] {
pub const FS_IOC_GETFLAGS: Ioctl = 0x40046601;
pub const FS_IOC_SETFLAGS: Ioctl = 0x80046602;
pub const FS_IOC_GETVERSION: Ioctl = 0x40047601;
pub const FS_IOC_SETVERSION: Ioctl = 0x80047602;
pub const FS_IOC32_GETFLAGS: Ioctl = 0x40046601;
pub const FS_IOC32_SETFLAGS: Ioctl = 0x80046602;
pub const FS_IOC32_GETVERSION: Ioctl = 0x40047601;
pub const FS_IOC32_SETVERSION: Ioctl = 0x80047602;
pub const TUNATTACHFILTER: Ioctl = 0x800854d5;
pub const TUNDETACHFILTER: Ioctl = 0x800854d6;
pub const TUNGETFILTER: Ioctl = 0x400854db;
} else if #[cfg(any(target_arch = "mips64", target_arch = "mips64r6"))] {
pub const FS_IOC_GETFLAGS: Ioctl = 0x40086601;
pub const FS_IOC_SETFLAGS: Ioctl = 0x80086602;
pub const FS_IOC_GETVERSION: Ioctl = 0x40087601;
pub const FS_IOC_SETVERSION: Ioctl = 0x80087602;
pub const FS_IOC32_GETFLAGS: Ioctl = 0x40046601;
pub const FS_IOC32_SETFLAGS: Ioctl = 0x80046602;
pub const FS_IOC32_GETVERSION: Ioctl = 0x40047601;
pub const FS_IOC32_SETVERSION: Ioctl = 0x80047602;
pub const TUNATTACHFILTER: Ioctl = 0x801054d5;
pub const TUNDETACHFILTER: Ioctl = 0x801054d6;
pub const TUNGETFILTER: Ioctl = 0x401054db;
}
}

cfg_if! {
if #[cfg(target_env = "musl")] {
Expand Down
Loading
Loading