~kris/9p

9hist

f9eb8afcf7158d83fb08060f191c06e4aed42194 — David du Colombier 25 years ago fa85013
Plan 9 from Bell Labs 2001-05-03
M bitsy/devuda1341.c => bitsy/devuda1341.c +8 -10
@@ 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)

M pc/devastar.c => pc/devastar.c +0 -5
@@ 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;
	}
}

M pc/devusb.c => pc/devusb.c +21 -10
@@ 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:

M pc/devvga.c => pc/devvga.c +5 -3
@@ 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();
		}
	}
}


M pc/etherec2t.c => pc/etherec2t.c +3 -2
@@ 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++){

M pc/etherga620.c => pc/etherga620.c +4 -0
@@ 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;
		}


M port/auth.c => port/auth.c +10 -8
@@ 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");
	}

M port/chan.c => port/chan.c +2 -1
@@ 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

M port/devaudio.c => port/devaudio.c +3 -5
@@ 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();

M port/devmnt.c => port/devmnt.c +61 -50
@@ 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;

M port/devproc.c => port/devproc.c +1 -1
@@ 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:

M port/devroot.c => port/devroot.c +1 -5
@@ 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

M port/devsrv.c => port/devsrv.c +5 -2
@@ 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

M port/devtls.c => port/devtls.c +1 -3
@@ 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);
}


M port/log.c => port/log.c +0 -5
@@ 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

M port/segment.c => port/segment.c +9 -2
@@ 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;