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: TrackedInodeThe inode associated with this directory.
removed: AtomicBoolWhether the directory is removed,
Implementations§
Source§impl Directory
impl Directory
Sourcepub fn new(inode: TrackedInode, ffs: Weak<FastFileSystemInner>) -> Option<Self>
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 owningFastFileSystemInner.
§Returns
Some(Directory): if the provided inode is valid and represents a directory.None: if the inode is not of typeFile::Directory.
Sourcepub fn read_dir(
&self,
ffs: &FastFileSystemInner,
) -> Result<Vec<(InodeNumber, String)>, KernelError>
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.
Sourcepub fn find(
&self,
ffs: &FastFileSystemInner,
entry: &str,
) -> Result<InodeNumber, KernelError>
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.
Sourcepub fn add_entry(
&self,
ffs: &Arc<FastFileSystemInner>,
entry: &str,
ino: InodeNumber,
tx: &RunningTransaction<'_>,
) -> Result<(), KernelError>
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).
Sourcepub fn take_entry(
&self,
ffs: &Arc<FastFileSystemInner>,
entry: &str,
tx: &RunningTransaction<'_>,
) -> Result<TrackedInode, KernelError>
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
impl Directory for Directory
Source§fn ino(&self) -> InodeNumber
fn ino(&self) -> InodeNumber
Inode number of the directory.
Source§fn link_count(&self) -> usize
fn link_count(&self) -> usize
Link count of the directory.
Source§fn open_entry(&self, entry: &str) -> Result<File, KernelError>
fn open_entry(&self, entry: &str) -> Result<File, KernelError>
Source§fn create_entry(&self, entry: &str, is_dir: bool) -> Result<File, KernelError>
fn create_entry(&self, entry: &str, is_dir: bool) -> Result<File, KernelError>
Source§fn unlink_entry(&self, entry: &str) -> Result<(), KernelError>
fn unlink_entry(&self, entry: &str) -> Result<(), KernelError>
Removes a directory entry by name.
§Errors
- Returns
KernelError::Busywhen entry’s Inode number is1as it means it’s a root directory. - Returns
KernelError::DirectoryNotEmptywhen the entry is a non-empty directory - Returns
KernelError::NoSuchEntryif specified entry does not exists.
§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>
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>
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.