1*c9537f57SPatrick WilliamsFrom 4b439b0953573e0383da7e092b1f516ba21f3398 Mon Sep 17 00:00:00 2001 2*c9537f57SPatrick WilliamsFrom: Dan Gohman <dev@sunfishcode.online> 3*c9537f57SPatrick WilliamsDate: Sun, 6 Apr 2025 05:22:49 -0700 4*c9537f57SPatrick WilliamsSubject: [PATCH] Define Linux ioctl codes on more architectures. 5*c9537f57SPatrick Williams 6*c9537f57SPatrick WilliamsDefine ioctl codes including `FICLONE` and `FS_IOC32_GETVERSION` using 7*c9537f57SPatrick Williams`_IOR` and `_IOW` so that they're automatically supported on all 8*c9537f57SPatrick Williamsarchitectures, including riscv32gc-unknown-linux-gnu. 9*c9537f57SPatrick Williams 10*c9537f57SPatrick WilliamsUpstream-Status: Backport [https://github.com/rust-lang/libc/pull/4382/] 11*c9537f57SPatrick WilliamsSigned-off-by: Khem Raj <raj.khem@gmail.com> 12*c9537f57SPatrick Williams--- 13*c9537f57SPatrick Williams src/unix/linux_like/linux/arch/generic/mod.rs | 75 ++++--------------- 14*c9537f57SPatrick Williams 1 file changed, 15 insertions(+), 60 deletions(-) 15*c9537f57SPatrick Williams 16*c9537f57SPatrick Williams--- a/src/unix/linux_like/linux/arch/generic/mod.rs 17*c9537f57SPatrick Williams+++ b/src/unix/linux_like/linux/arch/generic/mod.rs 18*c9537f57SPatrick Williams@@ -1,5 +1,5 @@ 19*c9537f57SPatrick Williams use crate::prelude::*; 20*c9537f57SPatrick Williams-use crate::Ioctl; 21*c9537f57SPatrick Williams+use crate::{Ioctl, _IOR, _IOW}; 22*c9537f57SPatrick Williams 23*c9537f57SPatrick Williams s! { 24*c9537f57SPatrick Williams pub struct termios2 { 25*c9537f57SPatrick Williams@@ -116,21 +116,8 @@ cfg_if! { 26*c9537f57SPatrick Williams // pub const SO_PREFER_BUSY_POLL: c_int = 69; 27*c9537f57SPatrick Williams // pub const SO_BUSY_POLL_BUDGET: c_int = 70; 28*c9537f57SPatrick Williams 29*c9537f57SPatrick Williams-cfg_if! { 30*c9537f57SPatrick Williams- if #[cfg(any( 31*c9537f57SPatrick Williams- target_arch = "x86", 32*c9537f57SPatrick Williams- target_arch = "x86_64", 33*c9537f57SPatrick Williams- target_arch = "arm", 34*c9537f57SPatrick Williams- target_arch = "aarch64", 35*c9537f57SPatrick Williams- target_arch = "riscv64", 36*c9537f57SPatrick Williams- target_arch = "s390x", 37*c9537f57SPatrick Williams- target_arch = "csky", 38*c9537f57SPatrick Williams- target_arch = "loongarch64" 39*c9537f57SPatrick Williams- ))] { 40*c9537f57SPatrick Williams- pub const FICLONE: c_ulong = 0x40049409; 41*c9537f57SPatrick Williams- pub const FICLONERANGE: c_ulong = 0x4020940D; 42*c9537f57SPatrick Williams- } 43*c9537f57SPatrick Williams-} 44*c9537f57SPatrick Williams+pub const FICLONE: Ioctl = _IOW::<c_int>(0x94, 9) as Ioctl; 45*c9537f57SPatrick Williams+pub const FICLONERANGE: Ioctl = _IOW::<crate::file_clone_range>(0x94, 13) as Ioctl; 46*c9537f57SPatrick Williams 47*c9537f57SPatrick Williams // Defined in unix/linux_like/mod.rs 48*c9537f57SPatrick Williams // pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; 49*c9537f57SPatrick Williams@@ -248,49 +235,18 @@ pub const TUNGETVNETBE: Ioctl = 0x800454 50*c9537f57SPatrick Williams pub const TUNSETSTEERINGEBPF: Ioctl = 0x800454e0; 51*c9537f57SPatrick Williams pub const TUNSETFILTEREBPF: Ioctl = 0x800454e1; 52*c9537f57SPatrick Williams 53*c9537f57SPatrick Williams-cfg_if! { 54*c9537f57SPatrick Williams- // Those type are constructed using the _IOC macro 55*c9537f57SPatrick Williams- // DD-SS_SSSS_SSSS_SSSS-TTTT_TTTT-NNNN_NNNN 56*c9537f57SPatrick Williams- // where D stands for direction (either None (00), Read (01) or Write (11)) 57*c9537f57SPatrick Williams- // where S stands for size (int, long, struct...) 58*c9537f57SPatrick Williams- // where T stands for type ('f','v','X'...) 59*c9537f57SPatrick Williams- // where N stands for NR (NumbeR) 60*c9537f57SPatrick Williams- if #[cfg(any( 61*c9537f57SPatrick Williams- target_arch = "x86", 62*c9537f57SPatrick Williams- target_arch = "arm", 63*c9537f57SPatrick Williams- target_arch = "csky" 64*c9537f57SPatrick Williams- ))] { 65*c9537f57SPatrick Williams- pub const FS_IOC_GETFLAGS: Ioctl = 0x80046601; 66*c9537f57SPatrick Williams- pub const FS_IOC_SETFLAGS: Ioctl = 0x40046602; 67*c9537f57SPatrick Williams- pub const FS_IOC_GETVERSION: Ioctl = 0x80047601; 68*c9537f57SPatrick Williams- pub const FS_IOC_SETVERSION: Ioctl = 0x40047602; 69*c9537f57SPatrick Williams- pub const FS_IOC32_GETFLAGS: Ioctl = 0x80046601; 70*c9537f57SPatrick Williams- pub const FS_IOC32_SETFLAGS: Ioctl = 0x40046602; 71*c9537f57SPatrick Williams- pub const FS_IOC32_GETVERSION: Ioctl = 0x80047601; 72*c9537f57SPatrick Williams- pub const FS_IOC32_SETVERSION: Ioctl = 0x40047602; 73*c9537f57SPatrick Williams- pub const TUNATTACHFILTER: Ioctl = 0x400854d5; 74*c9537f57SPatrick Williams- pub const TUNDETACHFILTER: Ioctl = 0x400854d6; 75*c9537f57SPatrick Williams- pub const TUNGETFILTER: Ioctl = 0x800854db; 76*c9537f57SPatrick Williams- } else if #[cfg(any( 77*c9537f57SPatrick Williams- target_arch = "x86_64", 78*c9537f57SPatrick Williams- target_arch = "riscv64", 79*c9537f57SPatrick Williams- target_arch = "aarch64", 80*c9537f57SPatrick Williams- target_arch = "s390x", 81*c9537f57SPatrick Williams- target_arch = "loongarch64" 82*c9537f57SPatrick Williams- ))] { 83*c9537f57SPatrick Williams- pub const FS_IOC_GETFLAGS: Ioctl = 0x80086601; 84*c9537f57SPatrick Williams- pub const FS_IOC_SETFLAGS: Ioctl = 0x40086602; 85*c9537f57SPatrick Williams- pub const FS_IOC_GETVERSION: Ioctl = 0x80087601; 86*c9537f57SPatrick Williams- pub const FS_IOC_SETVERSION: Ioctl = 0x40087602; 87*c9537f57SPatrick Williams- pub const FS_IOC32_GETFLAGS: Ioctl = 0x80046601; 88*c9537f57SPatrick Williams- pub const FS_IOC32_SETFLAGS: Ioctl = 0x40046602; 89*c9537f57SPatrick Williams- pub const FS_IOC32_GETVERSION: Ioctl = 0x80047601; 90*c9537f57SPatrick Williams- pub const FS_IOC32_SETVERSION: Ioctl = 0x40047602; 91*c9537f57SPatrick Williams- pub const TUNATTACHFILTER: Ioctl = 0x401054d5; 92*c9537f57SPatrick Williams- pub const TUNDETACHFILTER: Ioctl = 0x401054d6; 93*c9537f57SPatrick Williams- pub const TUNGETFILTER: Ioctl = 0x801054db; 94*c9537f57SPatrick Williams- } 95*c9537f57SPatrick Williams-} 96*c9537f57SPatrick Williams+pub const FS_IOC_GETFLAGS: Ioctl = _IOR::<c_long>('f' as u32, 1) as Ioctl; 97*c9537f57SPatrick Williams+pub const FS_IOC_SETFLAGS: Ioctl = _IOW::<c_long>('f' as u32, 2) as Ioctl; 98*c9537f57SPatrick Williams+pub const FS_IOC_GETVERSION: Ioctl = _IOR::<c_long>('v' as u32, 1) as Ioctl; 99*c9537f57SPatrick Williams+pub const FS_IOC_SETVERSION: Ioctl = _IOW::<c_long>('v' as u32, 2) as Ioctl; 100*c9537f57SPatrick Williams+pub const FS_IOC32_GETFLAGS: Ioctl = _IOR::<c_int>('f' as u32, 1) as Ioctl; 101*c9537f57SPatrick Williams+pub const FS_IOC32_SETFLAGS: Ioctl = _IOW::<c_int>('f' as u32, 2) as Ioctl; 102*c9537f57SPatrick Williams+pub const FS_IOC32_GETVERSION: Ioctl = _IOR::<c_int>('v' as u32, 1) as Ioctl; 103*c9537f57SPatrick Williams+pub const FS_IOC32_SETVERSION: Ioctl = _IOW::<c_int>('v' as u32, 2) as Ioctl; 104*c9537f57SPatrick Williams+ 105*c9537f57SPatrick Williams+pub const TUNATTACHFILTER: Ioctl = _IOW::<crate::sock_fprog>('T' as u32, 213) as Ioctl; 106*c9537f57SPatrick Williams+pub const TUNDETACHFILTER: Ioctl = _IOW::<crate::sock_fprog>('T' as u32, 214) as Ioctl; 107*c9537f57SPatrick Williams+pub const TUNGETFILTER: Ioctl = _IOR::<crate::sock_fprog>('T' as u32, 219) as Ioctl; 108*c9537f57SPatrick Williams 109*c9537f57SPatrick Williams cfg_if! { 110*c9537f57SPatrick Williams if #[cfg(any(target_arch = "arm", target_arch = "s390x"))] { 111