~kris/9p

9hist

15dbd11a73043027299fb69fa893f469665166c4 — David du Colombier 34 years ago a9d043d
Plan 9 from Bell Labs 1991-10-22
3 files changed, 64 insertions(+), 16 deletions(-)

M port/devcons.c
M port/devenv.c
M port/stil.c
M port/devcons.c => port/devcons.c +3 -0
@@ 225,6 225,9 @@ echo(int c)
		switch(c){
		case 0x14:
			break;	/* pass it on */
		case 'e':
			envdump();
			return;
		case 'm':
			mntdump();
			return;

M port/devenv.c => port/devenv.c +40 -1
@@ 28,6 28,7 @@ struct
	Envval	*free[EVFREE+1];
	char	*block;			/* the free page we are allocating from */
	char	*lim;			/* end of block */
	int	npage;			/* total pages gotten from newpage() */
}envalloc;

QLock	evlock;


@@ 366,9 367,10 @@ evalloc(ulong n)
			b += ALIGN + sizeof *ev;
		}
		b = (char*)VA(kmap(newpage(0, 0, 0)));
		envalloc.npage++;
		envalloc.lim = b + BY2PG;
	}

	
	ev = (Envval*)b;
	ev->val = b + sizeof *ev;
	ev->ref = 1;


@@ 400,6 402,43 @@ evfree(Envval *ev)
	envalloc.free[n] = ev;
}

void
envdump(void)
{
	Envval *ev;
	int i, j;

	qlock(&evlock);
	print("pages allocated: %d\n", envalloc.npage);
	print("bytes left in page: %d\n", envalloc.lim - envalloc.block);
	for(i = 0; i < EVFREE + 1; i++){
		j = 0;
		if(i == EVFREE)
			print("big blocks:\n");
		else
			print("%d byte blocks:\n", (i + 1) * ALIGN);
		for(ev = envalloc.free[i]; ev; ev = ev->next){
			if(j++ == 1000){
				print("circular\n");
				break;
			}
			if(j < 10)
				print("\tenv %d %lux n%lux p%lux r%d\n",
					ev->len, ev, ev->next, ev->prev, ev->ref);
		}
	}
	for(i = 0; i < EVHASH; i++){
		j = 0;
		for(ev = evhash[i].next; ev; ev = ev->next){
			if(j++ == 1000){
				print("hash bucket %d circular\n", i);
				break;
			}
		}
	}
	qunlock(&evlock);
}

/*
 *  to let the kernel set environment variables
 */

M port/stil.c => port/stil.c +21 -15
@@ 19,7 19,9 @@ char *ilstate[] = { "Closed", "Syncer", "Syncee", "Established", "Listening", "C

void	ilrcvmsg(Ipconv*, Block*);
void	ilackproc(void*);
void	ilsendctl(Ipconv *, Ilhdr *, int);
void	ilsendctl(Ipconv*, Ilhdr*, int, int);
void	ilackq(Ilcb*, Block*);
void	ilprocess(Ipconv*, Ilhdr*, Block*);

void
ilopen(Queue *q, Stream *s)


@@ 127,7 129,7 @@ iloput(Queue *q, Block *bp)
}

void
ilackq(Ilctl *ic, Block *bp)
ilackq(Ilcb *ic, Block *bp)
{
	Block *np;



@@ 148,7 150,7 @@ ilackq(Ilctl *ic, Block *bp)
}

void
ilackto(Ilctl *ic, ulong ackto)
ilackto(Ilcb *ic, ulong ackto)
{
	Ilhdr *h;
	Block *bp;


@@ 157,7 159,7 @@ ilackto(Ilctl *ic, ulong ackto)
		lock(ic);
		if(ic->unacked) {
			h = (Ilhdr *)ic->unacked->rptr;
			if(ackto < hngetl(h->ilack)) {
			if(ackto < nhgetl(h->ilack)) {
				unlock(ic);
				break;	
			}


@@ 184,7 186,8 @@ ilrcvmsg(Ipconv *ipc, Block *bp)
{
	Ilhdr *ih;
	int plen;
	Ipconv *s;
	Ipconv *s, *etab;
	short sp, dp;

	ih = (Ilhdr *)bp;



@@ 197,43 200,46 @@ ilrcvmsg(Ipconv *ipc, Block *bp)
		goto drop;
	}

	sp = nhgets(ih->ildst);
	dp = nhgets(ih->ilsrc);
	etab = &ipc[conf.ip];
	for(s = ipc; s < etab; s++) {
		if(s->sport == ih->ildst && s->dport == ih->ilsrc) {
		if(s->psrc == sp && s->pdst == dp) {
			ilprocess(s, ih, bp);
			return;
		}
			
	}
	for(s = ipc; s < etab; s++) {
		if(s->state == 	Illistening && s->sport == 0) {
		if(s->ilctl.state == Illistening && s->psrc == 0) {
			/* Do the listener stuff */
			ilprocess(s, ih, bp);
			return;
		}
	}
	ilsendctl(0, ih, Ilreset);
	ilsendctl(0, ih, Ilreset, 0);
drop:
	freeb(bp);
}

void
ilprocess(Ipconv *s, Ihdr *h, Block *bp)
ilprocess(Ipconv *s, Ilhdr *h, Block *bp)
{
	switch(s->ilctl.state) {
	case Ilclosed:
	case Ilclosing:
	case Illistener:
	case Illistening:
		error(Ehungup);
	}

	switch(h->type) {
	switch(h->iltype) {
	case Ilsync:
		if(s->ilctl.state == Ilsync)
			s->ilctl.state = Ilestablished;
		freeb(bp);
		break;
	case Ilack:
		ilackto(&s->ilctl, hngetl(g->ilack));
		ilackto(&s->ilctl, nhgetl(h->ilack));
		freeb(bp);
		break;
	case Ilquerey:


@@ 242,12 248,12 @@ ilprocess(Ipconv *s, Ihdr *h, Block *bp)
		break;
	case Ildataquery:
	case Ildata:
		ilackto(&s->ilctl, hngetl(h->ilack));
		ilackto(&s->ilctl, nhgetl(h->ilack));
		bp->rptr += IL_EHSIZE+IL_HDRSIZE;
		PUTNEXT(s->readq, bp);
		break;
	case Ilreset:
		s->ilctl.state = Closed;
		s->ilctl.state = Ilclosed;
		freeb(bp);
	}
}


@@ 324,7 330,7 @@ ilstart(Ipconv *ipc, int type, int window)
		break;
	case IL_ACTIVE:
		ic->state = Ilsyncer;
		ilsendctl(ipc, 0, Ilsync);
		ilsendctl(ipc, 0, Ilsync, 1);
		break;
	}