ref: cfb7b151dd1c6845afc2b39ee1deb4a01aa9a18c
dir: /test/test.fs/
# This is a demo description file for the fsgen filesystem generator.
# - Lines starting with # are comments
# - all functions need to be assigned to a file path
# - file paths have to start with / (root of the mountpoint)
# - lines enclosed with %{ and %} enclose code that is copied verbatim
# - path parts can be enclosed in {} to make a variable
# - variables can be accessed by name. Prevent collisions with other symbols.
# - handler functions start with the short name of the handler (see below), followed by {}.
#
# There are a few handler functions that are available:
# - read: r{ and r}
# - write: w{ and w}
# - stat: s{ and s}
# - directory listings (not implemented yet)
#
# Read through this example to get a better idea.
#
%{
#include "fns.h"
%}
# lines starting with a # are comments.
# you can access /mnt/fsgen/test/bla
/test/{fname}
r{
char buf[512];
int a;
if (strncmp("File", fname, 4) != 0) {
respond(r, "invalid filename");
return;
}
a = atoi(&fname[4]);
if (a < 0 || a > 3) {
respond(r, "invalid file entry");
return;
}
snprint(buf, sizeof buf, "read: %s\n", fname);
readstr(r, buf);
respond(r, nil);
r}
w{
respond(r, "write prohibited");
w}
/multi/{one}/{two}
r{
char buf[512];
snprint(buf, sizeof buf, read: %s → %s\n", one, two);
readstr(r, buf);
respond(r, nil);
r}
# implement a directory listing
/test
ls{
// fprint(2, "test_ls: %d\n", index);
switch (index) {
case 0:
dir->name = estrdup9p("File0");
break;
case 1:
dir->name = estrdup9p("File1");
break;
case 2:
dir->name = estrdup9p("File2");
break;
case 3:
dir->name = estrdup9p("File3");
break;
default:
return -1;
}
dir->uid = estrdup9p("none");
dir->gid = estrdup9p("none");
dir->muid = estrdup9p("none");
return 0;
ls}