浏览代码

feat: fuse access

liujingx 10 月之前
父节点
当前提交
4fa1f91ef7
共有 1 个文件被更改,包括 22 次插入0 次删除
  1. 22 0
      ext4_fuse/src/fuse_fs.rs

+ 22 - 0
ext4_fuse/src/fuse_fs.rs

@@ -337,6 +337,28 @@ impl Filesystem for Ext4FuseFs {
             Err(e) => reply.error(e.code() as i32),
             Err(e) => reply.error(e.code() as i32),
         }
         }
     }
     }
+
+    fn access(&mut self, req: &Request<'_>, ino: u64, mask: i32, reply: ReplyEmpty) {
+        let attr = self.fs.getattr(ino as u32).unwrap();
+        let mask = mask as u16;
+        // Check other
+        if attr.perm.contains(InodeMode::from_bits_truncate(mask)) {
+            return reply.ok();
+        }
+        // Check group
+        if attr.gid == req.gid() {
+            if attr.perm.contains(InodeMode::from_bits_truncate(mask << 3)) {
+                return reply.ok();
+            }
+        }
+        // Check user
+        if attr.uid == req.uid() {
+            if attr.perm.contains(InodeMode::from_bits_truncate(mask << 6)) {
+                return reply.ok();
+            }
+        }
+        reply.error(ErrCode::EACCES as i32);
+    }
 }
 }
 
 
 fn get_ttl() -> Duration {
 fn get_ttl() -> Duration {