rdif_block/
lib.rs

1#![no_std]
2
3extern crate alloc;
4
5pub use alloc::boxed::Box;
6pub use rdif_base::{DriverGeneric, ErrorBase};
7
8pub type Hardware = Box<dyn Interface>;
9
10/// Operations that require a block storage device driver to implement.
11pub trait Interface: DriverGeneric {
12    /// The number of blocks in this storage device.
13    ///
14    /// The total size of the device is `num_blocks() * block_size()`.
15    fn num_blocks(&self) -> u64;
16    /// The size of each block in bytes.
17    fn block_size(&self) -> usize;
18
19    /// Reads blocked data from the given block.
20    ///
21    /// The size of the buffer may exceed the block size, in which case multiple
22    /// contiguous blocks will be read.
23    fn read_block(&mut self, block_id: u64, buf: &mut [u8]) -> Result<(), ErrorBase>;
24
25    /// Writes blocked data to the given block.
26    ///
27    /// The size of the buffer may exceed the block size, in which case multiple
28    /// contiguous blocks will be written.
29    fn write_block(&mut self, block_id: u64, buf: &[u8]) -> Result<(), ErrorBase>;
30
31    /// Flushes the device to write all pending data to the storage.
32    fn flush(&mut self) -> Result<(), ErrorBase>;
33}