Plan 9 is built around 9P - a file system protocol which is a remarkably simple and surprisingly easy to implement. 9P operates over a stream connection, usually TCP or a Unix socket, and it can easily be forwarded over SSH. The mounting of a 9P file system is handled in-kernel in Plan 9, but on Mac OS and Linux, 9pfuse(4) is used to mount it.
plan9port provides the lib9p C library, making the implementation of a new file server even easier.
Services as Virtual File Systems
Now that we can easily implement a new file system, we can talk about virtual file systems. Virtual here means we are serving a file system which, while it behaves like a file system, represents something that ultimiately is not files and directories.
Perhaps every file system is virtual. Disks are sequences of fixed-size blocks of data, and "files and directories" is an arbitrary conceptual abstraction we impose to organize them.
There is no need to write clients: Once it is mounted, we use our normal suite of POSIX utilities to interact with the server.
osxsnarf is a nice example. It serves a file system with a directory containing a single file, named "snarf". If you want to update the Mac’s pasteboard:
$ echo 'hello, world!' >/mnt/snarf/snarf
If you don’t have it mounted, you can use the 9p utility:
$ echo 'hello, world!' |9 9p write snarf/snarf
In Plan 9, by convention, the clipboard is at
/dev/snarf, and we can
mount this service to shadow it. This means we’ve replaced Plan 9’s snarf
buffer with our Mac’s pasteboard, and none of the applications are the
wiser. This in just 196 lines of C.
The usefulness of these things to me is in how I can connect my laptop and my development box. My development box is a 24 core Threadripper that allows me to run lots of tests in parallel and build code quickly, while my laptop is a modern work-issue Macbook. With kak-plumb, I can import the plumber service onto my laptop, and with osxsnarf, I can export my Mac pasteboard to my dev server. This means that when I request the opening of a URL on my development box, it opens in my laptop’s Chrome, and I can instruct my editor (inside a tmux session on my development box) to copy some text, then seemlessly switch to my browser and paste with Command-V.