use abi::{error::Error, io::RawFd, option::RequestValue};

pub use abi::io::filesystem::*;

pub fn filesystem_control<'de, T: RequestValue<'de>>(
    fd: Option<RawFd>,
    buffer: &'de mut [u8],
    request: &T::Request,
) -> Result<T::Response, Error> {
    let len = T::store_request(request, buffer)?;
    let len = unsafe { crate::sys::filesystem_control(fd, T::VARIANT.into(), buffer, len) }?;
    T::load_response(&buffer[..len])
}
