use core::fmt;
use crate::time::Timestamp;
use crate::{AsHandle, AsPath, BorrowedHandle, ErrorKind, OwnedHandle, Result, sys};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct OpenOptions {
pub(crate) read: bool,
pub(crate) write: bool,
pub(crate) append: bool,
pub(crate) create: bool,
pub(crate) create_new: bool,
pub(crate) truncate: bool,
pub(crate) no_follow: bool,
pub(crate) directory: bool,
pub(crate) mode: u32,
#[cfg(windows)]
pub(crate) execute: bool,
}
impl OpenOptions {
#[inline]
pub const fn new() -> Self {
Self {
read: false,
write: false,
append: false,
create: false,
create_new: false,
truncate: false,
no_follow: false,
directory: false,
mode: 0o666,
#[cfg(windows)]
execute: false,
}
}
#[inline]
pub const fn read(mut self, read: bool) -> Self {
self.read = read;
self
}
#[inline]
pub const fn write(mut self, write: bool) -> Self {
self.write = write;
self
}
#[inline]
pub const fn append(mut self, append: bool) -> Self {
self.append = append;
self
}
#[inline]
pub const fn create(mut self, create: bool) -> Self {
self.create = create;
self
}
#[inline]
pub const fn create_new(mut self, create_new: bool) -> Self {
self.create_new = create_new;
self
}
#[inline]
pub const fn truncate(mut self, truncate: bool) -> Self {
self.truncate = truncate;
self
}
#[inline]
pub const fn no_follow(mut self, no_follow: bool) -> Self {
self.no_follow = no_follow;
self
}
#[inline]
pub const fn directory(mut self, directory: bool) -> Self {
self.directory = directory;
self
}
#[inline]
pub const fn mode(mut self, mode: u32) -> Self {
self.mode = mode;
self
}
pub(crate) fn check(&self) -> Result<()> {
let writes = self.write || self.append;
let truncate = self.truncate && !self.create_new;
let valid = if self.directory {
self.read && !writes && !self.create && !self.create_new && !self.truncate
} else {
(self.read || writes)
&& (writes || !(self.create || self.create_new || self.truncate))
&& !(truncate && (self.append || !self.write))
};
if valid {
Ok(())
} else {
Err(ErrorKind::InvalidInput.into())
}
}
}
impl Default for OpenOptions {
#[inline]
fn default() -> Self {
Self::new()
}
}
#[inline]
pub fn open<P: AsPath + ?Sized>(path: &P, options: &OpenOptions) -> Result<OwnedHandle> {
options.check()?;
sys::fs::open(path.as_path_bytes(), options)
}
fn relative(path: &[u8]) -> Result<&[u8]> {
let Some(&first) = path.first() else {
return Err(ErrorKind::NotFound.into());
};
if path.contains(&0)
|| sys::fs::is_separator(first)
|| path
.split(|&c| sys::fs::is_separator(c))
.any(|component| component == b"..")
{
return Err(ErrorKind::InvalidInput.into());
}
Ok(path)
}
#[inline]
pub fn open_at<P: AsPath + ?Sized>(
dir: impl AsHandle,
path: &P,
options: &OpenOptions,
) -> Result<OwnedHandle> {
options.check()?;
sys::fs::open_at(dir.as_handle(), relative(path.as_path_bytes())?, options)
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum FileType {
File,
Directory,
Symlink,
BlockDevice,
CharDevice,
Fifo,
Socket,
Unknown,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct Permissions(u32);
impl Permissions {
#[inline]
pub const fn from_mode(mode: u32) -> Self {
Self(mode & 0o7777)
}
#[inline]
pub const fn mode(self) -> u32 {
self.0
}
#[inline]
pub const fn readonly(self) -> bool {
self.0 & 0o222 == 0
}
#[inline]
pub const fn set_readonly(&mut self, readonly: bool) {
if readonly {
self.0 &= !0o222;
} else {
self.0 |= 0o200;
}
}
}
impl fmt::Debug for Permissions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Permissions({:#o})", self.0)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Metadata {
pub(crate) file_type: FileType,
pub(crate) len: u64,
pub(crate) mode: u32,
pub(crate) modified: Timestamp,
pub(crate) accessed: Timestamp,
pub(crate) created: Option<Timestamp>,
pub(crate) links: u64,
pub(crate) device: u64,
pub(crate) inode: u64,
pub(crate) raw: u32,
pub(crate) unix: UnixMetadata,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub(crate) struct UnixMetadata {
pub(crate) uid: u32,
pub(crate) gid: u32,
pub(crate) rdev: u64,
pub(crate) blocks: u64,
pub(crate) block_size: u32,
}
impl Metadata {
#[inline]
pub const fn file_type(&self) -> FileType {
self.file_type
}
#[inline]
pub const fn is_file(&self) -> bool {
matches!(self.file_type, FileType::File)
}
#[inline]
pub const fn is_dir(&self) -> bool {
matches!(self.file_type, FileType::Directory)
}
#[inline]
pub const fn is_symlink(&self) -> bool {
matches!(self.file_type, FileType::Symlink)
}
#[inline]
#[allow(clippy::len_without_is_empty)]
pub const fn len(&self) -> u64 {
self.len
}
#[inline]
pub const fn permissions(&self) -> Permissions {
Permissions(self.mode)
}
#[inline]
pub const fn modified(&self) -> Timestamp {
self.modified
}
#[inline]
pub const fn accessed(&self) -> Timestamp {
self.accessed
}
#[inline]
pub const fn created(&self) -> Option<Timestamp> {
self.created
}
#[inline]
pub const fn links(&self) -> u64 {
self.links
}
#[inline]
pub const fn device(&self) -> u64 {
self.device
}
#[inline]
pub const fn inode(&self) -> u64 {
self.inode
}
}
#[inline]
pub fn metadata<P: AsPath + ?Sized>(path: &P) -> Result<Metadata> {
sys::fs::metadata(path.as_path_bytes(), true)
}
#[inline]
pub fn symlink_metadata<P: AsPath + ?Sized>(path: &P) -> Result<Metadata> {
sys::fs::metadata(path.as_path_bytes(), false)
}
#[inline]
pub fn metadata_at<P: AsPath + ?Sized>(dir: impl AsHandle, path: &P) -> Result<Metadata> {
sys::fs::metadata_at(dir.as_handle(), relative(path.as_path_bytes())?, true)
}
#[inline]
pub fn symlink_metadata_at<P: AsPath + ?Sized>(dir: impl AsHandle, path: &P) -> Result<Metadata> {
sys::fs::metadata_at(dir.as_handle(), relative(path.as_path_bytes())?, false)
}
#[inline]
pub fn handle_metadata(handle: impl AsHandle) -> Result<Metadata> {
sys::fs::handle_metadata(handle.as_handle())
}
#[inline]
pub fn set_len(handle: impl AsHandle, len: u64) -> Result<()> {
if len > i64::MAX as u64 {
return Err(ErrorKind::InvalidInput.into());
}
sys::fs::set_len(handle.as_handle(), len)
}
#[inline]
pub fn sync_all(handle: impl AsHandle) -> Result<()> {
sys::fs::sync(handle.as_handle(), false)
}
#[inline]
pub fn sync_data(handle: impl AsHandle) -> Result<()> {
sys::fs::sync(handle.as_handle(), true)
}
#[inline]
pub fn allocate(handle: impl AsHandle, len: u64) -> Result<()> {
if len > i64::MAX as u64 {
return Err(ErrorKind::InvalidInput.into());
}
let handle = handle.as_handle();
if len == 0 {
return sys::fs::handle_metadata(handle).map(drop);
}
sys::fs::allocate(handle, len)
}
#[inline]
pub fn set_permissions<P: AsPath + ?Sized>(path: &P, permissions: Permissions) -> Result<()> {
sys::fs::set_permissions(path.as_path_bytes(), permissions.0)
}
#[inline]
pub fn set_permissions_at<P: AsPath + ?Sized>(
dir: impl AsHandle,
path: &P,
permissions: Permissions,
) -> Result<()> {
sys::fs::set_permissions_at(
dir.as_handle(),
relative(path.as_path_bytes())?,
permissions.0,
)
}
#[inline]
pub fn set_handle_permissions(handle: impl AsHandle, permissions: Permissions) -> Result<()> {
sys::fs::set_handle_permissions(handle.as_handle(), permissions.0)
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct FileTimes {
pub(crate) accessed: Option<Timestamp>,
pub(crate) modified: Option<Timestamp>,
}
impl FileTimes {
#[inline]
pub const fn new() -> Self {
Self {
accessed: None,
modified: None,
}
}
#[inline]
pub const fn accessed(mut self, time: Timestamp) -> Self {
self.accessed = Some(time);
self
}
#[inline]
pub const fn modified(mut self, time: Timestamp) -> Self {
self.modified = Some(time);
self
}
fn check(&self) -> Result<()> {
for time in [self.accessed, self.modified].into_iter().flatten() {
if time.nanos >= 1_000_000_000 {
return Err(ErrorKind::InvalidInput.into());
}
}
Ok(())
}
}
#[inline]
pub fn set_times<P: AsPath + ?Sized>(path: &P, times: FileTimes) -> Result<()> {
times.check()?;
sys::fs::set_times(path.as_path_bytes(), ×)
}
#[inline]
pub fn set_times_at<P: AsPath + ?Sized>(
dir: impl AsHandle,
path: &P,
times: FileTimes,
) -> Result<()> {
times.check()?;
sys::fs::set_times_at(dir.as_handle(), relative(path.as_path_bytes())?, ×)
}
#[inline]
pub fn set_handle_times(handle: impl AsHandle, times: FileTimes) -> Result<()> {
times.check()?;
sys::fs::set_handle_times(handle.as_handle(), ×)
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum LockKind {
Shared,
Exclusive,
}
#[inline]
pub fn lock(handle: impl AsHandle, kind: LockKind) -> Result<()> {
sys::fs::lock(handle.as_handle(), kind, true).map(drop)
}
#[inline]
pub fn try_lock(handle: impl AsHandle, kind: LockKind) -> Result<bool> {
sys::fs::lock(handle.as_handle(), kind, false)
}
#[inline]
pub fn unlock(handle: impl AsHandle) -> Result<()> {
sys::fs::unlock(handle.as_handle())
}
#[inline]
pub fn create_dir<P: AsPath + ?Sized>(path: &P) -> Result<()> {
sys::fs::create_dir(path.as_path_bytes(), 0o777)
}
#[inline]
pub fn create_dir_with_mode<P: AsPath + ?Sized>(path: &P, mode: u32) -> Result<()> {
sys::fs::create_dir(path.as_path_bytes(), mode)
}
#[inline]
pub fn create_dir_at<P: AsPath + ?Sized>(dir: impl AsHandle, path: &P) -> Result<()> {
sys::fs::create_dir_at(dir.as_handle(), relative(path.as_path_bytes())?, 0o777)
}
#[inline]
pub fn create_dir_at_with_mode<P: AsPath + ?Sized>(
dir: impl AsHandle,
path: &P,
mode: u32,
) -> Result<()> {
sys::fs::create_dir_at(dir.as_handle(), relative(path.as_path_bytes())?, mode)
}
#[inline]
pub fn remove_dir<P: AsPath + ?Sized>(path: &P) -> Result<()> {
sys::fs::remove_dir(path.as_path_bytes())
}
#[inline]
pub fn remove_dir_at<P: AsPath + ?Sized>(dir: impl AsHandle, path: &P) -> Result<()> {
sys::fs::remove_dir_at(dir.as_handle(), relative(path.as_path_bytes())?)
}
#[inline]
pub fn remove_file<P: AsPath + ?Sized>(path: &P) -> Result<()> {
sys::fs::remove_file(path.as_path_bytes())
}
#[inline]
pub fn remove_file_at<P: AsPath + ?Sized>(dir: impl AsHandle, path: &P) -> Result<()> {
sys::fs::remove_file_at(dir.as_handle(), relative(path.as_path_bytes())?)
}
#[inline]
pub fn rename<P: AsPath + ?Sized, Q: AsPath + ?Sized>(from: &P, to: &Q) -> Result<()> {
sys::fs::rename(from.as_path_bytes(), to.as_path_bytes())
}
#[inline]
pub fn rename_at<P: AsPath + ?Sized, Q: AsPath + ?Sized>(
from_dir: impl AsHandle,
from: &P,
to_dir: impl AsHandle,
to: &Q,
) -> Result<()> {
sys::fs::rename_at(
from_dir.as_handle(),
relative(from.as_path_bytes())?,
to_dir.as_handle(),
relative(to.as_path_bytes())?,
)
}
#[inline]
pub fn copy<P: AsPath + ?Sized, Q: AsPath + ?Sized>(from: &P, to: &Q) -> Result<u64> {
sys::fs::copy(from.as_path_bytes(), to.as_path_bytes())
}
#[allow(dead_code)]
pub(crate) fn copy_loop(from: BorrowedHandle<'_>, to: BorrowedHandle<'_>) -> Result<u64> {
let interrupted = |error: &crate::Error| error.kind() == ErrorKind::Interrupted;
let mut buf = [0u8; 16 * 1024];
let mut total = 0u64;
loop {
let len = match sys::io::read(from, &mut buf) {
Ok(0) => return Ok(total),
Ok(len) => len,
Err(error) if interrupted(&error) => continue,
Err(error) => return Err(error),
};
let mut data = &buf[..len];
while !data.is_empty() {
match sys::io::write(to, data) {
Ok(0) => return Err(ErrorKind::StorageFull.into()),
Ok(written) => data = &data[written.min(data.len())..],
Err(error) if interrupted(&error) => {}
Err(error) => return Err(error),
}
}
total += len as u64;
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Space {
pub(crate) total: u64,
pub(crate) free: u64,
pub(crate) available: u64,
}
impl Space {
#[inline]
pub const fn total(&self) -> u64 {
self.total
}
#[inline]
pub const fn free(&self) -> u64 {
self.free
}
#[inline]
pub const fn available(&self) -> u64 {
self.available
}
}
#[inline]
pub fn space<P: AsPath + ?Sized>(path: &P) -> Result<Space> {
sys::fs::space(path.as_path_bytes())
}
#[inline]
pub fn handle_space(handle: impl AsHandle) -> Result<Space> {
sys::fs::handle_space(handle.as_handle())
}
#[inline]
pub fn hard_link<P: AsPath + ?Sized, Q: AsPath + ?Sized>(original: &P, link: &Q) -> Result<()> {
sys::fs::hard_link(original.as_path_bytes(), link.as_path_bytes())
}
#[inline]
pub fn hard_link_at<P: AsPath + ?Sized, Q: AsPath + ?Sized>(
original_dir: impl AsHandle,
original: &P,
link_dir: impl AsHandle,
link: &Q,
) -> Result<()> {
sys::fs::hard_link_at(
original_dir.as_handle(),
relative(original.as_path_bytes())?,
link_dir.as_handle(),
relative(link.as_path_bytes())?,
)
}
#[inline]
pub fn symlink<P: AsPath + ?Sized, Q: AsPath + ?Sized>(target: &P, link: &Q) -> Result<()> {
sys::fs::symlink(target.as_path_bytes(), link.as_path_bytes())
}
#[inline]
pub fn symlink_at<P: AsPath + ?Sized, Q: AsPath + ?Sized>(
target: &P,
dir: impl AsHandle,
link: &Q,
) -> Result<()> {
sys::fs::symlink_at(
target.as_path_bytes(),
dir.as_handle(),
relative(link.as_path_bytes())?,
)
}
#[inline]
pub fn read_link<P: AsPath + ?Sized>(path: &P, buf: &mut [u8]) -> Result<usize> {
sys::fs::read_link(path.as_path_bytes(), buf)
}
#[inline]
pub fn read_link_at<P: AsPath + ?Sized>(
dir: impl AsHandle,
path: &P,
buf: &mut [u8],
) -> Result<usize> {
sys::fs::read_link_at(dir.as_handle(), relative(path.as_path_bytes())?, buf)
}
#[inline]
pub fn canonicalize<P: AsPath + ?Sized>(path: &P, buf: &mut [u8]) -> Result<usize> {
sys::fs::canonicalize(path.as_path_bytes(), buf)
}
#[inline]
pub fn current_dir(buf: &mut [u8]) -> Result<usize> {
sys::fs::current_dir(buf)
}
#[inline]
pub fn set_current_dir<P: AsPath + ?Sized>(path: &P) -> Result<()> {
sys::fs::set_current_dir(path.as_path_bytes())
}
#[cfg(feature = "alloc")]
fn to_vec(mut f: impl FnMut(&mut [u8]) -> Result<usize>) -> Result<alloc::vec::Vec<u8>> {
const MAX: usize = 1 << 20;
let mut buf = alloc::vec::Vec::new();
let mut size = 256;
loop {
buf.try_reserve_exact(size - buf.len())
.map_err(|_| ErrorKind::OutOfMemory)?;
buf.resize(size, 0);
match f(&mut buf) {
Ok(len) => {
buf.truncate(len);
return Ok(buf);
}
Err(error) if error.kind() == ErrorKind::BufferTooSmall && size < MAX => size *= 2,
Err(error) => return Err(error),
}
}
}
#[cfg(feature = "alloc")]
pub fn read_link_vec<P: AsPath + ?Sized>(path: &P) -> Result<alloc::vec::Vec<u8>> {
to_vec(|buf| read_link(path, buf))
}
#[cfg(feature = "alloc")]
pub fn read_link_at_vec<P: AsPath + ?Sized>(
dir: impl AsHandle,
path: &P,
) -> Result<alloc::vec::Vec<u8>> {
let dir = dir.as_handle();
to_vec(|buf| read_link_at(dir, path, buf))
}
#[cfg(feature = "alloc")]
pub fn canonicalize_vec<P: AsPath + ?Sized>(path: &P) -> Result<alloc::vec::Vec<u8>> {
to_vec(|buf| canonicalize(path, buf))
}
#[cfg(feature = "alloc")]
pub fn current_dir_vec() -> Result<alloc::vec::Vec<u8>> {
to_vec(current_dir)
}
pub struct Dir(sys::fs::Dir);
impl Dir {
pub fn open<P: AsPath + ?Sized>(path: &P) -> Result<Self> {
const OPTIONS: OpenOptions = OpenOptions::new().read(true).directory(true);
Ok(Self::from_handle(open(path, &OPTIONS)?))
}
pub fn open_at<P: AsPath + ?Sized>(dir: impl AsHandle, path: &P) -> Result<Self> {
const OPTIONS: OpenOptions = OpenOptions::new().read(true).directory(true);
Ok(Self::from_handle(open_at(dir, path, &OPTIONS)?))
}
#[inline]
pub fn from_handle(handle: OwnedHandle) -> Self {
Self(sys::fs::Dir::new(handle))
}
#[allow(clippy::should_implement_trait)]
pub fn next(&mut self) -> Result<Option<DirEntry<'_>>> {
loop {
let Some(raw) = self.0.next()? else {
return Ok(None);
};
if !matches!(self.0.name(&raw), b"." | b"..") {
return Ok(Some(DirEntry {
name: self.0.name(&raw),
file_type: raw.file_type,
inode: raw.inode,
}));
}
}
}
}
impl AsHandle for Dir {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
self.0.handle()
}
}
impl fmt::Debug for Dir {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Dir").field(&self.0.handle()).finish()
}
}
#[derive(Clone, Copy, Debug)]
pub struct DirEntry<'a> {
name: &'a [u8],
file_type: Option<FileType>,
inode: u64,
}
impl<'a> DirEntry<'a> {
#[inline]
pub const fn name(&self) -> &'a [u8] {
self.name
}
#[inline]
pub const fn file_type(&self) -> Option<FileType> {
self.file_type
}
#[inline]
pub const fn inode(&self) -> u64 {
self.inode
}
}
pub(crate) struct RawDirEntry {
pub(crate) name: (usize, usize),
pub(crate) file_type: Option<FileType>,
pub(crate) inode: u64,
}
#[cfg(windows)]
pub mod windows {
mod sealed {
pub trait Sealed {}
impl Sealed for crate::fs::OpenOptions {}
}
pub trait OpenOptionsExt: sealed::Sealed + Sized {
fn execute(self, execute: bool) -> Self;
}
impl OpenOptionsExt for super::OpenOptions {
#[inline]
fn execute(mut self, execute: bool) -> Self {
self.execute = execute;
self
}
}
pub trait MetadataExt {
fn file_attributes(&self) -> u32;
}
impl MetadataExt for super::Metadata {
#[inline]
fn file_attributes(&self) -> u32 {
self.raw
}
}
}
#[cfg(any(target_os = "linux", target_os = "fullrust"))]
pub mod linux;
#[cfg(any(target_os = "linux", target_os = "fullrust", target_os = "macos"))]
pub mod unix {
use crate::{AsHandle, AsPath, Result, sys};
pub trait MetadataExt {
fn raw_mode(&self) -> u32;
fn uid(&self) -> u32;
fn gid(&self) -> u32;
fn rdev(&self) -> u64;
fn blocks(&self) -> u64;
fn block_size(&self) -> u32;
}
impl MetadataExt for super::Metadata {
#[inline]
fn raw_mode(&self) -> u32 {
self.raw
}
#[inline]
fn uid(&self) -> u32 {
self.unix.uid
}
#[inline]
fn gid(&self) -> u32 {
self.unix.gid
}
#[inline]
fn rdev(&self) -> u64 {
self.unix.rdev
}
#[inline]
fn blocks(&self) -> u64 {
self.unix.blocks
}
#[inline]
fn block_size(&self) -> u32 {
self.unix.block_size
}
}
const UNCHANGED: u32 = u32::MAX;
#[inline]
pub fn chown<P: AsPath + ?Sized>(path: &P, uid: Option<u32>, gid: Option<u32>) -> Result<()> {
sys::fs::chown(
path.as_path_bytes(),
uid.unwrap_or(UNCHANGED),
gid.unwrap_or(UNCHANGED),
true,
)
}
#[inline]
pub fn lchown<P: AsPath + ?Sized>(path: &P, uid: Option<u32>, gid: Option<u32>) -> Result<()> {
sys::fs::chown(
path.as_path_bytes(),
uid.unwrap_or(UNCHANGED),
gid.unwrap_or(UNCHANGED),
false,
)
}
#[inline]
pub fn fchown(handle: impl AsHandle, uid: Option<u32>, gid: Option<u32>) -> Result<()> {
sys::fs::fchown(
handle.as_handle(),
uid.unwrap_or(UNCHANGED),
gid.unwrap_or(UNCHANGED),
)
}
#[inline]
pub fn mkfifo<P: AsPath + ?Sized>(path: &P, mode: u32) -> Result<()> {
sys::fs::mkfifo(path.as_path_bytes(), mode & 0o7777)
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum XattrMode {
#[default]
Any,
Create,
Replace,
}
pub fn get_xattr<P: AsPath + ?Sized>(
path: &P,
name: &str,
buf: &mut [u8],
) -> Result<Option<usize>> {
sys::fs::xattr::get(path.as_path_bytes(), name.as_bytes(), buf, true)
}
pub fn lget_xattr<P: AsPath + ?Sized>(
path: &P,
name: &str,
buf: &mut [u8],
) -> Result<Option<usize>> {
sys::fs::xattr::get(path.as_path_bytes(), name.as_bytes(), buf, false)
}
pub fn fget_xattr(handle: impl AsHandle, name: &str, buf: &mut [u8]) -> Result<Option<usize>> {
sys::fs::xattr::fget(handle.as_handle(), name.as_bytes(), buf)
}
pub fn set_xattr<P: AsPath + ?Sized>(
path: &P,
name: &str,
value: &[u8],
mode: XattrMode,
) -> Result<()> {
sys::fs::xattr::set(path.as_path_bytes(), name.as_bytes(), value, mode, true)
}
pub fn lset_xattr<P: AsPath + ?Sized>(
path: &P,
name: &str,
value: &[u8],
mode: XattrMode,
) -> Result<()> {
sys::fs::xattr::set(path.as_path_bytes(), name.as_bytes(), value, mode, false)
}
pub fn fset_xattr(
handle: impl AsHandle,
name: &str,
value: &[u8],
mode: XattrMode,
) -> Result<()> {
sys::fs::xattr::fset(handle.as_handle(), name.as_bytes(), value, mode)
}
pub fn remove_xattr<P: AsPath + ?Sized>(path: &P, name: &str) -> Result<()> {
sys::fs::xattr::remove(path.as_path_bytes(), name.as_bytes(), true)
}
pub fn lremove_xattr<P: AsPath + ?Sized>(path: &P, name: &str) -> Result<()> {
sys::fs::xattr::remove(path.as_path_bytes(), name.as_bytes(), false)
}
pub fn fremove_xattr(handle: impl AsHandle, name: &str) -> Result<()> {
sys::fs::xattr::fremove(handle.as_handle(), name.as_bytes())
}
pub fn list_xattr<P: AsPath + ?Sized>(path: &P, buf: &mut [u8]) -> Result<usize> {
sys::fs::xattr::list(path.as_path_bytes(), buf, true)
}
pub fn llist_xattr<P: AsPath + ?Sized>(path: &P, buf: &mut [u8]) -> Result<usize> {
sys::fs::xattr::list(path.as_path_bytes(), buf, false)
}
pub fn flist_xattr(handle: impl AsHandle, buf: &mut [u8]) -> Result<usize> {
sys::fs::xattr::flist(handle.as_handle(), buf)
}
}