Trait BlockDevice

Source
pub trait BlockDevice {
    // Required methods
    fn block_size(&self) -> usize;
    fn block_count(&self) -> usize;
    fn read_block(&self, block_index: usize, buf: &mut [u8]);
    fn write_block(&mut self, block_index: usize, buf: &[u8]);

    // Provided method
    fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<(), ()> { ... }
}

Required Methods§

Source

fn block_size(&self) -> usize

Determines the block size of this device. The returned value must never change.

Source

fn block_count(&self) -> usize

Determines the amount of blocks that this device has available.

Source

fn read_block(&self, block_index: usize, buf: &mut [u8])

Reads the block with the given block_index into the given buffer. The buffer must be at least as big as the value returned by BlockDevice::block_size, otherwise an implementation may panic.

Source

fn write_block(&mut self, block_index: usize, buf: &[u8])

Writes the given buffer into the block with the given block index. The buffer must be exactly as big as the value returned by BlockDevice::block_size, otherwise an implementation may panic.

Provided Methods§

Source

fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<(), ()>

Reads buf.len() bytes starting at at the given byte offset into the given buffer. Returns an error if the read would exceed the length of this block device.

Implementors§