Skip to content

Commit f13f57a

Browse files
Port statfs to x32
1 parent 90b2734 commit f13f57a

File tree

1 file changed

+63
-52
lines changed

1 file changed

+63
-52
lines changed

src/sys/statfs.rs

Lines changed: 63 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,79 +16,85 @@ pub type fsid_t = libc::fsid_t;
1616
pub struct Statfs(libc::statfs);
1717

1818
#[cfg(target_os = "freebsd")]
19-
#[derive(Eq, Copy, Clone, PartialEq, Debug)]
20-
pub struct FsType(pub u32);
19+
type fs_type_t = u32;
2120
#[cfg(target_os = "android")]
22-
#[derive(Eq, Copy, Clone, PartialEq, Debug)]
23-
pub struct FsType(pub libc::c_ulong);
21+
type fs_type_t = libc::c_ulong;
2422
#[cfg(all(target_os = "linux", target_arch = "s390x"))]
25-
#[derive(Eq, Copy, Clone, PartialEq, Debug)]
26-
pub struct FsType(pub u32);
23+
type fs_type_t = libc::c_uint;
2724
#[cfg(all(target_os = "linux", target_env = "musl"))]
28-
#[derive(Eq, Copy, Clone, PartialEq, Debug)]
29-
pub struct FsType(pub libc::c_ulong);
25+
type fs_type_t = libc::c_ulong;
3026
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
27+
type fs_type_t = libc::__fsword_t;
28+
29+
#[cfg(any(
30+
target_os = "freebsd",
31+
target_os = "android",
32+
all(target_os = "linux", target_arch = "s390x"),
33+
all(target_os = "linux", target_env = "musl"),
34+
all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))),
35+
))]
3136
#[derive(Eq, Copy, Clone, PartialEq, Debug)]
32-
pub struct FsType(pub libc::c_long);
37+
pub struct FsType(pub fs_type_t);
3338

