Skip to main content

BlockDevice

Trait BlockDevice 

Source
pub trait BlockDevice: Send {
    // Required methods
    fn read_blocks(&self, block_id: u64, buf: &mut [u8]) -> Result<u32>;
    fn write_blocks(&mut self, block_id: u64, buf: &[u8]) -> Result<u32>;
    fn flush(&mut self) -> Result<()>;
    fn block_size(&self) -> u32;
    fn block_count(&self) -> u64;

    // Provided methods
    fn open(&mut self) -> Result<()> { ... }
    fn close(&mut self) -> Result<()> { ... }
}
Expand description

Trait for block devices that can be used with ext4 filesystems.

Implementors must provide block-level read/write operations. All operations are performed on aligned blocks.

Required Methods§

Source

fn read_blocks(&self, block_id: u64, buf: &mut [u8]) -> Result<u32>

Read blocks from the device.

§Arguments
  • block_id - Starting block number
  • buf - Buffer to read into (must be block_size * block_count bytes)
§Returns

Number of blocks read, or error

Source

fn write_blocks(&mut self, block_id: u64, buf: &[u8]) -> Result<u32>

Write blocks to the device.

§Arguments
  • block_id - Starting block number
  • buf - Buffer to write from (must be block_size * block_count bytes)
§Returns

Number of blocks written, or error

Source

fn flush(&mut self) -> Result<()>

Flush any pending writes to the device.

Source

fn block_size(&self) -> u32

Get the physical block size in bytes.

Source

fn block_count(&self) -> u64

Get the total number of blocks.

Provided Methods§

Source

fn open(&mut self) -> Result<()>

Open the device (called before first I/O operation).

Default implementation does nothing.

Source

fn close(&mut self) -> Result<()>

Close the device (called when unmounting).

Default implementation does nothing.

Implementors§