possum/sys/
unix.rs

1use std::fs::File;
2use std::io;
3use std::path::Path;
4
5pub(crate) use nix::errno::errno;
6
7use crate::env::emulate_freebsd;
8use crate::sys::{DirMeta, FileSystemFlags};
9
10pub fn path_disk_allocation(path: &Path) -> std::io::Result<u64> {
11    let metadata = std::fs::metadata(path)?;
12    use std::os::unix::fs::MetadataExt;
13    Ok(metadata.blocks() * 512)
14}
15
16struct UnixFilesystemFlags {}
17
18impl FileSystemFlags for UnixFilesystemFlags {
19    fn supports_sparse_files(&self) -> bool {
20        // AFAIK, all unix systems support sparse files on all filesystems.
21        true
22    }
23
24    fn supports_block_cloning(&self) -> Option<bool> {
25        // AFAIK there's no way to check if a filesystem supports block cloning on non-Windows
26        // platforms, and even then it depends on where you're copying to/from, sometimes even on
27        // the same filesystem.
28        if emulate_freebsd() {
29            Some(false)
30        } else {
31            None
32        }
33    }
34}
35
36impl DirMeta for File {
37    fn file_system_flags(&self) -> io::Result<impl FileSystemFlags> {
38        Ok(UnixFilesystemFlags {})
39    }
40}