sel4_virtio_blk/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//
// Copyright 2024, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

#![no_std]

use core::convert::Infallible;
use core::ops::Deref;

use sel4_driver_interfaces::block::GetBlockDeviceLayout;
use virtio_drivers::device::blk::{VirtIOBlk, SECTOR_SIZE};
use virtio_drivers::{transport::Transport, Hal};

pub struct GetBlockDeviceLayoutWrapper<T>(pub T);

impl<H: Hal, T: Transport, U: Deref<Target = VirtIOBlk<H, T>>> GetBlockDeviceLayout
    for GetBlockDeviceLayoutWrapper<U>
{
    type Error = Infallible;

    fn get_block_size(&mut self) -> Result<usize, Self::Error> {
        Ok(SECTOR_SIZE)
    }

    fn get_num_blocks(&mut self) -> Result<u64, Self::Error> {
        Ok(self.0.deref().capacity())
    }
}