The Virtual File System

Lee Painter

Maverick Legacy Server 1.6.x introduces a modular Virtual File System that allows different types of file system to be mounted under a single virtual hierarchy. 

The 1.6.x file system uses implementations of AbstractFile and AbstractFileFactory to provide file system access. The Virtual File System allows you to combine many different AbstractFile implementations in a virtual folder structure, effectively 'mounting' an AbstractFile implementation on a given path.

Let's take a look at an example

sshContext.setFileSystemProvider(new FileSystemFactory() {
public FileSystem createInstance(Connection con,
String protocolInUse) throws PermissionDeniedException,
IOException {
AbstractFileSystem fs = new AbstractFileSystem(
new VirtualFileFactory(new VirtualMountTemplate("/",
"tmp/${username}", new VFSFileFactory())), con, protocolInUse);
return fs;
}
});

 

Here we have setup the Virtual File System in our Daemon's configure method. We have mounted a single file system for the users home directory that will use a folder with path 'tmp/$username}'. The ${username} gets replaced with the actual username of the connected user at runtime. When the user connects he will see this as the root of the file system because we passed in the value "/" in the VirtualMountTemplate constructor. 

Note that we use the VFSFileFactory. This is an implementation of AbstractFile that uses commons VFS2 so the path could be any valid URL that is available in the Commons VFS2 library, for example it could be an FTP, HTTPS, SMB or even SFTP url.

 

Adding Further Mounts

The VirtualFileFactory constructor takes a default mount, which acts as the users home directory. This is the only required mount in order to use the file system. You may pass additional VirtualMountTemplates in the constructor to mount further file systems. The following example for instance creates a mount under /ftp for the URL "ftp://ftp.example.com/" giving the user access to any files retrieveable over FTP on the given web server.

 

new VirtualFileFactory(new VirtualMountTemplate("/", "tmp/${username}", new VFSFileFactory()),
new VirtualMountTemplate("/ftp", "ftp://ftp.example.com/", new VFSFileFactory())),