Skip to content

Commit 1960b38

Browse files
committed
finish
1 parent c8b9d55 commit 1960b38

File tree

4 files changed

+431
-11
lines changed

4 files changed

+431
-11
lines changed

easy-fs/src/efs.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::{
55
use crate::BLOCK_SZ;
66
use alloc::sync::Arc;
77
use spin::Mutex;
8+
use core::mem::size_of;
89
///An easy file system on block
910
pub struct EasyFileSystem {
1011
///Real device
@@ -148,4 +149,14 @@ impl EasyFileSystem {
148149
(block_id - self.data_area_start_block) as usize,
149150
)
150151
}
152+
153+
/// 从块号和块内偏移计算inode编号
154+
pub fn get_inode_id(&self, block_id: u32, block_offset: usize) -> u32 {
155+
// 计算 inode 在 inode 区域中的索引
156+
let inodes_per_block = (BLOCK_SZ / size_of::<DiskInode>()) as u32;
157+
let inode_block_index = block_id - self.inode_area_start_block;
158+
let inode_index_in_block = block_offset / size_of::<DiskInode>();
159+
160+
inode_block_index * inodes_per_block + inode_index_in_block as u32
161+
}
151162
}

easy-fs/src/layout.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub struct DiskInode {
8686
pub indirect1: u32,
8787
pub indirect2: u32,
8888
type_: DiskInodeType,
89+
pub nlink: u32, // 新增:硬链接计数
8990
}
9091

9192
impl DiskInode {
@@ -97,6 +98,7 @@ impl DiskInode {
9798
self.indirect1 = 0;
9899
self.indirect2 = 0;
99100
self.type_ = type_;
101+
self.nlink = 1; // 初始化硬链接计数为1
100102
}
101103
/// Whether this inode is a directory
102104
pub fn is_dir(&self) -> bool {

0 commit comments

Comments
 (0)