1pub trait BlockDevice {
7 #[allow(clippy::result_unit_err)]
16 fn read_block(&self, block: u32, buf: &mut [u8; 512]) -> Result<(), ()>;
17}
18
19pub trait SectorDevice {
25 #[allow(clippy::result_unit_err)]
34 fn read_sector(&self, sector: u64, buf: &mut [u8; 512]) -> Result<(), ()>;
35}
36
37impl<T: BlockDevice> SectorDevice for T {
39 fn read_sector(&self, sector: u64, buf: &mut [u8; 512]) -> Result<(), ()> {
40 self.read_block(sector as u32, buf)
41 }
42}
43
44#[derive(Debug, Clone, Copy, PartialEq, Eq)]
46pub enum FsType {
47 Ofs,
49 Ffs,
51}
52
53impl FsType {
54 #[inline]
56 pub const fn data_block_size(self) -> usize {
57 match self {
58 Self::Ofs => crate::OFS_DATA_SIZE,
59 Self::Ffs => crate::FFS_DATA_SIZE,
60 }
61 }
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66pub enum EntryType {
67 Root,
69 Dir,
71 File,
73 HardLinkFile,
75 HardLinkDir,
77 SoftLink,
79}
80
81impl EntryType {
82 pub const fn from_sec_type(sec_type: i32) -> Option<Self> {
84 match sec_type {
85 crate::ST_ROOT => Some(Self::Root),
86 crate::ST_DIR => Some(Self::Dir),
87 crate::ST_FILE => Some(Self::File),
88 crate::ST_LFILE => Some(Self::HardLinkFile),
89 crate::ST_LDIR => Some(Self::HardLinkDir),
90 crate::ST_LSOFT => Some(Self::SoftLink),
91 _ => None,
92 }
93 }
94
95 #[inline]
97 pub const fn is_dir(self) -> bool {
98 matches!(self, Self::Root | Self::Dir | Self::HardLinkDir)
99 }
100
101 #[inline]
103 pub const fn is_file(self) -> bool {
104 matches!(self, Self::File | Self::HardLinkFile)
105 }
106}
107
108#[derive(Debug, Clone, Copy, Default)]
110pub struct FsFlags {
111 pub intl: bool,
113 pub dircache: bool,
115}
116
117impl FsFlags {
118 #[inline]
120 pub const fn from_dos_type(dos_type: u8) -> Self {
121 Self {
122 intl: (dos_type & crate::DOSFS_INTL) != 0,
123 dircache: (dos_type & crate::DOSFS_DIRCACHE) != 0,
124 }
125 }
126}
127
128#[derive(Debug, Clone, Copy, Default)]
130pub struct Access(pub u32);
131
132impl Access {
133 #[inline]
135 pub const fn new(raw: u32) -> Self {
136 Self(raw)
137 }
138
139 #[inline]
141 pub const fn is_delete_protected(self) -> bool {
142 (self.0 & crate::ACC_DELETE) != 0
143 }
144
145 #[inline]
147 pub const fn is_execute_protected(self) -> bool {
148 (self.0 & crate::ACC_EXECUTE) != 0
149 }
150
151 #[inline]
153 pub const fn is_write_protected(self) -> bool {
154 (self.0 & crate::ACC_WRITE) != 0
155 }
156
157 #[inline]
159 pub const fn is_read_protected(self) -> bool {
160 (self.0 & crate::ACC_READ) != 0
161 }
162
163 #[inline]
165 pub const fn is_archived(self) -> bool {
166 (self.0 & crate::ACC_ARCHIVE) != 0
167 }
168
169 #[inline]
171 pub const fn is_pure(self) -> bool {
172 (self.0 & crate::ACC_PURE) != 0
173 }
174
175 #[inline]
177 pub const fn is_script(self) -> bool {
178 (self.0 & crate::ACC_SCRIPT) != 0
179 }
180
181 #[inline]
183 pub const fn is_hold(self) -> bool {
184 (self.0 & crate::ACC_HOLD) != 0
185 }
186}