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§
Sourcefn read_sector(&self, sector: u64, buf: &mut [u8]) -> Result<(), BlockError>
fn read_sector(&self, sector: u64, buf: &mut [u8]) -> Result<(), BlockError>
Read a single sector from the device.
Sourcefn write_sector(&self, sector: u64, buf: &[u8]) -> Result<(), BlockError>
fn write_sector(&self, sector: u64, buf: &[u8]) -> Result<(), BlockError>
Write a single sector to the device.
Sourcefn sector_count(&self) -> u64
fn sector_count(&self) -> u64
Get the total number of sectors on the device.
Provided Methods§
Sourcefn read_sectors(
&self,
sector: u64,
count: u16,
buf: &mut [u8],
) -> Result<(), BlockError>
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.
Sourcefn write_sectors(
&self,
sector: u64,
count: u16,
buf: &[u8],
) -> Result<(), BlockError>
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".