axdriver_block/lib.rs
1//! Common traits and types for block storage device drivers (i.e. disk).
2
3#![no_std]
4#![cfg_attr(doc, feature(doc_cfg))]
5
6#[cfg(feature = "bcm2835-sdhci")]
7pub mod bcm2835sdhci;
8
9#[cfg(feature = "ramdisk")]
10pub mod ramdisk;
11
12#[doc(no_inline)]
13pub use axdriver_base::{BaseDriverOps, DevError, DevResult, DeviceType};
14
15/// Operations that require a block storage device driver to implement.
16pub trait BlockDriverOps: BaseDriverOps {
17 /// The number of blocks in this storage device.
18 ///
19 /// The total size of the device is `num_blocks() * block_size()`.
20 fn num_blocks(&self) -> u64;
21 /// The size of each block in bytes.
22 fn block_size(&self) -> usize;
23
24 /// Reads blocked data from the given block.
25 ///
26 /// The size of the buffer may exceed the block size, in which case multiple
27 /// contiguous blocks will be read.
28 fn read_block(&mut self, block_id: u64, buf: &mut [u8]) -> DevResult;
29
30 /// Writes blocked data to the given block.
31 ///
32 /// The size of the buffer may exceed the block size, in which case multiple
33 /// contiguous blocks will be written.
34 fn write_block(&mut self, block_id: u64, buf: &[u8]) -> DevResult;
35
36 /// Flushes the device to write all pending data to the storage.
37 fn flush(&mut self) -> DevResult;
38}