Directory

Struct Directory 

Source
pub struct Directory {
    pub ffs: Weak<FastFileSystemInner>,
    pub inode: TrackedInode,
    pub removed: AtomicBool,
}
Expand description

Represents a directory, which contains multiple directory entries.

This structure provides access to the directory’s inode, which stores information about the directory’s metadata and contents.

Fields§

§ffs: Weak<FastFileSystemInner>

Weak reference to the file system reference.

§inode: TrackedInode

The inode associated with this directory.

§removed: AtomicBool

Whether the directory is removed,

Implementations§

Source§

impl Directory

Source

pub fn new(inode: TrackedInode, ffs: Weak<FastFileSystemInner>) -> Option<Self>

Creates a new Directory from the given inode.

§Arguments
  • inode: The tracked inode representing this directory.
  • ffs: A weak reference to the owning FastFileSystemInner.
§Returns
  • Some(Directory): if the provided inode is valid and represents a directory.
  • None: if the inode is not of type File::Directory.
Source

pub fn read_dir( &self, ffs: &FastFileSystemInner, ) -> Result<Vec<(InodeNumber, String)>, KernelError>

Reads the contents of the directory.

This function lists all the entries within the directory as a [Vec].

A single entry is a tuple that consists of inode number and file name, that is (InodeNumber, String).

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

pub fn find( &self, ffs: &FastFileSystemInner, entry: &str, ) -> Result<InodeNumber, KernelError>

Finds the inode number corresponding to a directory entry by name.

§Arguments
  • ffs: Reference to the file system’s internal structure.
  • entry: The name of the directory entry to search for.
§Returns
  • Ok(inode_number): if the entry is found in the directory.
  • Err(KernelError): if the entry is not found or other errors occurs.
Source

pub fn add_entry( &self, ffs: &Arc<FastFileSystemInner>, entry: &str, ino: InodeNumber, tx: &RunningTransaction<'_>, ) -> Result<(), KernelError>

Adds a new entry to the directory.

§Arguments
  • ffs: Reference to the file system’s internal structure.
  • entry: The name of the new directory entry.
  • is_dir: Whether the entry is a subdirectory (true) or a regular file (false).
  • tx: A running transaction used to persist metadata changes.
§Returns
  • Ok(()): if the entry is successfully added.
  • Err(KernelError): if an error occurs (e.g., entry already exists or out of space).
Source

pub fn take_entry( &self, ffs: &Arc<FastFileSystemInner>, entry: &str, tx: &RunningTransaction<'_>, ) -> Result<TrackedInode, KernelError>

Takes an existing entry out of the directory.

§Arguments
  • ffs: Reference to the file system’s internal structure.
  • entry: The name of the entry to remove.
  • tx: A running transaction used to persist metadata changes.
§Returns
  • Ok(()): if the entry is successfully removed.
  • Err(KernelError): if the entry does not exist or an I/O error occurs.

Trait Implementations§

Source§

impl Directory for Directory

Source§

fn ino(&self) -> InodeNumber

Inode number of the directory.

Source§

fn size(&self) -> usize

Returns the size of the file in bytes.

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>

Add 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>

Removes a directory entry by name.

§Errors
§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 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.

Auto Trait Implementations§

§

impl !Freeze for Directory

§

impl !RefUnwindSafe for Directory

§

impl Send for Directory

§

impl Sync for Directory

§

impl Unpin for Directory

§

impl !UnwindSafe for Directory

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.