diff options
author | Chuyan Zhang <me@zcy.moe> | 2023-12-01 23:28:51 -0800 |
---|---|---|
committer | Chuyan Zhang <me@zcy.moe> | 2023-12-01 23:28:51 -0800 |
commit | 17b28b6f9f251a7ddccfd3d8d5daae7b1789bc34 (patch) | |
tree | e81f248dc7744481c6af82ab4a52d2b6cf30d564 /ayafs-core/src/filesystem | |
parent | 4e8448778cdec05f994f0e2772432fd90b6219d5 (diff) | |
download | myfs-17b28b6f9f251a7ddccfd3d8d5daae7b1789bc34.tar.gz myfs-17b28b6f9f251a7ddccfd3d8d5daae7b1789bc34.zip |
fix inode write_back, fix remove
Diffstat (limited to 'ayafs-core/src/filesystem')
-rw-r--r-- | ayafs-core/src/filesystem/trait_impl.rs | 26 |
1 files changed, 16 insertions, 10 deletions
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(); |