From 17b28b6f9f251a7ddccfd3d8d5daae7b1789bc34 Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Fri, 1 Dec 2023 23:28:51 -0800 Subject: fix inode write_back, fix remove --- ayafs-core/src/filesystem/trait_impl.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'ayafs-core/src/filesystem') diff --git a/ayafs-core/src/filesystem/trait_impl.rs b/ayafs-core/src/filesystem/trait_impl.rs index 78673ba..1c3c7b3 100644 --- a/ayafs-core/src/filesystem/trait_impl.rs +++ b/ayafs-core/src/filesystem/trait_impl.rs @@ -481,8 +481,9 @@ impl Filesystem for AyaFS { } fn unlink(&mut self, req: &Request<'_>, parent: u64, name: &OsStr, reply: ReplyEmpty) { - debug!("unlink(parent: {:#x?}, name: {:?})", parent, name,); - if let Some(parent_inode) = self.get_inode(parent as usize) { + debug!("unlink(parent: {:#x?}, name: {:?})", parent, name); + let parent = parent as usize; + if let Some(parent_inode) = self.get_inode(parent) { // 无权限删除 -> EACCES if !check_access( req.uid(), @@ -511,7 +512,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)) = - self.lookup_name(parent as usize, &parent_inode, name) + self.lookup_name(parent, &parent_inode, name) { let inode_index = inode_index as usize; @@ -546,11 +547,13 @@ impl Filesystem for AyaFS { // 删除 dir entry if let Err(err_code) = - self.remove_direntry(parent as usize, &mut parent_inode, name, entry_index) + self.remove_direntry(parent, &mut parent_inode, name, entry_index) { reply.error(err_code); return; } + parent_inode.size -= 1; + self.update_inode(parent, parent_inode); reply.ok(); } else { reply.error(ENOENT); @@ -561,8 +564,9 @@ impl Filesystem for AyaFS { } fn rmdir(&mut self, req: &Request<'_>, parent: u64, name: &OsStr, reply: ReplyEmpty) { - debug!("rmdir(parent: {:#x?}, name: {:?}", parent, name,); - if let Some(parent_inode) = self.get_inode(parent as usize) { + debug!("rmdir(parent: {:#x?}, name: {:?})", parent, name); + let parent = parent as usize; + if let Some(parent_inode) = self.get_inode(parent) { // 无权限删除 -> EACCES if !check_access( req.uid(), @@ -591,7 +595,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)) = - self.lookup_name(parent as usize, &parent_inode, name) + self.lookup_name(parent, &parent_inode, name) { let inode_index = inode_index as usize; // 要删除的 entry 是一般文件, 不用 rmdir @@ -618,12 +622,14 @@ impl Filesystem for AyaFS { // 删除 dir entry if let Err(err_code) = - self.remove_direntry(parent as usize, &mut parent_inode, name, entry_index) + self.remove_direntry(parent, &mut parent_inode, name, entry_index) { reply.error(err_code); return; } + parent_inode.size -= 1; + self.update_inode(parent, parent_inode); reply.ok(); } else { reply.error(ENOENT); @@ -1152,7 +1158,7 @@ impl Filesystem for AyaFS { _flush: bool, reply: ReplyEmpty, ) { - debug!("release(ino: {:#x?}, fh: {}", ino, fh); + debug!("release(ino: {:#x?}, fh: {})", ino, fh); if self.file_handle_map.contains_key(&fh) { self.file_handle_map.remove(&fh); reply.ok(); @@ -1266,7 +1272,7 @@ impl Filesystem for AyaFS { _flags: i32, reply: ReplyEmpty, ) { - debug!("releasedir(ino: {:#x?}, fh: {}", ino, fh); + debug!("releasedir(ino: {:#x?}, fh: {})", ino, fh); if self.file_handle_map.contains_key(&fh) { self.file_handle_map.remove(&fh); reply.ok(); -- cgit v1.2.3-70-g09d2