embedded_sdmmc/filesystem/
cluster.rs1#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
6#[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
7pub struct ClusterId(pub(crate) u32);
8
9impl ClusterId {
10 pub const INVALID: ClusterId = ClusterId(0xFFFF_FFF6);
12 pub const BAD: ClusterId = ClusterId(0xFFFF_FFF7);
14 pub const EMPTY: ClusterId = ClusterId(0x0000_0000);
16 pub const ROOT_DIR: ClusterId = ClusterId(0xFFFF_FFFC);
19 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}
35
36impl core::fmt::Debug for ClusterId {
37 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
38 write!(f, "ClusterId(")?;
39 match *self {
40 Self::INVALID => {
41 write!(f, "{:08}", "INVALID")?;
42 }
43 Self::BAD => {
44 write!(f, "{:08}", "BAD")?;
45 }
46 Self::EMPTY => {
47 write!(f, "{:08}", "EMPTY")?;
48 }
49 Self::ROOT_DIR => {
50 write!(f, "{:08}", "ROOT")?;
51 }
52 Self::END_OF_FILE => {
53 write!(f, "{:08}", "EOF")?;
54 }
55 ClusterId(value) => {
56 write!(f, "{:08x}", value)?;
57 }
58 }
59 write!(f, ")")?;
60 Ok(())
61 }
62}
63
64