RegularFile

Struct RegularFile 

Source
pub struct RegularFile(pub Arc<dyn RegularFile>);
Expand description

A handle to a regular file.

This struct provides a reference-counted handle to a file that supports reading and writing operations at the kernel level.

Tuple Fields§

§0: Arc<dyn RegularFile>

Implementations§

Source§

impl RegularFile

Source

pub fn ino(&self) -> InodeNumber

Inode number of the file.

Source

pub fn new(r: impl RegularFile + 'static) -> Self

Creates a new RegularFile handle from a given implementation of traits::RegularFile.

This function takes an instance of any type that implements the traits::RegularFile trait, wraps it in a reference-counted [Arc], and returns a RegularFile handle.

§Parameters
§Returns

A RegularFile handle that enables reference-counted access to the underlying file.

Source

pub fn size(&self) -> usize

Returns the size of the file in bytes.

Source

pub fn read( &self, position: usize, buf: &mut [u8], ) -> Result<usize, KernelError>

Reads data from the file into the provided buffer.

§Parameters
  • fba: The FileBlockNumber which to read.
  • buf: A mutable slice where the file content will be stored.
§Returns
  • Ok(usize): The number of bytes read.
  • Err(Error): An error if the read operation fails.
Source

pub fn write(&self, position: usize, buf: &[u8]) -> Result<usize, KernelError>

Writes data from the buffer into the file.

If the write position is beyond the current file size, file will be extended to minimum size required to reflect the update.

§Parameters
  • fba: The FileBlockNumber which to write.
  • buf: An slice containing the data to write.
§Returns
  • Ok(usize): The number of bytes written.
  • Err(Error): An error if the write operation fails.
Source

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

Maps a file block into memory.

This method retrieves the contents of the file at the specified file block number (fba) and returns it as a Page of the file block.

The memory-mapped page reflects the current contents of the file at the requested block, and it can be used for reading or modifying file data at page granularity.

§Parameters
  • fba: The file block number to map into memory. This is a logical offset into the file, measured in fixed-size blocks (not bytes).
§Returns
  • Ok(Page): A reference-counted, in-memory page containing the file block’s data.
  • Err(KernelError): If the file block cannot be found or loaded (e.g., out-of-bounds access).
Source

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

Write back the file to disk.

Trait Implementations§

Source§

impl Clone for RegularFile

Source§

fn clone(&self) -> RegularFile

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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.