Struct ape_fatfs::fs::FileSystem

source ·
pub struct FileSystem<IO: ReadWriteSeek, TP, OCC> { /* private fields */ }
Expand description

A FAT filesystem object.

FileSystem struct is representing a state of a mounted FAT volume.

Implementations§

source§

impl<IO: Read + Write + Seek, TP, OCC> FileSystem<IO, TP, OCC>

source

pub fn new<T: IntoStorage<IO>>( storage: T, options: FsOptions<TP, OCC> ) -> Result<Self, Error<IO::Error>>where IO::Error: From<ReadExactError<IO::Error>>,

Creates a new filesystem object instance.

Supplied storage parameter cannot be seeked. If there is a need to read a fragment of disk image (e.g. partition) library user should wrap the file struct in a struct limiting access to partition bytes only e.g. fscommon::StreamSlice.

Note: creating multiple filesystem objects with a single underlying storage can cause a filesystem corruption.

Errors

Errors that can be returned:

  • Error::CorruptedFileSystem will be returned if the boot sector and/or the file system information sector contains invalid values.
  • Error::Io will be returned if the provided storage object returned an I/O error.
Panics

Panics in non-optimized build if storage position returned by seek is not zero.

source

pub fn fat_type(&self) -> FatType

Returns a type of File Allocation Table (FAT) used by this filesystem.

source

pub fn volume_id(&self) -> u32

Returns a volume identifier read from BPB in the Boot Sector.

source

pub fn volume_label_as_bytes(&self) -> &[u8]

Returns a volume label from BPB in the Boot Sector as byte array slice.

Label is encoded in the OEM codepage. Note: This function returns label stored in the BPB block. Use read_volume_label_from_root_dir_as_bytes to read label from the root directory.

source

pub fn cluster_size(&self) -> u32

source

pub fn read_status_flags(&self) -> Result<FsStatusFlags, Error<IO::Error>>

Returns status flags for this volume.

Errors

Error::Io will be returned if the underlying storage object returned an I/O error.

source

pub fn stats(&self) -> Result<FileSystemStats, Error<IO::Error>>

Returns filesystem statistics like number of total and free clusters.

For FAT32 volumes number of free clusters from the FS Information Sector is returned (may be incorrect). For other FAT variants number is computed on the first call to this method and cached for later use.

Errors

Error::Io will be returned if the underlying storage object returned an I/O error.

source

pub fn unmount(self) -> Result<(), Error<IO::Error>>

Unmounts the filesystem.

Updates the FS Information Sector if needed.

Errors

Error::Io will be returned if the underlying storage object returned an I/O error.

source

pub fn root_dir(&self) -> Dir<'_, IO, TP, OCC>

Returns a root directory object allowing for futher penetration of a filesystem structure.

source§

impl<IO: ReadWriteSeek, TP, OCC: OemCpConverter> FileSystem<IO, TP, OCC>

source

pub fn volume_label(&self) -> String

Returns a volume label from BPB in the Boot Sector as String.

Non-ASCII characters are replaced by the replacement character (U+FFFD). Note: This function returns label stored in the BPB block. Use read_volume_label_from_root_dir to read label from the root directory.

source§

impl<IO: ReadWriteSeek, TP: TimeProvider, OCC: OemCpConverter> FileSystem<IO, TP, OCC>

source

pub fn read_volume_label_from_root_dir( &self ) -> Result<Option<String>, Error<IO::Error>>

Returns a volume label from root directory as String.

It finds file with VOLUME_ID attribute and returns its short name.

Errors

Error::Io will be returned if the underlying storage object returned an I/O error.

source

pub fn read_volume_label_from_root_dir_as_bytes( &self ) -> Result<Option<[u8; 11]>, Error<IO::Error>>

Returns a volume label from root directory as byte array.

Label is encoded in the OEM codepage. It finds file with VOLUME_ID attribute and returns its short name.

Errors

Error::Io will be returned if the underlying storage object returned an I/O error.

Trait Implementations§

source§

impl<IO: ReadWriteSeek, TP, OCC> Drop for FileSystem<IO, TP, OCC>

Drop implementation tries to unmount the filesystem when dropping.

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<IO, TP, OCC> !RefUnwindSafe for FileSystem<IO, TP, OCC>

§

impl<IO, TP, OCC> Send for FileSystem<IO, TP, OCC>where IO: Send, OCC: Send, TP: Send,

§

impl<IO, TP, OCC> !Sync for FileSystem<IO, TP, OCC>

§

impl<IO, TP, OCC> Unpin for FileSystem<IO, TP, OCC>where IO: Unpin, OCC: Unpin, TP: Unpin,

§

impl<IO, TP, OCC> UnwindSafe for FileSystem<IO, TP, OCC>where IO: UnwindSafe, OCC: UnwindSafe, TP: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.