Skip to content

Commit

Permalink
修复了unlink彻底删除文件时,没有回收inode的情况
Browse files Browse the repository at this point in the history
要提交的变更:
      修改:     easy-fs/src/efs.rs
      修改:     easy-fs/src/vfs.rs
  • Loading branch information
Eternal60f3 committed May 18, 2024
1 parent 1a0d00c commit fa18436
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions easy-fs/src/efs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,16 @@ impl EasyFileSystem {
(block_id - self.data_area_start_block) as usize,
)
}
/// dealloc a inode
pub fn dealloc_disk_inode(&mut self, inode_id: u32) {
get_block_cache(inode_id as usize, Arc::clone(&self.block_device))
.lock()
.modify(0, |disk_inode: &mut DataBlock| {
disk_inode.iter_mut().for_each(|p| *p = 0);
});
self.inode_bitmap.dealloc(
&self.block_device,
(inode_id - self.inode_area_start_block) as usize,
);
}
}
5 changes: 4 additions & 1 deletion easy-fs/src/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ impl Inode {
for data_block in data_blocks_dealloc.into_iter() {
fs.dealloc_data(data_block);
}
// fs.inode_bitmap.dealloc(&fs.block_device, self.id() as usize);
}
});

if self.link_cnt() == 0 {
fs.dealloc_disk_inode(self.id());
}
}
#[allow(unused)]
fn link_cnt(&self) -> usize {
Expand Down

0 comments on commit fa18436

Please sign in to comment.