summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChuyan Zhang <me@zcy.moe>2023-12-01 23:28:51 -0800
committerChuyan Zhang <me@zcy.moe>2023-12-01 23:28:51 -0800
commit17b28b6f9f251a7ddccfd3d8d5daae7b1789bc34 (patch)
treee81f248dc7744481c6af82ab4a52d2b6cf30d564
parent4e8448778cdec05f994f0e2772432fd90b6219d5 (diff)
downloadmyfs-17b28b6f9f251a7ddccfd3d8d5daae7b1789bc34.tar.gz
myfs-17b28b6f9f251a7ddccfd3d8d5daae7b1789bc34.zip
fix inode write_back, fix remove
-rw-r--r--ayafs-core/src/filesystem/trait_impl.rs26
-rw-r--r--ayafs-core/src/lib.rs16
-rw-r--r--recipe.txt13
3 files changed, 38 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());
diff --git a/recipe.txt b/recipe.txt
new file mode 100644
index 0000000..c897a1c
--- /dev/null
+++ b/recipe.txt
@@ -0,0 +1,13 @@
+# build the executables
+cargo build --release
+mv target/release/mkayafs target/release/mkfs.aya
+mv target/release/ayafs_cli target/release/ayafs
+
+# make filesystem (need root privilege)
+target/release/mkfs.aya [device_path] --user-id $(id -u) --group-id $(id -g)
+
+# mount filesystem (need root privilege)
+target/release/ayafs [device_path] [mount_point] --auto-unmount --allow-other &
+
+# clean up (need root privilege)
+fusermount -u [mount_point]