Dynamic filesystem mapper

Inject missing files into an existing directory tree through a new filesystem. File contents are provided on-demand upon first access using external handlers.

Similar to the functionality of UnionFS (and its FUSE-based implementations) or OverlayFS, this tool will mix an existing directory tree with yet unexisting files. Content of injected files will be provided on-demand using external handlers, such as for example simple scripts. Delivered content can be discarded immediately or written to disk for future use.

This is done in two steps: Augmenting directory listings with the desired filenames, and fetching and delivering the content as soon as these are opened. Existing files are not touched. By this means, fifuma is a fuse mapper in a sense that you can mount a filesystem that transparently maps certain files to handler outputs. It relies on the service of libfuse (from the libfuse-dev package or similar) for providing a filesystem layer.

Usecases for dynamic file handlers

A typical usage scenario would be injecting a *.srt subtitle file corresponding to each movie file found. Actual subtitles will be fetched online as soon as some media player tries to read it. Besides more technical applications, other related usecases could be providing album art using folder.jpg, music lyrics, and other additional metadata represented by standalone files. See below for example configuration and scripts for the album art scenario.

In general, this approach gives a generic and transparent way for advanced features that can then be used by many client applications. By only using plain files as “API”, the mountpoint can also be used for remote applications that rely on filesharing protocols such as SMB or DLNA.

Mount the filesystem mapper

./fifuma [-p|--persistent] [--filter=...] dir-handler file-handler src/ [dst/]
persistent
Per default, file contents are kept in memory and will be freed after the file has been closed. If this option is given, the data will be written to disk and is thus also available for future accesses.
filter
For performance and/or safety reasons, handled filenames can be restricted by this globbing pattern (not matching the path portion).
dir-handler
The directory handler gets called for augmenting directory listings. First argument is the path in question, relative to src (can thus be empty) – the working directory will be src as well. The (newline-separated) list of filenames to add can simply be echoed to stdout.
file-handler
The file handler gets called when the actual content of a previously injected file is needed. First argument is the filename in question, relative to src, as before. The data can be simply written to stdout. Note that as long as a file won’t be explicitly opened, this handler won’t be called and file attributes will be dummy values.
src
The folder containing the original content that will be mounted.
dst
Optional (read-only) mountpoint. If omitted, the source folder will be mounted over itself.

Example usage

As an example, the aforementioned album art scenario can be realised by using the included shell scripts for downloading folder images:

./fifuma --filter=folder.jpg ./example/folder.jpg.list.sh ./example/folder.jpg.get.sh ~/Music

When accessing your music library locally or via some other remote (multimedia or file-sharing) protocol, tools that look for these files will be served with images obtained by using the Wikipedia API. Please note that in this particular scenario, crawlers that will open all image files to be found (such as thumbnailers) can trigger lots of possibly needless downloads at once.

Code & Download