sel4_virtio_blk/
lib.rs

1//
2// Copyright 2024, Colias Group, LLC
3//
4// SPDX-License-Identifier: BSD-2-Clause
5//
6
7#![no_std]
8
9use core::convert::Infallible;
10use core::ops::Deref;
11
12use sel4_driver_interfaces::block::GetBlockDeviceLayout;
13use virtio_drivers::device::blk::{VirtIOBlk, SECTOR_SIZE};
14use virtio_drivers::{transport::Transport, Hal};
15
16pub struct GetBlockDeviceLayoutWrapper<T>(pub T);
17
18impl<H: Hal, T: Transport, U: Deref<Target = VirtIOBlk<H, T>>> GetBlockDeviceLayout
19    for GetBlockDeviceLayoutWrapper<U>
20{
21    type Error = Infallible;
22
23    fn get_block_size(&mut self) -> Result<usize, Self::Error> {
24        Ok(SECTOR_SIZE)
25    }
26
27    fn get_num_blocks(&mut self) -> Result<u64, Self::Error> {
28        Ok(self.0.deref().capacity())
29    }
30}