shithub: namespace-example

Download patch

ref: f86d02fc768075a4cfab130f340174fddbd69c2c
parent: da0a87c6b0b0294175e5f084118c8d587c65a8f4
author: glenda <[email protected]>
date: Fri Nov 27 05:17:37 EST 2020

"full

--- a/main.c
+++ b/main.c
@@ -93,21 +93,67 @@
 	return "not found";
 }
 
+int
+rootgen(int n, Dir *d, void *aux)
+{
+	Req *r = aux;
+
+	if(n >= nelem(roottab))
+		return -1;
+	fillstat(d, roottab[n].qid.path, r->fid->uid);
+	return 0;
+}
+
 void
 nread(Req *r)
 {
+	char buf[128];
+	int n = 0;
+	uvlong path = r->fid->qid.path;
+	vlong offset;
+	long count;
+	offset = r->ifcall.offset;
+	if(offset >= 1){
+		r->ofcall.count = 0;
+		respond(r, nil);
+		return;
+	}
 
+	if(path == Qroot){
+		dirread9p(r, rootgen, r);
+		respond(r, nil);
+		return;
+	}
+
+	switch(path){
+	case Qitem1:
+		n = snprint(buf, sizeof buf, "%s\n",
+			"test");
+		break;
+	case Qitem2:
+		n = snprint(buf, sizeof buf, "%s\n",
+			"lol test again");
+		break;
+	}
+	if(r->ifcall.count < n)
+		n = r->ifcall.count;
+	r->ofcall.count = n;
+	memmove(r->ofcall.data, buf, n);
+	respond(r, nil);
+
 }
 
+
 void
 nwrite(Req *r)
 {
+	respond(r, nil);
 }
 
 void 
 nopen(Req *r)
 {
-
+	respond(r, nil);
 }
 
 void
@@ -137,12 +183,13 @@
 };
 
 void
-threadmain(int argc, char **argv)
+main(int argc, char *argv[])
 {
-	print("This is a demo of namespace in plan9/9p /n");
-	print("This is not meant for real world use and is just a simple demo /n");
+	print("This is a demo of namespace in plan9/9p \n");
+	print("This is not meant for real world use and is just a simple demo \n");
 	char *mtpt, *srvn;
 	mtpt = "/mnt/namespace-test";
 	srvn = nil;
 	postmountsrv(&fs, srvn, mtpt, MREPL);
+	exits(nil);
 }
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,10 @@
+</$objtype/mkfile
+
+BIN=/bin
+TARG=nst
+OFILES=main.$O
+
+all:V:
+
+
+</sys/src/cmd/mkone