commit 4a5fb0a588d7b63e0a17f747f22989413dcc8313
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sun, 8 Nov 2020 21:09:28 +0000
bare bones
Diffstat:
A | README | | | 5 | +++++ |
A | domfs.c | | | 187 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | mkfile | | | 9 | +++++++++ |
3 files changed, 201 insertions(+), 0 deletions(-)
diff --git a/README b/README
@@ -0,0 +1,5 @@
+In the [current_year] web surfing is a serious business.
+Browsers rival video rendering, neural networks and games in their system requirements.
+And with back-of-the-envelope projections, you will need super computer clusters to access WWW in the future.
+
+Domfs aims to be a part of the future, by implementing one part of web browser responsible for upkeep of Display Object Model in simple and content-agnostic way and providing shared environment for other processes via magic of 9p.
diff --git a/domfs.c b/domfs.c
@@ -0,0 +1,187 @@
+#include <u.h>
+#include <libc.h>
+#include <fcall.h>
+#include <thread.h>
+#include <9p.h>
+
+static long qcount;
+
+typedef struct Stack Stack;
+typedef struct Dnode Dnode;
+
+struct Stack {
+ long length;
+ Dnode *list;
+};
+
+struct Dnode {
+ long id;
+ long parent;
+ Stack children;
+ char *type;
+ char *attr;
+ char *text;
+ Qid q;
+};
+
+void
+stackinit(Stack *S)
+{
+ S->length = 0;
+ S->list = nil;
+ return;
+}
+
+Dnode *
+stackpush(Stack *stack, Dnode *new)
+{
+ stack->list = realloc(stack->list, sizeof(Dnode) * (stack->length + 1));
+ stack->list[stack->length] = *new;
+ stack->length++;
+ return &stack->list[stack->length - 1];
+}
+
+
+static Stack nodes;
+static long ncount;
+
+long
+newnode(long parent)
+{
+ Dnode *ref;
+ Dnode new = {
+ .id = ncount,
+ .parent = parent,
+ .type = nil,
+ .attr = nil,
+ .text = nil,
+ .q = (Qid){qcount, 0, QTDIR},
+ };
+ stackinit(&new.children);
+ ncount++;
+ qcount++;
+ ref = stackpush(&nodes, &new);
+ stackpush(&nodes.list[parent].children, ref);
+ return ref->id;
+}
+
+Dnode *
+getnode(long n)
+{
+ Dnode *np;
+ for (np = nodes.list; np < nodes.list + nodes.length; np++)
+ if (np->id == n) return np;
+ return nil;
+}
+
+void
+fsattach(Req *r)
+{
+ r->fid->qid = getnode(0)->q;
+ r->ofcall.qid = r->fid->qid;
+ respond(r, nil);
+}
+
+int
+dirgen(int n, Dir *dir, void* aux)
+{
+ Dnode *N;
+ if (aux == nil) return -1;
+ N = aux;
+ // TODO: do it properly
+
+ if (n >= N->children.length) return -1;
+
+ dir->uid = strdup("domfs");
+ dir->gid = strdup("domfs");
+ dir->name = smprint("%ld", N->children.list[n].id);
+ dir->mode = 0555|DMDIR;
+ dir->qid = getnode(n)->q;
+
+ return 0;
+}
+
+void
+fsread(Req *r)
+{
+ dirread9p(r, dirgen, getnode(0));
+ respond(r, nil);
+}
+
+char*
+fswalk1(Fid *fid, char *name, Qid *qid)
+{
+ fprint(2, "fswalk1 fid->qid.path=%ulld name=%s\n", fid->qid.path, name);
+
+ *qid = (Qid){0, 0, QTDIR};
+ fid->qid = *qid;
+ return nil;
+}
+
+void
+fsstat(Req *r)
+{
+ nulldir(&r->d);
+ r->d.type = L'M';
+ r->d.dev = 1;
+ r->d.length = 0;
+ r->d.muid = strdup("");
+ r->d.atime = time(0);
+ r->d.mtime = time(0);
+ r->d.uid = strdup("domfs");
+ r->d.gid = strdup("domfs");
+ switch(r->fid->qid.path){
+ case 0:
+ r->d.qid = (Qid){0, 0, QTDIR};
+ r->d.name = strdup("/");
+ break;
+ default:
+ r->d.qid = (Qid){r->fid->qid.path, 0, QTDIR};
+ r->d.name = smprint("%ulld", r->fid->qid.path);
+ };
+ r->d.mode = 0777|DMDIR;
+ respond(r, nil);
+}
+
+void
+usage(void)
+{
+ fprint(2, "usage %s [-D][-m /n/dom][-s service]\n", argv0);
+ exits("usage");
+}
+
+void
+main(int argc, char **argv)
+{
+ char *srv, *mtpt;
+ srv = nil;
+ mtpt = "/n/dom";
+
+ ARGBEGIN {
+ case 'm':
+ mtpt = EARGF(usage());
+ break;
+ case 's':
+ srv = EARGF(usage());
+ break;
+ case 'D':
+ chatty9p++;
+ break;
+ default:
+ usage();
+ } ARGEND
+
+ stackinit(&nodes);
+ getnode(newnode(0))->type = "domroot";
+ getnode(newnode(0))->type = "A";
+ getnode(newnode(0))->type = "B";
+
+ Srv fs = {
+ .attach = fsattach,
+ .read = fsread,
+ .walk1 = fswalk1,
+ .stat = fsstat,
+ };
+
+ postmountsrv(&fs, srv, mtpt, MREPL);
+}
diff --git a/mkfile b/mkfile
@@ -0,0 +1,9 @@
+</$objtype/mkfile
+
+TARG=domfs
+
+OFILES=\
+ domfs.$O\
+
+BIN=/$objtype/bin
+</sys/src/cmd/mkone