RegularFile

Struct RegularFile 

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

A handle to a regular file in the filesystem.

This struct represents a low-level kernel handle to a regular file, associated with a specific TrackedInode and the backing FastFileSystemInner instance.

Fields§

§ffs: Weak<FastFileSystemInner>

Weak reference to the FastFileSystemInner.

§inode: TrackedInode

The inode associated with this file.

Implementations§

Source§

impl RegularFile

Source

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

Creates a new RegularFile from a given inode and filesystem reference.

Returns None if the provided inode does not represent a regular file.

§Parameters
  • inode: A tracked reference to the file’s inode.
  • ffs: A weak reference to the filesystem context.
§Returns
  • Some(RegularFile) if the inode is valid and represents a regular file.
  • None if the inode is invalid or not a regular file.

Trait Implementations§

Source§

impl RegularFile for RegularFile

Source§

fn ino(&self) -> InodeNumber

Inode number of the file.

Source§

fn size(&self) -> usize

Returns the size of the file in bytes.

Source§

fn read( &self, fba: FileBlockNumber, buf: &mut [u8; 4096], ) -> Result<bool, KernelError>

Reads data from the file into the provided buffer.

§Parameters
  • ofs: The FileBlockNumber which to read.
  • buf: A mutable array where the file content will be stored.
§Returns
  • Ok(true): If the read success.
  • Ok(false): If the read failed.
  • Err(Error): An error occured while the read operation.
Source§

fn write( &self, fba: FileBlockNumber, buf: &[u8; 4096], min_size: usize, ) -> Result<(), KernelError>

Writes a 4096-byte data into the specified file block.

This method writes the contents of buf to the file block indicated by fba. If the target block lies beyond the current end of the file, the file may be extended up to new_size bytes to accommodate the write.

However, if the target block lies beyond the current file size and new_size is insufficient to reach it, the write will fail.

§Parameters
  • fba: The FileBlockNumber indicating the block to write to.
  • buf: A buffer containing exactly 4096 bytes of data to write.
  • new_size: The desired minimum file size (in bytes) after the write. If this value is less than or equal to the current file size, no growth occurs.
§Returns
  • Ok(()) if the write is successful.
  • Err(KernelError) if the operation fails (e.g., out-of-bounds write, I/O error).
Source§

fn writeback(&self) -> Result<(), KernelError>

Write back the file to disk.
Source§

fn mmap(&self, fba: FileBlockNumber) -> Result<Page, KernelError>

Maps a file block into memory. Read more

Auto Trait Implementations§

§

impl Freeze for RegularFile

§

impl !RefUnwindSafe for RegularFile

§

impl Send for RegularFile

§

impl Sync for RegularFile

§

impl Unpin for RegularFile

§

impl !UnwindSafe for RegularFile

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.