diff options
Diffstat (limited to 'src/disk/data_block.rs')
-rw-r--r-- | src/disk/data_block.rs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/disk/data_block.rs b/src/disk/data_block.rs new file mode 100644 index 0000000..2160b91 --- /dev/null +++ b/src/disk/data_block.rs @@ -0,0 +1,94 @@ +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<usize> { + 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<usize> { + 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<usize> { + 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<usize> { + 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<usize> { + todo!() + } +} |