pub trait Block: Default {} #[derive(Default)] pub struct DataBlock([u8; 4096]); impl Block for DataBlock {} const FULL_MAP: u32 = 0b111_111_111_111_111; #[derive(Default)] pub struct DirectoryBlock { entries: [[u8; 256]; 15], inode_ids: [usize; 15], occupancy_map: u32, reserved: [u8; 132], } impl Block for DirectoryBlock {} impl DirectoryBlock { fn vacant(&self) -> bool { self.occupancy_map & FULL_MAP != FULL_MAP } fn first_free(&self) -> Option { todo!() } fn mark_busy(&mut self, entry_id: usize) { todo!() } /// 需要判断 entry_name.len() <= 255 pub fn write_entry(&mut self, entry_name: &[u8], entry_inode_id: usize) -> Option { if let Some(entry_id) = self.first_free() { self.mark_busy(entry_id); self.entries[entry_id].copy_from_slice(entry_name); self.inode_ids[entry_id] = entry_inode_id; Some(entry_id) } else { None } } } #[derive(Default)] pub struct IndirectBlock { pub entries: [u32; 1024], } impl Block for IndirectBlock {} impl IndirectBlock { pub fn full(&self) -> bool { todo!() } pub fn allocate(&mut self) -> Option { todo!() } } #[derive(Default)] pub struct DoubleIndirectBlock { pub indirect: [u32; 1024], } impl Block for DoubleIndirectBlock {} impl DoubleIndirectBlock { pub fn full(&self) -> bool { todo!() } pub fn allocate(&mut self) -> Option { todo!() } } #[derive(Default)] pub struct TripleIndirectBlock { pub double_indirect: [u32; 1024], } impl Block for TripleIndirectBlock {} impl TripleIndirectBlock { pub fn full(&self) -> bool { todo!() } pub fn allocate(&mut self) -> Option { todo!() } }