Skip to main content

Fat

Enum Fat 

Source
pub enum Fat {
    Fat12(Fat12),
    Fat16(Fat16),
    Fat32(Fat32),
}
Expand description

Allocation-table implementation selected for a mounted FAT volume.

Variants§

§

Fat12(Fat12)

FAT12 allocation table.

§

Fat16(Fat16)

FAT16 allocation table.

§

Fat32(Fat32)

FAT32 allocation table.

Implementations§

Source§

impl Fat

Source

pub fn next_cluster<T: Read + Seek>( &self, reader: &mut T, cluster: usize, ) -> Result<Option<u32>>

Returns the next cluster in a chain, or None at end-of-chain.

Source

pub fn fat_type(&self) -> FatType

Get the FAT type for informational purposes

Source

pub fn max_cluster(&self) -> u32

Highest valid cluster number on this volume (inclusive). Clusters 0 and 1 are reserved, so the chain-loop ceiling is max_cluster - 1 distinct clusters; one extra step lets the walker observe the end-of-chain marker before declaring a loop.

Source

pub fn walk_chain<T, F>( &self, reader: &mut T, start: u32, max_steps: u32, visit: F, ) -> Result<u32>
where T: Read + Seek, F: FnMut(u32),

Walk a cluster chain starting at start, calling visit for each cluster (including start) until the chain ends. Returns the last cluster visited.

Aborts with Error::ClusterLoop if more than max_steps clusters are walked. The natural upper bound is Self::max_cluster — any chain longer than that must repeat a cluster and is therefore corrupt.

Source

pub fn truncate_chain<T: Read + Write + Seek>( &self, rw: &mut T, cluster: usize, ) -> Result<u32>

Truncate a cluster chain after the specified cluster.

The specified cluster becomes the end of chain (marked with end-of-chain marker). All clusters following it are freed.

Returns the number of clusters freed.

Source

pub fn free_chain<T: Read + Write + Seek>( &self, rw: &mut T, cluster: usize, ) -> Result<u32>

Free a cluster chain starting at start, returns count of freed clusters.

Source

pub fn mark_bad<T: Read + Write + Seek>( &self, rw: &mut T, cluster: usize, ) -> Result<()>

Mark a cluster as bad in the FAT.

Writes the appropriate bad-cluster marker (0xFF7 / 0xFFF7 / 0x0FFFFFF7) to the FAT entry for the given cluster. This prevents the cluster from being allocated in the future.

Source

pub fn read_status_flags<T: Read + Seek>( &self, reader: &mut T, ) -> Result<(bool, bool)>

Read the FAT-resident status bits from FAT[1].

The FAT spec stores two volume-level status bits in the high bits of the FAT entry for cluster 1:

  • “clean shutdown” (set = clean, cleared = dirty)
  • “no I/O errors” (set = ok, cleared = errors during last use) FAT12 has no spare bits in its packed 12-bit entries, so it returns (false, false) (treat as “clean, no errors”) — matches the spec’s “FAT12 has no status word” reading.

Returns (dirty, io_errors) — both true means trouble.

Source

pub fn fat_copy_count(&self) -> usize

Returns the number of FAT copies on disk (typically 1 or 2).

Source

pub fn compare_entry<T: Read + Seek>( &self, reader: &mut T, cluster: usize, ) -> Result<bool>

Compare a FAT entry between the primary (index 0) and backup (index 1) copies.

Returns Ok(true) if both copies match, Ok(false) if they differ. Returns an error if there is only one FAT copy or on I/O failure.

Source

pub fn next_cluster_with_fallback<T: Read + Seek>( &self, reader: &mut T, cluster: usize, ) -> Result<Option<u32>>

Read the next cluster, falling back to the backup FAT copy on error.

Tries the primary FAT first. If reading fails and a backup FAT exists, reads from the backup copy instead.

Auto Trait Implementations§

§

impl Freeze for Fat

§

impl RefUnwindSafe for Fat

§

impl Send for Fat

§

impl Sync for Fat

§

impl Unpin for Fat

§

impl UnsafeUnpin for Fat

§

impl UnwindSafe for Fat

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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> MaybePod for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.