#![unstable(feature = "yggdrasil_os", issue = "none")]

use yggdrasil_rt::io::device as rt;
use yggdrasil_rt::sys as syscall;

use crate::io;
use crate::os::fd::AsRawFd;
use crate::sys::cvt_io;

#[unstable(feature = "yggdrasil_os", issue = "none")]
pub type DeviceRequest = rt::DeviceRequest;

#[unstable(feature = "yggdrasil_os", issue = "none")]
pub type MountOptions<'a> = rt::MountOptions<'a>;

#[unstable(feature = "yggdrasil_os", issue = "none")]
pub type UnmountOptions = rt::UnmountOptions;

#[unstable(feature = "yggdrasil_os", issue = "none")]
pub trait FdDeviceRequest {
    #[unstable(feature = "yggdrasil_os", issue = "none")]
    unsafe fn device_request(&self, req: &mut DeviceRequest) -> io::Result<()>;
}

#[unstable(feature = "yggdrasil_os", issue = "none")]
impl<T: AsRawFd> FdDeviceRequest for T {
    unsafe fn device_request(&self, req: &mut DeviceRequest) -> io::Result<()> {
        cvt_io(syscall::device_request(self.as_raw_fd(), req))?;
        Ok(())
    }
}

#[unstable(feature = "yggdrasil_os", issue = "none")]
pub unsafe fn mount_raw(options: &MountOptions<'_>) -> crate::io::Result<()> {
    cvt_io(syscall::mount(options))
}
