Overview

This page complements a proposal of implementing file system operations in Lua via a virtual filesystem layer in the lua interpreter. It describes the Proof-Of-Concept implementation comprising luafs and fsio.

Virtualizing file system operations has several advantages:

  • portability:
    • the platform differences are hidden in the driver layer, Lua programs stay the same on different platforms
    • the Lua interpreter sources can reduce platform dependend code
  • extensibility:
    • filesystems can be added without recompilation of the Lua interpreter
  • generalization:
    • anything which looks like a filesystem can be processed like a filesystem
  • reuseabilty:

    • tools which work on filesystems work on anything what can be made to look like a filesystems Disadvantages:
  • more code:

    • you need the virtual filesystem functions and the physical filesystem functions
  • efficiency

    • an additional function call level is interposed between the Application and the filesystem itself Specific motivations to propose a virtual filesystem layer for Lua:
  • want to mount "remote" filesystems like http, imap, smb

  • want to make Starkit like One-File Lua applications
  • want a comprehensive, clean interface to file and filesystem operations in Lua
  • want to port my "Baccus" archival backup system to Lua, since it seams easier to make C-extensions to Lua than to Tcl

Some Specifics of the Proposal

  • path separator is '/'
  • path names are Lua strings
  • Unified namespace, volumes (real filesystems) are mounted at arbitrary places in the namespace
  • Permissions not handled here, we only operate on accessible filesystem objects.
  • Authentication not handled here, can be done when setting up a volume before mounting it. The proposal also has been inspired by the Tcl Virtual File System

Proof-Of-Concept Implementation

A simplistic implementation of a virtual filesystem layer has been made which is comprised of two modules:

  • luafs the virtual filesystem layer as an fs module.
  • fsio a filesystem (volume) driver using only io and os library functions and the following POSIX utilities: ls, test, mkdir and rmdir. Caution: The implementation does not support union mounts, but rather features a simple mount/unmount mechanism via a single mount table with mountpoint=>volume entries.

The whole sample amounts to about 400 commented lines of Lua code. It has been tested under Debian Gnu Linux with the standard Lua 5.1.4 package but should be trivially adaptable to other platforms or configurations

Files

The following files are available

Instructions

Download all files into one directory, run test.lua and compare with the sample session output in test.output


CategoryLua