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