Directory

Trait Directory 

Source
pub trait Directory
where Self: Send + Sync,
{ // Required methods fn ino(&self) -> InodeNumber; fn size(&self) -> usize; fn link_count(&self) -> usize; fn open_entry(&self, entry: &str) -> Result<File, KernelError>; fn create_entry( &self, entry: &str, is_dir: bool, ) -> Result<File, KernelError>; fn unlink_entry(&self, entry: &str) -> Result<(), KernelError>; fn read_dir(&self) -> Result<Vec<(InodeNumber, String)>, KernelError>; fn removed(&self) -> Result<&AtomicBool, KernelError>; }
Expand description

Trait representing a directory in the filesystem.

A directory contains entries that reference other files or directories.

Required Methods§

Source

fn ino(&self) -> InodeNumber

Returns the inode number of the directory.

Source

fn size(&self) -> usize

Returns the size of the file in bytes.

Returns the link count of the directory.

Source

fn open_entry(&self, entry: &str) -> Result<File, KernelError>

Opens an entry by name.

§Parameters
  • entry: The name of the entry to open.
§Returns
  • Ok(File): The enumerate of the file (e.g., regular file, directory).
  • Err(Error): An error if the entry cannot be found or accessed.
Source

fn create_entry(&self, entry: &str, is_dir: bool) -> Result<File, KernelError>

Create an entry by name.

§Parameters
  • entry: The name of the entry to add.
  • is_dir: Indicate whether the entry is directory or not.
§Returns
  • Ok(()): If the entry was successfully added.
  • Err(Error): An error if the add fails.
Source

fn unlink_entry(&self, entry: &str) -> Result<(), KernelError>

Unlinks a directory entry by name.

§Parameters
  • entry: The name of the entry to remove.
§Returns
  • Ok(()): If the entry was successfully removed.
  • Err(Error): An error if the removal fails.
Source

fn read_dir(&self) -> Result<Vec<(InodeNumber, String)>, KernelError>

Reads the contents of the directory.

This function lists all the entries within the directory.

§Returns
  • Ok(()): If the directory was successfully read.
  • Err(Error): An error if the read operation fails.
Source

fn removed(&self) -> Result<&AtomicBool, KernelError>

Returns a reference of AtomicBool which contains whether directory is removed.

This is important because directory operations against the removed directory will result in undesirable behavior (e.g. unreachable file).

§Returns
  • Ok(()): If the directory was successfully read.
  • Err(Error): An error if the operation fails.

Implementors§