~kris/9p

9hist

6c0be7940e814ea5fe5044474ec683d5cb069fa3 — David du Colombier 31 years ago c3b0e30
Plan 9 from Bell Labs 1994-11-24
6 files changed, 99 insertions(+), 30 deletions(-)

M pc/ether509.c
M port/devcons.c
M port/devmnt.c
M port/portdat.h
M port/portfns.h
M port/qio.c
M pc/ether509.c => pc/ether509.c +4 -4
@@ 56,11 56,11 @@ enum {
	Rst		= 0x04,		/* Reset Adapter */
	Ena		= 0x01,		/* Enable Adapter */

	TxFreeBytes	= 0x0C,		/* window 1 */
	TxStatus	= 0x0B,
	Timer		= 0x0A,
	Fifo		= 0x00,		/* window 1 */
	RxStatus	= 0x08,
	Fifo		= 0x00,
	Timer		= 0x0A,
	TxStatus	= 0x0B,
	TxFreeBytes	= 0x0C,

					/* Status/Interrupt Bits */
	Latch		= 0x0001,	/* Interrupt Latch */

M port/devcons.c => port/devcons.c +8 -16
@@ 48,7 48,7 @@ printinit(void)
static void
putstrn0(char *str, int n, int usewrite)
{
	int m, x;
	int m;
	char *t;
	char buf[PRINTSIZE+2];



@@ 76,21 76,15 @@ putstrn0(char *str, int n, int usewrite)
			buf[m+1] = '\n';
			if(usewrite)
				qwrite(printq, buf, m+2);
			else {
				x = splhi();
				qproduce(printq, buf, m+2);
				splx(x);
			}
			else
				qiwrite(printq, buf, m+2);
			str = t + 1;
			n -= m + 1;
		} else {
			if(usewrite)
				qwrite(printq, str, n);
			else {
				x = splhi();
				qproduce(printq, str, n);
				splx(x);
			}
			else 
				qiwrite(printq, str, n);
			break;
		}
	}


@@ 247,14 241,14 @@ echo(Rune r, char *buf, int n)
	 */
	if(r == '\n'){
		if(printq)
			qproduce(printq, "\r", 1);
			qiwrite(printq, "\r", 1);
	} else if(r == 0x15){
		buf = "^U\n";
		n = 3;
	}
	screenputs(buf, n);
	if(printq)
		qproduce(printq, buf, n);
		qiwrite(printq, buf, n);
}

/*


@@ 518,9 512,7 @@ consread(Chan *c, void *buf, long n, ulong offset)
			qread(kbdq, &kbd.line[kbd.x], 1);
			ch = kbd.line[kbd.x];
			if(kbd.raw){
				i = splhi();
				qproduce(lineq, &kbd.line[kbd.x], 1);
				splx(i);
				qiwrite(lineq, &kbd.line[kbd.x], 1);
				continue;
			}
			eol = 0;

M port/devmnt.c => port/devmnt.c +1 -1
@@ 27,7 27,7 @@ struct Mntalloc
	Mnt	*list;		/* Mount devices in use */
	Mnt	*mntfree;	/* Free list */
	Mntrpc	*rpcfree;
	int	id;
	ulong	id;
	int	rpctag;
}mntalloc;


M port/portdat.h => port/portdat.h +1 -1
@@ 143,7 143,7 @@ struct Chan
	Chan*	link;
	ulong	offset;			/* in file */
	ushort	type;
	ushort	dev;
	ulong	dev;
	ushort	mode;			/* read/write */
	ushort	flag;
	Qid	qid;

M port/portfns.h => port/portfns.h +1 -0
@@ 204,6 204,7 @@ long		qread(Queue*, void*, int);
void		qreopen(Queue*);
void		qunlock(QLock*);
int		qwindow(Queue*);
long		qiwrite(Queue*, void*, int);
long		qwrite(Queue*, void*, int);
void		qsetlimit(Queue*, int);
void		qnoblock(Queue*, int);

M port/qio.c => port/qio.c +84 -8
@@ 170,15 170,22 @@ qconsume(Queue *q, void *vp, int len)
	/* sync with qwrite */
	lock(q);

	b = q->bfirst;
	if(b == 0){
		q->state |= Qstarve;
		unlock(q);
		return -1;
	}
	QDEBUG checkb(b, "qconsume 1");
	for(;;) {
		b = q->bfirst;
		if(b == 0){
			q->state |= Qstarve;
			unlock(q);
			return -1;
		}
		QDEBUG checkb(b, "qconsume 1");

		n = BLEN(b);
		if(n > 0)
			break;
		q->bfirst = b->next;
		freeb(b);
	};

	n = BLEN(b);
	if(n < len)
		len = n;
	memmove(p, b->rp, len);


@@ 606,6 613,69 @@ qwrite(Queue *q, void *vp, int len)
}

/*
 *  used by print() to write to a queue
 */
int
qiwrite(Queue *q, void *vp, int len)
{
	int n, sofar, dowakeup;
	Block *b;
	uchar *p = vp;

	dowakeup = 0;

	sofar = 0;
	do {
		n = len-sofar;
		if(n > 128*1024)
			n = 128*1024;

		b = allocb(n);
		memmove(b->wp, p+sofar, n);
		b->wp += n;

		ilock(q);

		QDEBUG checkb(b, "qiwrite");
		if(q->syncbuf){
			/* we guessed wrong and did an extra copy */
			if(n > q->synclen)
				n = q->synclen;
			memmove(q->syncbuf, b->rp, n);
			q->synclen = n;
			q->syncbuf = 0;
			dowakeup = 1;
			freeb(b);
		} else {
			/* we guessed right, queue it */
			if(q->bfirst)
				q->blast->next = b;
			else
				q->bfirst = b;
			q->blast = b;
			q->len += n;

			if(q->state & Qstarve){
				q->state &= ~Qstarve;
				dowakeup = 1;
			}
		}

		iunlock(q);

		if(dowakeup){
			if(q->kick)
				(*q->kick)(q->arg);
			wakeup(&q->rr);
		}

		sofar += n;
	} while(sofar < len && (q->state & Qmsg) == 0);

	return len;
}

/*
 *  Mark a queue as closed.  No further IO is permitted.
 *  All blocks are released.
 */


@@ 739,3 809,9 @@ qflush(Queue *q)
	/* wake up readers/writers */
	wakeup(&q->wr);
}

int
qstate(Queue *q)
{
	return q->state;
}