From f9eb8afcf7158d83fb08060f191c06e4aed42194 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 3 May 2001 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2001-05-03 --- bitsy/devuda1341.c | 18 ++++---- pc/devastar.c | 5 -- pc/devusb.c | 31 +++++++++---- pc/devvga.c | 8 ++-- pc/etherec2t.c | 5 +- pc/etherga620.c | 4 ++ port/auth.c | 18 ++++---- port/chan.c | 3 +- port/devaudio.c | 8 ++-- port/devmnt.c | 111 +++++++++++++++++++++++++-------------------- port/devproc.c | 2 +- port/devroot.c | 6 +-- port/devsrv.c | 7 ++- port/devtls.c | 4 +- port/log.c | 5 -- port/segment.c | 11 ++++- 16 files changed, 134 insertions(+), 112 deletions(-) diff --git a/bitsy/devuda1341.c b/bitsy/devuda1341.c index 9f4a942265df2d5f5941e5203b6aa3aea9f82728..0e19dc46e34959340b146be224fd8f10247c33f9 100644 --- a/bitsy/devuda1341.c +++ b/bitsy/devuda1341.c @@ -947,11 +947,10 @@ audioclose(Chan *c) if ((audio.amode & Awrite) == 0) { s = &audio.o; qlock(s); - while(waserror()) { - dmawait(s->dma); - if (dmaidle(s->dma)) - break; - } + while(waserror()) + ; + dmawait(s->dma); + poperror(); outdisable(); setempty(s); dmafree(s->dma); @@ -970,11 +969,10 @@ audioclose(Chan *c) s->filling = &s->buf[0]; sendaudio(s); } - while(waserror()) { - dmawait(s->dma); - if (dmaidle(s->dma)) - break; - } + while(waserror()) + ; + dmawait(s->dma); + poperror(); outdisable(); setempty(s); if ((audio.amode & Aread) == 0) diff --git a/pc/devastar.c b/pc/devastar.c index 9a18277c0f2647ababaeb4fb4f9679cf639473f4..f7129638cacd1cf91222a77dafcc4b8c912310fd 100644 --- a/pc/devastar.c +++ b/pc/devastar.c @@ -679,17 +679,12 @@ astarclose(Chan *c) case Qctl: ac = a->c + CHAN(c->qid.path); qlock(ac); - if(waserror()){ - qunlock(ac); - nexterror(); - } if(--(ac->opens) == 0){ disable(ac); qclose(ac->iq); qclose(ac->oq); } qunlock(ac); - poperror(); break; } } diff --git a/pc/devusb.c b/pc/devusb.c index 87f39d914880d055455d2ea5431be5ca45f2dff1..8718046c607dd244c3fe5930e7de1a3a3996cc88 100644 --- a/pc/devusb.c +++ b/pc/devusb.c @@ -1197,7 +1197,7 @@ usbdevice(Chan *c) d = usbdeviceofpath(c->qid.path); if(d == nil || d->id != c->qid.vers || d->state == Disabled) - error(Ehungup); + return nil; return d; } @@ -1515,6 +1515,8 @@ usbopen(Chan *c, int omode) switch(QID(c->qid)){ case Qctl: d = usbdevice(c); + if (d == nil) + error(Ehungup); if(0&&d->busy) error(Einuse); d->busy = 1; @@ -1524,6 +1526,8 @@ usbopen(Chan *c, int omode) default: d = usbdevice(c); + if (d == nil) + error(Ehungup); s = QID(c->qid) - Qep0; if(s >= 0 && s < nelem(d->ep)){ Endpt *e; @@ -1572,16 +1576,13 @@ usbclose(Chan *c) if(c->qid.path & CHDIR || c->qid.path < Q3rd) return; qlock(&usbstate); - if(waserror()){ - qunlock(&usbstate); - nexterror(); + d = usbdeviceofpath(c->qid.path); + if (d && d->id == c->qid.vers) { + if(QID(c->qid) == Qctl) + d->busy = 0; + if(c->flag & COPEN) + freedev(d); } - d = usbdevice(c); - if(QID(c->qid) == Qctl) - d->busy = 0; - if(c->flag & COPEN) - freedev(d); - poperror(); qunlock(&usbstate); } @@ -1672,11 +1673,15 @@ usbread(Chan *c, void *a, long n, vlong offset) case Qctl: d = usbdevice(c); + if (d == nil) + error(Ehungup); sprint(buf, "%11d %11d ", d->x, d->id); return readstr(offset, a, n, buf); case Qsetup: /* endpoint 0 */ d = usbdevice(c); + if (d == nil) + error(Ehungup); if((e = d->ep[0]) == nil) error(Eio); /* can't happen */ e->data01 = 1; @@ -1694,6 +1699,8 @@ usbread(Chan *c, void *a, long n, vlong offset) case Qstatus: d = usbdevice(c); + if (d == nil) + error(Ehungup); s = smalloc(READSTR); if(waserror()){ free(s); @@ -1710,6 +1717,8 @@ usbread(Chan *c, void *a, long n, vlong offset) default: d = usbdevice(c); + if (d == nil) + error(Ehungup); if((t -= Qep0) < 0 || t >= nelem(d->ep)) error(Eio); if((e = d->ep[t]) == nil || e->mode == OWRITE) @@ -1813,6 +1822,8 @@ usbwrite(Chan *c, void *a, long n, vlong) return n; } d = usbdevice(c); + if (d == nil) + error(Ehungup); t = QID(c->qid); switch(t){ case Qctl: diff --git a/pc/devvga.c b/pc/devvga.c index 457f4576b4b82b7b5983bb91868196375be87ddd..381099c997bee73e45ca5e91b30366b6a796a5c2 100644 --- a/pc/devvga.c +++ b/pc/devvga.c @@ -82,10 +82,12 @@ vgaclose(Chan* c) scr = &vgascreen[0]; if ((c->qid.path & ~CHDIR) == Qvgaovlctl) { - if (scr->dev->ovlctl) + if (scr->dev->ovlctl){ + if(waserror()) + return; scr->dev->ovlctl(scr, c, closectl, strlen(closectl)); - else - error(Enonexist); + poperror(); + } } } diff --git a/pc/etherec2t.c b/pc/etherec2t.c index 994b2f6181cf9d5c4b5d55c154e72148784d0209..33b21fe89b4c1546861c542626b2b17b318168fd 100644 --- a/pc/etherec2t.c +++ b/pc/etherec2t.c @@ -21,6 +21,7 @@ enum { static char* ec2tpcmcia[] = { "EC2T", /* Linksys Combo PCMCIA EthernetCard */ "PCMPC100", /* EtherFast 10/100 PC Card */ + "PCM100", /* EtherFast 10/100 Integrated PC Card */ "EN2216", /* Accton EtherPair-PCMCIA */ "FA410TX", /* Netgear FA410TX */ nil, @@ -116,9 +117,9 @@ reset(Ether* ether) */ dp8390reset(ether); sum = 0; - if(cistrcmp(type, "PCMPC100") == 0 || cistrcmp(type, "FA410TX") == 0){ + if(cistrcmp(type, "PCMPC100") == 0 || cistrcmp(type, "PCM100") == 0 || cistrcmp(type, "FA410TX") == 0){ /* - * The PCMPC100 has the ethernet address in I/O space. + * These NICs have the ethernet address in I/O space. * There's a checksum over 8 bytes which sums to 0xFF. */ for(i = 0; i < 8; i++){ diff --git a/pc/etherga620.c b/pc/etherga620.c index 8e6db83cb5a9ff4540b05cd0d5d3c3f05776a7f9..0d4f87025262a29ab3ed86900731ab3434ddb935 100644 --- a/pc/etherga620.c +++ b/pc/etherga620.c @@ -936,6 +936,10 @@ ga620pci(void) continue; case (0x620A<<16)|0x1385: /* Netgear GA620 */ case (0x630A<<16)|0x1385: /* Netgear GA620T */ + case (0x0001<<16)|0x12AE: /* Alteon Acenic fiber + * and DEC DEGPA-SA */ + case (0x0002<<16)|0x12AE: /* Alteon Acenic copper */ + case (0x0009<<16)|0x10A9: /* SGI Acenic */ break; } diff --git a/port/auth.c b/port/auth.c index e35db7d2848f6c110a2c7ec57a88227e92d81754..b4a8450d7f890ac69cf3587eb1a3ad09236e79f4 100644 --- a/port/auth.c +++ b/port/auth.c @@ -278,6 +278,7 @@ freesession(Session *s) ulong authrequest(Session *s, Fcall *f) { + Authenticator a; Crypt *cp; ulong id, dofree; @@ -315,10 +316,10 @@ authrequest(Session *s, Fcall *f) memmove(f->ticket, cp->tbuf, TICKETLEN); /* create an authenticator */ - memmove(cp->a.chal, s->schal, CHALLEN); - cp->a.num = AuthAc; - cp->a.id = id; - convA2M(&cp->a, f->auth, cp->t.key); + memmove(a.chal, s->schal, CHALLEN); + a.num = AuthAc; + a.id = id; + convA2M(&a, f->auth, cp->t.key); if(dofree) freecrypt(cp); return id; @@ -330,6 +331,7 @@ authrequest(Session *s, Fcall *f) void authreply(Session *s, ulong id, Fcall *f) { + Authenticator a; Crypt *cp; if(s == 0) @@ -345,16 +347,16 @@ authreply(Session *s, ulong id, Fcall *f) if(s == 0 || cp == 0 || s->authid[0] == 0 || strcmp(up->user, "none") == 0) return; - convM2A(f->rauth, &cp->a, cp->t.key); - if(cp->a.num != AuthAs){ + convM2A(f->rauth, &a, cp->t.key); + if(a.num != AuthAs){ print("bad encryption type\n"); error("server lies"); } - if(memcmp(cp->a.chal, s->cchal, sizeof(cp->a.chal))){ + if(memcmp(a.chal, s->cchal, sizeof(a.chal))){ print("bad returned challenge\n"); error("server lies"); } - if(cp->a.id != id){ + if(a.id != id){ print("bad returned id\n"); error("server lies"); } diff --git a/port/chan.c b/port/chan.c index 08ba09513512835cde5230189069399ea342b114..8d62ae532221ffe426683802688db882aa784e05 100644 --- a/port/chan.c +++ b/port/chan.c @@ -196,12 +196,13 @@ cclose(Chan *c) if(waserror()){ print("cclose error: type %C; error %s\n", devtab[c->type]->dc, up!=nil? up->error : "no user"); //BUG + chanfree(c); return; } devtab[c->type]->close(c); - chanfree(c); poperror(); + chanfree(c); } int diff --git a/port/devaudio.c b/port/devaudio.c index e07caab466780b06ebc62c7a0920802a14688333..ac9a336f9273a8bcbaad6df2055f5bff1332c7fb 100644 --- a/port/devaudio.c +++ b/port/devaudio.c @@ -908,7 +908,7 @@ audioclose(Chan *c) switch(c->qid.path & ~CHDIR) { default: - error(Eperm); + error(Eperm); /* can't happen */ break; case Qdir: @@ -932,10 +932,8 @@ audioclose(Chan *c) pokeaudio(); } audio.amode = Aclosed; - if(waserror()){ - qunlock(&audio); - nexterror(); - } + while(waserror()) + ; while(audio.active) waitaudio(); setempty(); diff --git a/port/devmnt.c b/port/devmnt.c index 3e2c97e3e836a79de60f58cdc7b4593103ecd3c7..7f04f66fd598eb2a32ed8e9936c54cfc217ab6a4 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -33,26 +33,26 @@ struct Mntalloc int rpctag; }mntalloc; -void mattach(Mnt*, Chan*, char*); -void mntauth(Mnt*, Mntrpc*, char*, ushort); -Mnt* mntchk(Chan*); -void mntdirfix(uchar*, Chan*); -Mntrpc* mntflushalloc(Mntrpc*); -void mntflushfree(Mnt*, Mntrpc*); -void mntfree(Mntrpc*); -void mntgate(Mnt*); -void mntpntfree(Mnt*); -void mntqrm(Mnt*, Mntrpc*); -Mntrpc* mntralloc(Chan*); -long mntrdwr(int, Chan*, void*, long, vlong); -long mnt9prdwr(int, Chan*, void*, long, vlong); -void mntrpcread(Mnt*, Mntrpc*); -void mountio(Mnt*, Mntrpc*); -void mountmux(Mnt*, Mntrpc*); -void mountrpc(Mnt*, Mntrpc*); -int rpcattn(void*); -void mclose(Mnt*, Chan*); -Chan* mntchan(void); +static void mattach(Mnt*, Chan*, char*); +static void mntauth(Mnt*, Mntrpc*, char*, ushort); +static Mnt* mntchk(Chan*); +static void mntdirfix(uchar*, Chan*); +static Mntrpc* mntflushalloc(Mntrpc*); +static void mntflushfree(Mnt*, Mntrpc*); +static void mntfree(Mntrpc*); +static void mntgate(Mnt*); +static void mntpntfree(Mnt*); +static void mntqrm(Mnt*, Mntrpc*); +static Mntrpc* mntralloc(Chan*); +static long mntrdwr(int, Chan*, void*, long, vlong); +static long mnt9prdwr(int, Chan*, void*, long, vlong); +static void mntrpcread(Mnt*, Mntrpc*); +static void mountio(Mnt*, Mntrpc*); +static void mountmux(Mnt*, Mntrpc*); +static void mountrpc(Mnt*, Mntrpc*); +static int rpcattn(void*); +static void mclose(Mnt*, Chan*); +static Chan* mntchan(void); void (*mntstats)(int, Chan*, uvlong, ulong); @@ -95,7 +95,7 @@ mntattach(char *muxattach) unlock(&mntalloc); c = mntchan(); if(waserror()) { - chanfree(c); + cclose(c); nexterror(); } mattach(m, c, bogus.spec); @@ -149,10 +149,7 @@ mntattach(char *muxattach) c = mntchan(); if(waserror()) { mclose(m, c); - /* Close must not be called since it will - * call mnt recursively - */ - chanfree(c); + cclose(c); nexterror(); } @@ -182,12 +179,17 @@ mntattach(char *muxattach) return c; } -Chan* +/* + * start off the channel as a root device + * until we've really gotten it started so + * an early close won't run through devmnt again + */ +static Chan* mntchan(void) { Chan *c; - c = devattach('M', 0); + c = devattach('/', 0); lock(&mntalloc); c->dev = mntalloc.id++; unlock(&mntalloc); @@ -195,7 +197,7 @@ mntchan(void) return c; } -void +static void mattach(Mnt *m, Chan *c, char *spec) { ulong id; @@ -215,12 +217,14 @@ mattach(Mnt *m, Chan *c, char *spec) strncpy(r->request.aname, spec, NAMELEN); id = authrequest(m->c->session, &r->request); mountrpc(m, r); - authreply(m->c->session, id, &r->reply); + c->type = devno('M', 0); c->qid = r->reply.qid; c->mchan = m->c; c->mqid = c->qid; + authreply(m->c->session, id, &r->reply); + poperror(); mntfree(r); } @@ -387,7 +391,7 @@ mntclunk(Chan *c, int t) poperror(); } -void +static void mclose(Mnt *m, Chan*) { Mntrpc *q, *r; @@ -404,7 +408,7 @@ mclose(Mnt *m, Chan*) mntpntfree(m); } -void +static void mntpntfree(Mnt *m) { Mnt *f, **l; @@ -511,7 +515,7 @@ mntwrite(Chan *c, void *buf, long n, vlong off) return mntrdwr(Twrite, c, buf, n, off); } -long +static long mnt9prdwr(int type, Chan *c, void *buf, long n, vlong off) { Mnt *m; @@ -548,7 +552,7 @@ mnt9prdwr(int type, Chan *c, void *buf, long n, vlong off) return nr; } -long +static long mntrdwr(int type, Chan *c, void *buf, long n, vlong off) { Mnt *m; @@ -603,9 +607,10 @@ mntrdwr(int type, Chan *c, void *buf, long n, vlong off) return cnt; } -void +static void mountrpc(Mnt *m, Mntrpc *r) { + char *sn, *cn; int t; r->reply.tag = 0; @@ -622,15 +627,21 @@ 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 rp %d\n", - up->text, up->pid, - r, r->request.tag, r->request.fid, r->request.type, r->reply.type, - r->reply.tag); + sn = "?"; + if(m->c->name != nil) + sn = m->c->name->s; + cn = "?"; + if(r->c != nil && r->c->name != nil) + cn = r->c->name->s; + print("mnt: proc %s %lud: mismatch from %s %s rep 0x%lux tag %d fid %d T%d R%d rp %d\n", + up->text, up->pid, sn, cn, + r, r->request.tag, r->request.fid, r->request.type, + r->reply.type, r->reply.tag); error(Emountrpc); } } -void +static void mountio(Mnt *m, Mntrpc *r) { int n; @@ -689,7 +700,7 @@ mountio(Mnt *m, Mntrpc *r) mntflushfree(m, r); } -void +static void mntrpcread(Mnt *m, Mntrpc *r) { int n; @@ -710,7 +721,7 @@ mntrpcread(Mnt *m, Mntrpc *r) } } -void +static void mntgate(Mnt *m) { Mntrpc *q; @@ -725,7 +736,7 @@ mntgate(Mnt *m) unlock(m); } -void +static void mountmux(Mnt *m, Mntrpc *r) { char *dp; @@ -766,7 +777,7 @@ mountmux(Mnt *m, Mntrpc *r) * Create a new flush request and chain the previous * requests from it */ -Mntrpc* +static Mntrpc* mntflushalloc(Mntrpc *r) { Mntrpc *fr; @@ -790,7 +801,7 @@ mntflushalloc(Mntrpc *r) * and if it hasn't been answered set the reply to to * Rflush. */ -void +static void mntflushfree(Mnt *m, Mntrpc *r) { Mntrpc *fr; @@ -807,7 +818,7 @@ mntflushfree(Mnt *m, Mntrpc *r) } } -Mntrpc* +static Mntrpc* mntralloc(Chan *c) { Mntrpc *new; @@ -844,7 +855,7 @@ mntralloc(Chan *c) return new; } -void +static void mntfree(Mntrpc *r) { lock(&mntalloc); @@ -861,7 +872,7 @@ mntfree(Mntrpc *r) unlock(&mntalloc); } -void +static void mntqrm(Mnt *m, Mntrpc *r) { Mntrpc **l, *f; @@ -880,7 +891,7 @@ mntqrm(Mnt *m, Mntrpc *r) unlock(m); } -Mnt* +static Mnt* mntchk(Chan *c) { Mnt *m; @@ -896,7 +907,7 @@ mntchk(Chan *c) return m; } -void +static void mntdirfix(uchar *dirbuf, Chan *c) { int r; @@ -908,7 +919,7 @@ mntdirfix(uchar *dirbuf, Chan *c) dirbuf[DIRLEN-1] = c->dev>>8; } -int +static int rpcattn(void *v) { Mntrpc *r; diff --git a/port/devproc.c b/port/devproc.c index aed13f94543d15eaa601d74124bef83d946ea89d..1e6b8af40982f6f5913597afd6c15a51b74222ac 100644 --- a/port/devproc.c +++ b/port/devproc.c @@ -49,7 +49,7 @@ Dirtab procdir[] = }; /* Segment type from portdat.h */ -char *sname[]={ "Text", "Data", "Bss", "Stack", "Shared", "Phys" }; +static char *sname[]={ "Text", "Data", "Bss", "Stack", "Shared", "Phys" }; /* * Qids are, in path: diff --git a/port/devroot.c b/port/devroot.c index 5f6b39314efd1a714e3b71c51086cd3fb193d155..352575f6606c9d502c8cf76263dc7d671d216572 100644 --- a/port/devroot.c +++ b/port/devroot.c @@ -128,12 +128,8 @@ rootopen(Chan *c, int omode) * sysremove() knows this is a nop */ static void -rootclose(Chan *c) +rootclose(Chan*) { - switch(c->qid.path) { - default: - break; - } } static int diff --git a/port/devsrv.c b/port/devsrv.c index 9f4e657daee8d8661e7cf0150105a4847a650708..5daf4190e2df00d9ac4b062025f30ec0471128ad 100644 --- a/port/devsrv.c +++ b/port/devsrv.c @@ -238,13 +238,16 @@ static void srvclose(Chan *c) { /* - * errors from srvremove will be caught by cclose and ignored. * in theory we need to override any changes in removability * since open, but since all that's checked is the owner, * which is immutable, all is well. */ - if(c->flag & CRCLOSE) + if(c->flag & CRCLOSE){ + if(waserror()) + return; srvremove(c); + poperror(); + } } static long diff --git a/port/devtls.c b/port/devtls.c index 8cb92e219fb8c4651c883ebc83e8e202dd4aa40a..8d726c1293a93c62b90ae490577b7d46ed6e07b1 100644 --- a/port/devtls.c +++ b/port/devtls.c @@ -571,7 +571,7 @@ tlsclose(Chan *c) unlock(&tdlock); if(tr->c != nil && !waserror()){ - checkstate(tr, t != Qdata, SOpen|SHandshake|SRClose); + checkstate(tr, 0, SOpen|SHandshake|SRClose); sendAlert(tr, ECloseNotify); poperror(); } @@ -1782,8 +1782,6 @@ tlshangup(TlsRec *tr) } qunlock(&tr->in.io); - tlsrecwrite(tr, RAlert, ECloseNotify); - tlsSetState(tr, SClosed, ~0); } diff --git a/port/log.c b/port/log.c index 8b724bb12293eec6bb9fabf4510783b58c8ba997..eae735ca35f57b7374bd9cdf0c2a865b3256c4e5 100644 --- a/port/log.c +++ b/port/log.c @@ -35,17 +35,12 @@ void logclose(Log *alog) { lock(alog); - if(waserror()){ - unlock(alog); - nexterror(); - } alog->opens--; if(alog->opens == 0){ free(alog->buf); alog->buf = nil; } unlock(alog); - poperror(); } static int diff --git a/port/segment.c b/port/segment.c index a7e8752933213bd421c9616ab065a67a3f36c3a2..c1e41a90959831a7230d0569ce05324a16752925 100644 --- a/port/segment.c +++ b/port/segment.c @@ -8,9 +8,16 @@ static void imagereclaim(void); static void imagechanreclaim(void); -/* System specific segattach devices */ #include "io.h" -#include "segment.h" + +/* + * Attachable segment types + */ +static Physseg physseg[10] = { + { SG_SHARED, "shared", 0, SEGMAXSIZE, 0, 0 }, + { SG_BSS, "memory", 0, SEGMAXSIZE, 0, 0 }, + { 0, 0, 0, 0, 0, 0 }, +}; static Lock physseglock;