3439
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
35-
pub const ADFS_SUPER_MAGIC: FsType = FsType(libc::ADFS_SUPER_MAGIC);
40+
pub const ADFS_SUPER_MAGIC: FsType = FsType(libc::ADFS_SUPER_MAGIC as fs_type_t);
3641
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
37-
pub const AFFS_SUPER_MAGIC: FsType = FsType(libc::AFFS_SUPER_MAGIC);
42+
pub const AFFS_SUPER_MAGIC: FsType = FsType(libc::AFFS_SUPER_MAGIC as fs_type_t);
3843
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
39-
pub const CODA_SUPER_MAGIC: FsType = FsType(libc::CODA_SUPER_MAGIC);
44+
pub const CODA_SUPER_MAGIC: FsType = FsType(libc::CODA_SUPER_MAGIC as fs_type_t);
4045
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
41-
pub const CRAMFS_MAGIC: FsType = FsType(libc::CRAMFS_MAGIC);
46+
pub const CRAMFS_MAGIC: FsType = FsType(libc::CRAMFS_MAGIC as fs_type_t);
4247
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
43-
pub const EFS_SUPER_MAGIC: FsType = FsType(libc::EFS_SUPER_MAGIC);
48+
pub const EFS_SUPER_MAGIC: FsType = FsType(libc::EFS_SUPER_MAGIC as fs_type_t);
4449
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
45-
pub const EXT2_SUPER_MAGIC: FsType = FsType(libc::EXT2_SUPER_MAGIC);
50+
pub const EXT2_SUPER_MAGIC: FsType = FsType(libc::EXT2_SUPER_MAGIC as fs_type_t);
4651
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
47-
pub const EXT3_SUPER_MAGIC: FsType = FsType(libc::EXT3_SUPER_MAGIC);
52+
pub const EXT3_SUPER_MAGIC: FsType = FsType(libc::EXT3_SUPER_MAGIC as fs_type_t);
4853
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
49-
pub const EXT4_SUPER_MAGIC: FsType = FsType(libc::EXT4_SUPER_MAGIC);
54+
pub const EXT4_SUPER_MAGIC: FsType = FsType(libc::EXT4_SUPER_MAGIC as fs_type_t);
5055
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
51-
pub const HPFS_SUPER_MAGIC: FsType = FsType(libc::HPFS_SUPER_MAGIC);
56+
pub const HPFS_SUPER_MAGIC: FsType = FsType(libc::HPFS_SUPER_MAGIC as fs_type_t);
5257
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
53-
pub const HUGETLBFS_MAGIC: FsType = FsType(libc::HUGETLBFS_MAGIC);
58+
pub const HUGETLBFS_MAGIC: FsType = FsType(libc::HUGETLBFS_MAGIC as fs_type_t);
5459
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
55-
pub const ISOFS_SUPER_MAGIC: FsType = FsType(libc::ISOFS_SUPER_MAGIC);
60+
pub const ISOFS_SUPER_MAGIC: FsType = FsType(libc::ISOFS_SUPER_MAGIC as fs_type_t);
5661
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
57-
pub const JFFS2_SUPER_MAGIC: FsType = FsType(libc::JFFS2_SUPER_MAGIC);
62+
pub const JFFS2_SUPER_MAGIC: FsType = FsType(libc::JFFS2_SUPER_MAGIC as fs_type_t);
5863
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
59-
pub const MINIX_SUPER_MAGIC: FsType = FsType(libc::MINIX_SUPER_MAGIC);
64+
pub const MINIX_SUPER_MAGIC: FsType = FsType(libc::MINIX_SUPER_MAGIC as fs_type_t);
6065
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
61-
pub const MINIX_SUPER_MAGIC2: FsType = FsType(libc::MINIX_SUPER_MAGIC2);
66+
pub const MINIX_SUPER_MAGIC2: FsType = FsType(libc::MINIX_SUPER_MAGIC2 as fs_type_t);
6267
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
63-
pub const MINIX2_SUPER_MAGIC: FsType = FsType(libc::MINIX2_SUPER_MAGIC);
68+
pub const MINIX2_SUPER_MAGIC: FsType = FsType(libc::MINIX2_SUPER_MAGIC as fs_type_t);
6469
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
65-
pub const MINIX2_SUPER_MAGIC2: FsType = FsType(libc::MINIX2_SUPER_MAGIC2);
70+
pub const MINIX2_SUPER_MAGIC2: FsType = FsType(libc::MINIX2_SUPER_MAGIC2 as fs_type_t);
6671
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
67-
pub const MSDOS_SUPER_MAGIC: FsType = FsType(libc::MSDOS_SUPER_MAGIC);
72+
pub const MSDOS_SUPER_MAGIC: FsType = FsType(libc::MSDOS_SUPER_MAGIC as fs_type_t);
6873
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
69-
pub const NCP_SUPER_MAGIC: FsType = FsType(libc::NCP_SUPER_MAGIC);
74+
pub const NCP_SUPER_MAGIC: FsType = FsType(libc::NCP_SUPER_MAGIC as fs_type_t);
7075
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
71-
pub const NFS_SUPER_MAGIC: FsType = FsType(libc::NFS_SUPER_MAGIC);
76+
pub const NFS_SUPER_MAGIC: FsType = FsType(libc::NFS_SUPER_MAGIC as fs_type_t);
7277
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
73-
pub const OPENPROM_SUPER_MAGIC: FsType = FsType(libc::OPENPROM_SUPER_MAGIC);
78+
pub const OPENPROM_SUPER_MAGIC: FsType = FsType(libc::OPENPROM_SUPER_MAGIC as fs_type_t);
7479
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
75-
pub const OVERLAYFS_SUPER_MAGIC: FsType = FsType(libc::OVERLAYFS_SUPER_MAGIC);
80+
pub const OVERLAYFS_SUPER_MAGIC: FsType = FsType(libc::OVERLAYFS_SUPER_MAGIC as fs_type_t);
7681
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
77-
pub const PROC_SUPER_MAGIC: FsType = FsType(libc::PROC_SUPER_MAGIC);
82+
pub const PROC_SUPER_MAGIC: FsType = FsType(libc::PROC_SUPER_MAGIC as fs_type_t);
7883
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
79-
pub const QNX4_SUPER_MAGIC: FsType = FsType(libc::QNX4_SUPER_MAGIC);
84+
pub const QNX4_SUPER_MAGIC: FsType = FsType(libc::QNX4_SUPER_MAGIC as fs_type_t);
8085
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
81-
pub const REISERFS_SUPER_MAGIC: FsType = FsType(libc::REISERFS_SUPER_MAGIC);
86+
pub const REISERFS_SUPER_MAGIC: FsType = FsType(libc::REISERFS_SUPER_MAGIC as fs_type_t);
8287
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
83-
pub const SMB_SUPER_MAGIC: FsType = FsType(libc::SMB_SUPER_MAGIC);
88+
pub const SMB_SUPER_MAGIC: FsType = FsType(libc::SMB_SUPER_MAGIC as fs_type_t);
8489
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
85-
pub const TMPFS_MAGIC: FsType = FsType(libc::TMPFS_MAGIC);
90+
pub const TMPFS_MAGIC: FsType = FsType(libc::TMPFS_MAGIC as fs_type_t);
8691
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
87-
pub const USBDEVICE_SUPER_MAGIC: FsType = FsType(libc::USBDEVICE_SUPER_MAGIC);
92+
pub const USBDEVICE_SUPER_MAGIC: FsType = FsType(libc::USBDEVICE_SUPER_MAGIC as fs_type_t);
8893
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
89-
pub const CGROUP_SUPER_MAGIC: FsType = FsType(libc::CGROUP_SUPER_MAGIC);
94+
pub const CGROUP_SUPER_MAGIC: FsType = FsType(libc::CGROUP_SUPER_MAGIC as fs_type_t);
9095
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
91-
pub const CGROUP2_SUPER_MAGIC: FsType = FsType(libc::CGROUP2_SUPER_MAGIC);
96+
pub const CGROUP2_SUPER_MAGIC: FsType = FsType(libc::CGROUP2_SUPER_MAGIC as fs_type_t);
97+
9298

