Version 24 of A template virtual filesystem

Updated 2006-10-30 06:56:11

SEH 20061030 -- The re-written and much-improved template vfs which I presented at Tcl'2006 [L1 ], and the collection of virtual filesystems built from it, have been uploaded to the CVS repository of the TclVFS project. They have also been released in a zip file as a subsidiary project on the sourceforge project page of the FILTR [L2 ].

The new template vfs sacrifices simplicity somewhat, in exchange for API's and functions intended to make it as easy as possible to write functional, scalable new virtual filesystems.

There is a new, greatly simplified programming interface which allows one to author a new vfs merely by overloading a few simple procs.

Error handling is significantly improved.

A complete set of caching functions is included with user-settable cache dwell times. These are intended to make virtual filesystems operating over networks much more efficient.

I hope the availability of this template will prompt more people to start writing virtual filesystems of their own. They are an incredible problem-solving tool. On to the core!


SEH 20060110 -- An update of this code has been posted to a Sourceforge project site [L3 ]. All future updates will be placed there as well.


SEH As a self-teaching exercise, I wrote a sample virtual filesystem that utilizes as much of the Tclvfs API as possible, although its function is trivially simple. The virtual filesystems included with the Tclvfs distribution are instructive, but they take a lot of shortcuts.


Discussion moved to Template tclvfs Discussion

Because it simply mirrors a real filesystem location, I believe this vfs is maximally featureful.

My aim for this vfs is to use it as a template for rapid development of new and more complex filesystems.

The Mount, Unmount and handler procedures are completely generic and should never need customization for new filesystems. Thus the task of creating a new virtual filesystem is reduced to filling in the procedures for handling the eight subcommands of the Tclvfs API, as well as mounting and unmounting specifics.


SEH -- 10/14/04 -- I tidied things up a bit, and added an execution trace to the 'close' command so that it will throw a proper error if an error occurs in the close callback procedure. Not too relevant for this vfs, but for more complex ones built on the template.

I also added a "-volume" option to the Mount command, so you can now do things like:

 ::vfs::template::Mount -volume $env(HOME) C:/

on Unix, and make pathnames originating on Windows acceptable. Problems syncing cross-platform filesystems solved! Schweet!

12/07/04 -- I had to rewrite the Access procedure to correct a misunderstanding about how the access handler worked; I took the opportunity to optimize it to minimize the number of disk reads required.

12/22/04 -- I made it more of a real template by removing references to "::vfs::template" within procedure bodies and replaced them with [namespace current]. Now the Mount, Unmount and handler procedures can be copied and pasted directly into new vfs code without editing.


 # templatevfs.tcl --
 #
 #         The template vfs simply mirrors a real directory to a virtual location.
 #
 # Usage: Mount ?-volume? <real directory> <virtual directory>
 #
 # Written by Stephen Huntley ([email protected])

20040720 CMcC: I just saw a real use for this - a trace fs. Someone was trying to work out why copy -force was failing, it would have been nice to be able to say to them: mount this on your directory and look at the log. Trivial addition to this template - log each argument to, and result from, underlying file system.

snitvfs has a reimplementation of this, in Snit.


[ Category Example | Category VFS ]