From 0b4125bf057862ef9df6092415bc64c5a2313864 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 4 Jan 2000 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2000-01-04 --- carrera/screen.c | 4 +- pc/vga.c | 2 +- port/devmnt.c | 107 ++++++++++++++++------------------------------- port/devsd.c | 29 ++++++++++--- port/portdat.h | 2 - 5 files changed, 62 insertions(+), 82 deletions(-) diff --git a/carrera/screen.c b/carrera/screen.c index 15762a7f0ee54dd3461411d36e7a89c6ddd88f6f..750467be56986b85a4f173abe7f7fceded19af8b 100644 --- a/carrera/screen.c +++ b/carrera/screen.c @@ -133,7 +133,7 @@ screenwin(void) greet = " Plan 9 Console "; p = addpt(window.min, Pt(10, 0)); q = memsubfontwidth(memdefont, greet); - memimagestring(gscreen, p, conscol, memdefont, greet); + memimagestring(gscreen, p, conscol, ZP, memdefont, greet); window.min.y += h+6; curpos = window.min; window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h; @@ -335,7 +335,7 @@ screenputc(char *buf) *xp++ = curpos.x; r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y + h); memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min); - memimagestring(gscreen, curpos, conscol, memdefont, buf); + memimagestring(gscreen, curpos, conscol, ZP, memdefont, buf); curpos.x += w; } } diff --git a/pc/vga.c b/pc/vga.c index d7b72dc290227ed281c84da391ca2ca0f6580a6c..4a7274aa252904e97ceb23e39ea6420ba1a8f386 100644 --- a/pc/vga.c +++ b/pc/vga.c @@ -121,7 +121,7 @@ vgascreenputc(VGAscr* scr, char* buf, Rectangle *flushr) *xp++ = curpos.x; r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y+h); memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min); - memimagestring(scr->gscreen, curpos, conscol, scr->memdefont, buf); + memimagestring(scr->gscreen, curpos, conscol, ZP, scr->memdefont, buf); combinerect(flushr, r); curpos.x += w; } diff --git a/port/devmnt.c b/port/devmnt.c index f7370eee9b1bc53cb5b3a81b94f4ef58db8ed8a8..ae0e141698bd528fca664370631364bcf223053e 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -15,9 +15,6 @@ struct Mntrpc Rendez r; /* Place to hang out */ char* rpc; /* I/O Data buffer */ char done; /* Rpc completed */ - char flushed; /* Flush was sent */ - ushort flushtag; /* Tag flush sent on */ - char flush[MAXMSG]; /* Somewhere to build flush */ uvlong stime; /* start time for mnt statistics */ ulong reqlen; /* request length for mnt statistics */ ulong replen; /* reply length for mnt statistics */ @@ -39,7 +36,7 @@ void mattach(Mnt*, Chan*, char*); void mntauth(Mnt*, Mntrpc*, char*, ushort); Mnt* mntchk(Chan*); void mntdirfix(uchar*, Chan*); -int mntflush(Mnt*, Mntrpc*); +void mntflush(Mnt*, Mntrpc*); void mntfree(Mntrpc*); void mntgate(Mnt*); void mntpntfree(Mnt*); @@ -60,8 +57,6 @@ void (*mntstats)(int, Chan*, uvlong, ulong); enum { Tagspace = 1, - Tagfls = 0x8000, - Tagend = 0xfffe, }; static void @@ -120,8 +115,6 @@ mntattach(char *muxattach) unlock(&mntalloc); exhausted("mount devices"); } - m->flushbase = Tagfls; - m->flushtag = Tagfls; } m->list = mntalloc.list; mntalloc.list = m; @@ -402,7 +395,6 @@ mclose(Mnt *m, Chan*) for(q = m->queue; q; q = r) { r = q->list; - q->flushed = 0; mntfree(q); } m->id = 0; @@ -628,10 +620,10 @@ mountrpc(Mnt *m, Mntrpc *r) default: if(t == r->request.type+1) break; - print("mnt: proc %s %lud: mismatch rep 0x%lux tag %d fid %d T%d R%d fls %d rp %d\n", + print("mnt: proc %s %lud: mismatch rep 0x%lux tag %d fid %d T%d R%d rp %d\n", up->text, up->pid, r, r->request.tag, r->request.fid, r->request.type, r->reply.type, - r->flushtag, r->reply.tag); + r->reply.tag); error(Emountrpc); } } @@ -642,7 +634,6 @@ mountio(Mnt *m, Mntrpc *r) int n; lock(m); - r->flushed = 0; r->m = m; r->list = m->queue; m->queue = r; @@ -653,21 +644,22 @@ mountio(Mnt *m, Mntrpc *r) if(n < 0) panic("bad message type in mountio"); if(waserror()) { - if(mntflush(m, r) == 0) + if(m->rip == up) + mntgate(m); + if(strcmp(up->error, Eintr) != 0) nexterror(); + mntflush(m, r); + return; } - else { - if(devtab[m->c->type]->dc == L'M'){ - if(mnt9prdwr(Twrite, m->c, r->rpc, n, 0) != n) - error(Emountrpc); - }else{ - if(devtab[m->c->type]->write(m->c, r->rpc, n, 0) != n) - error(Emountrpc); - } - r->stime = fastticks(nil); - r->reqlen = n; - poperror(); + if(devtab[m->c->type]->dc == L'M'){ + if(mnt9prdwr(Twrite, m->c, r->rpc, n, 0) != n) + error(Emountrpc); + }else{ + if(devtab[m->c->type]->write(m->c, r->rpc, n, 0) != n) + error(Emountrpc); } + r->stime = fastticks(nil); + r->reqlen = n; /* Gate readers onto the mount point one at a time */ for(;;) { @@ -675,15 +667,11 @@ mountio(Mnt *m, Mntrpc *r) if(m->rip == 0) break; unlock(m); - if(waserror()) { - if(mntflush(m, r) == 0) - nexterror(); - continue; - } sleep(&r->r, rpcattn, r); - poperror(); - if(r->done) + if(r->done){ + poperror(); return; + } } m->rip = up; unlock(m); @@ -692,6 +680,7 @@ mountio(Mnt *m, Mntrpc *r) mountmux(m, r); } mntgate(m); + poperror(); } void @@ -700,20 +689,12 @@ mntrpcread(Mnt *m, Mntrpc *r) int n; for(;;) { - if(waserror()) { - if(mntflush(m, r) == 0) { - mntgate(m); - nexterror(); - } - continue; - } r->reply.type = 0; r->reply.tag = 0; if(devtab[m->c->type]->dc == L'M') n = mnt9prdwr(Tread, m->c, r->rpc, MAXRPC, 0); else n = devtab[m->c->type]->read(m->c, r->rpc, MAXRPC, 0); - poperror(); if(n == 0) continue; @@ -747,8 +728,8 @@ mountmux(Mnt *m, Mntrpc *r) lock(m); l = &m->queue; for(q = *l; q; q = q->list) { - if((q->flushed==0 && q->request.tag == r->reply.tag) - || (q->flushed && q->flushtag == r->reply.tag)) { + // look for a reply to a message + if(q->request.tag == r->reply.tag) { *l = q->list; if(q != r) { /* @@ -775,41 +756,26 @@ mountmux(Mnt *m, Mntrpc *r) unlock(m); } -int +void mntflush(Mnt *m, Mntrpc *r) { - int n, l; - Fcall flush; + Mntrpc *fr; - lock(m); - if(r->done){ - unlock(m); - return 1; - } - r->flushtag = m->flushtag++; - if(m->flushtag == Tagend) - m->flushtag = m->flushbase; - r->flushed = 1; - unlock(m); + fr = mntralloc(0); - flush.type = Tflush; - flush.tag = r->flushtag; - flush.oldtag = r->request.tag; - n = convS2M(&flush, r->flush); - if(n < 0) - panic("bad message type in mntflush"); + fr->request.type = Tflush; + if(r->request.type == Tflush) + fr->request.oldtag = r->request.oldtag; + else + fr->request.oldtag = r->request.tag; - if(waserror()) { - if(strcmp(up->error, Eintr) == 0) - return 1; + mountio(m, fr); + mntfree(fr); + + if(!r->done){ + r->reply.type = Rflush; mntqrm(m, r); - return 0; } - l = devtab[m->c->type]->write(m->c, r->flush, n, 0); - if(l != n) - error(Ehungup); - poperror(); - return 1; } Mntrpc* @@ -845,8 +811,6 @@ mntralloc(Chan *c) unlock(&mntalloc); new->c = c; new->done = 0; - new->flushed = 0; - new->flushtag = 0; return new; } @@ -874,7 +838,6 @@ mntqrm(Mnt *m, Mntrpc *r) lock(m); r->done = 1; - r->flushed = 0; l = &m->queue; for(f = *l; f; f = f->list) { diff --git a/port/devsd.c b/port/devsd.c index 8bcb7f11f58a037c83ba109c087efaf6ca0b3cc9..d9bbf7d3b9207911d496b663b93cedbff97b454c 100644 --- a/port/devsd.c +++ b/port/devsd.c @@ -71,7 +71,6 @@ static int types[] = static int sdgen(Chan *c, Dirtab*, int, int s, Dir *dirp) { - Qid qid; Disk *d; Part *p; @@ -335,18 +334,38 @@ sdrdpart(Disk *d) p++; strcpy(p->name, "partition"); - p->beg = d->table[0].end - 1; - p->end = d->table[0].end; + p->beg = d->table[0].end - 2; + p->end = d->table[0].end - 1; p++; d->npart = 2; - scsibio(d->t, d->lun, SCSIread, b, 1, d->bsize, d->table[0].end-1); + /* + * Read second last sector from disk, null terminate. + * The last sector used to hold the partition tables. + * However, this sector is special on some PC's so we've + * started to use the second last sector as the partition + * table instead. To avoid reconfiguring all our old systems + * we still check if there is a valid partition table in + * the last sector if none is found in the second last. + */ + scsibio(d->t, d->lun, SCSIread, b, 1, d->bsize, d->table[0].end-2); b[d->bsize-1] = '\0'; + n = parsefields(b, line, nelem(line), "\n"); + if(n <= 0 || strncmp(line[0], MAGIC, sizeof(MAGIC)-1) != 0){ + /* try the last */ + scsibio(d->t, d->lun, SCSIread, b, 1, d->bsize, d->table[0].end-1); + b[d->bsize-1] = '\0'; + n = parsefields(b, line, nelem(line), "\n"); + /* only point partition file at last sector if there is one there */ + if(n > 0 && strncmp(line[0], MAGIC, sizeof(MAGIC)-1) == 0){ + d->table[1].beg++; + d->table[1].end++; + } + } /* * parse partition table. */ - n = parsefields(b, line, nelem(line), "\n"); if(n > 0 && strncmp(line[0], MAGIC, sizeof(MAGIC)-1) == 0) { for(i = 1; i < n; i++) { if(parsefields(line[i], field, nelem(field), " ") != 3) diff --git a/port/portdat.h b/port/portdat.h index 490dd3c75931fb1cedb87e0e328f0efea8df9467..836cf0aaee70f0e08cb8eb5ccad5af86847e9993 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -246,8 +246,6 @@ struct Mnt Mnt *list; /* Free list */ int flags; /* cache */ int blocksize; /* read/write block size */ - ushort flushtag; /* Tag to send flush on */ - ushort flushbase; /* Base tag of flush window for this buffer */ char *partial; /* Outstanding read data */ int npart; /* Sizeof remains */ };