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
impl RegularFile
Sourcepub fn ino(&self) -> InodeNumber
pub fn ino(&self) -> InodeNumber
Inode number of the file.
Sourcepub fn new(r: impl RegularFile + 'static) -> Self
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
r: An instance of a type that implementstraits::RegularFile.
§Returns
A RegularFile handle that enables reference-counted access to the
underlying file.
Sourcepub fn read(
&self,
position: usize,
buf: &mut [u8],
) -> Result<usize, KernelError>
pub fn read( &self, position: usize, buf: &mut [u8], ) -> Result<usize, KernelError>
Sourcepub fn write(&self, position: usize, buf: &[u8]) -> Result<usize, KernelError>
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: TheFileBlockNumberwhich 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.
Sourcepub fn mmap(&self, fba: FileBlockNumber) -> Result<Page, KernelError>
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).
Sourcepub fn writeback(&self) -> Result<(), KernelError>
pub fn writeback(&self) -> Result<(), KernelError>
Write back the file to disk.
Trait Implementations§
Source§impl Clone for RegularFile
impl Clone for RegularFile
Source§fn clone(&self) -> RegularFile
fn clone(&self) -> RegularFile
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto 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 Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)