embedded_sdmmc/filesystem/
cluster.rs1#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
8#[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
9pub struct ClusterId(pub(crate) u32);
10
11impl ClusterId {
12 pub const INVALID: ClusterId = ClusterId(0xFFFF_FFF6);
14 pub const BAD: ClusterId = ClusterId(0xFFFF_FFF7);
16 pub const EMPTY: ClusterId = ClusterId(0x0000_0000);
18 pub const ROOT_DIR: ClusterId = ClusterId(0xFFFF_FFFC);
21 pub const END_OF_FILE: ClusterId = ClusterId(0xFFFF_FFFF);
23}
24
25impl core::ops::Add<u32> for ClusterId {
26 type Output = ClusterId;
27 fn add(self, rhs: u32) -> ClusterId {
28 ClusterId(self.0 + rhs)
29 }
30}
31
32impl core::ops::AddAssign<u32> for ClusterId {
33 fn add_assign(&mut self, rhs: u32) {
34 self.0 += rhs;
35 }
36}
37
38impl core::fmt::Debug for ClusterId {
39 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
40 write!(f, "ClusterId(")?;
41 match *self {
42 Self::INVALID => {
43 write!(f, "{:08}", "INVALID")?;
44 }
45 Self::BAD => {
46 write!(f, "{:08}", "BAD")?;
47 }
48 Self::EMPTY => {
49 write!(f, "{:08}", "EMPTY")?;
50 }
51 Self::ROOT_DIR => {
52 write!(f, "{:08}", "ROOT")?;
53 }
54 Self::END_OF_FILE => {
55 write!(f, "{:08}", "EOF")?;
56 }
57 ClusterId(value) => {
58 write!(f, "{:08x}", value)?;
59 }
60 }
61 write!(f, ")")?;
62 Ok(())
63 }
64}
65
66