@@ -7,6 +7,8 @@ use std::os::unix::io::AsRawFd;
7
7
#[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
8
8
use std:: ffi:: CStr ;
9
9
10
+ use cfg_if:: cfg_if;
11
+
10
12
use crate :: { NixPath , Result , errno:: Errno } ;
11
13
12
14
/// Identifies a mounted file system
@@ -18,10 +20,30 @@ pub type fsid_t = libc::__fsid_t;
18
20
#[ cfg_attr( docsrs, doc( cfg( all( ) ) ) ) ]
19
21
pub type fsid_t = libc:: fsid_t ;
20
22
23
+ cfg_if ! {
24
+ if #[ cfg( any( target_os = "android" , target_os = "fuchsia" , target_os = "linux" ) ) ] {
25
+ type type_of_statfs = libc:: statfs64;
26
+ const LIBC_FSTATFS : unsafe extern fn
27
+ ( fd: libc:: c_int, buf: * mut type_of_statfs) -> libc:: c_int
28
+ = libc:: fstatfs64;
29
+ const LIBC_STATFS : unsafe extern fn
30
+ ( path: * const libc:: c_char, buf: * mut type_of_statfs) -> libc:: c_int
31
+ = libc:: statfs64;
32
+ } else {
33
+ type type_of_statfs = libc:: statfs;
34
+ const LIBC_FSTATFS : unsafe extern fn
35
+ ( fd: libc:: c_int, buf: * mut type_of_statfs) -> libc:: c_int
36
+ = libc:: fstatfs;
37
+ const LIBC_STATFS : unsafe extern fn
38
+ ( path: * const libc:: c_char, buf: * mut type_of_statfs) -> libc:: c_int
39
+ = libc:: statfs;
40
+ }
41
+ }
42
+
21
43
/// Describes a mounted file system
22
44
#[ derive( Clone , Copy ) ]
23
45
#[ repr( transparent) ]
24
- pub struct Statfs ( libc :: statfs ) ;
46
+ pub struct Statfs ( type_of_statfs ) ;
25
47
26
48
#[ cfg( target_os = "freebsd" ) ]
27
49
type fs_type_t = u32 ;
@@ -642,8 +664,8 @@ impl Debug for Statfs {
642
664
/// `path` - Path to any file within the file system to describe
643
665
pub fn statfs < P : ?Sized + NixPath > ( path : & P ) -> Result < Statfs > {
644
666
unsafe {
645
- let mut stat = mem:: MaybeUninit :: < libc :: statfs > :: uninit ( ) ;
646
- let res = path. with_nix_path ( |path| libc :: statfs ( path. as_ptr ( ) , stat. as_mut_ptr ( ) ) ) ?;
667
+ let mut stat = mem:: MaybeUninit :: < type_of_statfs > :: uninit ( ) ;
668
+ let res = path. with_nix_path ( |path| LIBC_STATFS ( path. as_ptr ( ) , stat. as_mut_ptr ( ) ) ) ?;
647
669
Errno :: result ( res) . map ( |_| Statfs ( stat. assume_init ( ) ) )
648
670
}
649
671
}
@@ -658,8 +680,8 @@ pub fn statfs<P: ?Sized + NixPath>(path: &P) -> Result<Statfs> {
658
680
/// `fd` - File descriptor of any open file within the file system to describe
659
681
pub fn fstatfs < T : AsRawFd > ( fd : & T ) -> Result < Statfs > {
660
682
unsafe {
661
- let mut stat = mem:: MaybeUninit :: < libc :: statfs > :: uninit ( ) ;
662
- Errno :: result ( libc :: fstatfs ( fd. as_raw_fd ( ) , stat. as_mut_ptr ( ) ) )
683
+ let mut stat = mem:: MaybeUninit :: < type_of_statfs > :: uninit ( ) ;
684
+ Errno :: result ( LIBC_FSTATFS ( fd. as_raw_fd ( ) , stat. as_mut_ptr ( ) ) )
663
685
. map ( |_| Statfs ( stat. assume_init ( ) ) )
664
686
}
665
687
}
0 commit comments