commit 44cea2d241c7e2cdfb6727db01593220de8a8371
parent 90fbc47d51545cf7c9c052265d3392ea2242ec0b
Author: Kris Maglione <bsdaemon@wmii.de>
Date: Mon, 12 Jun 2006 01:37:18 -0400
Added some more shape to fs2.c. This commit at least shows how trivial stating is now.
This still doesn't compile due to a lack of headers and parts of libixp that don't exist yet.
Diffstat:
| cmd/wm/fs2.c | | | 243 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- |
1 file changed, 203 insertions(+), 40 deletions(-)
diff --git a/cmd/wm/fs2.c b/cmd/wm/fs2.c
@@ -21,18 +21,24 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
typedef struct Dirtab Dirtab;
struct Dirtab
{
char *name;
+ unsigned char qtype;
unsigned int type;
unsigned int perm;
};
#define nil ((void *)0)
-enum { DMDIR, QTDIR, QTFILE };
+#define QID(t, i) (((long long)((t)&0xFF)<<32)|((i)&0xFFFFFFFF))
+#define TYPE(q) ((q)>>32&0xFF)
+#define ID(q) ((q)&0xFFFFFFFF)
+
+enum { DMDIR, DMAPPEND, QTDIR, QTFILE, QTAPPEND };
enum { FsRoot, FsDClient, FsDClients, FsDLBar,
FsDRBar, FsDSClient, FsDTag, FsDTags,
@@ -45,51 +51,51 @@ enum { FsRoot, FsDClient, FsDClients, FsDLBar,
Dirtab *dirtab[] =
{
[FsRoot] (Dirtab [])
- {{".", FsRoot, 0500|DMDIR },
- {"rbar", FsDRBar, 0700|DMDIR },
- {"lbar", FsDLBar, 0700|DMDIR },
- {"client", FsDClients, 0500|DMDIR },
- {"tag", FsDTags, 0500|DMDIR },
- {"ctl", FsFRctl, 0600 },
- {"colrules", FsFColRules, 0600 },
- {"tagrules", FsFTagRules, 0600 },
- {"font", FsFFont, 0600 },
- {"keys", FsFKeys, 0600 },
- {"event", FsFEvent, 0600 },
- {"normcolors", FsFCNorm, 0600 },
- {"selcolors", FsFCSel, 0600 },
+ {{".", QTDIR, FsRoot, 0500|DMDIR },
+ {"rbar", QTDIR, FsDRBar, 0700|DMDIR },
+ {"lbar", QTDIR, FsDLBar, 0700|DMDIR },
+ {"client", QTDIR, FsDClients, 0500|DMDIR },
+ {"tag", QTDIR, FsDTags, 0500|DMDIR },
+ {"ctl", QTAPPEND, FsFRctl, 0600|DMAPPEND },
+ {"colrules", QTFILE, FsFColRules, 0600 },
+ {"tagrules", QTFILE, FsFTagRules, 0600 },
+ {"font", QTFILE, FsFFont, 0600 },
+ {"keys", QTFILE, FsFKeys, 0600 },
+ {"event", QTFILE, FsFEvent, 0600 },
+ {"normcolors", QTFILE, FsFCNorm, 0600 },
+ {"selcolors", QTFILE, FsFCSel, 0600 },
{nil}},
[FsDRBar] (Dirtab [])
- {{".", FsDRBar, 0700|DMDIR },
- {"", FsFBar, 0600 },
+ {{".", QTDIR, FsDRBar, 0700|DMDIR },
+ {"", QTFILE, FsFBar, 0600 },
{nil}},
[FsDLBar] (Dirtab [])
- {{".", FsDRBar, 0700|DMDIR },
- {"", FsFBar, 0600 },
+ {{".", QTDIR, FsDRBar, 0700|DMDIR },
+ {"", QTFILE, FsFBar, 0600 },
{nil}},
[FsDClients] (Dirtab [])
- {{".", FsDClients, 0500|DMDIR },
- {"", FsDClient, 0500|DMDIR },
+ {{".", QTDIR, FsDClients, 0500|DMDIR },
+ {"", QTDIR, FsDClient, 0500|DMDIR },
{nil}},
[FsDClient] (Dirtab [])
- {{".", FsDClient, 0500|DMDIR },
- {"ctl", FsFCctl, 0200 },
- {"props", FsFprops, 0400 },
+ {{".", QTFILE, FsDClient, 0500|DMDIR },
+ {"ctl", QTAPPEND, FsFCctl, 0200|DMAPPEND },
+ {"props", QTFILE, FsFprops, 0400 },
{nil}},
[FsDSClient] (Dirtab [])
- {{".", FsDClient, 0500|DMDIR },
- {"ctl", FsFCctl, 0200 },
- {"index", FsFCindex, 0400 },
- {"props", FsFprops, 0400 },
+ {{".", QTDIR, FsDClient, 0500|DMDIR },
+ {"ctl", QTAPPEND, FsFCctl, 0200|DMAPPEND },
+ {"index", QTFILE, FsFCindex, 0400 },
+ {"props", QTFILE, FsFprops, 0400 },
{nil}},
[FsDTags] (Dirtab [])
- {{".", FsDTags, 0500|DMDIR },
- {"", FsDTag, 0500|DMDIR },
+ {{".", QTDIR, FsDTags, 0500|DMDIR },
+ {"", QTDIR, FsDTag, 0500|DMDIR },
{nil}},
[FsDTag] (Dirtab [])
- {{".", FsDTag, 0500|DMDIR },
- {"ctl", FsFTctl, 0200 },
- {"index", FsFTindex, 0400 },
+ {{".", QTDIR, FsDTag, 0500|DMDIR },
+ {"ctl", QTAPPEND, FsFTctl, 0200|DMAPPEND },
+ {"index", QTFILE, FsFTindex, 0400 },
{nil}}
};
@@ -153,6 +159,12 @@ lookup_file(FileId *parent, char *name)
case FsDRBar:
temp->ref = rbar;
break;
+ case FsFColRules:
+ temp->ref = crules;
+ break;
+ case FsFTagRules:
+ temp->ref = trules;
+ break;
}
if(name)
break;
@@ -167,13 +179,13 @@ lookup_file(FileId *parent, char *name)
*last = temp;
last = &temp->next;
temp->ref = c;
- temp->id = c.id;
+ temp->id = c->id;
temp->index = idx_of_client(c);
temp->tab = *dirtab[FsDSClient];
temp->tab.name = strdup("sel");
}
if(name)
- break;
+ goto LastItem;
}else{
if(name) {
i = (unsigned int)strtol(name, &name, 10);
@@ -187,21 +199,172 @@ lookup_file(FileId *parent, char *name)
*last = temp;
last = &temp->next;
temp->ref = c;
- temp->id = c.id;
+ temp->id = c->id;
temp->tab = *dirtab[FsDClient];
- asprintf(temp->tab.name, "%d", c->index);
+ asprintf(&temp->tab.name, "%d", c->index);
+ if(name)
+ goto LastItem;
}
- if(name)
- break;
}
if(name)
- goto End_This_Loop; /* label doesn't exist */
+ goto LastItem; /* label doesn't exist */
}
case FsDTags:
- /* and so forth */
+ View *v;
+ if(!name || !strncmp(name, "sel", 4)) {
+ if(sel) {
+ temp = get_file();
+ *last = temp;
+ last = &temp->next;
+ temp->ref = sel;
+ temp->id = sel->id;
+ temp->tab = *dirtab[FsDTag];
+ temp->tab.name = strdup("sel");
+ }
+ if(name)
+ goto LastItem;
+ }else{
+ for(v=view; v; v=v->next) {
+ if(!name || !strcmp(name, v->name)) {
+ temp = get_file();
+ *last = temp;
+ last = &temp->next;
+ temp->rev = v;
+ temp->id = v->id;
+ temp->name = strdup(v->name);
+ if(name)
+ goto LastItem;
+ }
+ }
+ }
+ case FsDRBar:
+ case FsDLBar:
+ Bar *b;
+ for(b=parent->ref; b; b=b->next) {
+ if(!name || strcmp(name, b->name)) {
+ temp = get_file();
+ *last = temp;
+ last = &temp->next;
+ temp->ref = b;
+ temp->id = b->id;
+ temp->tab = dirtab[FsDRBar][1];
+ temp->tab.name = strdup(bar->name);
+ }
+ }
}
}
}
+LastItem:
*last = nil;
return ret;
}
+
+void
+fs_walk(Req *r) {
+ FileId *f = r->fid->aux, *nf, **fi;
+ int i;
+
+ for(i=0; i < r->ifcall.nwname; i++) {
+ if(!strncmp(r->ifcall.wname[i], "..", 3)) {
+ if(f->next) f=f->next;
+ }else{
+ nf = lookup_file(f, r->ircall.wname[i]);
+ if(!nf)
+ break;
+ nf->next = f;
+ f = nf;
+ }
+ r->ofcall.wqid[i] = QID(f->tab.type, f->id);
+ }
+ if(i < r->ifcall.nwname) {
+ for(; f != r->fid->aux; f=nf) {
+ nf=f->next;
+ free_file(f);
+ }
+ respond(r, Enofile);
+ }
+
+ if(r->ifcall.fid != r->ifcall.newfid) {
+ r->newfid.aux = f;
+ for(fi=&r->newfid.aux; *fi != r->fid.aux; fi=&(*fi)->next);
+ for(; *fi; fi=&(*fi)->next) {
+ nf = get_file();
+ *nf = **fi;
+ *fi = nf;
+ }
+ }else
+ r->fid.aux = f;
+
+ r->fid.qid = r->ofcall.qid = r->ofcall.nwqid[i-1];
+ r->ofcall.nwqid = i;
+ r->fid.aux = f;
+ respond(r);
+}
+
+/* All of this stat stuf is ugly. */
+void
+fs_stat(Req *r) {
+ Stat s;
+ int size = IXP_MAX_STAT;
+ void *buf = cext_emallocz(size);
+ r->ofcall.stat = buf;
+
+ dostat(&s, 0, r->fid->aux);
+ ixp_pack_stat(&buf, &size, &s);
+ r->ofcall.nstat = IXP_MAX_STAT - size;
+ respond(r);
+}
+
+void
+fs_read(Req *r) {
+ void *buf;
+ unsigned int n, offset = 0;
+ int size;
+ FileId *f = r->fid->aux, *tf;
+
+ if(f->tab.perm & DMDIR) {
+ Stat s;
+ offset = 0;
+ size = r->ifcall->count;
+ buf = cext_emallocz(size);
+ f.ofcall.data = buf;
+
+ f = lookup_file(f, nil);
+ for(; f; f=f->next) {
+ dostat(&s, 0, f);
+ n = ixp_sizeof_stat(s);
+ offset += n;
+ if(offset >= f->ifcall.offset) {
+ if(size < n)
+ break;
+ ixp_pack_stat(&buf, &size, &s);
+ }
+ }
+
+ while((tf = f)) {
+ f = f->next;
+ free_file(tf);
+ }
+
+ f.ofcall.size = f.ifcall.size - size;
+ respond(f, nil);
+ }else{
+ }
+}
+
+void
+dostat(Stat *s, unsigned int len, FileId *f) {
+ s->type = 0;
+ s->dev = 0;
+ s->qid.path = QID(f->tab.type, f->id);
+ s->qid.vers = 0;
+ s->qid.type = f->tab.qtype;
+ s->mode = f->tab.perm;
+ s->atime = clock;
+ s->mtime = clock;
+ s->length = len;
+ s->name = f->tab.name;
+ s->uid = user;
+ s->gid = user;
+ s->muid = user;
+}