gdritter repos documents / master posts / file-system
master

Tree @master (Download .tar.gz)

file-system @master

cb58185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
The common mantra of Unix is that "everything is a file", and this is
to a mild extent true in most Unix variants, but Unix only takes that
concept so far. Lots of things are file-like until you prod them, and
then behave slightly unlike files—say, named pipes, which can sometimes
work as files and sometimes don't quite work as files.

The Plan 9 operating system (and its successor, Inferno) takes the
"everything is a file" notion much further. This is because _all_ file
systems are exposed via an indirect API, which means that it's quite
easy to build a file system by simply implementing the appropriate
socket communications. Linux has the ability to do this with FUSE, but
it's not used at all to the degree that it is in Plan 9.

I'm going to go through [...]

# Representing Data through a File System

Because you can build file systems easily, you can easily take a piece
of data and represent it as a file structure instead of a collection of
bytes. Plan 9 ships with, for example, `tarfs` and `9660srv`, which can
take tarballs and ISO images respectively and mount them as read-only
file systems.

Here is a file system I've written in 9P which takes a JSON file and
mounts it as a file system. Objects get represented as directories
with files or subdirectories named after each key. Arrays get
represented as directories with files or subdirectories named after
the indices. Everything else becomes a file containing the JSON
serialization of that piece of data.

    $ cat sample.json
    { "names": [ "Alouise"
               , "Eberhardt"
               , "Furtwangler"
               ]
    , "size": 3
    }
    $ mount.json sample.json tmp
    $ ls -R tmp
    tmp/
    names		size

	tmp/names
	1		2		3
    $ cat tmp/size && echo
    3
    $ cat tmp/names/1 && echo
    "Eberhardt"