How to specify base directory for FUSE filesystem?

643 views Asked by At

I am trying to create a FUSE filesystem called ordered-dirs using the Haskell wrapper over libfuse, HFuse. This filesystem is a "derived filesystem", i.e. it takes an existing directory (the "base directory") and produces a different view of it.

However, when I try to run my FUSE filesystem program, specifying the arguments in the ordinary mount way, I get an error:

$ ordered-dirs /home/robin/tasks/ /home/robin/to
fuse: invalid argument `/home/robin/to'

There is no way in HFuse (or in libfuse, it seems) to get the base directory (the first argument), so I had just written my own code to get it. But it's not this code that's failing - it's code within C libfuse itself - as the error message indicates.

So what is the correct way to pass the base directory to a fuse filesystem executable that uses libfuse to parse its arguments?

1

There are 1 answers

1
Robin Green On BEST ANSWER

Surprisingly, it seems that the way to do this is to simply strip the base directory argument from the command-line arguments that are parsed to the libfuse parser, so that libfuse never sees it.

In the particular case of HFuse, this can be done by calling fuseRun instead, which allows the command-line arguments to be passed in explicitly. You can see how I've done this here - here is the relevant code (in which I've called the base directory source):

main :: IO ()
main = do
    args <- getArgs
    let (maybeSource, remainder) = extractSource args
    source <- maybe (fail "source not specified") return maybeSource
    fuseRun "ordered-dirs" remainder (orderedDirOps source) defaultExceptionHandler