embedded_fat/filesystem/
cluster.rs

1/// Identifies a cluster on disk.
2///
3/// A cluster is a consecutive group of blocks. Each cluster has a a numeric ID.
4/// Some numeric IDs are reserved for special purposes.
5#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
6#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
7pub struct ClusterId(pub(crate) u32);
8
9impl ClusterId {
10    /// Magic value indicating an invalid cluster value.
11    pub const INVALID: ClusterId = ClusterId(0xFFFF_FFF6);
12    /// Magic value indicating a bad cluster.
13    pub const BAD: ClusterId = ClusterId(0xFFFF_FFF7);
14    /// Magic value indicating a empty cluster.
15    pub const EMPTY: ClusterId = ClusterId(0x0000_0000);
16    /// Magic value indicating the cluster holding the root directory (which
17    /// doesn't have a number in FAT16 as there's a reserved region).
18    pub const ROOT_DIR: ClusterId = ClusterId(0xFFFF_FFFC);
19    /// Magic value indicating that the cluster is allocated and is the final cluster for the file
20    pub const END_OF_FILE: ClusterId = ClusterId(0xFFFF_FFFF);
21}
22
23impl core::ops::Add<u32> for ClusterId {
24    type Output = ClusterId;
25    fn add(self, rhs: u32) -> ClusterId {
26        ClusterId(self.0 + rhs)
27    }
28}
29
30impl core::ops::AddAssign<u32> for ClusterId {
31    fn add_assign(&mut self, rhs: u32) {
32        self.0 += rhs;
33    }
34}