⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

VirtioBlkDevice

Struct VirtioBlkDevice 

Source
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

Source

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:

  1. Reset + ACKNOWLEDGE + DRIVER
  2. Read and negotiate features
  3. Set up virtqueue 0 (request queue)
  4. Set FEATURES_OK + DRIVER_OK
  5. Read device configuration (capacity)
Source

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).

Source

pub fn capacity_sectors(&self) -> u64

Get device capacity in 512-byte sectors.

Source

pub fn capacity_bytes(&self) -> u64

Get device capacity in bytes.

Source

pub fn is_read_only(&self) -> bool

Check if the device is read-only.

Source

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.

Source

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

Source§

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>

Write a block (512 bytes) at the given sector number.
Source§

fn capacity_sectors(&self) -> u64

Get the device capacity in sectors.
Source§

fn is_read_only(&self) -> bool

Check if the device is read-only.
Source§

fn block_size(&self) -> usize

Get the block size in bytes.

Auto Trait Implementations§

§

impl Freeze for VirtioBlkDevice

§

impl RefUnwindSafe for VirtioBlkDevice

§

impl Send for VirtioBlkDevice

§

impl Sync for VirtioBlkDevice

§

impl Unpin for VirtioBlkDevice

§

impl UnwindSafe for VirtioBlkDevice

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.