Command File System
1. Unpack archive
tar zxvf cmdfs-0.1
2. Configure build
sudo make install
cmdfs < source-dir > < mount-dir > [options]
Specify matching file extension(s) to apply command to
-o path-re=< regular expression >
Specify regexp of pathnames to apply command to
-o mime-re=< regular expression >
Specify regexp of mime types to apply command to (as returned by file -b --mime-type)
Pass unmatched files through to filesystem as symbolic links [default: files not listed or accessible]
Watch source directory tree for new files and cache them as they appear. New directories will be monitored [default: not monitored]
-o cache-dir=< dir >
Directory to save cache files [default: /tmp/cmdfs-cache.< USER >]
-o cache-size=< size in Mb >
Size to attempt to limit cache directory to. Files removed on least-recent access basis.[default: no limit]
-o cache-entries=< count >
Number of entries to attempt to limit cache directory to. Files removed on least-recent access basis.[default: no limit]
How It Works - An Example
Given a source tree, which includes, say, jpg images, we can generate a view filesystem which contains the same files resized to email size.
The filter command is set up as a fileystem option at mount time. In this case our filter option might be something like (using ImageMagick's convert command):
command=convert - -resize 20% -
Note we follow the UNIX convention of taking the standard input and filtering to standard output. Being a FUSE filesystem, the child process will be run under the group/user of the owner. The command is run within a shell (/bin/sh) process, as if started by /bin/sh -c ''
Obviously there'll be files in the source tree which we dont want to apply the filter to. In this case we identify files of interest by extension:
To mount the filesystem as above for a particular user:
cmdfs /home/bob/images /mnt/myphotos "-ocommand=convert - -resize 20% -,extension=jpg;gif;png"
As well as just matching on extension, files of interest can be selected by mime type, matching a regexp (cmdfs uses the file command to determine the mimetype):
Or just a plain path regexp (this allows us to exclude whole directory subtrees etc
These options can be combined to get the required filter selection.
By default, files which don't match a filter won't appear in the filesystem view. We may want to see the original files though, so the
option may be specified. This will generate symbolic links to the original files.
The image resize example is a good example of an application where we might want the files in the source filesystem to be filtered as they are added, rather than just on-demand. Cmdfs uses inotify to monitor all the directories in the tree, and automatically monitors new subdirectories as they are added:
When you copy the latest batch of files from your camera the resized versions will automatically be generated.
cmdfs only recreates view files if the modification date changes on the source. All files created using the filter are held in a cache directory, with a name created as a hash from the full path. By default this directory is located in /tmp/cmdfs-cache.< user name >, but can be changed:
cache-dir=< dir >
Note that some systems will clear the /tmp directory tree between reboots, which may or may not be desired.
The size of the cache directory can be limited using:
cache-size=< size in mb >
cache-entries=< number of files >
The least recently accessed cached files will be removed in the background to maintain these limits.
Mounting With fstab
To aid in mounting directories for multiple users, cmdfs accepts the source base directory as the first argument so it can be mounted using the conventional mount.fuse script from fstab. This allows supplying cmdfs# as the fs_spec (see man 5 fstab). The user_allow_other option needs to be enabled in /etc/fuse.conf to allow normal users to mount (see fuse.conf). An example fstab entry:
cmdfs#/media/myphotos /home/bob/images fuse user,allow_other,command=convert\040-\040-resize\04020%\040-,monitor,cache-size=500,extension=jpg;gif;png 0 0
Note that the spaces in the command need to be escaped using \040 for /etc/fstab to parse correctly.
In a hurry? Add it to your Download Basket!
What's New in version 0.2
- Remove base-dir option - specify with first argument for fstab
- Code tidy
- Bug, inotify event name not null terminated
- Update help and README