pub struct VirtioBlkDevice { /* private fields */ }Expand description
Virtio block device.
Manages a single virtio-blk PCI device with one request virtqueue (queue 0).
Implementations§
Source§impl VirtioBlkDevice
impl VirtioBlkDevice
Sourcepub fn new(io_base: u16) -> Result<Self, KernelError>
pub fn new(io_base: u16) -> Result<Self, KernelError>
Probe and initialize a virtio-blk device at the given PCI BAR0 I/O base.
Performs the full legacy virtio initialization sequence:
- Reset + ACKNOWLEDGE + DRIVER
- Read and negotiate features
- Set up virtqueue 0 (request queue)
- Set FEATURES_OK + DRIVER_OK
- Read device configuration (capacity)
Sourcepub fn from_mmio(
transport: VirtioMmioTransport,
queue: VirtQueue,
capacity_sectors: u64,
read_only: bool,
features: u32,
) -> Self
pub fn from_mmio( transport: VirtioMmioTransport, queue: VirtQueue, capacity_sectors: u64, read_only: bool, features: u32, ) -> Self
Construct from an MMIO transport + queue (used on AArch64/RISC-V).
Sourcepub fn capacity_sectors(&self) -> u64
pub fn capacity_sectors(&self) -> u64
Get device capacity in 512-byte sectors.
Sourcepub fn capacity_bytes(&self) -> u64
pub fn capacity_bytes(&self) -> u64
Get device capacity in bytes.
Sourcepub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
Check if the device is read-only.
Sourcepub fn read_block(
&mut self,
block_num: u64,
buf: &mut [u8],
) -> Result<(), KernelError>
pub fn read_block( &mut self, block_num: u64, buf: &mut [u8], ) -> Result<(), KernelError>
Read a single block (512 bytes) from the device.
block_num is the 0-based sector number. buf must be at least 512
bytes.
Sourcepub fn write_block(
&mut self,
block_num: u64,
data: &[u8],
) -> Result<(), KernelError>
pub fn write_block( &mut self, block_num: u64, data: &[u8], ) -> Result<(), KernelError>
Write a single block (512 bytes) to the device.
block_num is the 0-based sector number. data must be at least 512
bytes.
Trait Implementations§
Source§impl BlockDevice for VirtioBlkDevice
impl BlockDevice for VirtioBlkDevice
Source§fn read_block(
&mut self,
block_num: u64,
buf: &mut [u8],
) -> Result<(), KernelError>
fn read_block( &mut self, block_num: u64, buf: &mut [u8], ) -> Result<(), KernelError>
Read a block (512 bytes) at the given sector number.
Source§fn write_block(
&mut self,
block_num: u64,
data: &[u8],
) -> Result<(), KernelError>
fn write_block( &mut self, block_num: u64, data: &[u8], ) -> Result<(), KernelError>
Write a block (512 bytes) at the given sector number.
Source§fn capacity_sectors(&self) -> u64
fn capacity_sectors(&self) -> u64
Get the device capacity in sectors.
Source§fn is_read_only(&self) -> bool
fn is_read_only(&self) -> bool
Check if the device is read-only.
Source§fn block_size(&self) -> usize
fn block_size(&self) -> usize
Get the block size in bytes.