Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/port/stfcall.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname port/stfcall.c 1991/0521
## diff -e /dev/null /n/bootesdump/1991/0521/sys/src/9/port/stfcall.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"errno.h"

#include	"fcall.h"

#define DPRINT 	if(fcalldebug)kprint

int fcalldebug = 0;

typedef struct Fcalld	Fcalld;

struct Fcalld{
	int	dev;		/* ref. for debug output */
	int	state;
	int	type;		/* of current message */
	int	need;		/* bytes remaining in current message */
	int	nhdr;		/* bytes of header treasured up in hdr */
	uchar	hdr[16];
};

enum {
	Startup, Startup1, Begin, Header, Data
};

/*
 *  fcall stream module definition
 */
static void fcalliput(Queue*, Block*);
static void fcalloput(Queue*, Block*);
static void fcallopen(Queue*, Stream*);
static void fcallclose(Queue*);
static void fcallreset(void);
Qinfo fcallinfo =
{
	fcalliput,
	fcalloput,
	fcallopen,
	fcallclose,
	"fcall",
	fcallreset
};

static Block *	putmsg(Queue*, Block*, int);

static uchar msglen[] = {
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  3,  3,  3,  3,  0, 67,  5,  3, 89, 13,  7,  5, 33, 13,
	  6, 13, 38, 13, 15,  8, 16,  7,  5,  5,  5,  5,  5,121,121,  5,
	 35, 13,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
};
static void
fcallreset(void)
{}

static void
fcallopen(Queue *q, Stream *s)
{
	Fcalld *f;

	DPRINT("fcallopen %d\n", s->dev);

	q->ptr = allocb(sizeof(Fcalld));
	f = (Fcalld *)((Block *)q->ptr)->base;
	f->dev = s->dev;
	f->state = Startup;
	f->type = 0;
	f->need = 0;
	f->nhdr = 0;
}

static void
fcallclose(Queue * q)
{
	Fcalld *f = (Fcalld *)((Block *)q->ptr)->base;

	DPRINT("fcallstclose %d\n", f->dev);
	freeb(q->ptr);
	q->ptr = 0;
}

void
fcalloput(Queue *q, Block *bp)
{
	PUTNEXT(q, bp);
}


static void
fcalliput(Queue *q, Block *bp)
{
	Fcalld *f = (Fcalld *)((Block *)q->ptr)->base;
	int len, n;

	len = BLEN(bp);
	DPRINT("fcalliput %d: blen=%d\n", f->dev, len);
	if(bp->type != M_DATA){
		DPRINT("fcalliput %d: type=%d\n", f->dev, bp->type);
		PUTNEXT(q, bp);
		return;
	}
	bp->flags &= ~S_DELIM;
	if(len == 0){
		freeb(bp);
		return;
	}
	while(len > 0)switch(f->state){
	case Startup:
		if (len == 1 && bp->rptr[0] == 'O'){
			DPRINT("fcalliput %d: O\n", f->dev);
			PUTNEXT(q, bp);
			f->state = Startup1;
			return;
		}
		if(bp->rptr[0] == 'O' && bp->rptr[1] == 'K'){
			DPRINT("fcalliput %d: OK\n", f->dev);
			bp = putmsg(q, bp, 2);
			len -= 2;
		}
		f->state = Begin;
		break;

	case Startup1:
		if(bp->rptr[0] == 'K'){
			DPRINT("fcalliput %d: K\n", f->dev);
			bp = putmsg(q, bp, 1);
			len -= 1;
			f->state = Begin;
			break;
		}
		f->type = 'O';
		f->need = msglen['O']-1;
		f->state = Data;
		DPRINT("fcalliput %d: type=%d, need=%d\n",
			f->dev, f->type, f->need);
		break;

	case Begin:
		f->type = bp->rptr[0];
		f->need = msglen[f->type];
		f->nhdr = 0;
		if(f->type == Twrite || f->type == Rread)
			f->state = Header;
		else
			f->state = Data;
		DPRINT("fcalliput %d: type=%d, need=%d\n",
			f->dev, f->type, f->need);
		break;

	case Header:
		n = f->need;
		if(n > len)
			n = len;
		memmove(&f->hdr[f->nhdr], bp->rptr, n);
		f->nhdr += n;
		DPRINT("fcalliput %d: nhdr=%d\n",
			f->dev, f->nhdr);
		if(n == f->need){
			f->need += f->hdr[f->nhdr-3];
			f->need += f->hdr[f->nhdr-2] << 8;
			f->state = Data;
			DPRINT("fcalliput %d: need=%d\n",
				f->dev, f->need);
		}
		/* fall through */

	case Data:
		if(f->need > len){
			f->need -= len;
			PUTNEXT(q, bp);
			return;
		}
		bp = putmsg(q, bp, f->need);
		len -= f->need;
		f->state = Begin;
		break;
	}
}

