diff options
Diffstat (limited to 'src/disk')
-rw-r--r-- | src/disk/allocation.rs | 26 |
1 files changed, 21 insertions, 5 deletions
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::<IndirectBlock>(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 + }; } } } |