cmdfs 0.4

Command File System
cmdfs is a FUSE-based virtual filesystem which applies an arbitary filter command to selected files in a source directory tree to create the destination files. Includes configurable caching and monitoring of the source tree to limit CPU use and prefetch data.

Build

 1. Unpack archive

 tar zxvf cmdfs-0.1

 2. Configure build

 cd cmdfs-0.1
 ./configure


 3. Build

 make

 4. Install

 sudo make install

Synposis

cmdfs < source-dir > < mount-dir > [options]

options
 -o extension=ext1[;ext2[;...]]
 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)

 -o link-thru
 Pass unmatched files through to filesystem as symbolic links [default: files not listed or accessible]
 
 -o monitor
 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:

extension=jpg;gif;png

To mount the filesystem as above for a particular user:

 cmdfs /home/bob/images /mnt/myphotos "-ocommand=convert - -resize 20% -,extension=jpg;gif;png"

Selection Filters


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):

mime-re=image/*

Or just a plain path regexp (this allows us to exclude whole directory subtrees etc

path-re=.*/my-images/

These options can be combined to get the required filter selection.

Unmatched Files

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

link-thru

option may be specified. This will generate symbolic links to the original files.

Monitoring

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:

monitor

When you copy the latest batch of files from your camera the resized versions will automatically be generated.

Caching

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 >

and/or

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.

last updated on:
March 24th, 2010, 18:56 GMT
price:
FREE!
developed by:
Mike Swain
license type:
GPL (GNU General Public License) 
category:
ROOT \ System \ Filesystems

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

2 Screenshots
cmdfs - Usage messagecmdfs - Usage message
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
read full changelog

Add your review!

SUBMIT