1#[cfg(any(target_os = "android", target_os = "linux"))] 2#[test] 3fn test_statfs_abi() { 4 use rustix::fs::{FsWord, StatFs, NFS_SUPER_MAGIC, PROC_SUPER_MAGIC}; 5 6 // Ensure these all have consistent types. 7 let t: StatFs = unsafe { std::mem::zeroed() }; 8 let _s: FsWord = t.f_type; 9 let _u: FsWord = PROC_SUPER_MAGIC; 10 let _v: FsWord = NFS_SUPER_MAGIC; 11 12 // Ensure that after all the platform-specific dancing we have to do, this 13 // constant comes out with the correct value. 14 #[cfg(all(libc, not(target_env = "musl")))] 15 { 16 assert_eq!( 17 i128::from(PROC_SUPER_MAGIC), 18 i128::from(libc::PROC_SUPER_MAGIC) 19 ); 20 assert_eq!( 21 i128::from(NFS_SUPER_MAGIC), 22 i128::from(libc::NFS_SUPER_MAGIC) 23 ); 24 } 25 26 #[cfg(linux_raw)] 27 { 28 assert_eq!( 29 i128::from(PROC_SUPER_MAGIC), 30 i128::from(linux_raw_sys::general::PROC_SUPER_MAGIC) 31 ); 32 assert_eq!( 33 i128::from(NFS_SUPER_MAGIC), 34 i128::from(linux_raw_sys::general::NFS_SUPER_MAGIC) 35 ); 36 } 37 38 assert_eq!(PROC_SUPER_MAGIC, 0x0000_9fa0); 39 assert_eq!(NFS_SUPER_MAGIC, 0x0000_6969); 40} 41 42#[cfg(not(target_os = "netbsd"))] 43#[test] 44fn test_statfs() { 45 let statfs = rustix::fs::statfs("Cargo.toml").unwrap(); 46 let f_blocks = statfs.f_blocks; 47 assert_ne!(f_blocks, 0); 48 // Previously we checked f_files != 0 here, but at least btrfs doesn't set 49 // that. 50} 51 52#[cfg(not(target_os = "netbsd"))] 53#[test] 54fn test_fstatfs() { 55 let file = std::fs::File::open("Cargo.toml").unwrap(); 56 let statfs = rustix::fs::fstatfs(&file).unwrap(); 57 let f_blocks = statfs.f_blocks; 58 assert_ne!(f_blocks, 0); 59 // Previously we checked f_files != 0 here, but at least btrfs doesn't set 60 // that. 61} 62 63/// Test that files in procfs are in a filesystem with `PROC_SUPER_MAGIC`. 64#[cfg(any(target_os = "android", target_os = "linux"))] 65#[test] 66fn test_statfs_procfs() { 67 let statfs = rustix::fs::statfs("/proc/self/maps").unwrap(); 68 69 // Do the field access outside the assert to work around Rust 1.48 thinking 70 // that this is otherwise a packed field borrow. 71 let f_type = statfs.f_type; 72 73 assert_eq!(f_type, rustix::fs::PROC_SUPER_MAGIC); 74} 75 76#[test] 77fn test_statvfs() { 78 let statvfs = rustix::fs::statvfs("Cargo.toml").unwrap(); 79 80 let f_frsize = statvfs.f_frsize; 81 assert_ne!(f_frsize, 0); 82} 83 84#[test] 85fn test_fstatvfs() { 86 let file = std::fs::File::open("Cargo.toml").unwrap(); 87 let statvfs = rustix::fs::fstatvfs(&file).unwrap(); 88 89 let f_frsize = statvfs.f_frsize; 90 assert_ne!(f_frsize, 0); 91} 92