rdif_block/
lib.rs

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