Skip to content

Commit c883cf6

Browse files
committed
refactor: change file off bindings in linux uclibc
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 uClibc module under Linux, such that a more cohesive interface is exposed. Among those changes, the patch also switches the default definition of types with LFS64 "variants," such that they use that definition by default. This affects types such as `off_t` and `ino_t`, for which support varied between platforms to either the regular definition upstream or the LFS64 definition. Beyond that, a few LFS64-specific routines have been deprecated in favor of their unsuffixed variants. Much in the same vein as the prior changes, this follows the trend towards supporting a single unsuffixed type whose bitwidth is 64-bits. It has been assumed that this extends as well to routines making use of such types. Lastly, it must be noted that all changes submitted in this patch match the definition of upstream uclibc-ng, but not necessarily of the original uClibc (now unmaintained.) This was done by performing a regex search through all header files under `**/{platform}/bits/*.h`, where `{platform}` is replaced by one of: `common`, `common-generic`, `arm`, `x86_64` or `mips`. The search term in question included any uses of the `__USE_FILE_OFFSET64` or `__USE_LARGEFILE64` feature test macros. The latter gates functionality that exposes 64-bit types, while the former ensures the unsuffixed variants are defined in terms of the suffixed types/routines. By default, upstream builds of uclibc-ng will have LFS support added by default lest otherwise configured. This is shown in the make configuration script generated by running make defconfig in the root worktree.
1 parent f4d6777 commit c883cf6

6 files changed

Lines changed: 172 additions & 306 deletions

File tree

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

Lines changed: 25 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
use crate::off64_t;
21
use crate::prelude::*;
32

43
pub type wchar_t = c_uint;
54
pub type time_t = c_long;
65

76
pub type clock_t = c_long;
8-
pub type fsblkcnt_t = c_ulong;
9-
pub type fsfilcnt_t = c_ulong;
10-
pub type ino_t = c_ulong;
11-
pub type off_t = c_long;
127
pub type pthread_t = c_ulong;
138
pub type suseconds_t = c_long;
149

1510
pub type nlink_t = c_uint;
1611
pub type blksize_t = c_long;
17-
pub type blkcnt_t = c_long;
1812

13+
pub type statfs64 = statfs;
14+
pub type stat64 = stat;
15+
16+
#[deprecated(
17+
since = "0.2.187",
18+
note = "Use `fsblkcnt_t` instead. The unsuffixed type is defined in terms of the suffixed type \
19+
in default builds of upstream uclibc-ng, and the `libc` crate is itself phasing out \
20+
support for suffixed variants in favor of a single fixed-width unsuffixed type."
21+
)]
1922
pub type fsblkcnt64_t = u64;
23+
#[deprecated(
24+
since = "0.2.187",
25+
note = "Use `fsfilcnt_t` instead. The unsuffixed type is defined in terms of the suffixed type \
26+
in default builds of upstream uclibc-ng, and the `libc` crate is itself phasing out \
27+
support for suffixed variants in favor of a single fixed-width unsuffixed type."
28+
)]
2029
pub type fsfilcnt64_t = u64;
2130
pub type __u64 = c_ulonglong;
2231
pub type __s64 = c_longlong;
@@ -43,56 +52,25 @@ s! {
4352
}
4453