9399
impl Statfs {
94100
/// Magic code defining system type
@@ -138,7 +144,7 @@ impl Statfs {
138144

139145
/// Optimal transfer block size
140146
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
141-
pub fn optimal_transfer_size(&self) -> libc::c_long {
147+
pub fn optimal_transfer_size(&self) -> libc::__fsword_t {
142148
self.0.f_bsize
143149
}
144150

@@ -177,7 +183,7 @@ impl Statfs {
177183
/// Size of a block
178184
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
179185
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
180-
pub fn block_size(&self) -> libc::c_long {
186+
pub fn block_size(&self) -> libc::__fsword_t {
181187
self.0.f_bsize
182188
}
183189

@@ -219,7 +225,7 @@ impl Statfs {
219225

220226
/// Maximum length of filenames
221227
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
222-
pub fn maximum_name_length(&self) -> libc::c_long {
228+
pub fn maximum_name_length(&self) -> libc::__fsword_t {
223229
self.0.f_namelen
224230
}
225231

@@ -248,7 +254,7 @@ impl Statfs {
248254
}
249255

250256
/// Total data blocks in filesystem
251-
#[cfg(all(target_os = "linux", target_env = "musl"))]
257+
#[cfg(all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32"))))]
252258
pub fn blocks(&self) -> u64 {
253259
self.0.f_blocks
254260
}
@@ -261,7 +267,7 @@ impl Statfs {
261267
target_os = "freebsd",
262268
target_os = "openbsd",
263269
target_os = "dragonfly",
264-
all(target_os = "linux", target_env = "musl")
270+
all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32")))
265271
)))]
266272
pub fn blocks(&self) -> libc::c_ulong {
267273
self.0.f_blocks
@@ -286,7 +292,7 @@ impl Statfs {
286292
}
287293

288294
/// Free blocks in filesystem
289-
#[cfg(all(target_os = "linux", target_env = "musl"))]
295+
#[cfg(all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32"))))]
290296
pub fn blocks_free(&self) -> u64 {
291297
self.0.f_bfree
292298
}
@@ -299,7 +305,7 @@ impl Statfs {
299305
target_os = "freebsd",
300306
target_os = "openbsd",
301307
target_os = "dragonfly",
302-
all(target_os = "linux", target_env = "musl")
308+
all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32")))
303309
)))]
304310
pub fn blocks_free(&self) -> libc::c_ulong {
305311
self.0.f_bfree
@@ -324,7 +330,7 @@ impl Statfs {
324330
}
325331

326332
/// Free blocks available to unprivileged user
327-
#[cfg(all(target_os = "linux", target_env = "musl"))]
333+
#[cfg(all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32"))))]
328334
pub fn blocks_available(&self) -> u64 {
329335
self.0.f_bavail
330336
}
@@ -337,7 +343,7 @@ impl Statfs {
337343
target_os = "freebsd",
338344
target_os = "openbsd",
339345
target_os = "dragonfly",
340-
all(target_os = "linux", target_env = "musl")
346+
all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32")))
341347
)))]
342348
pub fn blocks_available(&self) -> libc::c_ulong {
343349
self.0.f_bavail
@@ -362,8 +368,8 @@ impl Statfs {
362368
}
363369

364370
/// Total file nodes in filesystem
365-
#[cfg(all(target_os = "linux", target_env = "musl"))]
366-
pub fn files(&self) -> u64 {
371+
#[cfg(all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32"))))]
372+
pub fn files(&self) -> libc::fsfilcnt_t {
367373
self.0.f_files
368374
}
369375

@@ -375,7 +381,7 @@ impl Statfs {
375381
target_os = "freebsd",
376382
target_os = "openbsd",
377383
target_os = "dragonfly",
378-
all(target_os = "linux", target_env = "musl")
384+
all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32")))
379385
)))]
380386
pub fn files(&self) -> libc::c_ulong {
381387
self.0.f_files
@@ -385,7 +391,6 @@ impl Statfs {
385391
#[cfg(any(
386392
target_os = "android",
387393
target_os = "ios",
388-
all(target_os = "linux", target_env = "musl"),
389394
target_os = "macos",
390395
target_os = "openbsd"
391396
))]
@@ -405,6 +410,12 @@ impl Statfs {
405410
self.0.f_ffree
406411
}
407412

413+
/// Free file nodes in filesystem
414+
#[cfg(all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32"))))]
415+
pub fn files_free(&self) -> libc::fsfilcnt_t {
416+
self.0.f_ffree
417+
}
418+
408419
/// Free file nodes in filesystem
409420
#[cfg(not(any(
410421
target_os = "ios",
@@ -413,7 +424,7 @@ impl Statfs {
413424
target_os = "freebsd",
414425
target_os = "openbsd",
415426
target_os = "dragonfly",
416-
all(target_os = "linux", target_env = "musl")
427+
all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32")))
417428
)))]
418429
pub fn files_free(&self) -> libc::c_ulong {
419430
self.0.f_ffree

0 commit comments

Comments
 (0)