static Block *
putmsg(Queue *q, Block *bp, int n)
{
	Block *xbp;
	int k;

	DPRINT("putmsg: n=%d\n\n", n);
	k = BLEN(bp) - n;
	if(k == 0){
		bp->flags |= S_DELIM;
		PUTNEXT(q, bp);
		return 0;
	}
	if(n <= k){
		xbp = allocb(n);
		memmove(xbp->wptr, bp->rptr, n);
		xbp->wptr += n;
		bp->rptr += n;
		xbp->flags |= S_DELIM;
		PUTNEXT(q, xbp);
		return bp;
	}
	xbp = allocb(k);
	memmove(xbp->wptr, bp->rptr+n, k);
	xbp->wptr += k;
	bp->wptr -= k;
	bp->flags |= S_DELIM;
	PUTNEXT(q, bp);
	return xbp;
}
.
## diffname port/stfcall.c 1991/0522
## diff -e /n/bootesdump/1991/0521/sys/src/9/port/stfcall.c /n/bootesdump/1991/0522/sys/src/9/port/stfcall.c
10c
#define DPRINT 	if(fcalldebug)print
.
## diffname port/stfcall.c 1991/1003
## diff -e /n/bootesdump/1991/0522/sys/src/9/port/stfcall.c /n/bootesdump/1991/1003/sys/src/9/port/stfcall.c
55c
	 35, 13, 69, 35,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
.
10c
#define DPRINT 	if(fcalldebug)kprint
.
## diffname port/stfcall.c 1992/0111
## diff -e /n/bootesdump/1991/1003/sys/src/9/port/stfcall.c /n/bootesdump/1992/0111/sys/src/9/port/stfcall.c
6c
#include	"../port/error.h"
.
## diffname port/stfcall.c 1992/0318
## diff -e /n/bootesdump/1992/0111/sys/src/9/port/stfcall.c /n/bootesdump/1992/0318/sys/src/9/port/stfcall.c
201,223c
	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);
.
195,199c
	if(q->len < len)
		return;
.
193d
191a
	case Rread:			/* Fmt: TGGFFCC */
		len = Rreadhdr;
		off = Rreadcnt;
		break;
.
165,190c
		return;
	case Twrite:			/* Fmt: TGGFFOOOOOOOOCC */
		len = Twritehdr;	/* T = type, G = tag, F = fid */
		off = Twritecnt;	/* O = offset, C = count */