4554
pub struct stat {
46-
pub st_dev: c_ulonglong,
47-
__pad1: Padding<c_ushort>,
48-
pub st_ino: crate::ino_t,
49-
pub st_mode: crate::mode_t,
50-
pub st_nlink: crate::nlink_t,
51-
pub st_uid: crate::uid_t,
52-
pub st_gid: crate::gid_t,
53-
pub st_rdev: c_ulonglong,
54-
__pad2: Padding<c_ushort>,
55-
pub st_size: off_t,
56-
pub st_blksize: crate::blksize_t,
57-
pub st_blocks: crate::blkcnt_t,
58-
pub st_atime: crate::time_t,
59-
pub st_atime_nsec: c_long,
60-
pub st_mtime: crate::time_t,
61-
pub st_mtime_nsec: c_long,
62-
pub st_ctime: crate::time_t,
63-
pub st_ctime_nsec: c_long,
64-
__unused4: Padding<c_ulong>,
65-
__unused5: Padding<c_ulong>,
66-
}
67-
68-
pub struct stat64 {
69-
pub st_dev: c_ulonglong,
70-
pub __pad1: c_uint,
55+
pub st_dev: crate::dev_t,
56+
__pad1: Padding<c_uint>,
7157
pub __st_ino: crate::ino_t,
7258
pub st_mode: crate::mode_t,
7359
pub st_nlink: crate::nlink_t,
7460
pub st_uid: crate::uid_t,
7561
pub st_gid: crate::gid_t,
76-
pub st_rdev: c_ulonglong,
77-
pub __pad2: c_uint,
78-
pub st_size: off64_t,
62+
pub st_rdev: crate::dev_t,
63+
__pad2: Padding<c_uint>,
64+
pub st_size: crate::off_t,
7965
pub st_blksize: crate::blksize_t,
80-
pub st_blocks: crate::blkcnt64_t,
66+
pub st_blocks: crate::blkcnt_t,
8167
pub st_atime: crate::time_t,
82-
pub st_atime_nsec: c_long,
68+
pub st_atime_nsec: c_ulong,
8369
pub st_mtime: crate::time_t,
84-
pub st_mtime_nsec: c_long,
70+
pub st_mtime_nsec: c_ulong,
8571
pub st_ctime: crate::time_t,
86-
pub st_ctime_nsec: c_long,
87-
pub st_ino: crate::ino64_t,
88-
}
89-
90-
pub struct flock {
91-
pub l_type: c_short,
92-
pub l_whence: c_short,
93-
pub l_start: off_t,
94-
pub l_len: off_t,
95-
pub l_pid: crate::pid_t,
72+
pub st_ctime_nsec: c_ulong,
73+
pub st_ino: crate::ino_t,
9674
}
9775

9876
pub struct sysinfo {
@@ -128,37 +106,6 @@ s! {
128106
pub f_spare: [c_int; 4],
129107
}
130108

131-
pub struct statfs64 {
132-
pub f_type: c_int,
133-
pub f_bsize: c_int,
134-
pub f_blocks: crate::fsblkcnt64_t,
135-
pub f_bfree: crate::fsblkcnt64_t,
136-
pub f_bavail: crate::fsblkcnt64_t,
137-
pub f_files: crate::fsfilcnt64_t,
138-
pub f_ffree: crate::fsfilcnt64_t,
139-
pub f_fsid: crate::fsid_t,
140-
pub f_namelen: c_int,
141-
pub f_frsize: c_int,
142-
pub f_flags: c_int,
143-
pub f_spare: [c_int; 4],
144-
}
145-
146-
pub struct statvfs64 {
147-
pub f_bsize: c_ulong,
148-
pub f_frsize: c_ulong,
149-
pub f_blocks: u64,
150-
pub f_bfree: u64,
151-
pub f_bavail: u64,
152-
pub f_files: u64,
153-
pub f_ffree: u64,
154-
pub f_favail: u64,
155-
pub f_fsid: c_ulong,
156-
__f_unused: Padding<c_int>,
157-
pub f_flag: c_ulong,
158-
pub f_namemax: c_ulong,
159-
__f_spare: [c_int; 6],
160-
}
161-
162109
pub struct sigset_t {
163110
__val: [c_ulong; 2],
164111
}

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

Lines changed: 40 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
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;
11+
#[deprecated(
12+
since = "0.2.187",
13+
note = "Use `fsblkcnt_t` instead. The unsuffixed type is defined in terms of the unsuffixed \
14+
type in all default builds of upstream uClibc, and the `libc` crate is phasing out \
15+
support for suffixed variants in favor of a single fixed-width suffixed variant."
16+
)]
1717
pub type fsblkcnt64_t = u64;
18+
#[deprecated(
19+
since = "0.2.187",
20+
note = "Use `fsfilcnt_t` instead. The unsuffixed type is defined in terms of the unsuffixed \
21+
type in all default builds of upstream uClibc, and the `libc` crate is phasing out \
22+
support for suffixed variants in favor of a single fixed-width suffixed variant."
23+
)]
1824
pub type fsfilcnt64_t = u64;
1925

