pub struct Ext4Inode {
fs: Arc<Mutex<Ext4>>,
ino: u32,
dentry: SpinLock<Weak<Dentry>>,
}Expand description
Ext4 Inode 包装
Fields§
§fs: Arc<Mutex<Ext4>>ext4_rs 文件系统对象
ino: u32Inode 号
dentry: SpinLock<Weak<Dentry>>关联的 Dentry(弱引用,避免循环引用) 用于获取完整路径,而不是在 Inode 中重复存储
Implementations§
Source§impl Ext4Inode
impl Ext4Inode
Sourcepub fn new(fs: Arc<Mutex<Ext4>>, ino: u32) -> Self
pub fn new(fs: Arc<Mutex<Ext4>>, ino: u32) -> Self
创建新的 Ext4Inode
注意:初始创建时 dentry 为空,VFS 会在创建 Dentry 后调用 set_dentry()
Sourcefn get_full_path(&self) -> Result<String, FsError>
fn get_full_path(&self) -> Result<String, FsError>
辅助方法:获取完整路径(从 Dentry 动态获取)
Sourcefn convert_inode_type(ft: InodeFileType) -> InodeType
fn convert_inode_type(ft: InodeFileType) -> InodeType
辅助方法:将 ext4_rs 的 InodeFileType 转换为 VFS InodeType
Sourcefn convert_dir_entry_type(dentry_type: u8) -> InodeType
fn convert_dir_entry_type(dentry_type: u8) -> InodeType
辅助方法:将ext4_rs的DirEntryType转换为VFS InodeType
Trait Implementations§
Source§impl Inode for Ext4Inode
impl Inode for Ext4Inode
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>
重命名或移动文件/目录
§安全性保证
- 并发安全:持有文件系统锁直到操作完成,防止竞态条件
- 失败回滚:关键操作失败时会尝试恢复到原始状态
- 参数验证:严格检查所有前置条件
§安全性限制 ⚠️
- 非崩溃安全:由于 ext4_rs 没有事务日志支持,系统崩溃时可能导致文件系统不一致
- 最坏情况:文件可能同时出现在两个位置,或完全丢失
- 建议:关键操作后调用
sync()确保数据写入磁盘
- 回滚非原子:回滚操作本身也可能失败(如磁盘已满)
- 简化的循环检测:只检查是否移动到自身,未实现完整的祖先链遍历
§注意事项
- 操作持有全局文件系统锁,可能影响并发性能
- 跨目录移动目录比简单重命名更耗时(需要更新 “..” 引用)
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 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(可选方法)