Version 23 of A template virtual filesystem

Updated 2006-01-10 08:27:43

SEH 20060110 -- An update of this code has been posted to a Sourceforge project site [L1 ]. 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 ]