Skip to main content

RamInode

Struct RamInode 

Source
pub struct RamInode { /* private fields */ }
Expand description

RamFS Inode结构

存储文件元数据和数据

Implementations§

Source§

impl RamInode

Source

pub fn new_file(ino: usize) -> RamInode

创建新的文件inode

Source

pub fn new_directory(ino: usize) -> RamInode

创建新的目录inode

Source

pub fn metadata(&self) -> FileMetadata

Return file metadata for stat-like callers.

Return the inode link count.

Source

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

从文件的指定位置读取数据

§参数
  • offset - 起始位置
  • buf - 读取缓冲区
§返回值
  • Ok(n) - 成功读取n字节
  • Err(e) - 读取失败
Source

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

向文件的指定位置写入数据

§参数
  • offset - 起始位置
  • buf - 要写入的数据
§返回值
  • Ok(n) - 成功写入n字节
  • Err(e) - 写入失败
Source

pub fn truncate(&mut self, size: usize) -> Result<(), FileError>

将文件截断到指定大小

§参数
  • size - 新的文件大小
§示例
  • truncate(0): 清空文件
  • truncate(100): 将文件设置为100字节
Source

pub fn add_entry( &mut self, name: String, inode: Arc<Mutex<RamInode>>, ) -> Result<(), FileError>

向目录添加条目

§参数
  • name - 条目名称
  • inode - Inode引用
§错误
  • NotDirectory - 不是目录
  • AlreadyExists - 条目已存在
Source

pub fn lookup(&self, name: &str) -> Result<Arc<Mutex<RamInode>>, FileError>

在目录中查找条目

§参数
  • name - 要查找的条目名称
§返回值
  • Ok(inode) - 找到的条目
  • Err(NotFound) - 条目不存在
Source

pub fn remove_entry(&mut self, name: &str) -> Result<(), FileError>

从目录中删除条目

§参数
  • name - 要删除的条目名称
§注意

只删除目录项,不删除inode (当引用计数为0时,Inode会自动释放)

Source

pub fn list_entries(&self) -> Result<Vec<String>, FileError>

列出目录中的所有条目

§返回值

条目名称的向量(按字母顺序排序)

Trait Implementations§

Source§

impl Inode for RamInode

实现Inode trait

Source§

fn ino(&self) -> usize

Source§

fn file_type(&self) -> FileType

Source§

fn size(&self) -> usize

Source§

fn mode(&self) -> u32

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.