pub struct File<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize>where
D: BlockDevice,
T: TimeSource,{ /* private fields */ }Expand description
A handle for an open file on disk, which closes on drop.
In contrast to a RawFile, a File holds a mutable reference to its
parent VolumeManager, which restricts which operations you can perform.
If you drop a value of this type, it closes the file automatically, but any
error that may occur will be ignored. To handle potential errors, use
the File::close method.
Implementations§
Source§impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>where
D: BlockDevice,
T: TimeSource,
impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>where
D: BlockDevice,
T: TimeSource,
Sourcepub fn new(
raw_file: RawFile,
volume_mgr: &'a VolumeManager<D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>,
) -> Self
pub fn new( raw_file: RawFile, volume_mgr: &'a VolumeManager<D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>, ) -> Self
Create a new File from a RawFile
Sourcepub fn read(&self, buffer: &mut [u8]) -> Result<usize, Error<D::Error>>
pub fn read(&self, buffer: &mut [u8]) -> Result<usize, Error<D::Error>>
Read from the file
Returns how many bytes were read, or an error.
See VolumeManager::read for details, except the file given is this
file.
Sourcepub fn write(&self, buffer: &[u8]) -> Result<(), Error<D::Error>>
pub fn write(&self, buffer: &[u8]) -> Result<(), Error<D::Error>>
Write to the file
See VolumeManager::write for details, except the file given is this
file.
Sourcepub fn is_eof(&self) -> bool
pub fn is_eof(&self) -> bool
Check if a file is at End Of File.
See VolumeManager::file_eof for details, except the file given is this
file.
Sourcepub fn seek_from_current(&self, offset: i32) -> Result<(), Error<D::Error>>
pub fn seek_from_current(&self, offset: i32) -> Result<(), Error<D::Error>>
Seek a file with an offset from the current position.
See VolumeManager::file_seek_from_current for details, except the
file given is this file.
Sourcepub fn seek_from_start(&self, offset: u32) -> Result<(), Error<D::Error>>
pub fn seek_from_start(&self, offset: u32) -> Result<(), Error<D::Error>>
Seek a file with an offset from the start of the file.
See VolumeManager::file_seek_from_start for details, except the
file given is this file.
Sourcepub fn seek_from_end(&self, offset: u32) -> Result<(), Error<D::Error>>
pub fn seek_from_end(&self, offset: u32) -> Result<(), Error<D::Error>>
Seek a file with an offset back from the end of the file.
See VolumeManager::file_seek_from_end for details, except the file
given is this file.
Sourcepub fn length(&self) -> u32
pub fn length(&self) -> u32
Get the length of a file
See VolumeManager::file_length for details, except the file given
is this file.
Sourcepub fn offset(&self) -> u32
pub fn offset(&self) -> u32
Get the current offset of a file
See VolumeManager::file_offset for details, except the file given
is this file.
Sourcepub fn to_raw_file(self) -> RawFile
pub fn to_raw_file(self) -> RawFile
Convert back to a raw file
Sourcepub fn flush(&self) -> Result<(), Error<D::Error>>
pub fn flush(&self) -> Result<(), Error<D::Error>>
Flush any written data by updating the directory entry.
See VolumeManager::flush_file for details, except the file given
is this file.
Sourcepub fn close(self) -> Result<(), Error<D::Error>>
pub fn close(self) -> Result<(), Error<D::Error>>
Consume the File handle and close it. The behavior of this is similar
to using core::mem::drop or letting the File go out of scope,
except this lets the user handle any errors that may occur in the process,
whereas when using drop, any errors will be discarded silently.
Trait Implementations§
Source§impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Debug for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>where
D: BlockDevice,
T: TimeSource,
impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Debug for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>where
D: BlockDevice,
T: TimeSource,
Source§impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Drop for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>where
D: BlockDevice,
T: TimeSource,
impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Drop for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>where
D: BlockDevice,
T: TimeSource,
Source§impl<D: BlockDevice, T: TimeSource, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> ErrorType for File<'_, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
impl<D: BlockDevice, T: TimeSource, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> ErrorType for File<'_, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
Source§impl<D: BlockDevice, T: TimeSource, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Read for File<'_, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
impl<D: BlockDevice, T: TimeSource, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize> Read for File<'_, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
Source§fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf. Read more