From 565b2725a8c996b516c9293e9ffbcdb2f85ed6d1 Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Wed, 10 Jun 2026 19:04:15 +0200 Subject: [PATCH 1/3] linux(uclibc): add `cfg` for lfs bindings Add a `cfg` to enable LFS bindings under 32-bit targets. This does not apply to 64-bit targets. Their suffixed types are equivalent to their unsuffixed types. They unconditionally get both suffixed and unsuffixed types. This `cfg` replicates a build option upstream. Sources follow. - Upstream uclibc-ng sources showing `ino_t` defined in terms of its 64-bit variant, and the definition for the 64-bit variant. There's a "chain" of types that leads to the final type with which `ino64_t` is defined. This chain is made most obvious by the final type alias, which appends a `_TYPE` and prepends two underscores to the type identifier in question. Notice how the `__uquad_t` type is always defined as a 64-bit type, even on systems where that requires using a record type with a two-element array (32-bit per element). - Upstream uclibc-ng sources showing `off_t` defined in terms of its 64-bit variant when LFS64 support and `__USE_FILE_OFFSET64` are enabled. Much like the above, there's a "chain" of types leading to the type whose bitwidth is made clear. The chain is shortened to the last few types. - Upstream uclibc-ng sources showing `rlim_t` defined in terms of its 64-bit variant when LFS64 support and `__USE_FILE_OFFSET64` are enabled. This follows the same reasoning as the above. - Upstream uclibc-ng sources showing `blkcnt_t` defined in terms of its 64-bit variant. This follows the same reasoning as the above. - Upstream uclibc-ng sources showing `fsblckcnt_t` and `fsfilcnt_t` defined in terms of their 64-bit variants. This first of the below sources also includes references to the above types. --- build.rs | 9 +++++++ libc-test/build/main.rs | 4 ++++ src/unix/linux_like/linux/uclibc/arm/mod.rs | 8 ------- .../linux/uclibc/mips/mips32/mod.rs | 13 +++------- .../linux/uclibc/mips/mips64/mod.rs | 4 ---- src/unix/linux_like/linux/uclibc/mod.rs | 24 ++++++++++++++++++- .../linux_like/linux/uclibc/x86_64/mod.rs | 8 ------- 7 files changed, 39 insertions(+), 31 deletions(-) diff --git a/build.rs b/build.rs index 95fb1d1c6c00d..69a6ac6d8dc27 100644 --- a/build.rs +++ b/build.rs @@ -40,6 +40,8 @@ const ALLOWED_CFGS: &[&str] = &[ "musl_redir_time64", "vxworks_lt_25_09", "libc_pauthtest", + // Corresponds with `__USE_FILE_OFFSET64` in uClibc. + "uclibc_file_offset_bits64", ]; // Extra values to allow for check-cfg. @@ -238,6 +240,13 @@ fn main() { } } + if target_env == "uclibc" + && target_ptr_width == "32" + && env::var("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_OFF64").is_ok() + { + set_cfg("uclibc_file_offset_bits64") + } + // On CI: deny all warnings if libc_ci { set_cfg("libc_deny_warnings"); diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index a3404430c4151..3cb5c389e9d08 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -3983,6 +3983,10 @@ fn test_linux(t: &Target) { // glibc versions older than 2.29. .define("__GLIBC_USE_DEPRECATED_SCANF", None); + if uclibc && p32 && env::var("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_OFF64").is_ok() { + cfg.cfg("uclibc_file_offset_bits64", None); + } + config_gnu_bits(t, &mut cfg); // The L4Re libc headers contain some L4Re helper functions which are not needed for the libc // interface and must not be added to the libc crate diff --git a/src/unix/linux_like/linux/uclibc/arm/mod.rs b/src/unix/linux_like/linux/uclibc/arm/mod.rs index f8870d3267294..a032794937ecc 100644 --- a/src/unix/linux_like/linux/uclibc/arm/mod.rs +++ b/src/unix/linux_like/linux/uclibc/arm/mod.rs @@ -4,18 +4,10 @@ use crate::prelude::*; pub type wchar_t = c_uint; pub type clock_t = c_long; -pub type fsblkcnt_t = c_ulong; -pub type fsfilcnt_t = c_ulong; -pub type ino_t = c_ulong; -pub type off_t = c_long; pub type pthread_t = c_ulong; pub type nlink_t = c_uint; pub type blksize_t = c_long; -pub type blkcnt_t = c_long; - -pub type fsblkcnt64_t = u64; -pub type fsfilcnt64_t = u64; s! { pub struct cmsghdr { diff --git a/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs b/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs index 2c253f0164f11..1ce2000802801 100644 --- a/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs @@ -3,15 +3,8 @@ use crate::prelude::*; pub type clock_t = i32; pub type wchar_t = i32; -pub type off_t = i32; -pub type ino_t = u32; -pub type blkcnt_t = i32; pub type blksize_t = i32; pub type nlink_t = u32; -pub type fsblkcnt_t = c_ulong; -pub type fsfilcnt_t = c_ulong; -pub type fsblkcnt64_t = u64; -pub type fsfilcnt64_t = u64; s! { pub struct stat { @@ -24,7 +17,7 @@ s! { pub st_gid: crate::gid_t, pub st_rdev: crate::dev_t, pub st_pad2: [c_long; 1], - pub st_size: off_t, + pub st_size: crate::off_t, st_pad3: Padding, pub st_atime: crate::time_t, pub st_atime_nsec: c_long, @@ -227,8 +220,8 @@ s! { pub struct flock { pub l_type: c_short, pub l_whence: c_short, - pub l_start: off_t, - pub l_len: off_t, + pub l_start: crate::off_t, + pub l_len: crate::off_t, pub l_sysid: c_long, pub l_pid: crate::pid_t, pad: Padding<[c_long; 4]>, diff --git a/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs b/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs index a6a63a33a93b3..08a046a9ab5fd 100644 --- a/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs @@ -1,11 +1,7 @@ use crate::off64_t; use crate::prelude::*; -pub type blkcnt_t = i64; pub type blksize_t = i64; -pub type fsblkcnt_t = c_ulong; -pub type fsfilcnt_t = c_ulong; -pub type ino_t = u64; pub type nlink_t = u64; pub type off_t = i64; pub type wchar_t = i32; diff --git a/src/unix/linux_like/linux/uclibc/mod.rs b/src/unix/linux_like/linux/uclibc/mod.rs index 4bc4848b429fe..d0766230911b2 100644 --- a/src/unix/linux_like/linux/uclibc/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mod.rs @@ -8,7 +8,6 @@ pub type shmatt_t = c_ulong; pub type msgqnum_t = c_ulong; pub type msglen_t = c_ulong; pub type regoff_t = c_int; -pub type rlim_t = c_ulong; pub type __rlimit_resource_t = c_ulong; pub type __priority_which_t = c_uint; @@ -23,6 +22,29 @@ cfg_if! { } } +cfg_if! { + if #[cfg(uclibc_file_offset_bits64)] { + pub type ino_t = u64; + pub type off_t = i64; + pub type rlim_t = u64; + pub type blkcnt_t = i64; + pub type fsblkcnt_t = u64; + pub type fsfilcnt_t = u64; + } else { + pub type ino_t = c_ulong; + pub type off_t = c_long; + pub type rlim_t = c_ulong; + pub type blkcnt_t = c_long; + pub type fsblkcnt_t = c_ulong; + pub type fsfilcnt_t = c_ulong; + } +} + +// Other LFS types have definitions provided by top-level modules (i.e. `unix`, +// `linux_like` and `linux`.) +pub type fsblkcnt64_t = u64; +pub type fsfilcnt64_t = u64; + cfg_if! { if #[cfg(doc)] { // Used in `linux::arch` to define ioctl constants. diff --git a/src/unix/linux_like/linux/uclibc/x86_64/mod.rs b/src/unix/linux_like/linux/uclibc/x86_64/mod.rs index af4bedbc082cc..0d150b9bfc976 100644 --- a/src/unix/linux_like/linux/uclibc/x86_64/mod.rs +++ b/src/unix/linux_like/linux/uclibc/x86_64/mod.rs @@ -3,13 +3,8 @@ use crate::off64_t; use crate::prelude::*; -pub type blkcnt_t = i64; pub type blksize_t = i64; pub type clock_t = i64; -pub type fsblkcnt_t = c_ulong; -pub type fsfilcnt_t = c_ulong; -pub type fsword_t = c_long; -pub type ino_t = c_ulong; pub type nlink_t = c_uint; pub type off_t = c_long; // [uClibc docs] Note stat64 has the same shape as stat for x86-64. @@ -17,9 +12,6 @@ pub type stat64 = stat; pub type wchar_t = c_int; pub type pthread_t = c_ulong; -pub type fsblkcnt64_t = u64; -pub type fsfilcnt64_t = u64; - s! { pub struct ipc_perm { pub __key: crate::key_t, From b17843ba3707f8ab93332d37286894f41c638a39 Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Thu, 25 Jun 2026 11:22:32 +0200 Subject: [PATCH 2/3] linux(uclibc): fix `stat` struct family defs Fixe the definitions of: - `stat`. - `statfs`. - `statvfs`. The analogous 64-bit types were also tweaked. They are equivalent on some target architectures. They only needed to be aliased. Sources follow. - Upstream uclibc-ng sources showing how `statvfs` and `statvfs64` are independent, but like the above, have equivalent definitions when `__USE_FILE_OFFSET64` is defined. This also shows how there does not seem to be a need for the fields to be reordered depending on the system's endianness. - Upstream uclibc-ng sources showing how `statfs` and `statfs64` are independent, but like the above, have equivalent definitions when `__USE_FILE_OFFSET64` is defined. A bunch of field types were changed to both accurately reflect the upstream types used, and to add missing fields. The former has not been documented in full in the below sources because the types involved are already part of the sources cited in other list items. Some required special-casing in MIPS platforms has been necessary, as there were fields that had altogether different types. These were only ever so slightly tweaked for the same reasons as above. `statfs` in MIPS got unified as the definitions for both the o32 and N64/N32 ABIs are equivalent under `__USE_FILE_OFFSET64`. - Upstream uclibc-ng sources showing the same as the above but for `stat` and `stat64`. There was also some special casing required in MIPS platforms, though the definitions for both x86_64 and arm converged. These have been kept in their corresponding modules because there's need for MIPS to have their own and it was decided against a top-level, field-specific `cfg`. --- src/unix/linux_like/linux/uclibc/arm/mod.rs | 75 +++++++++--------- .../linux/uclibc/mips/mips32/mod.rs | 78 ++++++------------- .../linux/uclibc/mips/mips64/mod.rs | 70 ++++------------- src/unix/linux_like/linux/uclibc/mips/mod.rs | 34 ++++++++ src/unix/linux_like/linux/uclibc/mod.rs | 38 ++++++--- .../linux_like/linux/uclibc/x86_64/mod.rs | 54 +++++-------- 6 files changed, 162 insertions(+), 187 deletions(-) diff --git a/src/unix/linux_like/linux/uclibc/arm/mod.rs b/src/unix/linux_like/linux/uclibc/arm/mod.rs index a032794937ecc..bd417cefd594c 100644 --- a/src/unix/linux_like/linux/uclibc/arm/mod.rs +++ b/src/unix/linux_like/linux/uclibc/arm/mod.rs @@ -1,4 +1,3 @@ -use crate::off64_t; use crate::prelude::*; pub type wchar_t = c_uint; @@ -31,47 +30,68 @@ s! { } pub struct stat { - pub st_dev: c_ulonglong, + pub st_dev: crate::dev_t, + + #[cfg(not(uclibc_file_offset_bits64))] __pad1: Padding, + #[cfg(not(uclibc_file_offset_bits64))] pub st_ino: crate::ino_t, + + #[cfg(uclibc_file_offset_bits64)] + __pad1: Padding, + #[cfg(uclibc_file_offset_bits64)] + pub __st_ino: crate::ino_t, + pub st_mode: crate::mode_t, pub st_nlink: crate::nlink_t, pub st_uid: crate::uid_t, pub st_gid: crate::gid_t, - pub st_rdev: c_ulonglong, + pub st_rdev: crate::dev_t, + + #[cfg(not(uclibc_file_offset_bits64))] __pad2: Padding, - pub st_size: off_t, + + #[cfg(uclibc_file_offset_bits64)] + __pad2: Padding, + + pub st_size: crate::off_t, pub st_blksize: crate::blksize_t, pub st_blocks: crate::blkcnt_t, pub st_atime: crate::time_t, - pub st_atime_nsec: c_long, + pub st_atime_nsec: c_ulong, pub st_mtime: crate::time_t, - pub st_mtime_nsec: c_long, + pub st_mtime_nsec: c_ulong, pub st_ctime: crate::time_t, - pub st_ctime_nsec: c_long, - __unused4: Padding, - __unused5: Padding, + pub st_ctime_nsec: c_ulong, + + #[cfg(not(uclibc_file_offset_bits64))] + __uclibc_unused4: Padding, + #[cfg(not(uclibc_file_offset_bits64))] + __uclibc_unused5: Padding, + + #[cfg(uclibc_file_offset_bits64)] + pub st_ino: crate::ino_t, } pub struct stat64 { - pub st_dev: c_ulonglong, - pub __pad1: c_uint, + pub st_dev: crate::dev_t, + __pad1: Padding, pub __st_ino: crate::ino_t, pub st_mode: crate::mode_t, pub st_nlink: crate::nlink_t, pub st_uid: crate::uid_t, pub st_gid: crate::gid_t, - pub st_rdev: c_ulonglong, - pub __pad2: c_uint, - pub st_size: off64_t, + pub st_rdev: crate::dev_t, + __pad2: Padding, + pub st_size: crate::off64_t, pub st_blksize: crate::blksize_t, pub st_blocks: crate::blkcnt64_t, pub st_atime: crate::time_t, - pub st_atime_nsec: c_long, + pub st_atime_nsec: c_ulong, pub st_mtime: crate::time_t, - pub st_mtime_nsec: c_long, + pub st_mtime_nsec: c_ulong, pub st_ctime: crate::time_t, - pub st_ctime_nsec: c_long, + pub st_ctime_nsec: c_ulong, pub st_ino: crate::ino64_t, } @@ -113,7 +133,7 @@ s! { pub f_namelen: c_int, pub f_frsize: c_int, pub f_flags: c_int, - pub f_spare: [c_int; 4], + f_spare: Padding<[c_int; 4]>, } pub struct statfs64 { @@ -124,27 +144,12 @@ s! { pub f_bavail: crate::fsblkcnt64_t, pub f_files: crate::fsfilcnt64_t, pub f_ffree: crate::fsfilcnt64_t, + pub f_fsid: crate::fsid_t, pub f_namelen: c_int, pub f_frsize: c_int, pub f_flags: c_int, - pub f_spare: [c_int; 4], - } - - pub struct statvfs64 { - pub f_bsize: c_ulong, - pub f_frsize: c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: c_ulong, - __f_unused: Padding, - pub f_flag: c_ulong, - pub f_namemax: c_ulong, - __f_spare: [c_int; 6], + f_spare: Padding<[c_int; 4]>, } pub struct sigset_t { diff --git a/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs b/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs index 1ce2000802801..229446b2b9bef 100644 --- a/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs @@ -1,4 +1,3 @@ -use crate::off64_t; use crate::prelude::*; pub type clock_t = i32; @@ -16,16 +15,29 @@ s! { pub st_uid: crate::uid_t, pub st_gid: crate::gid_t, pub st_rdev: crate::dev_t, - pub st_pad2: [c_long; 1], + + #[cfg(not(uclibc_file_offset_bits64))] + st_pad2: Padding<[c_long; 1]>, + + #[cfg(uclibc_file_offset_bits64)] + st_pad2: Padding<[c_long; 2]>, + pub st_size: crate::off_t, + + #[cfg(not(uclibc_file_offset_bits64))] st_pad3: Padding, + pub st_atime: crate::time_t, - pub st_atime_nsec: c_long, + pub st_atime_nsec: c_ulong, pub st_mtime: crate::time_t, - pub st_mtime_nsec: c_long, + pub st_mtime_nsec: c_ulong, pub st_ctime: crate::time_t, - pub st_ctime_nsec: c_long, + pub st_ctime_nsec: c_ulong, pub st_blksize: crate::blksize_t, + + #[cfg(uclibc_file_offset_bits64)] + st_pad4: Padding, + pub st_blocks: crate::blkcnt_t, st_pad5: Padding<[c_long; 14]>, } @@ -40,33 +52,17 @@ s! { pub st_gid: crate::gid_t, pub st_rdev: crate::dev_t, st_pad2: Padding<[c_long; 2]>, - pub st_size: off64_t, + pub st_size: crate::off64_t, pub st_atime: crate::time_t, - pub st_atime_nsec: c_long, + pub st_atime_nsec: c_ulong, pub st_mtime: crate::time_t, - pub st_mtime_nsec: c_long, + pub st_mtime_nsec: c_ulong, pub st_ctime: crate::time_t, - pub st_ctime_nsec: c_long, + pub st_ctime_nsec: c_ulong, pub st_blksize: crate::blksize_t, st_pad3: Padding, pub st_blocks: crate::blkcnt64_t, - st_pad5: Padding<[c_long; 14]>, - } - - pub struct statvfs64 { - pub f_bsize: c_ulong, - pub f_frsize: c_ulong, - pub f_blocks: crate::fsblkcnt64_t, - pub f_bfree: crate::fsblkcnt64_t, - pub f_bavail: crate::fsblkcnt64_t, - pub f_files: crate::fsfilcnt64_t, - pub f_ffree: crate::fsfilcnt64_t, - pub f_favail: crate::fsfilcnt64_t, - pub f_fsid: c_ulong, - pub __f_unused: c_int, - pub f_flag: c_ulong, - pub f_namemax: c_ulong, - pub __f_spare: [c_int; 6], + st_pad4: Padding<[c_long; 14]>, } pub struct pthread_attr_t { @@ -162,36 +158,6 @@ s! { __glibc_reserved5: Padding, } - pub struct statfs { - pub f_type: c_long, - pub f_bsize: c_long, - pub f_frsize: c_long, - pub f_blocks: crate::fsblkcnt_t, - pub f_bfree: crate::fsblkcnt_t, - pub f_files: crate::fsblkcnt_t, - pub f_ffree: crate::fsblkcnt_t, - pub f_bavail: crate::fsblkcnt_t, - pub f_fsid: crate::fsid_t, - - pub f_namelen: c_long, - f_spare: [c_long; 6], - } - - pub struct statfs64 { - pub f_type: c_long, - pub f_bsize: c_long, - pub f_frsize: c_long, - pub f_blocks: crate::fsblkcnt64_t, - pub f_bfree: crate::fsblkcnt64_t, - pub f_files: crate::fsblkcnt64_t, - pub f_ffree: crate::fsblkcnt64_t, - pub f_bavail: crate::fsblkcnt64_t, - pub f_fsid: crate::fsid_t, - pub f_namelen: c_long, - pub f_flags: c_long, - pub f_spare: [c_long; 5], - } - pub struct msghdr { pub msg_name: *mut c_void, pub msg_namelen: crate::socklen_t, diff --git a/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs b/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs index 08a046a9ab5fd..62faf98c48dec 100644 --- a/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs @@ -1,4 +1,3 @@ -use crate::off64_t; use crate::prelude::*; pub type blksize_t = i64; @@ -6,52 +5,30 @@ pub type nlink_t = u64; pub type off_t = i64; pub type wchar_t = i32; +pub type stat64 = stat; + s! { pub struct stat { - pub st_dev: c_ulong, - st_pad1: Padding<[c_long; 2]>, + pub st_dev: c_uint, + st_pad1: Padding<[c_int; 3]>, pub st_ino: crate::ino_t, pub st_mode: crate::mode_t, pub st_nlink: crate::nlink_t, pub st_uid: crate::uid_t, pub st_gid: crate::gid_t, - pub st_rdev: c_ulong, - st_pad2: Padding<[c_ulong; 1]>, - pub st_size: off_t, - st_pad3: Padding, - pub st_atime: crate::time_t, - pub st_atime_nsec: c_long, - pub st_mtime: crate::time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: crate::time_t, - pub st_ctime_nsec: c_long, - pub st_blksize: crate::blksize_t, - st_pad4: Padding, + pub st_rdev: c_uint, + st_pad2: Padding<[c_uint; 3]>, + pub st_size: crate::off_t, + pub st_atime: c_int, + pub st_atime_nsec: c_int, + pub st_mtime: c_int, + pub st_mtime_nsec: c_int, + pub st_ctime: c_int, + pub st_ctime_nsec: c_int, + pub st_blksize: c_int, + st_pad3: Padding, pub st_blocks: crate::blkcnt_t, - st_pad5: Padding<[c_long; 7]>, - } - - pub struct stat64 { - pub st_dev: c_ulong, - st_pad1: Padding<[c_long; 2]>, - pub st_ino: crate::ino64_t, - pub st_mode: crate::mode_t, - pub st_nlink: crate::nlink_t, - pub st_uid: crate::uid_t, - pub st_gid: crate::gid_t, - pub st_rdev: c_ulong, - st_pad2: Padding<[c_long; 2]>, - pub st_size: off64_t, - pub st_atime: crate::time_t, - pub st_atime_nsec: c_long, - pub st_mtime: crate::time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: crate::time_t, - pub st_ctime_nsec: c_long, - pub st_blksize: crate::blksize_t, - st_pad3: Padding, - pub st_blocks: crate::blkcnt64_t, - st_pad5: Padding<[c_long; 7]>, + st_pad4: Padding<[c_int; 14]>, } pub struct pthread_attr_t { @@ -123,21 +100,6 @@ s! { __glibc_reserved5: Padding, } - pub struct statfs { - pub f_type: c_long, - pub f_bsize: c_long, - pub f_frsize: c_long, - pub f_blocks: crate::fsblkcnt_t, - pub f_bfree: crate::fsblkcnt_t, - pub f_files: crate::fsblkcnt_t, - pub f_ffree: crate::fsblkcnt_t, - pub f_bavail: crate::fsblkcnt_t, - pub f_fsid: crate::fsid_t, - - pub f_namelen: c_long, - f_spare: [c_long; 6], - } - pub struct msghdr { pub msg_name: *mut c_void, pub msg_namelen: crate::socklen_t, diff --git a/src/unix/linux_like/linux/uclibc/mips/mod.rs b/src/unix/linux_like/linux/uclibc/mips/mod.rs index 8d17aa8e98e9a..c7c37b7318ea2 100644 --- a/src/unix/linux_like/linux/uclibc/mips/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mips/mod.rs @@ -2,6 +2,40 @@ use crate::prelude::*; pub type pthread_t = c_ulong; +s! { + pub struct statfs { + pub f_type: c_long, + pub f_bsize: c_long, + pub f_frsize: c_long, + pub f_blocks: crate::fsblkcnt_t, + pub f_bfree: crate::fsblkcnt_t, + pub f_files: crate::fsblkcnt_t, + pub f_ffree: crate::fsblkcnt_t, + pub f_bavail: crate::fsblkcnt_t, + + pub f_fsid: crate::fsid_t, + pub f_namelen: c_long, + pub f_flags: c_long, + f_spare: Padding<[c_long; 5]>, + } + + pub struct statfs64 { + pub f_type: c_long, + pub f_bsize: c_long, + pub f_frsize: c_long, + pub f_blocks: crate::fsblkcnt64_t, + pub f_bfree: crate::fsblkcnt64_t, + pub f_files: crate::fsblkcnt64_t, + pub f_ffree: crate::fsblkcnt64_t, + pub f_bavail: crate::fsblkcnt64_t, + + pub f_fsid: crate::fsid_t, + pub f_namelen: c_long, + pub f_flags: c_long, + f_spare: Padding<[c_long; 5]>, + } +} + pub const SFD_CLOEXEC: c_int = 0x080000; pub const NCCS: usize = 32; diff --git a/src/unix/linux_like/linux/uclibc/mod.rs b/src/unix/linux_like/linux/uclibc/mod.rs index d0766230911b2..5bfa522d7263f 100644 --- a/src/unix/linux_like/linux/uclibc/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mod.rs @@ -1,7 +1,3 @@ -// FIXME(ulibc): this module has definitions that are redundant with the parent -#![allow(dead_code)] - -use crate::off64_t; use crate::prelude::*; pub type shmatt_t = c_ulong; @@ -66,15 +62,29 @@ s! { pub f_files: crate::fsfilcnt_t, pub f_ffree: crate::fsfilcnt_t, pub f_favail: crate::fsfilcnt_t, - #[cfg(target_endian = "little")] pub f_fsid: c_ulong, #[cfg(target_pointer_width = "32")] __f_unused: Padding, - #[cfg(target_endian = "big")] + pub f_flag: c_ulong, + pub f_namemax: c_ulong, + __f_spare: Padding<[c_int; 6]>, + } + + pub struct statvfs64 { + pub f_bsize: c_ulong, + pub f_frsize: c_ulong, + pub f_blocks: crate::fsblkcnt64_t, + pub f_bfree: crate::fsblkcnt64_t, + pub f_bavail: crate::fsblkcnt64_t, + pub f_files: crate::fsfilcnt64_t, + pub f_ffree: crate::fsfilcnt64_t, + pub f_favail: crate::fsfilcnt64_t, pub f_fsid: c_ulong, + #[cfg(target_pointer_width = "32")] + __f_unused: Padding, pub f_flag: c_ulong, pub f_namemax: c_ulong, - __f_spare: [c_int; 6], + __f_spare: Padding<[c_int; 6]>, } pub struct regex_t { @@ -420,8 +430,18 @@ extern "C" { flags: c_int, ) -> c_int; - pub fn pwritev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off64_t) -> ssize_t; - pub fn preadv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off64_t) -> ssize_t; + pub fn pwritev( + fd: c_int, + iov: *const crate::iovec, + iovcnt: c_int, + offset: crate::off64_t, + ) -> ssize_t; + pub fn preadv( + fd: c_int, + iov: *const crate::iovec, + iovcnt: c_int, + offset: crate::off64_t, + ) -> ssize_t; pub fn sethostid(hostid: c_long) -> c_int; pub fn fanotify_mark( diff --git a/src/unix/linux_like/linux/uclibc/x86_64/mod.rs b/src/unix/linux_like/linux/uclibc/x86_64/mod.rs index 0d150b9bfc976..0fbbcf98bebe4 100644 --- a/src/unix/linux_like/linux/uclibc/x86_64/mod.rs +++ b/src/unix/linux_like/linux/uclibc/x86_64/mod.rs @@ -1,6 +1,5 @@ //! Definitions for uclibc on 64bit systems -use crate::off64_t; use crate::prelude::*; pub type blksize_t = i64; @@ -12,6 +11,8 @@ pub type stat64 = stat; pub type wchar_t = c_int; pub type pthread_t = c_ulong; +pub type stat64 = stat; + s! { pub struct ipc_perm { pub __key: crate::key_t, @@ -99,7 +100,7 @@ s! { } pub struct stat { - pub st_dev: c_ulong, + pub st_dev: crate::dev_t, pub st_ino: crate::ino_t, // According to uclibc/libc/sysdeps/linux/x86_64/bits/stat.h, order of // nlink and mode are swapped on 64 bit systems. @@ -107,8 +108,9 @@ s! { pub st_mode: crate::mode_t, pub st_uid: crate::uid_t, pub st_gid: crate::gid_t, - pub st_rdev: c_ulong, // dev_t - pub st_size: off_t, // file size + __pad0: Padding, + pub st_rdev: crate::dev_t, // dev_t + pub st_size: crate::off_t, // file size pub st_blksize: crate::blksize_t, pub st_blocks: crate::blkcnt_t, pub st_atime: crate::time_t, @@ -117,7 +119,7 @@ s! { pub st_mtime_nsec: c_ulong, pub st_ctime: crate::time_t, pub st_ctime_nsec: c_ulong, - st_pad4: Padding<[c_long; 3]>, + __uclibc_unused: Padding<[c_long; 3]>, } // FIXME(1.0): This should not implement `PartialEq` @@ -137,49 +139,35 @@ s! { } pub struct statfs { - // FIXME(ulibc) - pub f_type: fsword_t, - pub f_bsize: fsword_t, + pub f_type: c_long, + pub f_bsize: c_long, pub f_blocks: crate::fsblkcnt_t, pub f_bfree: crate::fsblkcnt_t, pub f_bavail: crate::fsblkcnt_t, pub f_files: crate::fsfilcnt_t, pub f_ffree: crate::fsfilcnt_t, + pub f_fsid: crate::fsid_t, - pub f_namelen: fsword_t, - pub f_frsize: fsword_t, - f_spare: [fsword_t; 5], + pub f_namelen: c_long, + pub f_frsize: c_long, + pub f_flags: c_long, + f_spare: Padding<[c_long; 4]>, } pub struct statfs64 { - pub f_type: c_int, - pub f_bsize: c_int, + pub f_type: c_long, + pub f_bsize: c_long, pub f_blocks: crate::fsblkcnt64_t, pub f_bfree: crate::fsblkcnt64_t, pub f_bavail: crate::fsblkcnt64_t, pub f_files: crate::fsfilcnt64_t, pub f_ffree: crate::fsfilcnt64_t, - pub f_fsid: crate::fsid_t, - pub f_namelen: c_int, - pub f_frsize: c_int, - pub f_flags: c_int, - pub f_spare: [c_int; 4], - } - pub struct statvfs64 { - pub f_bsize: c_ulong, - pub f_frsize: c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: c_ulong, - __f_unused: Padding, - pub f_flag: c_ulong, - pub f_namemax: c_ulong, - __f_spare: [c_int; 6], + pub f_fsid: crate::fsid_t, + pub f_namelen: c_long, + pub f_frsize: c_long, + pub f_flags: c_long, + f_spare: Padding<[c_long; 4]>, } pub struct msghdr { From e1f4a8c74247ea69b02f60a9e190da23caa455c8 Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Thu, 25 Jun 2026 11:24:50 +0200 Subject: [PATCH 3/3] linux(uclibc): fix cross-architecture `flock` def Replace existing definitions. They were not correct under MIPS. This target needed some special casing. Sources follow. - Upstream uclibc-ng sources showing how `flock` and `flock64` are independent, but when defined with `__USE_FILE_OFFSET64`, will end up having the same record layout. The second source shows how this definition can actually be unified across all child modules to the `uclibc` module because the fields that are conditionally compiled under MIPS will never be any different if `__USE_FILE_OFFSET64` is defined. --- src/unix/linux_like/linux/uclibc/arm/mod.rs | 16 ++++++++-------- .../linux_like/linux/uclibc/mips/mips32/mod.rs | 10 ---------- src/unix/linux_like/linux/uclibc/mips/mod.rs | 12 ++++++++++++ src/unix/linux_like/linux/uclibc/mod.rs | 8 ++++++++ src/unix/linux_like/linux/uclibc/x86_64/mod.rs | 8 ++++++++ 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/unix/linux_like/linux/uclibc/arm/mod.rs b/src/unix/linux_like/linux/uclibc/arm/mod.rs index bd417cefd594c..229ab07883964 100644 --- a/src/unix/linux_like/linux/uclibc/arm/mod.rs +++ b/src/unix/linux_like/linux/uclibc/arm/mod.rs @@ -9,6 +9,14 @@ pub type nlink_t = c_uint; pub type blksize_t = c_long; s! { + pub struct flock { + pub l_type: c_short, + pub l_whence: c_short, + pub l_start: crate::off_t, + pub l_len: crate::off_t, + pub l_pid: crate::pid_t, + } + pub struct cmsghdr { pub cmsg_len: size_t, pub cmsg_level: c_int, @@ -95,14 +103,6 @@ s! { pub st_ino: crate::ino64_t, } - pub struct flock { - pub l_type: c_short, - pub l_whence: c_short, - pub l_start: off_t, - pub l_len: off_t, - pub l_pid: crate::pid_t, - } - pub struct sysinfo { pub uptime: c_long, pub loads: [c_ulong; 3], diff --git a/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs b/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs index 229446b2b9bef..51a4c3c22271b 100644 --- a/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs @@ -183,16 +183,6 @@ s! { pub c_cc: [crate::cc_t; crate::NCCS], } - pub struct flock { - pub l_type: c_short, - pub l_whence: c_short, - pub l_start: crate::off_t, - pub l_len: crate::off_t, - pub l_sysid: c_long, - pub l_pid: crate::pid_t, - pad: Padding<[c_long; 4]>, - } - pub struct sysinfo { pub uptime: c_long, pub loads: [c_ulong; 3], diff --git a/src/unix/linux_like/linux/uclibc/mips/mod.rs b/src/unix/linux_like/linux/uclibc/mips/mod.rs index c7c37b7318ea2..a5e209ea4ca8b 100644 --- a/src/unix/linux_like/linux/uclibc/mips/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mips/mod.rs @@ -34,6 +34,18 @@ s! { pub f_flags: c_long, f_spare: Padding<[c_long; 5]>, } + + pub struct flock { + pub l_type: c_short, + pub l_whence: c_short, + pub l_start: crate::off_t, + pub l_len: crate::off_t, + #[cfg(not(all(uclibc_file_offset_bits64, target_arch = "mips64")))] + pub l_sysid: c_long, + pub l_pid: crate::pid_t, + #[cfg(not(all(uclibc_file_offset_bits64, target_arch = "mips64")))] + pad: [c_long; 4], + } } pub const SFD_CLOEXEC: c_int = 0x080000; diff --git a/src/unix/linux_like/linux/uclibc/mod.rs b/src/unix/linux_like/linux/uclibc/mod.rs index 5bfa522d7263f..1f7bb70d13acf 100644 --- a/src/unix/linux_like/linux/uclibc/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mod.rs @@ -52,6 +52,14 @@ cfg_if! { } s! { + pub struct flock64 { + pub l_type: c_short, + pub l_whence: c_short, + pub l_start: crate::off64_t, + pub l_len: crate::off64_t, + pub l_pid: crate::pid_t, + } + pub struct statvfs { // Different than GNU! pub f_bsize: c_ulong, diff --git a/src/unix/linux_like/linux/uclibc/x86_64/mod.rs b/src/unix/linux_like/linux/uclibc/x86_64/mod.rs index 0fbbcf98bebe4..cc286d918436e 100644 --- a/src/unix/linux_like/linux/uclibc/x86_64/mod.rs +++ b/src/unix/linux_like/linux/uclibc/x86_64/mod.rs @@ -14,6 +14,14 @@ pub type pthread_t = c_ulong; pub type stat64 = stat; s! { + pub struct flock { + pub l_type: c_short, + pub l_whence: c_short, + pub l_start: crate::off_t, + pub l_len: crate::off_t, + pub l_pid: crate::pid_t, + } + pub struct ipc_perm { pub __key: crate::key_t, pub uid: crate::uid_t,