diff --git a/libc-test/build.rs b/libc-test/build.rs index 85182f88cd35..dff27809d31c 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1986,6 +1986,8 @@ fn test_android(target: &str) { // sigval is a struct in Rust, but a union in C: "sigval" => format!("union sigval"), + "Ioctl" => "int".to_string(), + // put `struct` in front of all structs:. t if is_struct => format!("struct {}", t), diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index a15912611a0a..d2a6ac3750d4 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -634,6 +634,8 @@ FF1 FFDLY FF_CNT FF_MAX +FICLONE +FICLONERANGE FILE FILENAME_MAX FIOCLEX @@ -750,6 +752,8 @@ IFF_DYNAMIC IFF_LOOPBACK IFF_MASTER IFF_MULTICAST +IFF_NAPI +IFF_NAPI_FRAGS IFF_NOARP IFF_NOTRAILERS IFF_NO_CARRIER @@ -3321,6 +3325,7 @@ fgetpos fgets fgets_unlocked fgetxattr +file_clone_range fileno flistxattr flock diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 13d882be0075..09c571018a0e 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -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; @@ -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, @@ -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; @@ -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; @@ -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::(T_TYPE, 200); -pub const TUNSETDEBUG: c_int = _IOW::(T_TYPE, 201); -pub const TUNSETIFF: c_int = _IOW::(T_TYPE, 202); -pub const TUNSETPERSIST: c_int = _IOW::(T_TYPE, 203); -pub const TUNSETOWNER: c_int = _IOW::(T_TYPE, 204); -pub const TUNSETLINK: c_int = _IOW::(T_TYPE, 205); -pub const TUNSETGROUP: c_int = _IOW::(T_TYPE, 206); -pub const TUNGETFEATURES: c_int = _IOR::(T_TYPE, 207); -pub const TUNSETOFFLOAD: c_int = _IOW::(T_TYPE, 208); -pub const TUNSETTXFILTER: c_int = _IOW::(T_TYPE, 209); -pub const TUNGETIFF: c_int = _IOR::(T_TYPE, 210); -pub const TUNGETSNDBUF: c_int = _IOR::(T_TYPE, 211); -pub const TUNSETSNDBUF: c_int = _IOW::(T_TYPE, 212); -pub const TUNATTACHFILTER: c_int = _IOW::(T_TYPE, 213); -pub const TUNDETACHFILTER: c_int = _IOW::(T_TYPE, 214); -pub const TUNGETVNETHDRSZ: c_int = _IOR::(T_TYPE, 215); -pub const TUNSETVNETHDRSZ: c_int = _IOW::(T_TYPE, 216); -pub const TUNSETQUEUE: c_int = _IOW::(T_TYPE, 217); -pub const TUNSETIFINDEX: c_int = _IOW::(T_TYPE, 218); -pub const TUNGETFILTER: c_int = _IOR::(T_TYPE, 219); -pub const TUNSETVNETLE: c_int = _IOW::(T_TYPE, 220); -pub const TUNGETVNETLE: c_int = _IOR::(T_TYPE, 221); -pub const TUNSETVNETBE: c_int = _IOW::(T_TYPE, 222); -pub const TUNGETVNETBE: c_int = _IOR::(T_TYPE, 223); -pub const TUNSETSTEERINGEBPF: c_int = _IOR::(T_TYPE, 224); -pub const TUNSETFILTEREBPF: c_int = _IOR::(T_TYPE, 225); -pub const TUNSETCARRIER: c_int = _IOW::(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; @@ -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( @@ -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(ty: u32, nr: u32) -> c_int { - super::_IOC(super::_IOC_READ, ty, nr, mem::size_of::()) as c_int -} - -/// Build an ioctl number for an write-only ioctl. -pub const fn _IOW(ty: u32, nr: u32) -> c_int { - super::_IOC(super::_IOC_WRITE, ty, nr, mem::size_of::()) as c_int -} - -/// Build an ioctl number for a read-write ioctl. -pub const fn _IOWR(ty: u32, nr: u32) -> c_int { - super::_IOC( - super::_IOC_READ | super::_IOC_WRITE, - ty, - nr, - mem::size_of::(), - ) as c_int -} diff --git a/src/unix/linux_like/linux/arch/generic/mod.rs b/src/unix/linux_like/linux/arch/generic/mod.rs index ec3179b431f9..5e12c848893a 100644 --- a/src/unix/linux_like/linux/arch/generic/mod.rs +++ b/src/unix/linux_like/linux/arch/generic/mod.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use crate::{Ioctl, _IOR, _IOW}; +use crate::Ioctl; s! { pub struct termios2 { @@ -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::(0x94, 9) as Ioctl; -pub const FICLONERANGE: Ioctl = _IOW::(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; @@ -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::('f' as u32, 1) as Ioctl; -pub const FS_IOC_SETFLAGS: Ioctl = _IOW::('f' as u32, 2) as Ioctl; -pub const FS_IOC_GETVERSION: Ioctl = _IOR::('v' as u32, 1) as Ioctl; -pub const FS_IOC_SETVERSION: Ioctl = _IOW::('v' as u32, 2) as Ioctl; -pub const FS_IOC32_GETFLAGS: Ioctl = _IOR::('f' as u32, 1) as Ioctl; -pub const FS_IOC32_SETFLAGS: Ioctl = _IOW::('f' as u32, 2) as Ioctl; -pub const FS_IOC32_GETVERSION: Ioctl = _IOR::('v' as u32, 1) as Ioctl; -pub const FS_IOC32_SETVERSION: Ioctl = _IOW::('v' as u32, 2) as Ioctl; - -pub const TUNATTACHFILTER: Ioctl = _IOW::('T' as u32, 213) as Ioctl; -pub const TUNDETACHFILTER: Ioctl = _IOW::('T' as u32, 214) as Ioctl; -pub const TUNGETFILTER: Ioctl = _IOR::('T' as u32, 219) as Ioctl; cfg_if! { if #[cfg(any(target_arch = "arm", target_arch = "s390x"))] { diff --git a/src/unix/linux_like/linux/arch/mips/mod.rs b/src/unix/linux_like/linux/arch/mips/mod.rs index eee7cc81a47e..1e16097a3018 100644 --- a/src/unix/linux_like/linux/arch/mips/mod.rs +++ b/src/unix/linux_like/linux/arch/mips/mod.rs @@ -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; @@ -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")] { diff --git a/src/unix/linux_like/linux/arch/powerpc/mod.rs b/src/unix/linux_like/linux/arch/powerpc/mod.rs index 588b99a2d0f2..2d81b9301548 100644 --- a/src/unix/linux_like/linux/arch/powerpc/mod.rs +++ b/src/unix/linux_like/linux/arch/powerpc/mod.rs @@ -113,9 +113,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; @@ -209,68 +206,6 @@ pub const BLKIOOPT: Ioctl = 0x20001279; pub const BLKSSZGET: Ioctl = 0x20001268; pub const BLKPBSZGET: Ioctl = 0x2000127B; //pub const FIOQSIZE: Ioctl = 0x40086680; -// 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(target_arch = "powerpc")] { - 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(target_arch = "powerpc64")] { - 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; - } -} pub const TIOCM_LE: c_int = 0x001; pub const TIOCM_DTR: c_int = 0x002; diff --git a/src/unix/linux_like/linux/arch/sparc/mod.rs b/src/unix/linux_like/linux/arch/sparc/mod.rs index 86af2ad14bcd..4c108ba7b71c 100644 --- a/src/unix/linux_like/linux/arch/sparc/mod.rs +++ b/src/unix/linux_like/linux/arch/sparc/mod.rs @@ -199,35 +199,6 @@ pub const BLKPBSZGET: Ioctl = 0x2000127B; //pub const TIOCGRS485: Ioctl = 0x40205441; //pub const TIOCSRS485: Ioctl = 0xc0205442; -// 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; - pub const TIOCM_LE: c_int = 0x001; pub const TIOCM_DTR: c_int = 0x002; pub const TIOCM_RTS: c_int = 0x004; @@ -274,37 +245,3 @@ cfg_if! { pub const RLIM_INFINITY: crate::rlim_t = 0x7fffffff; } } - -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(target_arch = "sparc")] { - 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(target_arch = "sparc64")] { - 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; - } -} diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index 3a90a70d710e..ddaea762ecc3 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -1162,33 +1162,6 @@ pub const REG_EEND: c_int = 14; pub const REG_ESIZE: c_int = 15; pub const REG_ERPAREN: c_int = 16; -cfg_if! { - if #[cfg(any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "arm", - target_arch = "aarch64", - target_arch = "loongarch64", - target_arch = "riscv64", - target_arch = "s390x" - ))] { - pub const TUNSETCARRIER: Ioctl = 0x400454e2; - pub const TUNGETDEVNETNS: Ioctl = 0x54e3; - } else if #[cfg(any( - target_arch = "mips", - target_arch = "mips64", - target_arch = "powerpc", - target_arch = "powerpc64", - target_arch = "sparc", - target_arch = "sparc64" - ))] { - pub const TUNSETCARRIER: Ioctl = 0x800454e2; - pub const TUNGETDEVNETNS: Ioctl = 0x200054e3; - } else { - // Unknown target_arch - } -} - extern "C" { pub fn fgetspent_r( fp: *mut crate::FILE, diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 86741adb43d8..cb1a1df0afc2 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -3,6 +3,8 @@ use core::mem::size_of; use crate::prelude::*; +use crate::{_IOR, _IOW, _IOWR}; +use crate::sock_filter; pub type useconds_t = u32; pub type dev_t = u64; @@ -748,19 +750,6 @@ s! { pub addr_mask: u8, } - // linux/filter.h - pub struct sock_filter { - pub code: __u16, - pub jt: __u8, - pub jf: __u8, - pub k: __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, @@ -815,13 +804,6 @@ s! { pub nla_type: u16, } - pub struct file_clone_range { - pub src_fd: crate::__s64, - pub src_offset: crate::__u64, - pub src_length: crate::__u64, - pub dest_offset: crate::__u64, - } - pub struct __c_anonymous_ifru_map { pub mem_start: c_ulong, pub mem_end: c_ulong, @@ -2894,46 +2876,6 @@ pub const IFLA_INFO_XSTATS: c_ushort = 3; pub const IFLA_INFO_SLAVE_KIND: c_ushort = 4; pub const IFLA_INFO_SLAVE_DATA: c_ushort = 5; -// linux/if_tun.h -/* TUNSETIFF ifr flags */ -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; -// Used in TUNSETIFF to bring up tun/tap without carrier -pub const IFF_NO_CARRIER: c_int = 0x0040; -pub const IFF_NO_PI: c_int = 0x1000; -// Read queue size -pub const TUN_READQ_SIZE: c_short = 500; -// TUN device type flags: deprecated. Use IFF_TUN/IFF_TAP instead. -pub const TUN_TUN_DEV: c_short = crate::IFF_TUN as c_short; -pub const TUN_TAP_DEV: c_short = crate::IFF_TAP as c_short; -pub const TUN_TYPE_MASK: c_short = 0x000f; -// This flag has no real effect -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; -// read-only flag -pub const IFF_PERSIST: c_int = 0x0800; -pub const IFF_NOFILTER: c_int = 0x1000; -// Socket options -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; - // Since Linux 3.1 pub const SEEK_DATA: c_int = 3; pub const SEEK_HOLE: c_int = 4; @@ -4702,25 +4644,25 @@ pub const PTP_MAX_SAMPLES: c_uint = 25; // Maximum allowed offset measurement sa const PTP_CLK_MAGIC: u32 = b'=' as u32; -pub const PTP_CLOCK_GETCAPS: c_uint = _IOR::(PTP_CLK_MAGIC, 1); -pub const PTP_EXTTS_REQUEST: c_uint = _IOW::(PTP_CLK_MAGIC, 2); -pub const PTP_PEROUT_REQUEST: c_uint = _IOW::(PTP_CLK_MAGIC, 3); -pub const PTP_ENABLE_PPS: c_uint = _IOW::(PTP_CLK_MAGIC, 4); -pub const PTP_SYS_OFFSET: c_uint = _IOW::(PTP_CLK_MAGIC, 5); -pub const PTP_PIN_GETFUNC: c_uint = _IOWR::(PTP_CLK_MAGIC, 6); -pub const PTP_PIN_SETFUNC: c_uint = _IOW::(PTP_CLK_MAGIC, 7); -pub const PTP_SYS_OFFSET_PRECISE: c_uint = _IOWR::(PTP_CLK_MAGIC, 8); -pub const PTP_SYS_OFFSET_EXTENDED: c_uint = _IOWR::(PTP_CLK_MAGIC, 9); - -pub const PTP_CLOCK_GETCAPS2: c_uint = _IOR::(PTP_CLK_MAGIC, 10); -pub const PTP_EXTTS_REQUEST2: c_uint = _IOW::(PTP_CLK_MAGIC, 11); -pub const PTP_PEROUT_REQUEST2: c_uint = _IOW::(PTP_CLK_MAGIC, 12); -pub const PTP_ENABLE_PPS2: c_uint = _IOW::(PTP_CLK_MAGIC, 13); -pub const PTP_SYS_OFFSET2: c_uint = _IOW::(PTP_CLK_MAGIC, 14); -pub const PTP_PIN_GETFUNC2: c_uint = _IOWR::(PTP_CLK_MAGIC, 15); -pub const PTP_PIN_SETFUNC2: c_uint = _IOW::(PTP_CLK_MAGIC, 16); -pub const PTP_SYS_OFFSET_PRECISE2: c_uint = _IOWR::(PTP_CLK_MAGIC, 17); -pub const PTP_SYS_OFFSET_EXTENDED2: c_uint = _IOWR::(PTP_CLK_MAGIC, 18); +pub const PTP_CLOCK_GETCAPS: Ioctl = _IOR::(PTP_CLK_MAGIC, 1); +pub const PTP_EXTTS_REQUEST: Ioctl = _IOW::(PTP_CLK_MAGIC, 2); +pub const PTP_PEROUT_REQUEST: Ioctl = _IOW::(PTP_CLK_MAGIC, 3); +pub const PTP_ENABLE_PPS: Ioctl = _IOW::(PTP_CLK_MAGIC, 4); +pub const PTP_SYS_OFFSET: Ioctl = _IOW::(PTP_CLK_MAGIC, 5); +pub const PTP_PIN_GETFUNC: Ioctl = _IOWR::(PTP_CLK_MAGIC, 6); +pub const PTP_PIN_SETFUNC: Ioctl = _IOW::(PTP_CLK_MAGIC, 7); +pub const PTP_SYS_OFFSET_PRECISE: Ioctl = _IOWR::(PTP_CLK_MAGIC, 8); +pub const PTP_SYS_OFFSET_EXTENDED: Ioctl = _IOWR::(PTP_CLK_MAGIC, 9); + +pub const PTP_CLOCK_GETCAPS2: Ioctl = _IOR::(PTP_CLK_MAGIC, 10); +pub const PTP_EXTTS_REQUEST2: Ioctl = _IOW::(PTP_CLK_MAGIC, 11); +pub const PTP_PEROUT_REQUEST2: Ioctl = _IOW::(PTP_CLK_MAGIC, 12); +pub const PTP_ENABLE_PPS2: Ioctl = _IOW::(PTP_CLK_MAGIC, 13); +pub const PTP_SYS_OFFSET2: Ioctl = _IOW::(PTP_CLK_MAGIC, 14); +pub const PTP_PIN_GETFUNC2: Ioctl = _IOWR::(PTP_CLK_MAGIC, 15); +pub const PTP_PIN_SETFUNC2: Ioctl = _IOW::(PTP_CLK_MAGIC, 16); +pub const PTP_SYS_OFFSET_PRECISE2: Ioctl = _IOWR::(PTP_CLK_MAGIC, 17); +pub const PTP_SYS_OFFSET_EXTENDED2: Ioctl = _IOWR::(PTP_CLK_MAGIC, 18); // enum ptp_pin_function pub const PTP_PF_NONE: c_uint = 0; @@ -5949,26 +5891,6 @@ pub const EPIOCGPARAMS: Ioctl = 0x80088a02; pub const SI_DETHREAD: c_int = -7; pub const TRAP_PERF: c_int = 6; -/// Build an ioctl number for an argumentless ioctl. -pub const fn _IO(ty: u32, nr: u32) -> u32 { - super::_IOC(super::_IOC_NONE, ty, nr, 0) -} - -/// Build an ioctl number for an read-only ioctl. -pub const fn _IOR(ty: u32, nr: u32) -> u32 { - super::_IOC(super::_IOC_READ, ty, nr, size_of::()) -} - -/// Build an ioctl number for an write-only ioctl. -pub const fn _IOW(ty: u32, nr: u32) -> u32 { - super::_IOC(super::_IOC_WRITE, ty, nr, size_of::()) -} - -/// Build an ioctl number for a read-write ioctl. -pub const fn _IOWR(ty: u32, nr: u32) -> u32 { - super::_IOC(super::_IOC_READ | super::_IOC_WRITE, ty, nr, size_of::()) -} - f! { pub fn NLA_ALIGN(len: c_int) -> c_int { return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1); @@ -6961,8 +6883,6 @@ extern "C" { ) -> ssize_t; pub fn klogctl(syslog_type: c_int, bufp: *mut c_char, len: c_int) -> c_int; - - pub fn ioctl(fd: c_int, request: Ioctl, ...) -> c_int; } // LFS64 extensions diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 6ed732e73f5c..6fc763ef7191 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -212,6 +212,32 @@ s! { } } +cfg_if! { + if #[cfg(not(target_os = "emscripten"))] { + s! { + pub struct file_clone_range { + pub src_fd: crate::__s64, + pub src_offset: crate::__u64, + pub src_length: crate::__u64, + pub dest_offset: crate::__u64, + } + + // linux/filter.h + pub struct sock_filter { + pub code: __u16, + pub jt: __u8, + pub jf: __u8, + pub k: __u32, + } + + pub struct sock_fprog { + pub len: c_ushort, + pub filter: *mut sock_filter, + } + } + } +} + cfg_if! { if #[cfg(any(target_env = "gnu", target_os = "android"))] { s! { @@ -1481,6 +1507,93 @@ pub const ARPHRD_IEEE802154: u16 = 804; pub const ARPHRD_VOID: u16 = 0xFFFF; pub const ARPHRD_NONE: u16 = 0xFFFE; +cfg_if! { + if #[cfg(not(target_os = "emscripten"))] { + // linux/if_tun.h + /* TUNSETIFF ifr flags */ + 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; + // Used in TUNSETIFF to bring up tun/tap without carrier + pub const IFF_NO_CARRIER: c_int = 0x0040; + pub const IFF_NO_PI: c_int = 0x1000; + // Read queue size + pub const TUN_READQ_SIZE: c_short = 500; + // TUN device type flags: deprecated. Use IFF_TUN/IFF_TAP instead. + pub const TUN_TUN_DEV: c_short = crate::IFF_TUN as c_short; + pub const TUN_TAP_DEV: c_short = crate::IFF_TAP as c_short; + pub const TUN_TYPE_MASK: c_short = 0x000f; + // This flag has no real effect + 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; + // read-only flag + pub const IFF_PERSIST: c_int = 0x0800; + pub const IFF_NOFILTER: c_int = 0x1000; + // Socket options + 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: Ioctl = _IOW::(T_TYPE, 200); + pub const TUNSETDEBUG: Ioctl = _IOW::(T_TYPE, 201); + pub const TUNSETIFF: Ioctl = _IOW::(T_TYPE, 202); + pub const TUNSETPERSIST: Ioctl = _IOW::(T_TYPE, 203); + pub const TUNSETOWNER: Ioctl = _IOW::(T_TYPE, 204); + pub const TUNSETLINK: Ioctl = _IOW::(T_TYPE, 205); + pub const TUNSETGROUP: Ioctl = _IOW::(T_TYPE, 206); + pub const TUNGETFEATURES: Ioctl = _IOR::(T_TYPE, 207); + pub const TUNSETOFFLOAD: Ioctl = _IOW::(T_TYPE, 208); + pub const TUNSETTXFILTER: Ioctl = _IOW::(T_TYPE, 209); + pub const TUNGETIFF: Ioctl = _IOR::(T_TYPE, 210); + pub const TUNGETSNDBUF: Ioctl = _IOR::(T_TYPE, 211); + pub const TUNSETSNDBUF: Ioctl = _IOW::(T_TYPE, 212); + pub const TUNATTACHFILTER: Ioctl = _IOW::(T_TYPE, 213); + pub const TUNDETACHFILTER: Ioctl = _IOW::(T_TYPE, 214); + pub const TUNGETVNETHDRSZ: Ioctl = _IOR::(T_TYPE, 215); + pub const TUNSETVNETHDRSZ: Ioctl = _IOW::(T_TYPE, 216); + pub const TUNSETQUEUE: Ioctl = _IOW::(T_TYPE, 217); + pub const TUNSETIFINDEX: Ioctl = _IOW::(T_TYPE, 218); + pub const TUNGETFILTER: Ioctl = _IOR::(T_TYPE, 219); + pub const TUNSETVNETLE: Ioctl = _IOW::(T_TYPE, 220); + pub const TUNGETVNETLE: Ioctl = _IOR::(T_TYPE, 221); + pub const TUNSETVNETBE: Ioctl = _IOW::(T_TYPE, 222); + pub const TUNGETVNETBE: Ioctl = _IOR::(T_TYPE, 223); + pub const TUNSETSTEERINGEBPF: Ioctl = _IOR::(T_TYPE, 224); + pub const TUNSETFILTEREBPF: Ioctl = _IOR::(T_TYPE, 225); + pub const TUNSETCARRIER: Ioctl = _IOW::(T_TYPE, 226); + pub const TUNGETDEVNETNS: Ioctl = _IO(T_TYPE, 227); + + // linux/fs.h + pub const FS_IOC_GETFLAGS: Ioctl = _IOR::('f' as u32, 1); + pub const FS_IOC_SETFLAGS: Ioctl = _IOW::('f' as u32, 2); + pub const FS_IOC_GETVERSION: Ioctl = _IOR::('v' as u32, 1); + pub const FS_IOC_SETVERSION: Ioctl = _IOW::('v' as u32, 2); + pub const FS_IOC32_GETFLAGS: Ioctl = _IOR::('f' as u32, 1); + pub const FS_IOC32_SETFLAGS: Ioctl = _IOW::('f' as u32, 2); + pub const FS_IOC32_GETVERSION: Ioctl = _IOR::('v' as u32, 1); + pub const FS_IOC32_SETVERSION: Ioctl = _IOW::('v' as u32, 2); + + pub const FICLONE: Ioctl = _IOW::(0x94, 9); + pub const FICLONERANGE: Ioctl = _IOW::(0x94, 13); + } +} + cfg_if! { if #[cfg(target_os = "emscripten")] { // Emscripten does not define any `*_SUPER_MAGIC` constants. @@ -1632,11 +1745,7 @@ cfg_if! { // https://github.com/search?q=repo%3Atorvalds%2Flinux+%22%23define+_IOC_NONE%22&type=code cfg_if! { - if #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "l4re" - ))] { + if #[cfg(not(target_os = "emscripten"))] { const _IOC_NRBITS: u32 = 8; const _IOC_TYPEBITS: u32 = 8; @@ -1680,7 +1789,7 @@ cfg_if! { // adapted from https://github.com/torvalds/linux/blob/8a696a29c6905594e4abf78eaafcb62165ac61f1/rust/kernel/ioctl.rs /// Build an ioctl number, analogous to the C macro of the same name. - const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> u32 { + const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> Ioctl { // FIXME(ctest) the `garando_syntax` crate (used by ctest in the CI test suite) // cannot currently parse these `debug_assert!`s // @@ -1689,10 +1798,34 @@ cfg_if! { // debug_assert!(nr <= _IOC_NRMASK); // debug_assert!(size <= (_IOC_SIZEMASK as usize)); - (dir << _IOC_DIRSHIFT) + ((dir << _IOC_DIRSHIFT) | (ty << _IOC_TYPESHIFT) | (nr << _IOC_NRSHIFT) - | ((size as u32) << _IOC_SIZESHIFT) + | ((size as u32) << _IOC_SIZESHIFT)) as Ioctl + } + + /// Build an ioctl number for an argumentless ioctl. + pub const fn _IO(ty: u32, nr: u32) -> Ioctl { + _IOC(_IOC_NONE, ty, nr, 0) + } + + /// Build an ioctl number for an read-only ioctl. + pub const fn _IOR(ty: u32, nr: u32) -> Ioctl { + _IOC(_IOC_READ, ty, nr, mem::size_of::()) + } + + /// Build an ioctl number for an write-only ioctl. + pub const fn _IOW(ty: u32, nr: u32) -> Ioctl { + _IOC(_IOC_WRITE, ty, nr, mem::size_of::()) + } + + /// Build an ioctl number for a read-write ioctl. + pub const fn _IOWR(ty: u32, nr: u32) -> Ioctl { + _IOC(_IOC_READ | _IOC_WRITE, ty, nr, mem::size_of::()) + } + + extern "C" { + pub fn ioctl(fd: c_int, request: Ioctl, ...) -> c_int; } } }