Search code examples
rustfuse

How can I find the path in rust-fuse?


I am trying to write a FUSE interface for a REST API in Rust. I am using the rust-fuse library. I need the dir path in the readdir callback function when implementing the Filesystem trait, but the function only takes an inode!

How can I find the path to the file? Is it somehow embedded in the Request?

I could create an inode <-> path map, but that makes things too complicated. The Python and Haskell FUSE libraries both pass the path as a parameter to the callback functions rather than an inode.

fn readdir(&mut self,
           req: &Request,
           ino: u64,
           _fh: u64,
           offset: u64,
           mut reply: ReplyDirectory) {
    // ...
}

Solution

  • It appears the library doesn't provide this yet:

    From the README (emphasis mine):

    To Do

    There's still a lot of stuff to be done. Feel free to contribute.

    • Interrupting a filesystem operation isn't handled yet. An additional more high level API would be nice. It should provide pathnames instead inode numbers and automatically handle concurrency and interruption (like the FUSE C library's high level API).

    It appears you will need to assign a unique inode when you open / list the directory/file, keep track of a mapping of inodes to paths, and use that later on.

    Depending on your API structure, you may also be able to encode some amount of information into the inode directly. For example, maybe you have < 32 endpoints, so you can encode each endpoint as a 5-bit number and decode that later. Then only a subset of inodes need to have arbitrary values.