TmpfsInode

Struct TmpfsInode 

Source
pub struct TmpfsInode {
    metadata: SpinLock<InodeMetadata>,
    data: Mutex<Vec<Option<Arc<FrameTracker>>>>,
    parent: Mutex<Weak<TmpfsInode>>,
    children: Mutex<BTreeMap<String, Arc<TmpfsInode>>>,
    stats: Arc<Mutex<TmpfsStats>>,
    self_ref: Mutex<Weak<TmpfsInode>>,
}
Expand description

Tmpfs Inode 实现

文件数据直接存储在物理页中,按需分配

Fields§

§metadata: SpinLock<InodeMetadata>

Inode 元数据

§data: Mutex<Vec<Option<Arc<FrameTracker>>>>

文件数据页(稀疏存储) 索引:页号 (offset / PAGE_SIZE) 值:物理帧 (None 表示空洞)

§parent: Mutex<Weak<TmpfsInode>>

父目录(弱引用,避免循环引用)

§children: Mutex<BTreeMap<String, Arc<TmpfsInode>>>

子节点(仅对目录有效)

§stats: Arc<Mutex<TmpfsStats>>

Tmpfs 统计信息(共享引用)

§self_ref: Mutex<Weak<TmpfsInode>>

指向自身的弱引用(用于 lookup “.” 和作为子节点的父节点)

Implementations§

Source§

impl TmpfsInode

Source

pub fn new( inode_no: usize, inode_type: InodeType, mode: FileMode, parent: Weak<TmpfsInode>, stats: Arc<Mutex<TmpfsStats>>, ) -> Arc<Self>

创建新的 tmpfs inode(通用构造函数)

Source

pub fn new_root(stats: Arc<Mutex<TmpfsStats>>) -> Arc<Self>

创建根目录

Source

fn alloc_inode_no(&self) -> usize

分配新的 inode 编号

Source

fn can_alloc_pages(&self, num_pages: usize) -> bool

检查是否有足够的空间分配新页

Source

fn inc_allocated_pages(&self, num: usize)

增加已分配页数

Source

fn dec_allocated_pages(&self, num: usize)

减少已分配页数

Source

fn update_atime(&self)

更新访问时间

Source

fn update_mtime(&self)

更新修改时间

Source

fn reserve_page(&self) -> Result<(), FsError>

Source

fn cancel_page_reservation(&self)

Trait Implementations§

Source§

impl Inode for TmpfsInode

Source§

fn metadata(&self) -> Result<InodeMetadata, FsError>

获取文件元数据
Source§

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

从指定偏移量读取数据 Read more
Source§

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

向指定偏移量写入数据
Source§

fn lookup(&self, name: &str) -> Result<Arc<dyn Inode>, FsError>

在目录中查找子项 Read more
Source§

fn create(&self, name: &str, mode: FileMode) -> Result<Arc<dyn Inode>, FsError>

在目录中创建文件
Source§

fn mkdir(&self, name: &str, mode: FileMode) -> Result<Arc<dyn Inode>, FsError>

在目录中创建子目录
删除普通文件/链接
Source§

fn rmdir(&self, name: &str) -> Result<(), FsError>

删除目录
Source§

fn readdir(&self) -> Result<Vec<DirEntry>, FsError>

列出目录内容
Source§

fn truncate(&self, new_size: usize) -> Result<(), FsError>

截断文件到指定大小
Source§

fn sync(&self) -> Result<(), FsError>

同步文件数据到存储设备
Source§

fn as_any(&self) -> &dyn Any

向下转型为 &dyn Any,用于支持 downcast
创建符号链接
创建硬链接
Source§

fn rename( &self, _old_name: &str, _new_parent: Arc<dyn Inode>, _new_name: &str, ) -> Result<(), FsError>

重命名/移动 (原子操作)
Source§

fn set_times( &self, atime: Option<TimeSpec>, mtime: Option<TimeSpec>, ) -> Result<(), FsError>

设置文件时间戳
读取符号链接的目标路径
Source§

fn mknod( &self, name: &str, mode: FileMode, dev: u64, ) -> Result<Arc<dyn Inode>, FsError>

创建设备文件节点
Source§

fn chmod(&self, _mode: FileMode) -> Result<(), FsError>

修改文件权限模式 Read more
Source§

fn chown(&self, _uid: u32, _gid: u32) -> Result<(), FsError>

修改文件所有者和组 Read more
Source§

fn set_dentry(&self, _dentry: Weak<Dentry>)

设置 Dentry(可选方法)
Source§

fn get_dentry(&self) -> Option<Arc<Dentry>>

获取 Dentry(可选方法)

Auto Trait Implementations§

§

impl !Freeze for TmpfsInode

§

impl !RefUnwindSafe for TmpfsInode

§

impl Send for TmpfsInode

§

impl Sync for TmpfsInode

§

impl Unpin for TmpfsInode

§

impl !UnwindSafe for TmpfsInode

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.