1
1
//! Get filesystem statistics, non-portably
2
2
//!
3
3
//! See [`statvfs`](crate::sys::statvfs) for a portable alternative.
4
- #[ cfg( not( any ( target_os = "linux" , target_os = "android" ) ) ) ]
4
+ #[ cfg( not( linux_android ) ) ]
5
5
use std:: ffi:: CStr ;
6
6
use std:: fmt:: { self , Debug } ;
7
7
use std:: mem;
@@ -12,8 +12,7 @@ use cfg_if::cfg_if;
12
12
#[ cfg( all(
13
13
feature = "mount" ,
14
14
any(
15
- target_os = "dragonfly" ,
16
- target_os = "freebsd" ,
15
+ freebsdlike,
17
16
target_os = "macos" ,
18
17
target_os = "netbsd" ,
19
18
target_os = "openbsd"
@@ -32,7 +31,7 @@ pub type fsid_t = libc::__fsid_t;
32
31
pub type fsid_t = libc:: fsid_t ;
33
32
34
33
cfg_if ! {
35
- if #[ cfg( any( target_os = "android" , target_os = "fuchsia" , target_os = "linux ") ) ] {
34
+ if #[ cfg( any( linux_android , target_os = "fuchsia" ) ) ] {
36
35
type type_of_statfs = libc:: statfs64;
37
36
const LIBC_FSTATFS : unsafe extern fn
38
37
( fd: libc:: c_int, buf: * mut type_of_statfs) -> libc:: c_int
@@ -288,10 +287,7 @@ pub const XENFS_SUPER_MAGIC: FsType =
288
287
#[ cfg( linux_android) ]
289
288
#[ allow( missing_docs) ]
290
289
pub const NSFS_MAGIC : FsType = FsType ( libc:: NSFS_MAGIC as fs_type_t ) ;
291
- #[ cfg( all(
292
- any( target_os = "linux" , target_os = "android" ) ,
293
- not( target_env = "musl" )
294
- ) ) ]
290
+ #[ cfg( all( linux_android, not( target_env = "musl" ) ) ) ]
295
291
#[ allow( missing_docs) ]
296
292
pub const XFS_SUPER_MAGIC : FsType = FsType ( libc:: XFS_SUPER_MAGIC as fs_type_t ) ;
297
293
@@ -307,7 +303,7 @@ impl Statfs {
307
303
}
308
304
309
305
/// Magic code defining system type
310
- #[ cfg( not( any ( target_os = "linux" , target_os = "android" ) ) ) ]
306
+ #[ cfg( not( linux_android ) ) ]
311
307
pub fn filesystem_type_name ( & self ) -> & str {
312
308
let c_str = unsafe { CStr :: from_ptr ( self . 0 . f_fstypename . as_ptr ( ) ) } ;
313
309
c_str. to_str ( ) . unwrap ( )
@@ -434,8 +430,7 @@ impl Statfs {
434
430
#[ cfg( all(
435
431
feature = "mount" ,
436
432
any(
437
- target_os = "dragonfly" ,
438
- target_os = "freebsd" ,
433
+ freebsdlike,
439
434
target_os = "macos" ,
440
435
target_os = "netbsd" ,
441
436
target_os = "openbsd"
@@ -500,11 +495,10 @@ impl Statfs {
500
495
/// Total data blocks in filesystem
501
496
#[ cfg( any(
502
497
apple_targets,
503
- target_os = "android" ,
498
+ linux_android ,
504
499
target_os = "freebsd" ,
505
500
target_os = "fuchsia" ,
506
501
target_os = "openbsd" ,
507
- target_os = "linux" ,
508
502
) ) ]
509
503
pub fn blocks ( & self ) -> u64 {
510
504
self . 0 . f_blocks
@@ -525,11 +519,10 @@ impl Statfs {
525
519
/// Free blocks in filesystem
526
520
#[ cfg( any(
527
521
apple_targets,
528
- target_os = "android" ,
522
+ linux_android ,
529
523
target_os = "freebsd" ,
530
524
target_os = "fuchsia" ,
531
525
target_os = "openbsd" ,
532
- target_os = "linux" ,
533
526
) ) ]
534
527
pub fn blocks_free ( & self ) -> u64 {
535
528
self . 0 . f_bfree
@@ -548,12 +541,7 @@ impl Statfs {
548
541
}
549
542
550
543
/// Free blocks available to unprivileged user
551
- #[ cfg( any(
552
- apple_targets,
553
- target_os = "android" ,
554
- target_os = "fuchsia" ,
555
- target_os = "linux" ,
556
- ) ) ]
544
+ #[ cfg( any( apple_targets, linux_android, target_os = "fuchsia" ) ) ]
557
545
pub fn blocks_available ( & self ) -> u64 {
558
546
self . 0 . f_bavail
559
547
}
@@ -579,11 +567,10 @@ impl Statfs {
579
567
/// Total file nodes in filesystem
580
568
#[ cfg( any(
581
569
apple_targets,
582
- target_os = "android" ,
570
+ linux_android ,
583
571
target_os = "freebsd" ,
584
572
target_os = "fuchsia" ,
585
573
target_os = "openbsd" ,
586
- target_os = "linux" ,
587
574
) ) ]
588
575
pub fn files ( & self ) -> u64 {
589
576
self . 0 . f_files
@@ -604,10 +591,9 @@ impl Statfs {
604
591
/// Free file nodes in filesystem
605
592
#[ cfg( any(
606
593
apple_targets,
607
- target_os = "android" ,
594
+ linux_android ,
608
595
target_os = "fuchsia" ,
609
596
target_os = "openbsd" ,
610
- target_os = "linux" ,
611
597
) ) ]
612
598
pub fn files_free ( & self ) -> u64 {
613
599
self . 0 . f_ffree
@@ -651,8 +637,7 @@ impl Debug for Statfs {
651
637
#[ cfg( all(
652
638
feature = "mount" ,
653
639
any(
654
- target_os = "dragonfly" ,
655
- target_os = "freebsd" ,
640
+ freebsdlike,
656
641
target_os = "macos" ,
657
642
target_os = "netbsd" ,
658
643
target_os = "openbsd"
0 commit comments