Skip to main content

fuser_iouring/
lib.rs

1pub mod ll {
2    pub mod fuse_abi;
3}
4mod mount;
5mod transport;
6
7use std::io;
8use std::path::Path;
9use crate::ll::fuse_abi::*;
10
11pub use mount::MountOption;
12pub use libc;
13
14#[derive(Debug, Clone, Copy)]
15pub struct Request {
16    pub unique: u64,
17    pub uid: u32,
18    pub gid: u32,
19    pub pid: u32,
20}
21
22pub trait FileSystem {
23    fn init(&self, _req: &Request, req: &FuseInitIn) -> Result<FuseInitOut, i32> {
24        let flags = req.flags & (FUSE_BIG_WRITES | FUSE_ASYNC_READ);
25        Ok(FuseInitOut{
26            major: 7 , minor: 18, max_readahead: req.max_readahead, flags: flags, max_background: 0, congestion_threshold: 0,
27            max_write: 1024*1024, time_gran: 1, padding: [0; 9]
28        })
29    }
30
31    fn lookup(&self , _req: &Request, _parent: u64 , _name: &[u8]) -> Result<FuseEntryOut, i32> { Err(libc::ENOSYS) }
32    fn getattr(&self, _req: &Request, _ino: u64) -> Result<FuseAttrOut, i32> { Err(libc::ENOSYS) }
33    fn setattr(&self, _req: &Request, _ino: u64, _arg: &FuseSetAttrIn) -> Result<FuseAttrOut, i32> { Err(libc::ENOSYS) }
34    fn mkdir(&self, _req: &Request, _parent: u64, _name: &[u8], _mode: u32) -> Result<FuseEntryOut, i32> { Err(libc::ENOSYS) }
35    fn create(&self, _req: &Request, _parent: u64, _name: &[u8], _mode: u32 ) -> Result<(FuseEntryOut, FuseOpenOut), i32> { Err(libc::ENOSYS) }
36    fn write(&self, _req: &Request, _ino: u64, _offset: u64, _data: &[u8]) -> Result<u32, i32> { Err(libc::ENOSYS) }
37    fn read(&self, _req: &Request, _ino: u64, _offset: u64, _size: u32) -> Result<Vec<u8>, i32> { Err(libc::ENOSYS) }
38    fn readdir(&self, _req: &Request, _ino: u64, _offset: u64) -> Result<Vec<u8>, i32> { Err(libc::ENOSYS) }
39    fn readdirplus(&self, _req: &Request, _ino: u64, _offset: u64) -> Result<Vec<u8> , i32> { Err(libc::ENOSYS) }
40    
41    fn access(&self , _req: &Request, _ino: u64, _mask: u32) -> Result<() , i32> { Ok(()) }
42    fn open(&self, _req: &Request, _ino: u64, _flags: u32) -> Result<FuseOpenOut, i32> {
43        Ok(FuseOpenOut { fh:0, open_flags:0, padding: 0 })
44    }
45    fn opendir(&self, _req: &Request, _ino: u64, _flags: u32) -> Result<FuseOpenOut, i32> {
46        Ok(FuseOpenOut { fh:0, open_flags:0, padding: 0 })
47    }
48    
49    fn unlink(&self, _req: &Request, _parent: u64, _name: &[u8]) -> Result<(), i32> { Err(libc::ENOSYS) }
50    fn rmdir(&self, _req: &Request, _parent: u64, _name: &[u8]) -> Result<(), i32> { Err(libc::ENOSYS) }
51    fn rename(&self, _req: &Request, _parent: u64, _name: &[u8], _newparent: u64, _newname: &[u8]) -> Result<(), i32> { Err(libc::ENOSYS) }
52
53    fn symlink(&self, _req: &Request, _parent: u64, _name: &[u8], _target: &[u8]) -> Result<FuseEntryOut, i32> {Err(libc::ENOSYS) }
54    fn readlink(&self, _req: &Request, _ino: u64) -> Result<Vec<u8>, i32> {Err(libc::ENOSYS) }
55    fn link(&self, _req: &Request, _ino: u64, _newparent: u64, _newname: &[u8]) -> Result<FuseEntryOut, i32> {Err(libc::ENOSYS) }
56
57    fn statfs(&self, _req: &Request, _ino: u64) -> Result<FuseStatfsOut, i32> {Err(libc::ENOSYS) }
58
59}
60
61pub fn mount<F, P>(fs: F, mountpoint: P, options: &[MountOption]) -> io::Result<()>
62where
63    F: FileSystem + Send + 'static,
64    P: AsRef<Path>,
65{
66    let session = mount::Session::new(mountpoint.as_ref(), options)?;
67
68    // Start the io_uring loop
69    transport::run_uring_loop(session.fd , fs)?;
70
71    Ok(())
72}