From abf0ec9b801664f280f4c7da37110ac638086fdc Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 3 Feb 1996 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1996-02-03 --- pc/main.c | 45 ++++++++++++++++++++++++++++------ port/devtinyfs.c | 63 ++++++++++++++++++++++++++++++------------------ 2 files changed, 77 insertions(+), 31 deletions(-) diff --git a/pc/main.c b/pc/main.c index 35ad98756e646913c27479e5de8645231db43247..7383a7a3187b5e824fe332d42daff2ce92979d50 100644 --- a/pc/main.c +++ b/pc/main.c @@ -354,29 +354,60 @@ romscan(void) } } +static int +getcfields(char *lp, char **fields, int n, char sep) +{ + int i; + + for(i=0; lp && *lp && i ' '. + */ + p = cp; + for(q = cp; *q; q++){ + if(*q == '\r') + continue; + if(*q == '\t') + *q = ' '; + *p++ = *q; + } + *p = 0; + + n = getcfields(cp, line, MAXCONF, '\n'); for(j = 0; j < n; j++){ - cp = strchr(line[j], '\r'); - if(cp) - *cp = 0; + if(*line[j] == '#') + continue; cp = strchr(line[j], '='); if(cp == 0) continue; diff --git a/port/devtinyfs.c b/port/devtinyfs.c index eb2c4845d0fce7842956aa5d8f8099ccf907f15c..9f12616f9cd80d1e8fe45275597bd866a04e068c 100644 --- a/port/devtinyfs.c +++ b/port/devtinyfs.c @@ -28,6 +28,9 @@ enum{ Notapin= 0xffff, Notabno= 0xffff, + + Fcreating= 1, + Frmonclose= 2, }; /* representation of a Tdir on medium */ @@ -57,7 +60,7 @@ struct Tfile { ushort bno; ushort dbno; ushort pin; - char creating; + uchar flag; ulong length; }; @@ -271,7 +274,7 @@ newfile(Tfs *fs, char *name) expand(fs); } - f->creating = 1; + f->flag = Fcreating; f->dbno = Notabno; f->bno = mapalloc(fs); @@ -553,20 +556,31 @@ tinyfsclose(Chan *c) if(c->qid.path != CHDIR){ f = &fs->f[c->qid.path]; f->r--; - if(f->r == 0 && f->creating){ - /* remove all other files with this name */ - for(i = 0; i < fs->fsize; i++){ - nf = &fs->f[i]; - if(f == nf) - continue; - if(strcmp(nf->name, f->name) == 0) - freefile(fs, nf, Notabno); + if(f->r == 0){ + if(f->creating){ + /* remove all other files with this name */ + for(i = 0; i < fs->fsize; i++){ + nf = &fs->f[i]; + if(f == nf) + continue; + if(strcmp(nf->name, f->name) == 0){ + if(nf->r) + nf->flag |= Frmonclose; + else + freefile(fs, nf, Notabno); + } + } + f->flag &= ~(Frmonclose|Fcreating); } + if(f->flag & Frmonclose){ + freefile(fs, f, Notabno); } } /* dereference fs and remove on zero refs */ fs->r--; + unlock(fs); + qlock(&tinyfs); if(fs->ref == 0){ for(l = &fs->l; *l;){ if(*l == fs){ @@ -575,30 +589,31 @@ tinyfsclose(Chan *c) } l = &(*l)->next; } - for(f = fs->f; f; f = nf){ - nf = f->next; - free(f); - } + free(fs-f); free(fs->map); close(fs->c); - free(fs); + memset(fs, 0, sizeof(*fs)); } - unlock(fs); qunlock(&tinyfs); } long tinyfsread(Chan *c, void *a, long n, ulong offset) { - switch(c->qid.path & ~CHDIR){ - case Qdir: + Tfs *fs; + Tfile *f; + int sofar, i; + + if(c->qid.path & CHDIR) return devdirread(c, a, n, tinyfstab, Ntinyfstab, tinyfsgen); - case Qdata: - break; - default: - n=0; - break; - } + + fs = tinyfs.fs[c->dev]; + f = &fs->f[c->qid.path]; + if(offset >= f->length) + return 0; + if(n + offset >= f->length) + n = f->length - offset; + return n; }