ros_fs::virt_fs

Struct MemInode

Source
pub struct MemInode {
    block_id: usize,
    block_offset: usize,
    fs: Arc<Mutex<FileSystem>>,
    dev: Arc<dyn BlockDevice>,
}
Expand description

内存 inode

用于表示虚拟文件系统中的一个 inode,提供了对 inode 的基本操作,存储在内存中,由物理文件系统提供支持。

Fields§

§block_id: usize§block_offset: usize§fs: Arc<Mutex<FileSystem>>§dev: Arc<dyn BlockDevice>

Implementations§

Source§

impl MemInode

Source

pub fn new( block_id: usize, block_offset: usize, fs: Arc<Mutex<FileSystem>>, dev: Arc<dyn BlockDevice>, ) -> Self

创建一个新的内存 inode

§参数
  • block_id:块 ID
  • block_offset:块偏移
  • fs:物理文件系统
  • dev:块设备
Source

fn read_disk_inode<R>(&self, adapter: impl FnOnce(&DiskInode) -> R) -> Option<R>

读取 inode

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

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

Source

fn modify_disk_inode<R>( &self, adapter: impl FnOnce(&mut DiskInode) -> R, ) -> Option<R>

修改 inode

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

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

Source

pub fn find(&self, name: &str) -> Option<Arc<MemInode>>

根据文件名查找 inode

目前仅支持单级目录,查找时会遍历目录项,查找到对应的文件名则返回 inode

§参数
  • name:文件名
§返回

如果找到则返回 inode,否则返回 None

Source

pub fn find_inode_id(&self, name: &str, disk_inode: &DiskInode) -> Option<u32>

根据文件名在目录中查找 inode 编号

§参数
  • name:文件名
  • disk_inode:目录的磁盘 inode
§返回

如果找到则返回 inode 编号,否则返回 None

Source

pub fn ls(&self) -> Vec<String>

列出目录下的所有文件

Source

pub fn create(&self, name: &str, inode_type: InodeType) -> Arc<MemInode>

创建一个新的 inode

§参数
  • name:文件名
  • inode_type:inode 类型,目前仅支持文件
Source

pub fn clear(&self)

删除一个 inode,清除其数据块和 inode

Source

pub fn increase_size( &self, new_size: u32, disk_inode: &mut DiskInode, fs: &mut MutexGuard<'_, FileSystem>, )

增加 inode 的大小

§参数
  • new_size:新的大小
  • disk_inode:磁盘 inode
  • fs:物理文件系统
Source

pub fn read_at(&self, offset: usize, buf: &mut [u8]) -> usize

读取 inode 数据

§参数
  • offset:文件内偏移
  • buf:目标缓冲区
§返回

返回读取的字节数

Source

pub fn write_at(&self, offset: usize, buf: &[u8]) -> usize

写入 inode 数据

§参数
  • offset:文件内偏移
  • buf:源缓冲区
§返回

返回写入的字节数

Source

pub fn get_size(&self) -> u32

获取 inode 的大小

Source

pub fn get_type(&self) -> InodeType

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.