From 886df6daf6bb6b922276157dba1cc099e897a9ea Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Sat, 18 Nov 2023 02:43:01 -0800 Subject: Major refactor of file hierarchy --- src/filesystem/mod.rs | 2 + src/filesystem/trait_impl.rs | 189 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 src/filesystem/mod.rs create mode 100644 src/filesystem/trait_impl.rs (limited to 'src/filesystem') diff --git a/src/filesystem/mod.rs b/src/filesystem/mod.rs new file mode 100644 index 0000000..1eaa8e8 --- /dev/null +++ b/src/filesystem/mod.rs @@ -0,0 +1,2 @@ +/// Where upper filesystem calls are implemented. +pub mod trait_impl; diff --git a/src/filesystem/trait_impl.rs b/src/filesystem/trait_impl.rs new file mode 100644 index 0000000..9f157a5 --- /dev/null +++ b/src/filesystem/trait_impl.rs @@ -0,0 +1,189 @@ +use std::ffi::OsStr; +use std::time::SystemTime; +use fuser::{Filesystem, KernelConfig, ReplyAttr, ReplyData, ReplyDirectory, ReplyEmpty, ReplyEntry, ReplyLseek, ReplyWrite, Request, TimeOrNow}; +use libc::{c_int, ENOENT, ENOSPC, ENOSYS}; +use log::debug; +use crate::AyaFS; + +impl Filesystem for AyaFS { + fn init(&mut self, _req: &Request<'_>, _config: &mut KernelConfig) -> Result<(), c_int> { + debug!("Filesystem::init called."); + Ok(()) + } + + fn destroy(&mut self) { + debug!("Filesystem::destroy()"); + } + + fn lookup(&mut self, _req: &Request<'_>, parent: u64, name: &OsStr, reply: ReplyEntry) { + debug!( + "Filesystem::lookup called with parent {} name {}", + parent, + name.to_str().unwrap() + ); + let parent = parent as usize; + if let Some(inode) = self.get_inode(parent) { + // debug!("{:?}", inode); + } + // if self.inode_active(parent) { + // let (block, offset) = self.locate_inode(parent); + // let inode = self.get_inode(block, offset); + // debug!("{:?}", inode); + // } + reply.error(ENOENT); + } + + fn forget(&mut self, _req: &Request<'_>, _ino: u64, _nlookup: u64) { + debug!("Filesystem::forget()"); + todo!("This is a dumb implementation") + } + + fn getattr(&mut self, _req: &Request<'_>, ino: u64, reply: ReplyAttr) { + debug!("Filesystem::getattr(ino: {})", ino); + let ino = ino as usize; + if let Some(inode) = self.get_inode(ino) { + // debug!("{:?}", inode); + } + reply.error(ENOENT); + } + + fn setattr( + &mut self, + _req: &Request<'_>, + ino: u64, + mode: Option, + uid: Option, + gid: Option, + size: Option, + _atime: Option, + _mtime: Option, + _ctime: Option, + fh: Option, + _crtime: Option, + _chgtime: Option, + _bkuptime: Option, + flags: Option, + reply: ReplyAttr, + ) { + debug!( + "Filesystem::setattr(ino: {:#x?}, mode: {:?}, uid: {:?}, \ + gid: {:?}, size: {:?}, fh: {:?}, flags: {:?})", + ino, mode, uid, gid, size, fh, flags + ); + reply.error(ENOSYS); + } + + fn readlink(&mut self, _req: &Request<'_>, ino: u64, reply: ReplyData) { + debug!("[Not Implemented] readlink(ino: {})", ino); + reply.error(ENOSYS); + } + + fn mknod( + &mut self, + _req: &Request<'_>, + parent: u64, + name: &OsStr, + mode: u32, + umask: u32, + rdev: u32, + reply: ReplyEntry, + ) { + debug!( + "Filesystem::mknod(parent: {}, name: {:?}, mode: {}, umask: {}, rdev: {})", + parent, name, mode, umask, rdev + ); + reply.error(ENOSPC); + } + + fn mkdir( + &mut self, + _req: &Request<'_>, + parent: u64, + name: &OsStr, + mode: u32, + umask: u32, + reply: ReplyEntry, + ) { + debug!( + "Filesystem::mkdir(parent: {}, name: {:?}, mode: {}, umask: {})", + parent, name, mode, umask + ); + if let Some(inode) = self.get_inode(parent as usize) { + } else { + reply.error(ENOENT); + } + // reply.error(ENOSPC); + } + + fn read( + &mut self, + _req: &Request<'_>, + ino: u64, + _fh: u64, + offset: i64, + _size: u32, + _flags: i32, + _lock_owner: Option, + reply: ReplyData, + ) { + todo!() + } + + fn readdir( + &mut self, + _req: &Request<'_>, + ino: u64, + _fh: u64, + offset: i64, + mut reply: ReplyDirectory, + ) { + todo!() + } + + fn access(&mut self, _req: &Request<'_>, ino: u64, mask: i32, reply: ReplyEmpty) { + debug!("Filesystem::getattr(ino: {}, mask: {})", ino, mask); + if let Some(inode) = self.get_inode(ino as usize) { + reply.ok() + } else { + reply.error(ENOENT) + } + } + + fn lseek( + &mut self, + _req: &Request<'_>, + ino: u64, + fh: u64, + offset: i64, + whence: i32, + reply: ReplyLseek, + ) { + debug!( + "lseek(ino: {:#x?}, fh: {}, offset: {}, whence: {})", + ino, fh, offset, whence + ); + reply.error(ENOSYS); + } + + fn copy_file_range( + &mut self, + _req: &Request<'_>, + ino_in: u64, + fh_in: u64, + offset_in: i64, + ino_out: u64, + fh_out: u64, + offset_out: i64, + len: u64, + flags: u32, + reply: ReplyWrite, + ) { + debug!( + "copy_file_range(ino_in: {:#x?}, fh_in: {}, \ + offset_in: {}, ino_out: {:#x?}, fh_out: {}, offset_out: {}, \ + len: {}, flags: {})", + ino_in, fh_in, offset_in, ino_out, fh_out, offset_out, len, flags + ); + reply.error(ENOSYS); + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2