From 3f29c3b274ba79e4413b14697b6253c67cb38481 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 18 Oct 1993 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1993-10-18 --- port/cache.c | 86 +++++++++++++++++++++++++++++++------------------- port/chan.c | 9 ++++-- port/devproc.c | 27 ++++++++++++++-- port/portdat.h | 1 - 4 files changed, 85 insertions(+), 38 deletions(-) diff --git a/port/cache.c b/port/cache.c index bca1642f2e541d2185d2ab56fb6c9e022963cf8e..d3dc9f7a4e160adc3144810e213676f00727c858 100644 --- a/port/cache.c +++ b/port/cache.c @@ -72,16 +72,29 @@ cinit(void) void cprint(Chan *c, Mntcache *m, char *s) { + ulong o; + int nb, ct; Extent *e; char buf[128]; - +return; ptpath(c->path, buf, sizeof(buf)); - pprint("%s: 0x%lux.0x%lux %d %d %s\n", - s, m->path, m->vers, m->type, m->dev, buf); + nb = 0; + ct = 1; + if(m->list) + o = m->list->start; + for(e = m->list; e; e = e->next) { + nb += e->len; + if(o != e->start) + ct = 0; + o = e->start+e->len; + } + pprint("%s: 0x%lux.0x%lux %d %d %s (%d %c)\n", + s, m->path, m->vers, m->type, m->dev, buf, nb, ct ? 'C' : 'N'); - for(e = m->list; e; e = e->next) - pprint("\t%4d %5d %4d %lux\n", + for(e = m->list; e; e = e->next) { + if(0) pprint("\t%4d %5d %4d %lux\n", e->bid, e->start, e->len, e->cache); + } } Page* @@ -130,21 +143,26 @@ ctail(Mntcache *m) cache.tail = m; } else { - cache.head = cache.tail = m; - m->prev = m->next = 0; + cache.head = m; + cache.tail = m; + m->prev = 0; + m->next = 0; } } void copen(Chan *c) { + int h; + Extent *e, *next; Mntcache *m, *f, **l; - if((c->qid.path&CHDIR) || (c->flag&CTEXT)) + if(c->qid.path&CHDIR) return; + h = c->qid.path%NHASH; lock(&cache); - for(m = cache.hash[c->qid.path%NHASH]; m; m = m->hash) { + for(m = cache.hash[h]; m; m = m->hash) { if(m->path == c->qid.path) if(m->dev == c->dev && m->type == c->type) { c->mcp = m; @@ -153,11 +171,14 @@ copen(Chan *c) /* File was updated, invalidate cache */ if(m->vers != c->qid.vers) { + m->vers = c->qid.vers; qlock(m); cnodata(m); - m->vers = c->qid.vers; qunlock(m); +cprint(c, m, "open mod"); } +else +cprint(c, m, "open cached"); return; } } @@ -167,25 +188,32 @@ copen(Chan *c) l = &cache.hash[m->path%NHASH]; for(f = *l; f; f = f->hash) { if(f == m) { - *l = f->hash; + *l = m->hash; break; } l = &f->hash; } - l = &cache.hash[c->qid.path%NHASH]; - m->hash = *l; - *l = m; - ctail(m); m->Qid = c->qid; m->dev = c->dev; m->type = c->type; + + l = &cache.hash[h]; + m->hash = *l; + *l = m; + ctail(m); + c->mcp = m; + e = m->list; + m->list = 0; unlock(&cache); - qlock(m); - cnodata(m); - qunlock(m); + while(e) { + next = e->next; + free(e); + e = next; + } +cprint(c, m, "open new"); } static int @@ -193,12 +221,12 @@ cdev(Mntcache *m, Chan *c) { if(m->path != c->qid.path) return 0; - if(m->vers != c->qid.vers) - return 0; if(m->dev != c->dev) return 0; if(m->type != c->type) return 0; + if(m->vers != c->qid.vers) + return 0; return 1; } @@ -211,9 +239,6 @@ cread(Chan *c, uchar *buf, int len, ulong offset) Extent *e, **t; int o, l, total; - if(c->qid.path & CHDIR) - return 0; - m = c->mcp; if(m == 0) return 0; @@ -226,7 +251,7 @@ cread(Chan *c, uchar *buf, int len, ulong offset) t = &m->list; for(e = *t; e; e = e->next) { - if(offset > e->start && offset < e->start+e->len) + if(offset >= e->start && offset < e->start+e->len) break; t = &e->next; } @@ -274,7 +299,7 @@ cread(Chan *c, uchar *buf, int len, ulong offset) if(e == 0 || e->start != offset) break; } -if(len) print("P"); else print("F"); + qunlock(m); return total; } @@ -307,10 +332,12 @@ cchain(uchar *buf, ulong offset, int len, Extent **tail) e->cache = p; e->start = offset; e->len = l; + lock(&cache); e->bid = cache.pgno; cache.pgno += BY2PG; unlock(&cache); + p->daddr = e->bid; k = kmap(p); memmove((void*)VA(k), buf, l); @@ -350,7 +377,7 @@ cpgmove(Extent *e, uchar *buf, int boff, int len) } void -cxupdate(Chan *c, uchar *buf, int len, ulong offset) +cupdate(Chan *c, uchar *buf, int len, ulong offset) { Mntcache *m; Extent *tail; @@ -457,12 +484,6 @@ cxupdate(Chan *c, uchar *buf, int len, ulong offset) qunlock(m); } -void -cupdate(Chan *c, uchar *buf, int len, ulong offset) -{ - cxupdate(c, buf, len, offset); -} - void cwrite(Chan* c, uchar *buf, int len, ulong offset) { @@ -502,6 +523,7 @@ cwrite(Chan* c, uchar *buf, int len, ulong offset) if(p->len == 0) panic("del empty extent"); } + /* Pack sequential write if there is space */ if(ee == offset && p->len < BY2PG) { o = len; if(o > BY2PG - p->len) diff --git a/port/chan.c b/port/chan.c index 643e408862b9ce2a6a9994477a6bf7dde09c726f..68a90de40adbb27e467b86130a3ac3511da3a132 100644 --- a/port/chan.c +++ b/port/chan.c @@ -613,10 +613,13 @@ namec(char *name, int amode, int omode, ulong perm) } Open: /* else error() in open has wrong value of c saved */ - saveregisters(); - c = (*devtab[c->type].open)(c, omode); + saveregisters(); + if(omode == OEXEC) - c->flag |= CTEXT; + c->flag &= ~CCACHE; + + c = (*devtab[c->type].open)(c, omode); + if(omode & OCEXEC) c->flag |= CCEXEC; if(omode & ORCLOSE) diff --git a/port/devproc.c b/port/devproc.c index e5b58f323b81b4a3c71d1b8a85683c8f2284a665..33a52def7f1fc362c922c869ae9c3e9e60e81b31 100644 --- a/port/devproc.c +++ b/port/devproc.c @@ -16,6 +16,7 @@ enum Qkregs, Qmem, Qnote, + Qnoteid, Qnotepg, Qns, Qproc, @@ -34,6 +35,7 @@ Dirtab procdir[] = "kregs", {Qkregs}, sizeof(Ureg), 0000, "mem", {Qmem}, 0, 0000, "note", {Qnote}, 0, 0000, + "noteid", {Qnoteid}, 0, 0666, "notepg", {Qnotepg}, 0, 0000, "ns", {Qns}, 0, 0400, "proc", {Qproc}, 0, 0400, @@ -188,6 +190,7 @@ procopen(Chan *c, int omode) case Qctl: case Qnote: + case Qnoteid: case Qmem: case Qstatus: case Qwait: @@ -470,6 +473,8 @@ procread(Chan *c, void *va, long n, ulong offset) } a += ptpath(mw->cm->to->path, a, n); return a - (char*)va; + case Qnoteid: + return readnum(offset, va, n, p->noteid, NUMSIZE); } error(Egreg); return 0; /* not reached */ @@ -516,7 +521,8 @@ mntscan(Mntwalk *mw) long procwrite(Chan *c, void *va, long n, ulong offset) { - Proc *p; + int id; + Proc *p, *t, *et; char buf[ERRLEN]; if(c->qid.path & CHDIR) @@ -578,7 +584,24 @@ procwrite(Chan *c, void *va, long n, ulong offset) if(!postnote(p, 0, buf, NUser)) error("note not posted"); break; - + case Qnoteid: + id = atoi((char*)va); + if(id == p->pid) { + p->noteid = id; + break; + } + t = proctab(0); + for(et = t+conf.nproc; t < et; t++) { + if(id == t->noteid) { + if(strcmp(p->user, t->user) != 0) + error(Eperm); + p->noteid = id; + break; + } + } + if(p->noteid != id) + error(Ebadarg); + break; default: pprint("unknown qid in procwrite\n"); error(Egreg); diff --git a/port/portdat.h b/port/portdat.h index 74ec747b916ac84d03551c86bef9169204c15b76..32f2352eceec531d894f53ccb9c9d7e22084f879 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -110,7 +110,6 @@ enum CRCLOSE = 0x0020, /* remove on close */ CRECOV = 0x0040, /* requires recovery */ CCACHE = 0x0080, /* client cache */ - CTEXT = 0x0100, /* text file */ }; struct Path