diff options
author | Chuyan Zhang <me@zcy.moe> | 2023-12-03 00:44:48 -0800 |
---|---|---|
committer | Chuyan Zhang <me@zcy.moe> | 2023-12-03 00:44:48 -0800 |
commit | 21a9ce8e53224100f331d9a666bc00c630964724 (patch) | |
tree | a57b71974becd920120241b6e947f1082870fee6 /ayafs-core/src/filesystem | |
parent | f5c92834f79dfdf8007daa019f401c5e51a7596f (diff) | |
download | myfs-21a9ce8e53224100f331d9a666bc00c630964724.tar.gz myfs-21a9ce8e53224100f331d9a666bc00c630964724.zip |
fix directory entry counting
Diffstat (limited to 'ayafs-core/src/filesystem')
-rw-r--r-- | ayafs-core/src/filesystem/trait_impl.rs | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/ayafs-core/src/filesystem/trait_impl.rs b/ayafs-core/src/filesystem/trait_impl.rs index 39dba1a..48afac3 100644 --- a/ayafs-core/src/filesystem/trait_impl.rs +++ b/ayafs-core/src/filesystem/trait_impl.rs @@ -497,7 +497,7 @@ impl Filesystem for AyaFS { let mut parent_inode = parent_inode.clone(); // 不存在 -> No such file or directory - if let Ok((inode_index, entry_index, mut inode)) = + if let Ok((inode_index, _, mut inode)) = self.lookup_name(parent, &parent_inode, name) { let inode_index = inode_index as usize; @@ -533,12 +533,11 @@ impl Filesystem for AyaFS { // 删除 dir entry if let Err(err_code) = - self.remove_direntry(parent, &mut parent_inode, name, entry_index) + self.remove_direntry(parent, &mut parent_inode, name) { reply.error(err_code); return; } - parent_inode.size -= 1; self.update_inode(parent, parent_inode); reply.ok(); } else { @@ -580,7 +579,7 @@ impl Filesystem for AyaFS { let mut parent_inode = parent_inode.clone(); // 不存在 -> No such file or directory - if let Ok((inode_index, entry_index, inode)) = + if let Ok((inode_index, _, inode)) = self.lookup_name(parent, &parent_inode, name) { let inode_index = inode_index as usize; @@ -592,7 +591,9 @@ impl Filesystem for AyaFS { // 一定有 . 和 .. 所以 size == 2 就是空目录 // 目录非空 -> ENOTEMPTY - if inode.size > 2 { + let direntry_map = self.dir_entry_map.get(&inode_index).unwrap(); + if direntry_map.len() > 2 { + trace!("deleting inode {} failed, having {} directory entries", inode_index, direntry_map.len()); reply.error(ENOTEMPTY); return; } @@ -608,13 +609,12 @@ impl Filesystem for AyaFS { // 删除 dir entry if let Err(err_code) = - self.remove_direntry(parent, &mut parent_inode, name, entry_index) + self.remove_direntry(parent, &mut parent_inode, name) { reply.error(err_code); return; } - parent_inode.size -= 1; self.update_inode(parent, parent_inode); reply.ok(); } else { @@ -810,7 +810,7 @@ impl Filesystem for AyaFS { let mut parent_inode = parent_inode.clone(); match self.lookup_name(parent, &parent_inode, name) { - Ok((_inode_index, entry_index, _inode)) => { + Ok((_inode_index, _, _inode)) => { if let Some(new_parent_inode) = self.get_inode(new_parent) { if !check_access( req.uid(), @@ -830,7 +830,7 @@ impl Filesystem for AyaFS { let mut new_parent_inode = new_parent_inode.clone(); match self.lookup_name(new_parent, &new_parent_inode, new_name) { - Ok((_new_inode_index, new_entry_index, _new_inode)) => { + Ok((_new_inode_index, _, _new_inode)) => { // 新文件存在 if flags & RENAME_NOREPLACE != 0 { // 指定 noreplace 之后不允许覆盖文件 @@ -859,7 +859,6 @@ impl Filesystem for AyaFS { parent, &mut parent_inode, name, - entry_index, ) { reply.error(err_code); return; @@ -868,7 +867,6 @@ impl Filesystem for AyaFS { new_parent, &mut new_parent_inode, new_name, - new_entry_index, ) { reply.error(err_code); return; @@ -894,7 +892,6 @@ impl Filesystem for AyaFS { parent, &mut parent_inode, name, - entry_index, ) { reply.error(err_code); return; |