diff options
Diffstat (limited to 'ayafs-core/src')
-rw-r--r-- | ayafs-core/src/filesystem/trait_impl.rs | 26 | ||||
-rw-r--r-- | ayafs-core/src/lib.rs | 16 |
2 files changed, 25 insertions, 17 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(); diff --git a/ayafs-core/src/lib.rs b/ayafs-core/src/lib.rs index db3ac28..d73619b 100644 --- a/ayafs-core/src/lib.rs +++ b/ayafs-core/src/lib.rs @@ -218,13 +218,15 @@ impl AyaFS { while let Some((inode_index, dir_entry_map)) = self.dir_entry_map.pop_lru() { debug!("writing back direntry map for inode {}", inode_index); - let mut inode = self.get_inode(inode_index).unwrap().clone(); - self.write_back_direntry( - inode_index, - &mut inode, - dir_entry_map, - ).unwrap(); - self.update_inode(inode_index, inode); + if let Some(inode) = self.get_inode(inode_index) { + let mut inode = inode.clone(); + self.write_back_direntry( + inode_index, + &mut inode, + dir_entry_map, + ).unwrap(); + self.update_inode(inode_index, inode); + } } // dir entry 的 write back 是写回到 block / inode cache 里, 所以要在前面 debug!("data_bitmap stopping at: {:?}", self.data_bitmap.peek()); |