ros_fs::fs

Struct FileSystem

Source
pub struct FileSystem {
    pub dev: Arc<dyn BlockDevice>,
    pub inode_bitmap: Bitmap,
    pub data_bitmap: Bitmap,
    inode_area_start: u32,
    data_area_start: u32,
}
Expand description

文件系统

一个文件系统包含了一个块设备,一个 inode 位图,一个数据块位图,inode 区域的起始块号,数据区域的起始块号

文件系统物理结构:

  • 超级块 SuperBlock, 包含了文件系统的元信息
  • inode 位示图 Bitmap, 用于标记 inode 块的使用情况
  • inode 区域, 用于存储 inode 结构
  • 数据块位示图 Bitmap, 用于标记数据块的使用情况
  • 数据区域, 用于存储文件数据

Fields§

§dev: Arc<dyn BlockDevice>§inode_bitmap: Bitmap§data_bitmap: Bitmap§inode_area_start: u32§data_area_start: u32

Implementations§

Source§

impl FileSystem

Source

pub fn new( dev: Arc<dyn BlockDevice>, total_blocks: u32, inode_bitmap_blocks: u32, ) -> Arc<Mutex<Self>>

创建一个新的文件系统

在块设备上创建一个新的文件系统,划分出超级块 SuperBlock、inode 位图、inode 区域、数据块位图、数据区域

并将第一个 inode 分配给根目录

§参数
  • dev:块设备
  • total_blocks:总块数
  • inode_bitmap_blocks:inode 位图的块数
Source

pub fn get_disk_inode_pos(&self, inode_id: u32) -> (u32, usize)

获取 inode 的磁盘位置

根据 inode 编号计算 inode 所在的块号和偏移量,一个磁盘块可以存放多个 inode。

§参数
  • inode_id:inode 编号
§返回

inode 所在的块号和偏移量

Source

pub fn get_data_block_id(&self, offset: u32) -> u32

获取数据块的编号

根据数据块的偏移量计算数据块的编号

§参数
  • offset:数据块的偏移量
§返回

数据块的编号

Source

pub fn alloc_inode(&self) -> u32

分配一个 inode

在 inode 位图中分配一个 inode

§返回

inode 编号

Source

pub fn alloc_data_block(&self) -> u32

分配一个数据块

在数据块位图中分配一个数据块

§返回

数据块编号

Source

pub fn free_inode(&self, inode_id: u32)

释放一个 inode

从 inode 位图中释放一个 inode

§参数
  • inode_id:inode 编号
Source

pub fn free_data_block(&self, data_block_id: u32)

释放一个数据块

从数据块位图中释放一个数据块,并清空数据块内容

§参数
  • data_block_id:数据块编号
Source

pub fn open(dev: Arc<dyn BlockDevice>) -> Arc<Mutex<Self>>

打开一个已有的文件系统

从块设备中打开一个已有的文件系统,读取超级块,inode 位图,数据块位图等信息

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.