Skip to content

Commit c120d9a

Browse files
committed
linux(uclibc): change file offset bindings
The currently exposed bindings to file offset types and routines are often found to be either lacking or incorrect in the current worktree. This has been fixed by means of changing multiple type definitions across child modules of the `linux/uclibc` module, such that a more cohesive interface is exposed. Types with LFS64 variants in 32-bit platforms will now have equivalent definitions to their "unsuffixed" variants if the `uclibc_file_offset_bits` `cfg` is set. In 64-bit machine word targets, both the unsuffixed and suffixed types are unconditionally exposed with the same bit width.
1 parent 413bb61 commit c120d9a

7 files changed

Lines changed: 231 additions & 265 deletions

File tree

build.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const ALLOWED_CFGS: &[&str] = &[
3535
// Corresponds to `_REDIR_TIME64` in musl: symbol redirects to __*_time64
3636
"musl_redir_time64",
3737
"vxworks_lt_25_09",
38+
// Corresponds with `__USE_FILE_OFFSET64` in uClibc.
39+
"uclibc_file_offset_bits64",
3840
];
3941

4042
// Extra values to allow for check-cfg.
@@ -131,11 +133,6 @@ fn main() {
131133
}
132134
}
133135

134-
let uclibc_use_time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64");
135-
if target_env == "uclibc" && uclibc_use_time64 {
136-
set_cfg("linux_time_bits64");
137-
}
138-
139136
let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok();
140137
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64");
141138
if linux_time_bits64 {
@@ -180,6 +177,13 @@ fn main() {
180177
}
181178
}
182179

