MirrorFS is a Lua module that implements a FUSE mirroring a directory.
It can be useful as an example of how to use Flu, but it could also have creative uses.
It is only tested on Linux with Lua 5.3.
Check out the examples in the
Starting a filesystem
local fs = mirrorfs.new(root, mountpoint) fs:main()
root must be an absolute path (i.e. start with
mirrorfs can log operations and their results. To log to a file, just
fs.logfile before starting the filesystem. You can also override
fs.log method whose signature is
log(self, ...), where
... are the
same arguments as
To modify the behavior of MirrorFS, you need to implement handlers for
filesystem calls. They have the same interface as in Flu, except that
they take the filesystem object as their first argument and that the
argument is already prefixed by the mirrored path.
To override a handler, just assign it to the corresponding key in the filesystem object:
fs.release = function(self, path, fi) ... end
To unset a handler, just call the
Check out the
Making calls fail
To make a handler return a POSIX error, the easiest solution is to use
mirrorfs.fail with a string or a number representing a POSIX error code:
-- those two lines do the same thing mirrorfs.fail("ENOMEM") mirrorfs.fail(12)
MirrorFS also provides two helpers:
check that behaves like
fail instead of
pcheck which is used to check the return
value of most luaposix calls.
If you raise a normal error in an handler, it will be interpreted as
Some FUSE handlers (
readdir, etc) interact with file or directory
descriptors. The filesystem instance has three methods to manage their state:
clear_descriptor. If you need to
use them, read the implementation of the default handlers in
and use it as an example.
- Copyright (c) 2015-2016 Pierre Chapuis