use std::io;
use std::os::unix::io::AsRawFd as _;
use std::path::Path;
use crate::platform::fs::ExtentSharing;
const NON_SHARING: &[&str] = &["hfs", "msdos", "exfat"];
pub fn extent_sharing(path: &Path) -> io::Result<ExtentSharing> {
let file = std::fs::File::open(path)?;
let mut info: libc::statfs = unsafe { std::mem::zeroed() };
if unsafe { libc::fstatfs(file.as_raw_fd(), &mut info) } != 0 {
return Err(io::Error::last_os_error());
}
let name: Vec<u8> = info
.f_fstypename
.iter()
.take_while(|&&byte| byte != 0)
.map(|&byte| byte as u8)
.collect();
let name = String::from_utf8_lossy(&name);
Ok(if NON_SHARING.iter().any(|fs| name.eq_ignore_ascii_case(fs)) {
ExtentSharing::Exclusive
} else {
ExtentSharing::Unknown
})
}