26+
pub type stat64 = stat;
27+
2028
s! {
2129
pub struct stat {
2230
pub st_dev: crate::dev_t,
@@ -27,59 +35,20 @@ s! {
2735
pub st_uid: crate::uid_t,
2836
pub st_gid: crate::gid_t,
2937
pub st_rdev: crate::dev_t,
30-
pub st_pad2: [c_long; 1],
31-
pub st_size: off_t,
32-
st_pad3: Padding<c_long>,
38+
st_pad2: [c_long; 2],
39+
pub st_size: crate::off_t,
3340
pub st_atime: crate::time_t,
34-
pub st_atime_nsec: c_long,
41+
pub st_atime_nsec: c_ulong,
3542
pub st_mtime: crate::time_t,
36-
pub st_mtime_nsec: c_long,
43+
pub st_mtime_nsec: c_ulong,
3744
pub st_ctime: crate::time_t,
38-
pub st_ctime_nsec: c_long,
45+
pub st_ctime_nsec: c_ulong,
3946
pub st_blksize: crate::blksize_t,
47+
st_pad4: Padding<c_long>,
4048
pub st_blocks: crate::blkcnt_t,
4149
st_pad5: Padding<[c_long; 14]>,
4250
}
4351

44-
pub struct stat64 {
45-
pub st_dev: crate::dev_t,
46-
st_pad1: Padding<[c_long; 2]>,
47-
pub st_ino: crate::ino64_t,
48-
pub st_mode: crate::mode_t,
49-
pub st_nlink: crate::nlink_t,
50-
pub st_uid: crate::uid_t,
51-
pub st_gid: crate::gid_t,
52-
pub st_rdev: crate::dev_t,
53-
st_pad2: Padding<[c_long; 2]>,
54-
pub st_size: off64_t,
55-
pub st_atime: crate::time_t,
56-
pub st_atime_nsec: c_long,
57-
pub st_mtime: crate::time_t,
58-
pub st_mtime_nsec: c_long,
59-
pub st_ctime: crate::time_t,
60-
pub st_ctime_nsec: c_long,
61-
pub st_blksize: crate::blksize_t,
62-
st_pad3: Padding<c_long>,
63-
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],
81-
}
82-
8352
pub struct pthread_attr_t {
8453
__size: [u32; 9],
8554
}
@@ -108,6 +77,12 @@ s! {
10877
pub _pad: [c_int; 29],
10978
}
11079

80+
#[deprecated(
81+
since = "0.2.187",
82+
note = "Use `glob` instead. The suffixed variant exposed in `libc` has no differences \
83+
whatsoever with the unsuffixed variant because we don't expose the fields that are \
84+
function pointers."
85+
)]
11186
pub struct glob64_t {
11287
pub gl_pathc: size_t,
11388
pub gl_pathv: *mut *mut c_char,
@@ -173,36 +148,6 @@ s! {
173148
__glibc_reserved5: Padding<c_ulong>,
174149
}
175150

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-
206151
pub struct msghdr {
207152
pub msg_name: *mut c_void,
208153
pub msg_namelen: crate::socklen_t,
@@ -228,16 +173,6 @@ s! {
228173
pub c_cc: [crate::cc_t; crate::NCCS],
229174
}
230175

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-
241176
pub struct sysinfo {
242177
pub uptime: c_long,
243178
pub loads: [c_ulong; 3],
@@ -665,7 +600,6 @@ pub const SYS_process_mrelease: c_long = 4000 + 448;
665600
pub const SYS_futex_waitv: c_long = 4000 + 449;
666601
pub const SYS_set_mempolicy_home_node: c_long = 4000 + 450;
667602

668-
#[link(name = "util")]
669603
extern "C" {
670604
pub fn sysctl(
671605
name: *mut c_int,
@@ -675,12 +609,26 @@ extern "C" {
675609
newp: *mut c_void,
676610
newlen: size_t,
677611
) -> c_int;
612+
#[deprecated(
613+
since = "0.2.187",
614+
note = "Use `glob` instead. The suffixed variant exposed in `libc` has no differences \
615+
whatsoever with the unsuffixed variant because we don't expose the fields that are \
616+
function pointers."
617+
)]
618+
#[allow(deprecated)]
678619
pub fn glob64(
679620
pattern: *const c_char,
680621
flags: c_int,
681622
errfunc: Option<extern "C" fn(epath: *const c_char, errno: c_int) -> c_int>,
682623
pglob: *mut glob64_t,
683624
) -> c_int;
625+
#[deprecated(
626+
since = "0.2.187",
627+
note = "Use `glob` instead. The suffixed variant exposed in `libc` has no differences \
628+
whatsoever with the unsuffixed variant because we don't expose the fields that are \
629+
function pointers."
630+
)]
631+
#[allow(deprecated)]
684632
pub fn globfree64(pglob: *mut glob64_t);
685633
pub fn pthread_attr_getaffinity_np(
686634
attr: *const crate::pthread_attr_t,

0 commit comments

Comments
 (0)