5 - Examples

Here are some filesystem examples.hellofs is just a minimal example. luafs is a basic filesystem that exposes a Lua table as a directory. It can be used as a model to expose some data from a Lua state in your own applications. fwfs is a forwarding filesystem, that can be used as a base to make on the fly operations on file I/O.

5.1 - hellofs

hellofs is the Hello World! of FUSE filesystems. It creates a directory with a single file called hello that contain the string "Hello World!".

Example:

<pre>
$ mkdir tmpdir
$ ./hellofs.lua tmpdir
$ ls tmpdir
hello
$ cat tmpdir/hello
Hello World!
$ fusermount -u tmpdir

Source code: hellofs.lua

5.2 - luafs

luafs expose a table as a directory. The subtables are exposed as subdirectories, while the string and userdata fields are exposed as regular files. You can create new files, and write to them: that will create new strings in the table hierarchy.

Example:

$ mkdir tmpdir
$ ./luafs.lua tmpdir
$ ls tmpdir
$ echo Hello World! > tmpdir/hello
$ ls tmpdir
hello
$ cat tmpdir/hello
Hello World!
$ mkdir tmpdir/subdir
$ ls tmpdir
hello subdir/
$ echo foo > tmpdir/subdir/bar
$ ls tmpdir/subdir
bar
$ cat tmpdir/subdir/bar
foo
$ fusermount -u tmpdir

Source code: luafs.lua

5.3 - fwfs

fwfs creates a directory that will forward all I/O to another directory. It's meant to be used as a base for any filesystem that is backed on disk, and that is doing something to the files on the fly. For example it can do filesystem encryption, it can make several directories on different disks appear as a single one, etc.

Example:

$ mkdir srcdir
$ echo Hello World! > srcdir/hello
$ mkdir dstdir
$ ./fwfs.lua srcdir dstdir
$ ls dstdir
hello
$ cat dstdir/hello
Hello World!
$ mkdir dstdir/subdir
$ ls srcdir
hello subdir/
$ echo foo > dstdir/subdir/bar
$ ls srcdir/subdir
bar
$ cat srcdir/subdir/bar
foo
$ fusermount -u dstdir

Source code: fwfs.lua