ros_fs::block_cache

Struct BlockCache

Source
pub struct BlockCache {
    cache: [u8; 512],
    id: usize,
    dev: Arc<dyn BlockDevice>,
    modified: bool,
}
Expand description

块缓存

用于缓存块设备中的块,减少对块设备的读写次数。

当块缓存被销毁时,会将缓存中的数据写回到块设备中。

Fields§

§cache: [u8; 512]§id: usize§dev: Arc<dyn BlockDevice>§modified: bool

Implementations§

Source§

impl BlockCache

Source

pub fn new(id: usize, dev: Arc<dyn BlockDevice>) -> Self

创建一个新的块缓存

Source

fn get_addr_at(&self, offset: usize) -> usize

Source

fn get_at<T>(&self, offset: usize) -> Option<usize>
where T: Sized,

获取指定偏移处的数据

Source

pub fn get_ref_at<T>(&self, offset: usize) -> Option<&T>
where T: Sized,

获取指定偏移处的数据的引用

Source

pub fn get_mut_at<T>(&mut self, offset: usize) -> Option<&mut T>
where T: Sized,

获取指定偏移处的数据的可变引用

Source

pub fn read_at<T, R>( &self, offset: usize, adapter: impl FnOnce(&T) -> R, ) -> Option<R>
where T: Sized,

读取指定偏移处的数据

在读取数据时,可以通过适配器对数据进行处理

§参数
  • offset:偏移
  • adapter:适配器, 用于在读取数据时进行处理
§返回

返回 适配器 的返回值,如果读取失败则返回 None

Source

pub fn modify_at<T, R>( &mut self, offset: usize, adapter: impl FnOnce(&mut T) -> R, ) -> Option<R>
where T: Sized,

修改指定偏移处的数据

在修改数据时,可以通过适配器对数据进行处理

§参数
  • offset:偏移
  • adapter:适配器, 用于在修改数据时进行处理
§返回

返回 适配器 的返回值,如果修改失败则返回 None

Source

pub fn sync(&mut self)

将缓存中的数据写回到块设备中

Trait Implementations§

Source§

impl Drop for BlockCache

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.