Ext4Inode

Struct Ext4Inode 

Source
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: u32

Inode 号

§dentry: SpinLock<Weak<Dentry>>

关联的 Dentry(弱引用,避免循环引用) 用于获取完整路径,而不是在 Inode 中重复存储

Implementations§

Source§

impl Ext4Inode

Source

pub fn new(fs: Arc<Mutex<Ext4>>, ino: u32) -> Self

创建新的 Ext4Inode

注意:初始创建时 dentry 为空,VFS 会在创建 Dentry 后调用 set_dentry()

Source

fn get_full_path(&self) -> Result<String, FsError>

辅助方法:获取完整路径(从 Dentry 动态获取)

Source

fn convert_inode_type(ft: InodeFileType) -> InodeType

辅助方法:将 ext4_rs 的 InodeFileType 转换为 VFS InodeType

Source

fn convert_dir_entry_type(dentry_type: u8) -> InodeType

辅助方法:将ext4_rs的DirEntryType转换为VFS InodeType

Trait Implementations§

Source§

impl Inode for Ext4Inode

Source§

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>

获取文件元数据
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, size: usize) -> Result<(), FsError>

截断文件到指定大小
Source§

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

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

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

设置 Dentry(可选方法)
Source§

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

获取 Dentry(可选方法)
Source§

fn as_any(&self) -> &dyn Any

向下转型为 &dyn Any,用于支持 downcast
Source§

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

设置文件时间戳
Source§

fn chown(&self, uid: u32, gid: u32) -> Result<(), FsError>

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

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

修改文件权限模式 Read more
读取符号链接的目标路径
Source§

fn mknod( &self, _name: &str, _mode: FileMode, _dev: u64, ) -> Result<Arc<dyn Inode>, FsError>

创建设备文件节点

Auto Trait Implementations§

§

impl !Freeze for Ext4Inode

§

impl !RefUnwindSafe for Ext4Inode

§

impl Send for Ext4Inode

§

impl Sync for Ext4Inode

§

impl Unpin for Ext4Inode

§

impl !UnwindSafe for Ext4Inode

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.