Skip to main content

BlockDevice

Trait BlockDevice 

Source
pub trait BlockDevice {
    // Required methods
    fn read_sector(&self, sector: u64, buf: &mut [u8]) -> Result<(), BlockError>;
    fn write_sector(&self, sector: u64, buf: &[u8]) -> Result<(), BlockError>;
    fn sector_count(&self) -> u64;

    // Provided methods
    fn read_sectors(
        &self,
        sector: u64,
        count: u16,
        buf: &mut [u8],
    ) -> Result<(), BlockError> { ... }
    fn write_sectors(
        &self,
        sector: u64,
        count: u16,
        buf: &[u8],
    ) -> Result<(), BlockError> { ... }
}
Expand description

Block device trait (implemented by VirtIO-blk and AHCI drivers)

Required Methods§

Source

fn read_sector(&self, sector: u64, buf: &mut [u8]) -> Result<(), BlockError>

Read a single sector from the device.

Source

fn write_sector(&self, sector: u64, buf: &[u8]) -> Result<(), BlockError>

Write a single sector to the device.

Source

fn sector_count(&self) -> u64

Get the total number of sectors on the device.

Provided Methods§

Source

fn read_sectors( &self, sector: u64, count: u16, buf: &mut [u8], ) -> Result<(), BlockError>

Read multiple contiguous sectors in a single I/O operation.

The default implementation falls back to calling read_sector in a loop. Drivers that support multi-sector commands (AHCI, NVMe, VirtIO with large descriptors) SHOULD override this for bulk throughput.

Source

fn write_sectors( &self, sector: u64, count: u16, buf: &[u8], ) -> Result<(), BlockError>

Write multiple contiguous sectors in a single I/O operation.

The default implementation falls back to calling write_sector in a loop. Drivers that support multi-sector commands SHOULD override this.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§