mod common;
mod errors;
use std::{fs, ops::Range};
use cfg_if::cfg_if;
use rustix::fs::FileTypeExt;
cfg_if! {
if #[cfg(all(target_os = "linux", feature = "use_linux"))] {
mod linux;
use linux as backend;
} else {
mod fallback;
use fallback as backend;
}
}
pub use backend::{
copy_file_bytes,
copy_file_offset,
copy_node,
copy_sparse,
probably_sparse,
next_sparse_segments,
map_extents,
reflink,
};
pub use common::{
allocate_file,
copy_file,
copy_owner,
copy_permissions,
copy_timestamps,
is_same_file,
merge_extents,
sync,
};
pub use errors::Error;
pub const XATTR_SUPPORTED: bool = {
cfg_if! {
if #[cfg(any(target_os = "linux", target_os = "freebsd"))] {
true
} else {
false
}
}
};
#[derive(Debug)]
pub enum FileType {
File,
Dir,
Symlink,
Socket,
Fifo,
Char,
Block,
Other
}
impl From<fs::FileType> for FileType {
fn from(ft: fs::FileType) -> Self {
if ft.is_dir() {
FileType::Dir
} else if ft.is_file() {
FileType::File
} else if ft.is_symlink() {
FileType::Symlink
} else if ft.is_socket() {
FileType::Socket
} else if ft.is_fifo() {
FileType::Fifo
} else if ft.is_char_device() {
FileType::Char
} else if ft.is_block_device() {
FileType::Block
} else {
FileType::Other
}
}
}
#[derive(Debug, PartialEq)]
pub struct Extent {
pub start: u64,
pub end: u64,
pub shared: bool,
}
impl From<Extent> for Range<u64> {
fn from(e: Extent) -> Self {
e.start..e.end
}
}