summaryrefslogtreecommitdiff
path: root/src/disk
diff options
context:
space:
mode:
authorChuyan Zhang <me@zcy.moe>2023-11-27 00:11:55 -0800
committerChuyan Zhang <me@zcy.moe>2023-11-27 00:11:55 -0800
commitec2f349a648e4d87fba12d20e338b1cd6d8ef29a (patch)
tree867221cfc9d46b10fee508de5b63996f12704051 /src/disk
parent9d1368b0ea380a9446b4697af668d1685464b6c7 (diff)
downloadmyfs-ec2f349a648e4d87fba12d20e338b1cd6d8ef29a.tar.gz
myfs-ec2f349a648e4d87fba12d20e338b1cd6d8ef29a.zip
Fix directory stuff
Diffstat (limited to 'src/disk')
-rw-r--r--src/disk/allocation.rs26
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
+ };
}
}
}