.
153,163c
	bp = q->first;
	switch(bp->rptr[0]) {		/* This is the type */
	default:
		len = msglen[bp->rptr[0]];
		if(len == 0)
			error(Emountrpc);
		if(q->len >= len)
			upstream(q, len);
.
138,151c
	/* Stash the data */
	bp->flags &= ~S_DELIM;
	putq(q, bp);
.
122,136d
117,118c
	if(BLEN(bp) == 0) {
.
110,113c
	if(bp->type != M_DATA) {
.
107,108c
	ulong len, need, off;
.
103a
	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);
}

.
102a
void
upstream(Queue *q, ulong len)
{
	Block *bl, **tail, *bp;
	ulong l;
.
90,94c
	USED(q);
.
74,84c
	USED(q, s);
.
69c
{
}
.
47,66d
39,44c
	[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,
.
37c
Qinfo fcallinfo = { fcalliput, fcalloput, fcallopen, fcallclose, "fcall", fcallreset };

static uchar msglen[256] =
.
25,31d
10,22c
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 */
.
## diffname port/stfcall.c 1992/0319
## diff -e /n/bootesdump/1992/0318/sys/src/9/port/stfcall.c /n/bootesdump/1992/0319/sys/src/9/port/stfcall.c
111a
if(bl->rptr[0] == 73) print("fcall Rclunk %d\n", blen(bl));
.
## diffname port/stfcall.c 1992/0320
## diff -e /n/bootesdump/1992/0319/sys/src/9/port/stfcall.c /n/bootesdump/1992/0320/sys/src/9/port/stfcall.c
154,163c
		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);
	}
.
143,152c
		case Twrite:			/* Fmt: TGGFFOOOOOOOOCC */
			len = Twritehdr;	/* T = type, G = tag, F = fid */
			off = Twritecnt;	/* O = offset, C = count */
			break;
.
141a
			continue;
.
134,140c
	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;
	
.
112d
## diffname port/stfcall.c 1992/0321
## diff -e /n/bootesdump/1992/0320/sys/src/9/port/stfcall.c /n/bootesdump/1992/0321/sys/src/9/port/stfcall.c
2c
#include	"../port/lib.h"
.
## diffname port/stfcall.c 1992/0619
## diff -e /n/bootesdump/1992/0321/sys/src/9/port/stfcall.c /n/bootesdump/1992/0619/sys/src/9/port/stfcall.c
8,9d
## diffname port/stfcall.c 1992/0910
## diff -e /n/bootesdump/1992/0619/sys/src/9/port/stfcall.c /n/bootesdump/1992/0910/sys/src/9/port/stfcall.c
138,139c
			if(len == 0){
				bp = allocb(0);
				bp->type = M_HANGUP;
				PUTNEXT(q, bp);
				return;
			}
.
10c
	Twritehdr	= 16,	/* Min bytes for Twrite */
.
## diffname port/stfcall.c 1993/0330
## diff -e /n/bootesdump/1992/0910/sys/src/9/port/stfcall.c /n/bootesdump/1993/0330/sys/src/9/port/stfcall.c
57,58d
33,34c
	[Tattach]	5+2*NAMELEN+TICKETLEN+AUTHENTLEN,
	[Rattach]	13+AUTHENTLEN,
.
27,28c
	[Tsession]	3+CHALLEN,
	[Rsession]	3+NAMELEN+DOMLEN+CHALLEN,
.
## diffname port/stfcall.c 1993/0410
## diff -e /n/bootesdump/1993/0330/sys/src/9/port/stfcall.c /n/bootesdump/1993/0410/sys/src/9/port/stfcall.c
161,163c

		/*
		 *  the lock here is wrong.  it should be a qlock since
		 *  the pullup may block.  not worth fixing.
		 */
		lock(q);
		bp = q->first = pullup(q->first, len);
		if(bp == 0)
			q->len = 0;
		unlock(q);
.
## diffname port/stfcall.c 1993/0501
## diff -e /n/bootesdump/1993/0410/sys/src/9/port/stfcall.c /n/fornaxdump/1993/0501/sys/src/brazil/port/stfcall.c
161,170c
	
		pullup(q->first, len);
		bp = q->first;
.
56a
	[Tauth]		69,
	[Rauth]		35,
.
33,34c
	[Tattach]	89,
	[Rattach]	13,
.
27,28c
	[Tsession]	3,
	[Rsession]	3,
.
## diffname port/stfcall.c 1993/0804 # deleted
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/port/stfcall.c /n/fornaxdump/1993/0804/sys/src/brazil/port/stfcall.c
1,172d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.