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
impl TmpfsInode
Sourcepub fn new(
inode_no: usize,
inode_type: InodeType,
mode: FileMode,
parent: Weak<TmpfsInode>,
stats: Arc<Mutex<TmpfsStats>>,
) -> Arc<Self>
pub fn new( inode_no: usize, inode_type: InodeType, mode: FileMode, parent: Weak<TmpfsInode>, stats: Arc<Mutex<TmpfsStats>>, ) -> Arc<Self>
创建新的 tmpfs inode(通用构造函数)
Sourcepub fn new_root(stats: Arc<Mutex<TmpfsStats>>) -> Arc<Self>
pub fn new_root(stats: Arc<Mutex<TmpfsStats>>) -> Arc<Self>
创建根目录
Sourcefn alloc_inode_no(&self) -> usize
fn alloc_inode_no(&self) -> usize
分配新的 inode 编号
Sourcefn can_alloc_pages(&self, num_pages: usize) -> bool
fn can_alloc_pages(&self, num_pages: usize) -> bool
检查是否有足够的空间分配新页
Sourcefn inc_allocated_pages(&self, num: usize)
fn inc_allocated_pages(&self, num: usize)
增加已分配页数
Sourcefn dec_allocated_pages(&self, num: usize)
fn dec_allocated_pages(&self, num: usize)
减少已分配页数
Sourcefn update_atime(&self)
fn update_atime(&self)
更新访问时间
Sourcefn update_mtime(&self)
fn update_mtime(&self)
更新修改时间
fn reserve_page(&self) -> Result<(), FsError>
fn cancel_page_reservation(&self)
Trait Implementations§
Source§impl Inode for TmpfsInode
impl Inode for TmpfsInode
Source§fn metadata(&self) -> Result<InodeMetadata, FsError>
fn metadata(&self) -> Result<InodeMetadata, FsError>
获取文件元数据
Source§fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<usize, FsError>
fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<usize, FsError>
从指定偏移量读取数据 Read more
Source§fn rename(
&self,
_old_name: &str,
_new_parent: Arc<dyn Inode>,
_new_name: &str,
) -> Result<(), FsError>
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>
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>
fn mknod( &self, name: &str, mode: FileMode, dev: u64, ) -> Result<Arc<dyn Inode>, FsError>
创建设备文件节点
Source§fn set_dentry(&self, _dentry: Weak<Dentry>)
fn set_dentry(&self, _dentry: Weak<Dentry>)
设置 Dentry(可选方法)
Source§fn get_dentry(&self) -> Option<Arc<Dentry>>
fn get_dentry(&self) -> Option<Arc<Dentry>>
获取 Dentry(可选方法)