180+
if target_env == "uclibc"
181+
&& target_ptr_width == "32"
182+
&& env::var("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_FILE_OFFSET_BITS").is_ok()
183+
{
184+
set_cfg("uclibc_file_offset_bits64");
185+
}
186+
183187
// On CI: deny all warnings
184188
if libc_ci {
185189
set_cfg("libc_deny_warnings");

src/unix/linux_like/linux/uclibc/arm/mod.rs

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::off64_t;
21
use crate::prelude::*;
32

43
pub type wchar_t = c_uint;
@@ -15,22 +14,23 @@ cfg_if! {
1514
}
1615

1716
pub type clock_t = c_long;
18-
pub type fsblkcnt_t = c_ulong;
19-
pub type fsfilcnt_t = c_ulong;
20-
pub type ino_t = c_ulong;
21-
pub type off_t = c_long;
2217
pub type pthread_t = c_ulong;
2318

2419
pub type nlink_t = c_uint;
2520
pub type blksize_t = c_long;
26-
pub type blkcnt_t = c_long;
2721

28-
pub type fsblkcnt64_t = u64;
29-
pub type fsfilcnt64_t = u64;
3022
pub type __u64 = c_ulonglong;
3123
pub type __s64 = c_longlong;
3224

3325
s! {
26+
pub struct flock {
27+
pub l_type: c_short,
28+
pub l_whence: c_short,
29+
pub l_start: crate::off_t,
30+
pub l_len: crate::off_t,
31+
pub l_pid: crate::pid_t,
32+
}
33+
3434
pub struct cmsghdr {
3535
pub cmsg_len: size_t,
3636
pub cmsg_level: c_int,
@@ -52,58 +52,71 @@ s! {
5252
}
5353

5454
pub struct stat {
55-
pub st_dev: c_ulonglong,
55+
pub st_dev: crate::dev_t,
56+
57+
#[cfg(not(uclibc_file_offset_bits64))]
5658
__pad1: Padding<c_ushort>,
59+
#[cfg(not(uclibc_file_offset_bits64))]
5760
pub st_ino: crate::ino_t,
61+
62+
#[cfg(uclibc_file_offset_bits64)]
63+
__pad1: Padding<c_uint>,
64+
#[cfg(uclibc_file_offset_bits64)]
65+
pub __st_ino: crate::ino_t,
66+
5867
pub st_mode: crate::mode_t,
5968
pub st_nlink: crate::nlink_t,
6069
pub st_uid: crate::uid_t,
6170
pub st_gid: crate::gid_t,
62-
pub st_rdev: c_ulonglong,
71+
pub st_rdev: crate::dev_t,
72+
73+
#[cfg(not(uclibc_file_offset_bits64))]
6374
__pad2: Padding<c_ushort>,
64-
pub st_size: off_t,
75+
76+
#[cfg(uclibc_file_offset_bits64)]
77+
__pad2: Padding<c_uint>,
78+
79+
pub st_size: crate::off_t,
6580
pub st_blksize: crate::blksize_t,
6681
pub st_blocks: crate::blkcnt_t,
6782
pub st_atime: crate::time_t,
68-
pub st_atime_nsec: c_long,
83+
pub st_atime_nsec: c_ulong,
6984
pub st_mtime: crate::time_t,
70-
pub st_mtime_nsec: c_long,
85+
pub st_mtime_nsec: c_ulong,
7186
pub st_ctime: crate::time_t,
72-
pub st_ctime_nsec: c_long,
73-
__unused4: Padding<c_ulong>,
74-
__unused5: Padding<c_ulong>,
87+
pub st_ctime_nsec: c_ulong,
88+
89+
#[cfg(not(uclibc_file_offset_bits64))]
90+
__uclibc_unused4: Padding<c_ulong>,
91+
#[cfg(not(uclibc_file_offset_bits64))]
92+
__uclibc_unused5: Padding<c_ulong>,
93+
94+
#[cfg(uclibc_file_offset_bits64)]
95+
pub st_ino: crate::ino_t,
7596
}
7697

7798
pub struct stat64 {
78-
pub st_dev: c_ulonglong,
79-
pub __pad1: c_uint,
99+
pub st_dev: crate::dev_t,
100+
__pad1: Padding<c_uint>,
80101
pub __st_ino: crate::ino_t,
81102
pub st_mode: crate::mode_t,
82103
pub st_nlink: crate::nlink_t,
83104
pub st_uid: crate::uid_t,
84105
pub st_gid: crate::gid_t,
85-
pub st_rdev: c_ulonglong,
86-
pub __pad2: c_uint,
87-
pub st_size: off64_t,
106+
pub st_rdev: crate::dev_t,
107+
__pad2: Padding<c_uint>,
108+
pub st_size: crate::off64_t,
88109
pub st_blksize: crate::blksize_t,
89110
pub st_blocks: crate::blkcnt64_t,
90111
pub st_atime: crate::time_t,
91-
pub st_atime_nsec: c_long,
112+
pub st_atime_nsec: c_ulong,
92113
pub st_mtime: crate::time_t,
93-
pub st_mtime_nsec: c_long,
114+
pub st_mtime_nsec: c_ulong,
94115
pub st_ctime: crate::time_t,
95-
pub st_ctime_nsec: c_long,
116+
pub st_ctime_nsec: c_ulong,
96117
pub st_ino: crate::ino64_t,
97118
}
98119

99-
pub struct flock {
100-
pub l_type: c_short,
101-
pub l_whence: c_short,
102-
pub l_start: off_t,
103-
pub l_len: off_t,
104-
pub l_pid: crate::pid_t,
105-
}
106-
107120
pub struct sysinfo {
108121
pub uptime: c_long,
109122
pub loads: [c_ulong; 3],
@@ -134,7 +147,7 @@ s! {
134147
pub f_namelen: c_int,
135148
pub f_frsize: c_int,
136149
pub f_flags: c_int,
137-
pub f_spare: [c_int; 4],
150+
f_spare: Padding<[c_int; 4]>,
138151
}
139152

140153
pub struct statfs64 {
@@ -145,27 +158,12 @@ s! {
145158
pub f_bavail: crate::fsblkcnt64_t,
146159
pub f_files: crate::fsfilcnt64_t,
147160
pub f_ffree: crate::fsfilcnt64_t,
161+
148162
pub f_fsid: crate::fsid_t,
149163
pub f_namelen: c_int,
150164
pub f_frsize: c_int,
151165
pub f_flags: c_int,
152-
pub f_spare: [c_int; 4],
153-
}
154-
155-
pub struct statvfs64 {
156-
pub f_bsize: c_ulong,
157-
pub f_frsize: c_ulong,
158-
pub f_blocks: u64,
159-
pub f_bfree: u64,
160-
pub f_bavail: u64,
161-
pub f_files: u64,
162-
pub f_ffree: u64,
163-
pub f_favail: u64,
164-
pub f_fsid: c_ulong,
165-
__f_unused: Padding<c_int>,
166-
pub f_flag: c_ulong,
167-
pub f_namemax: c_ulong,
168-
__f_spare: [c_int; 6],
166+
f_spare: Padding<[c_int; 4]>,
169167
}
170168

171169
pub struct sigset_t {

src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs

Lines changed: 23 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
use crate::off64_t;
21
use crate::prelude::*;
32

43
pub type clock_t = i32;
54
pub type time_t = i32;
65
pub type suseconds_t = i32;
76
pub type wchar_t = i32;
8-
pub type off_t = i32;
9-
pub type ino_t = u32;
10-
pub type blkcnt_t = i32;
117
pub type blksize_t = i32;
128
pub type nlink_t = u32;
13-
pub type fsblkcnt_t = c_ulong;
14-
pub type fsfilcnt_t = c_ulong;
159
pub type __u64 = c_ulonglong;
1610
pub type __s64 = c_longlong;
17-
pub type fsblkcnt64_t = u64;
18-
pub type fsfilcnt64_t = u64;
1911

2012
s! {
2113
pub struct stat {
@@ -27,16 +19,29 @@ s! {
2719
pub st_uid: crate::uid_t,
2820
pub st_gid: crate::gid_t,
2921
pub st_rdev: crate::dev_t,
30-
pub st_pad2: [c_long; 1],
31-
pub st_size: off_t,
22+
23+
#[cfg(not(uclibc_file_offset_bits64))]
24+
st_pad2: Padding<[c_long; 1]>,
25+
26+
#[cfg(uclibc_file_offset_bits64)]
27+
st_pad2: Padding<[c_long; 2]>,
28+
29+
pub st_size: crate::off_t,
30+
31+
#[cfg(not(uclibc_file_offset_bits64))]
3232
st_pad3: Padding<c_long>,
33+
3334
pub st_atime: crate::time_t,
34-
pub st_atime_nsec: c_long,
35+
pub st_atime_nsec: c_ulong,
3536
pub st_mtime: crate::time_t,
36-
pub st_mtime_nsec: c_long,
37+
pub st_mtime_nsec: c_ulong,
3738
pub st_ctime: crate::time_t,
38-
pub st_ctime_nsec: c_long,
39+
pub st_ctime_nsec: c_ulong,
3940
pub st_blksize: crate::blksize_t,
41+
42+
#[cfg(uclibc_file_offset_bits64)]
43+
st_pad4: Padding<c_long>,
44+
4045
pub st_blocks: crate::blkcnt_t,
4146
st_pad5: Padding<[c_long; 14]>,
4247
}
@@ -51,33 +56,17 @@ s! {
5156
pub st_gid: crate::gid_t,
5257
pub st_rdev: crate::dev_t,
5358
st_pad2: Padding<[c_long; 2]>,
54-
pub st_size: off64_t,
59+
pub st_size: crate::off64_t,
5560
pub st_atime: crate::time_t,
56-
pub st_atime_nsec: c_long,
61+
pub st_atime_nsec: c_ulong,
5762
pub st_mtime: crate::time_t,
58-
pub st_mtime_nsec: c_long,
63+
pub st_mtime_nsec: c_ulong,
5964
pub st_ctime: crate::time_t,
60-
pub st_ctime_nsec: c_long,
65+
pub st_ctime_nsec: c_ulong,
6166
pub st_blksize: crate::blksize_t,
6267
st_pad3: Padding<c_long>,
6368
pub st_blocks: crate::blkcnt64_t,
64-
st_pad5: Padding<[c_long; 14]>,
65-
}
66-
67-
pub struct statvfs64 {
68-
pub f_bsize: c_ulong,
69-
pub f_frsize: c_ulong,
70-
pub f_blocks: crate::fsblkcnt64_t,
71-
pub f_bfree: crate::fsblkcnt64_t,
72-
pub f_bavail: crate::fsblkcnt64_t,
73-
pub f_files: crate::fsfilcnt64_t,
74-
pub f_ffree: crate::fsfilcnt64_t,
75-
pub f_favail: crate::fsfilcnt64_t,
76-
pub f_fsid: c_ulong,
77-
pub __f_unused: c_int,
78-
pub f_flag: c_ulong,
79-
pub f_namemax: c_ulong,
80-
pub __f_spare: [c_int; 6],
69+
st_pad4: Padding<[c_long; 14]>,
8170
}
8271

8372
pub struct pthread_attr_t {
@@ -173,36 +162,6 @@ s! {
173162
__glibc_reserved5: Padding<c_ulong>,
174163
}
175164

176-
pub struct statfs {
177-
pub f_type: c_long,
178-
pub f_bsize: c_long,
179-
pub f_frsize: c_long,
180-
pub f_blocks: crate::fsblkcnt_t,
181-
pub f_bfree: crate::fsblkcnt_t,
182-
pub f_files: crate::fsblkcnt_t,
183-
pub f_ffree: crate::fsblkcnt_t,
184-
pub f_bavail: crate::fsblkcnt_t,
185-
pub f_fsid: crate::fsid_t,
186-
187-
pub f_namelen: c_long,
188-
f_spare: [c_long; 6],
189-
}
190-
191-
pub struct statfs64 {
192-
pub f_type: c_long,
193-
pub f_bsize: c_long,
194-
pub f_frsize: c_long,
195-
pub f_blocks: crate::fsblkcnt64_t,
196-
pub f_bfree: crate::fsblkcnt64_t,
197-
pub f_files: crate::fsblkcnt64_t,
198-
pub f_ffree: crate::fsblkcnt64_t,
199-
pub f_bavail: crate::fsblkcnt64_t,
200-
pub f_fsid: crate::fsid_t,
201-
pub f_namelen: c_long,
202-
pub f_flags: c_long,
203-
pub f_spare: [c_long; 5],
204-
}
205-
206165
pub struct msghdr {
207166
pub msg_name: *mut c_void,
208167
pub msg_namelen: crate::socklen_t,
@@ -228,16 +187,6 @@ s! {
228187
pub c_cc: [crate::cc_t; crate::NCCS],
229188
}
230189

231-
pub struct flock {
232-
pub l_type: c_short,
233-
pub l_whence: c_short,
234-
pub l_start: off_t,
235-
pub l_len: off_t,
236-
pub l_sysid: c_long,
237-
pub l_pid: crate::pid_t,
238-
pad: Padding<[c_long; 4]>,
239-
}
240-
241190
pub struct sysinfo {
242191
pub uptime: c_long,
243192
pub loads: [c_ulong; 3],
@@ -665,7 +614,6 @@ pub const SYS_process_mrelease: c_long = 4000 + 448;
665614
pub const SYS_futex_waitv: c_long = 4000 + 449;
666615
pub const SYS_set_mempolicy_home_node: c_long = 4000 + 450;
667616

668-
#[link(name = "util")]
669617
extern "C" {
670618
pub fn sysctl(
671619
name: *mut c_int,

0 commit comments

Comments
 (0)