mod bad_block;
mod ftl;
pub mod hardware;
mod journal;
mod wear_leveling;
pub use hardware::{FlashGeometry, FlashHardware};
use crate::StorageBackend;
use crate::error::BackendError;
use core::fmt::{Debug, Formatter};
use ftl::FlashTranslationLayer;
pub struct FlashBackend<H: FlashHardware> {
ftl: FlashTranslationLayer<H>,
}
impl<H: FlashHardware> Debug for FlashBackend<H> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("FlashBackend").finish_non_exhaustive()
}
}
impl<H: FlashHardware> FlashBackend<H> {
pub fn mount(hw: H) -> core::result::Result<Self, BackendError> {
let ftl = FlashTranslationLayer::mount(hw)?;
Ok(Self { ftl })
}
pub fn format(hw: H) -> core::result::Result<Self, BackendError> {
let ftl = FlashTranslationLayer::format(hw)?;
Ok(Self { ftl })
}
}
impl<H: FlashHardware> StorageBackend for FlashBackend<H> {
fn len(&self) -> core::result::Result<u64, BackendError> {
self.ftl.len()
}
fn read(&self, offset: u64, out: &mut [u8]) -> core::result::Result<(), BackendError> {
self.ftl.read(offset, out)
}
fn set_len(&self, len: u64) -> core::result::Result<(), BackendError> {
self.ftl.set_len(len)
}
fn sync_data(&self) -> core::result::Result<(), BackendError> {
self.ftl.sync()
}
fn write(&self, offset: u64, data: &[u8]) -> core::result::Result<(), BackendError> {
self.ftl.write(offset, data)
}
fn close(&self) -> core::result::Result<(), BackendError> {
self.ftl.close()
}
}