sel4_driver_interfaces/
block.rs

1//
2// Copyright 2024, Colias Group, LLC
3//
4// SPDX-License-Identifier: BSD-2-Clause
5//
6
7use core::cell::RefCell;
8use core::fmt;
9use core::ops::Deref;
10
11use lock_api::{Mutex, RawMutex};
12use serde::{Deserialize, Serialize};
13
14use crate::{WrappedMutex, WrappedRefCell, WrappedRefCellError};
15
16#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
17pub struct MacAddress(pub [u8; 6]);
18
19pub trait GetBlockDeviceLayout {
20    type Error: fmt::Debug;
21
22    fn get_block_size(&mut self) -> Result<usize, Self::Error>;
23
24    fn get_num_blocks(&mut self) -> Result<u64, Self::Error>;
25}
26
27impl<T: Deref<Target = RefCell<U>>, U: GetBlockDeviceLayout> GetBlockDeviceLayout
28    for &WrappedRefCell<T>
29{
30    type Error = WrappedRefCellError<U::Error>;
31
32    fn get_block_size(&mut self) -> Result<usize, Self::Error> {
33        self.with_mut(|this| this.get_block_size())
34    }
35
36    fn get_num_blocks(&mut self) -> Result<u64, Self::Error> {
37        self.with_mut(|this| this.get_num_blocks())
38    }
39}
40
41impl<R: RawMutex, T: Deref<Target = Mutex<R, U>>, U: GetBlockDeviceLayout> GetBlockDeviceLayout
42    for &WrappedMutex<T>
43{
44    type Error = U::Error;
45
46    fn get_block_size(&mut self) -> Result<usize, Self::Error> {
47        self.with_mut(|this| this.get_block_size())
48    }
49
50    fn get_num_blocks(&mut self) -> Result<u64, Self::Error> {
51        self.with_mut(|this| this.get_num_blocks())
52    }
53}