ref: da0a87c6b0b0294175e5f084118c8d587c65a8f4
parent: 48c2835479a9e2f1fee7d4a3240cb580bba7bc6e
author: glenda <[email protected]>
date: Thu Nov 26 23:41:44 EST 2020
added more functions
--- a/main.c
+++ b/main.c
@@ -4,11 +4,95 @@
#include <thread.h>
#include <9p.h>
+enum {
+ Qroot,
+ Qitem1,
+ Qitem2,
+};
+
+typedef struct F {
+ char *name;
+ Qid qid;
+ ulong mode;
+} F;
+
+
+F root = {
+ "/", {Qroot, 0, QTDIR}, 0555|DMDIR
+};
+
+F roottab[] = {
+ "item1", {Qitem1, 0, QTFILE}, 0444,
+ "item2", {Qitem2, 0, QTFILE}, 0444,
+};
+
+enum {Cmdrange};
+Cmdtab cmd[] = {
+ Cmdrange, "range", 3,
+};
+
+F*
+filebypath(uvlong path)
+{
+ int i;
+
+ if(path == Qroot)
+ return &root;
+ for(i = 0; i < nelem(roottab); i++)
+ if(path == roottab[i].qid.path)
+ return &roottab[i];
+ return nil;
+}
+
void
+fillstat(Dir *d, uvlong path, char *user)
+{
+ F *f;
+
+ f = filebypath(path);
+ d->name = estrdup9p(f->name);
+ d->qid = f->qid;
+ d->mode = f->mode;
+ d->uid = estrdup9p(user);
+ d->gid = estrdup9p(user);
+ d->muid = estrdup9p(user);
+ d->length = 0;
+ d->atime = time(0);
+ d->mtime = time(0);
+}
+
+void
nattach(Req *r)
{
+ r->fid->qid = filebypath(Qroot)->qid;
+ r->ofcall.qid = r->fid->qid;
+ respond(r, nil);
}
+char*
+nwalk1(Fid *fid, char *name, Qid *qid)
+{
+ int i;
+
+ switch(fid->qid.path){
+ case Qroot:
+ for(i = 0; i < nelem(roottab); i++){
+ if(strcmp(roottab[i].name, name) == 0){
+ *qid = roottab[i].qid;
+ fid->qid = *qid;
+ return nil;
+ }
+ }
+ if(strcmp("..", name) == 0){
+ *qid = root.qid;
+ fid->qid = *qid;
+ return nil;
+ }
+ break;
+ }
+ return "not found";
+}
+
void
nread(Req *r)
{
@@ -29,10 +113,16 @@
void
nstat(Req *r)
{
+ fillstat(&r->d, r->fid->qid.path, r->fid->uid);
+ respond(r, nil);
+ return;
}
void
-ndestroyfid(Req *r){
+ndestroyfid(Fid *fid)
+{
+ if(fid->aux != nil)
+ free(fid->aux);
}
Srv fs = {
@@ -44,7 +134,7 @@
.write = nwrite,
.destroyfid = ndestroyfid,
-}
+};
void
threadmain(int argc, char **argv)
@@ -54,4 +144,5 @@
char *mtpt, *srvn;
mtpt = "/mnt/namespace-test";
srvn = nil;
+ postmountsrv(&fs, srvn, mtpt, MREPL);
}