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§
Sourcefn block_size(&self) -> usize
fn block_size(&self) -> usize
Determines the block size of this device. The returned value must never change.
Sourcefn block_count(&self) -> usize
fn block_count(&self) -> usize
Determines the amount of blocks that this device has available.
Sourcefn read_block(&self, block_index: usize, buf: &mut [u8])
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.
Sourcefn write_block(&mut self, block_index: usize, buf: &[u8])
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.