From 74a99ee4cf795dbc5cc5a4df336908ed718c0043 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 17 Oct 1993 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1993-10-17 --- port/cache.c | 49 ++++++++++++++++++++++++++++++++----------------- port/chan.c | 2 ++ port/portdat.h | 1 + 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/port/cache.c b/port/cache.c index 5cde0b9c06d18cba414b2dd3e33d03f78e1b8712..bca1642f2e541d2185d2ab56fb6c9e022963cf8e 100644 --- a/port/cache.c +++ b/port/cache.c @@ -41,7 +41,8 @@ struct Mntcache typedef struct Cache Cache; struct Cache { - Ref; + Lock; + int pgno; Mntcache *head; Mntcache *tail; Mntcache *hash[NHASH]; @@ -54,7 +55,6 @@ cinit(void) int i; Mntcache *m; - cache.ref = 1; cache.head = xalloc(sizeof(Mntcache)*NFILE); m = cache.head; @@ -70,15 +70,17 @@ cinit(void) } void -cprint(Mntcache *m, char *s) +cprint(Chan *c, Mntcache *m, char *s) { Extent *e; + char buf[128]; - print("%s: 0x%lux.0x%lux %d %d\n", - s, m->path, m->vers, m->type, m->dev); + 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); for(e = m->list; e; e = e->next) - print("\t%4d %5d %4d %lux\n", + pprint("\t%4d %5d %4d %lux\n", e->bid, e->start, e->len, e->cache); } @@ -138,7 +140,7 @@ copen(Chan *c) { Mntcache *m, *f, **l; - if(c->qid.path & CHDIR) + if((c->qid.path&CHDIR) || (c->flag&CTEXT)) return; lock(&cache); @@ -207,7 +209,7 @@ cread(Chan *c, uchar *buf, int len, ulong offset) Page *p; Mntcache *m; Extent *e, **t; - int o, l, total, end; + int o, l, total; if(c->qid.path & CHDIR) return 0; @@ -222,15 +224,10 @@ cread(Chan *c, uchar *buf, int len, ulong offset) return 0; } - end = offset+len; t = &m->list; for(e = *t; e; e = e->next) { if(offset > e->start && offset < e->start+e->len) break; - if(offset < e->start) { - qunlock(m); - return 0; - } t = &e->next; } @@ -277,6 +274,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; } @@ -309,7 +307,10 @@ cchain(uchar *buf, ulong offset, int len, Extent **tail) e->cache = p; e->start = offset; e->len = l; - e->bid = incref(&cache); + lock(&cache); + e->bid = cache.pgno; + cache.pgno += BY2PG; + unlock(&cache); p->daddr = e->bid; k = kmap(p); memmove((void*)VA(k), buf, l); @@ -460,7 +461,6 @@ void cupdate(Chan *c, uchar *buf, int len, ulong offset) { cxupdate(c, buf, len, offset); - cprint(c->mcp, "cupdate"); } void @@ -485,10 +485,11 @@ cwrite(Chan* c, uchar *buf, int len, ulong offset) } m->vers++; + c->qid.vers++; p = 0; for(f = m->list; f; f = f->next) { - if(offset >= f->start) + if(f->start >= offset) break; p = f; } @@ -501,6 +502,21 @@ cwrite(Chan* c, uchar *buf, int len, ulong offset) if(p->len == 0) panic("del empty extent"); } + if(ee == offset && p->len < BY2PG) { + o = len; + if(o > BY2PG - p->len) + o = BY2PG - p->len; + if(cpgmove(p, buf, p->len, o)) { + p->len += o; + buf += o; + len -= o; + offset += o; + if(len <= 0) { + qunlock(m); + return; + } + } + } } eblock = offset+len; @@ -521,5 +537,4 @@ cwrite(Chan* c, uchar *buf, int len, ulong offset) tail->next = f; } qunlock(m); -cprint(m, "cwrite"); } diff --git a/port/chan.c b/port/chan.c index 83a7d381a95ff67d1b64fca11fb7b3e45b49673a..643e408862b9ce2a6a9994477a6bf7dde09c726f 100644 --- a/port/chan.c +++ b/port/chan.c @@ -615,6 +615,8 @@ namec(char *name, int amode, int omode, ulong perm) /* else error() in open has wrong value of c saved */ saveregisters(); c = (*devtab[c->type].open)(c, omode); + if(omode == OEXEC) + c->flag |= CTEXT; if(omode & OCEXEC) c->flag |= CCEXEC; if(omode & ORCLOSE) diff --git a/port/portdat.h b/port/portdat.h index 32f2352eceec531d894f53ccb9c9d7e22084f879..74ec747b916ac84d03551c86bef9169204c15b76 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -110,6 +110,7 @@ enum CRCLOSE = 0x0020, /* remove on close */ CRECOV = 0x0040, /* requires recovery */ CCACHE = 0x0080, /* client cache */ + CTEXT = 0x0100, /* text file */ }; struct Path