use crate::{backend, io, path};
use backend::c;
use backend::fd::AsFd;
use bitflags::bitflags;
bitflags! {
pub struct XattrFlags: c::c_uint {
const CREATE = c::XATTR_CREATE as c::c_uint;
const REPLACE = c::XATTR_REPLACE as c::c_uint;
}
}
#[inline]
pub fn getxattr<P: path::Arg, Name: path::Arg>(
path: P,
name: Name,
value: &mut [u8],
) -> io::Result<usize> {
path.into_with_c_str(|path| {
name.into_with_c_str(|name| backend::fs::syscalls::getxattr(path, name, value))
})
}
#[inline]
pub fn lgetxattr<P: path::Arg, Name: path::Arg>(
path: P,
name: Name,
value: &mut [u8],
) -> io::Result<usize> {
path.into_with_c_str(|path| {
name.into_with_c_str(|name| backend::fs::syscalls::lgetxattr(path, name, value))
})
}
#[inline]
pub fn fgetxattr<Fd: AsFd, Name: path::Arg>(
fd: Fd,
name: Name,
value: &mut [u8],
) -> io::Result<usize> {
name.into_with_c_str(|name| backend::fs::syscalls::fgetxattr(fd.as_fd(), name, value))
}
#[inline]
pub fn setxattr<P: path::Arg, Name: path::Arg>(
path: P,
name: Name,
value: &[u8],
flags: XattrFlags,
) -> io::Result<()> {
path.into_with_c_str(|path| {
name.into_with_c_str(|name| backend::fs::syscalls::setxattr(path, name, value, flags))
})
}
#[inline]
pub fn lsetxattr<P: path::Arg, Name: path::Arg>(
path: P,
name: Name,
value: &[u8],
flags: XattrFlags,
) -> io::Result<()> {
path.into_with_c_str(|path| {
name.into_with_c_str(|name| backend::fs::syscalls::lsetxattr(path, name, value, flags))
})
}
#[inline]
pub fn fsetxattr<Fd: AsFd, Name: path::Arg>(
fd: Fd,
name: Name,
value: &[u8],
flags: XattrFlags,
) -> io::Result<()> {
name.into_with_c_str(|name| backend::fs::syscalls::fsetxattr(fd.as_fd(), name, value, flags))
}
#[inline]
pub fn listxattr<P: path::Arg>(path: P, list: &mut [c::c_char]) -> io::Result<usize> {
path.into_with_c_str(|path| backend::fs::syscalls::listxattr(path, list))
}
#[inline]
pub fn llistxattr<P: path::Arg>(path: P, list: &mut [c::c_char]) -> io::Result<usize> {
path.into_with_c_str(|path| backend::fs::syscalls::llistxattr(path, list))
}
#[inline]
pub fn flistxattr<Fd: AsFd>(fd: Fd, list: &mut [c::c_char]) -> io::Result<usize> {
backend::fs::syscalls::flistxattr(fd.as_fd(), list)
}
pub fn removexattr<P: path::Arg, Name: path::Arg>(path: P, name: Name) -> io::Result<()> {
path.into_with_c_str(|path| {
name.into_with_c_str(|name| backend::fs::syscalls::removexattr(path, name))
})
}
pub fn lremovexattr<P: path::Arg, Name: path::Arg>(path: P, name: Name) -> io::Result<()> {
path.into_with_c_str(|path| {
name.into_with_c_str(|name| backend::fs::syscalls::lremovexattr(path, name))
})
}
pub fn fremovexattr<Fd: AsFd, Name: path::Arg>(fd: Fd, name: Name) -> io::Result<()> {
name.into_with_c_str(|name| backend::fs::syscalls::fremovexattr(fd.as_fd(), name))
}