ax_driver_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#[cfg(feature = "ramdisk-static")]
13pub mod ramdisk_static;
14
15#[cfg(feature = "ahci")]
16pub mod ahci;
17#[cfg(feature = "sdmmc")]
18pub mod sdmmc;
19
20#[doc(no_inline)]
21pub use ax_driver_base::{BaseDriverOps, DevError, DevResult, DeviceType};
22
23/// Operations that require a block storage device driver to implement.
24pub trait BlockDriverOps: BaseDriverOps {
25 /// The number of blocks in this storage device.
26 ///
27 /// The total size of the device is `num_blocks() * block_size()`.
28 fn num_blocks(&self) -> u64;
29 /// The size of each block in bytes.
30 fn block_size(&self) -> usize;
31
32 /// Reads blocked data from the given block.
33 ///
34 /// The size of the buffer may exceed the block size, in which case multiple
35 /// contiguous blocks will be read.
36 fn read_block(&mut self, block_id: u64, buf: &mut [u8]) -> DevResult;
37
38 /// Writes blocked data to the given block.
39 ///
40 /// The size of the buffer may exceed the block size, in which case multiple
41 /// contiguous blocks will be written.
42 fn write_block(&mut self, block_id: u64, buf: &[u8]) -> DevResult;
43
44 /// Flushes the device to write all pending data to the storage.
45 fn flush(&mut self) -> DevResult;
46}