Skip to main content

BlockDevice

Trait BlockDevice 

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

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

Trait for block device operations.

Implement this trait to provide a custom block device backend. The block device must support reading and writing at block granularity.

Required Methods§

Source

fn block_size(&self) -> u32

Returns the physical block size in bytes.

Source

fn block_count(&self) -> u64

Returns the total number of blocks.

Source

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

Read blocks from the device.

§Arguments
  • buf - Buffer to read into (must be at least block_count * block_size bytes)
  • block_id - Starting block number
  • block_count - Number of blocks to read
Source

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

Write blocks to the device.

§Arguments
  • buf - Buffer to write from (must be at least block_count * block_size bytes)
  • block_id - Starting block number
  • block_count - Number of blocks to write

Provided Methods§

Source

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

Open the device (optional).

Source

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

Close the device (optional).

Implementors§

Source§

impl<T> BlockDevice for IoBlockDevice<T>
where T: Read + Write + Seek + Send,