plan 9 kernel history: overview | file list | diff list

1992/0619/port/stfcall.c (diff list | history)

port/stfcall.c on 1991/0521
1991/0521    
#include	"u.h" 
1992/0321    
#include	"../port/lib.h" 
1991/0521    
#include	"mem.h" 
#include	"dat.h" 
#include	"fns.h" 
1992/0111    
#include	"../port/error.h" 
1991/0521    
 
1992/0318    
enum 
{ 
	Twritehdr	= 15,	/* Min bytes for Twrite */ 
	Rreadhdr	= 8,	/* Min bytes for Rread */ 
	Twritecnt	= 13,	/* Offset in byte stream of write count */ 
	Rreadcnt	= 5,	/* Offset for Readcnt */ 
1991/0521    
}; 
 
static void fcalliput(Queue*, Block*); 
static void fcalloput(Queue*, Block*); 
static void fcallopen(Queue*, Stream*); 
static void fcallclose(Queue*); 
static void fcallreset(void); 
1992/0318    
Qinfo fcallinfo = { fcalliput, fcalloput, fcallopen, fcallclose, "fcall", fcallreset }; 
 
static uchar msglen[256] = 
1991/0521    
{ 
1992/0318    
	[Tnop]		3, 
	[Rnop]		3, 
	[Tsession]	3, 
	[Rsession]	3, 
	[Terror]	0, 
	[Rerror]	67, 
	[Tflush]	5, 
	[Rflush]	3, 
	[Tattach]	89, 
	[Rattach]	13, 
	[Tclone]	7, 
	[Rclone]	5, 
	[Twalk]		33, 
	[Rwalk]		13, 
	[Topen]		6, 
	[Ropen]		13, 
	[Tcreate]	38, 
	[Rcreate]	13, 
	[Tread]		15, 
	[Rread]		8, 
	[Twrite]	16, 
	[Rwrite]	7, 
	[Tclunk]	5, 
	[Rclunk]	5, 
	[Tremove]	5, 
	[Rremove]	5, 
	[Tstat]		5, 
	[Rstat]		121, 
	[Twstat]	121, 
	[Rwstat]	5, 
	[Tclwalk]	35, 
	[Rclwalk]	13, 
	[Tauth]		69, 
	[Rauth]		35, 
1991/0521    
}; 
 
static void 
fcallreset(void) 
1992/0318    
{ 
} 
1991/0521    
 
static void 
fcallopen(Queue *q, Stream *s) 
{ 
1992/0318    
	USED(q, s); 
1991/0521    
} 
 
static void 
fcallclose(Queue * q) 
{ 
1992/0318    
	USED(q); 
1991/0521    
} 
 
void 
fcalloput(Queue *q, Block *bp) 
{ 
	PUTNEXT(q, bp); 
} 
 
1992/0318    
void 
upstream(Queue *q, ulong len) 
{ 
	Block *bl, **tail, *bp; 
	ulong l; 
1991/0521    
 
1992/0318    
	tail = &bl; 
	while(len) { 
		l = BLEN(q->first); 
		if(l > len) 
			break; 
		bp = getq(q);			/* Consume all of block */ 
		*tail = bp; 
		tail = &bp->next; 
		len -= l; 
	} 
	if(len) {				/* Consume partial block */ 
		lock(q); 
		*tail = copyb(q->first, len); 
		q->first->rptr += len; 
		q->len -= len; 
		unlock(q); 
	} 
	for(bp = bl; bp->next; bp = bp->next) 
		; 
	bp->flags |= S_DELIM; 
	PUTNEXT(q, bl); 
} 
 
1991/0521    
static void 
fcalliput(Queue *q, Block *bp) 
{ 
1992/0318    
	ulong len, need, off; 
1991/0521    
 
1992/0318    
	if(bp->type != M_DATA) { 
1991/0521    
		PUTNEXT(q, bp); 
		return; 
	} 
1992/0318    
	if(BLEN(bp) == 0) { 
1991/0521    
		freeb(bp); 
		return; 
	} 
 
1992/0318    
	/* Stash the data */ 
	bp->flags &= ~S_DELIM; 
	putq(q, bp); 
1991/0521    
 
1992/0320    
	for(;;) { 
		bp = q->first; 
		if(bp == 0) 
			return; 
		switch(bp->rptr[0]) {		/* This is the type */ 
		default: 
			len = msglen[bp->rptr[0]]; 
			if(len == 0) 
				error(Emountrpc); 
			if(q->len < len) 
				return; 
	 
1992/0318    
			upstream(q, len); 
1992/0320    
			continue; 
1991/0521    
 
1992/0320    
		case Twrite:			/* Fmt: TGGFFOOOOOOOOCC */ 
			len = Twritehdr;	/* T = type, G = tag, F = fid */ 
			off = Twritecnt;	/* O = offset, C = count */ 
			break; 
1991/0521    
 
1992/0320    
		case Rread:			/* Fmt: TGGFFCC */ 
			len = Rreadhdr; 
			off = Rreadcnt; 
			break; 
		} 
	 
		if(q->len < len) 
			return; 
	 
		pullup(q->first, len); 
		bp = q->first; 
		need = len+bp->rptr[off]+(bp->rptr[off+1]<<8); 
		if(q->len < need) 
			return; 
	 
		upstream(q, need); 
	} 
1991/0521    
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)