From ec2f349a648e4d87fba12d20e338b1cd6d8ef29a Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Mon, 27 Nov 2023 00:11:55 -0800 Subject: Fix directory stuff --- src/disk/allocation.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/disk/allocation.rs') diff --git a/src/disk/allocation.rs b/src/disk/allocation.rs index b88e7d5..a4bb3f7 100644 --- a/src/disk/allocation.rs +++ b/src/disk/allocation.rs @@ -398,7 +398,7 @@ impl AyaFS { } impl AyaFS { - fn get_block_index( + pub(crate) fn get_block_index( &mut self, inode: &Inode, mut block_index_within_inode: usize, @@ -406,7 +406,11 @@ impl AyaFS { // direct block if block_index_within_inode < DIRECT_NUMBER { let block_index = inode.direct[block_index_within_inode] as usize; - return Some(block_index); + return if self.data_bitmap.query(block_index) { + Some(block_index) + } else { + None + }; } else { block_index_within_inode -= DIRECT_NUMBER; } @@ -418,7 +422,11 @@ impl AyaFS { self.get_block::(inode.single_indirect as usize) { let block_index = indirect_block.block.entries[block_index_within_inode] as usize; - Some(block_index) + if self.data_bitmap.query(block_index) { + Some(block_index) + } else { + None + } } else { None }; @@ -443,7 +451,11 @@ impl AyaFS { [block_index_within_inode % INODE_PER_BLOCK] as usize; // 拿到 DirectoryBlock 的 index - return Some(block_index); + return if self.data_bitmap.query(block_index) { + Some(block_index) + } else { + None + }; } } return None; @@ -474,7 +486,11 @@ impl AyaFS { [block_index_within_inode % INODE_PER_BLOCK] as usize; // DirectoryBlock 的 index - return Some(block_index); + return if self.data_bitmap.query(block_index) { + Some(block_index) + } else { + None + }; } } } -- cgit v1.2.3-70-g09d2