#![no_std]
use flagset::{flags, FlagSet};
flags! {
pub enum StatusFlag: u8 {
NotInitialized = 0x01,
WriteProtected = 0x02,
ErrorOccured = 0x04,
}
}
pub type Status = FlagSet<StatusFlag>;
pub type Lba = u64;
pub type SectorSize = usize;
pub type BlockSize = usize;
pub type DataArea = (Lba, Lba);
#[derive(Debug, Clone, Copy)]
pub enum Error<T> {
NotInitialized,
AlreadyInitialized,
NotSupported,
WriteProtected,
InvalidArgument,
Hardware(T),
}
pub enum IoctlCmd<'a> {
CtrlSync,
GetSectorCount(&'a mut Lba),
GetSectorSize(&'a mut SectorSize),
GetBlockSize(&'a mut BlockSize),
CtrlTrim(&'a DataArea),
}
pub trait DiskioDevice {
type HardwareError;
fn status(&self) -> Status;
fn reset(&mut self) {}
fn initialize(&mut self) -> Result<(), Error<Self::HardwareError>>;
fn read(&self, buf: &mut [u8], lba: Lba) -> Result<(), Error<Self::HardwareError>>;
fn write(&self, buf: &[u8], lba: Lba) -> Result<(), Error<Self::HardwareError>>;
fn ioctl(&self, cmd: IoctlCmd) -> Result<(), Error<Self::HardwareError>>;
}