File tree Expand file tree Collapse file tree 4 files changed +431
-11
lines changed
Expand file tree Collapse file tree 4 files changed +431
-11
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use super::{
55use crate :: BLOCK_SZ ;
66use alloc:: sync:: Arc ;
77use spin:: Mutex ;
8+ use core:: mem:: size_of;
89///An easy file system on block
910pub 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}
Original file line number Diff line number Diff 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
9192impl 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 {
You can’t perform that action at this time.
0 commit comments