~kris/9p

9hist

dfb098dfba44decd80493446437b0a7a9b813b26 — David du Colombier 33 years ago 54a4079
Plan 9 from Bell Labs 1993-04-03
6 files changed, 57 insertions(+), 438 deletions(-)

M boot/local.c
M port/auth.c
M port/devmnt.c
D port/fcall.c
M power/fptrap.c
M power/l.s
M boot/local.c => boot/local.c +15 -1
@@ 3,6 3,7 @@
#include <../boot/boot.h>

static char *disk;
static char *niob;

void
configlocal(Method *mp)


@@ 11,6 12,8 @@ configlocal(Method *mp)
		disk = sys;
	else
		disk = mp->arg;
	if(niob = strchr(disk, ' '))	/* assign = */
		*niob++ = 0;
	USED(mp);
}



@@ 27,6 30,7 @@ connectlocal(void)
	char d[DIRLEN];
	char partition[2*NAMELEN];
	char *dev;
	char *args[16], **argp;

	if(stat("/fs", d) < 0)
		return -1;


@@ 54,7 58,17 @@ connectlocal(void)
		dup(p[1], 1);
		close(p[0]);
		close(p[1]);
		execl("/fs", "fs", "-f", partition, "-s", 0);
		argp = args;
		*argp++ = "fs";
		if(niob){
			*argp++ = "-B";
			*argp++ = niob;
		}
		*argp++ = "-f";
		*argp++ = partition;
		*argp++ = "-s";
		*argp = 0;
		exec("/fs", args);
		fatal("can't exec fs");
	default:
		break;

M port/auth.c => port/auth.c +12 -5
@@ 130,6 130,7 @@ sysfsession(ulong *arg)
		memset(s, 0, sizeof(Session));
		for(i = 0; i < CHALLEN; i++)
			s->cchal[i] = nrand(256);
		f->tag = NOTAG;
		f->type = Tsession;
		memmove(f->chal, s->cchal, CHALLEN);
		n = convS2M(f, buf);


@@ 237,10 238,12 @@ sysfauth(ulong *arg)
void
freesession(Session *s)
{
	Crypt *cp;
	Crypt *cp, *next;

	for(cp = s->cache; cp; cp = cp->next)
	for(cp = s->cache; cp; cp = next) {
		next = cp->next;
		freecrypt(cp);
	}
	free(s);
}



@@ 262,9 265,14 @@ authrequest(Session *s, Fcall *f)

	/* look for ticket in cache */
	dofree = 0;
	lock(s);
	for(cp = s->cache; cp; cp = cp->next)
		if(strcmp(cp->t.cuid, u->p->user) == 0)
			break;

	id = s->cid++;
	unlock(s);

	if(cp == 0){
		/*
		 *  create a ticket using hostkey, this solves the


@@ 280,9 288,6 @@ authrequest(Session *s, Fcall *f)
		dofree = 1;
	} else
		memmove(f->ticket, cp->tbuf, TICKETLEN);
	lock(s);
	id = s->cid++;
	unlock(s);

	/* create an authenticator */
	memmove(cp->a.chal, s->schal, CHALLEN);


@@ 305,9 310,11 @@ authreply(Session *s, ulong id, Fcall *f)
	if(s == 0)
		return;

	lock(s);
	for(cp = s->cache; cp; cp = cp->next)
		if(strcmp(cp->t.cuid, u->p->user) == 0)
			break;
	unlock(s);

	/* we're getting around authentication */
	if(s == 0 || cp == 0 || s->authid[0] == 0 || strcmp(u->p->user, "none") == 0)

M port/devmnt.c => port/devmnt.c +4 -2
@@ 193,14 193,16 @@ mattach(Mnt *m, char *spec)

	if(waserror()){
		mntfree(r);
		/* Close must not be called since it will call mnt recursively */
		/* Close must not be called since
		 * it will call mnt recursively
		 */
		chanfree(c);
		nexterror();
	}

	r->request.type = Tattach;
	r->request.fid = c->fid;
	memmove(r->request.uname, u->p->user, NAMELEN);
	memmove(r->request.uname, up->user, NAMELEN);
	strncpy(r->request.aname, spec, NAMELEN);
	id = authrequest(m->c->session, &r->request);
	mountrpc(m, r);

D port/fcall.c => port/fcall.c +0 -418
@@ 1,418 0,0 @@
#include	<u.h>
#include	<libc.h>
#include	"fcall.h"

#define	CHAR(x)		*p++ = f->x
#define	SHORT(x)	p[0] = f->x; p[1] = f->x>>8; p += 2
#define	LONG(x)		p[0] = f->x; p[1] = f->x>>8; p[2] = f->x>>16; p[3] = f->x>>24; p += 4
#define	VLONG(x)	p[0] = f->x; p[1] = f->x>>8; p[2] = f->x>>16; p[3] = f->x>>24;\
				p[4] = 0; p[5] = 0; p[6] = 0; p[7] = 0; p += 8
#define	STRING(x,n)	memmove(p, f->x, n); p += n

int
convS2M(Fcall *f, char *ap)
{
	uchar *p;

	p = (uchar*)ap;
	CHAR(type);
	SHORT(tag);
	switch(f->type)
	{
	default:
		print("convS2M: bad type: %d\n", f->type);
		return 0;

	case Tnop:
		break;

	case Tsession:
		break;

	case Tflush:
		SHORT(oldtag);
		break;

	case Tattach:
		SHORT(fid);
		STRING(uname, sizeof(f->uname));
		STRING(aname, sizeof(f->aname));
		STRING(auth, sizeof(f->auth));
		break;

	case Tauth:
		SHORT(fid);
		STRING(uname, sizeof(f->uname));
		STRING(chal, 8+NAMELEN);
		break;

	case Tclone:
		SHORT(fid);
		SHORT(newfid);
		break;

	case Twalk:
		SHORT(fid);
		STRING(name, sizeof(f->name));
		break;

	case Topen:
		SHORT(fid);
		CHAR(mode);
		break;

	case Tcreate:
		SHORT(fid);
		STRING(name, sizeof(f->name));
		LONG(perm);
		CHAR(mode);
		break;

	case Tread:
		SHORT(fid);
		VLONG(offset);
		SHORT(count);
		break;

	case Twrite:
		SHORT(fid);
		VLONG(offset);
		SHORT(count);
		p++;	/* pad(1) */
		STRING(data, f->count);
		break;

	case Tclunk:
		SHORT(fid);
		break;

	case Tremove:
		SHORT(fid);
		break;

	case Tstat:
		SHORT(fid);
		break;

	case Twstat:
		SHORT(fid);
		STRING(stat, sizeof(f->stat));
		break;

	case Tclwalk:
		SHORT(fid);
		SHORT(newfid);
		STRING(name, sizeof(f->name));
		break;
/*
 */
	case Rnop:
		break;

	case Rsession:
		break;

	case Rerror:
		STRING(ename, sizeof(f->ename));
		break;

	case Rflush:
		break;

	case Rattach:
		SHORT(fid);
		LONG(qid.path);
		LONG(qid.vers);
		break;

	case Rauth:
		SHORT(fid);
		STRING(chal, 8+8+7+7);
		break;

	case Rclone:
		SHORT(fid);
		break;

	case Rclwalk:
	case Rwalk:
		SHORT(fid);
		LONG(qid.path);
		LONG(qid.vers);
		break;

	case Ropen:
		SHORT(fid);
		LONG(qid.path);
		LONG(qid.vers);
		break;

	case Rcreate:
		SHORT(fid);
		LONG(qid.path);
		LONG(qid.vers);
		break;

	case Rread:
		SHORT(fid);
		SHORT(count);
		p++;	/* pad(1) */
		STRING(data, f->count);
		break;

	case Rwrite:
		SHORT(fid);
		SHORT(count);
		break;

	case Rclunk:
		SHORT(fid);
		break;

	case Rremove:
		SHORT(fid);
		break;

	case Rstat:
		SHORT(fid);
		STRING(stat, sizeof(f->stat));
		break;

	case Rwstat:
		SHORT(fid);
		break;
	}
	return p - (uchar*)ap;
}

int
convD2M(Dir *f, char *ap)
{
	uchar *p;

	p = (uchar*)ap;
	STRING(name, sizeof(f->name));
	STRING(uid, sizeof(f->uid));
	STRING(gid, sizeof(f->gid));
	LONG(qid.path);
	LONG(qid.vers);
	LONG(mode);
	LONG(atime);
	LONG(mtime);
	VLONG(length);
	SHORT(type);
	SHORT(dev);
	return p - (uchar*)ap;
}

#undef	CHAR
#undef	SHORT
#undef	LONG
#undef	VLONG
#undef	STRING

#define	CHAR(x)		f->x = *p++
#define	SHORT(x)	f->x = (p[0] | (p[1]<<8)); p += 2
#define	LONG(x)		f->x = (p[0] | (p[1]<<8) |\
				(p[2]<<16) | (p[3]<<24)); p += 4
#define	VLONG(x)	f->x = (p[0] | (p[1]<<8) |\
				(p[2]<<16) | (p[3]<<24)); p += 8
#define	STRING(x,n)	memmove(f->x, p, n); p += n

int
convM2S(char *ap, Fcall *f, int n)
{
	uchar *p;

	p = (uchar*)ap;
	CHAR(type);
	SHORT(tag);
	switch(f->type)
	{
	default:
		print("convM2S: bad type: %d\n", f->type);
		return 0;

	case Tnop:
		break;

	case Tsession:
		break;

	case Tflush:
		SHORT(oldtag);
		break;

	case Tattach:
		SHORT(fid);
		STRING(uname, sizeof(f->uname));
		STRING(aname, sizeof(f->aname));
		STRING(auth, sizeof(f->auth));
		break;

	case Tauth:
		SHORT(fid);
		STRING(uname, sizeof(f->uname));
		STRING(chal, 8+NAMELEN);
		break;

	case Tclone:
		SHORT(fid);
		SHORT(newfid);
		break;

	case Twalk:
		SHORT(fid);
		STRING(name, sizeof(f->name));
		break;

	case Topen:
		SHORT(fid);
		CHAR(mode);
		break;

	case Tcreate:
		SHORT(fid);
		STRING(name, sizeof(f->name));
		LONG(perm);
		CHAR(mode);
		break;

	case Tread:
		SHORT(fid);
		VLONG(offset);
		SHORT(count);
		break;

	case Twrite:
		SHORT(fid);
		VLONG(offset);
		SHORT(count);
		p++;	/* pad(1) */
		f->data = (char*)p; p += f->count;
		break;

	case Tclunk:
		SHORT(fid);
		break;

	case Tremove:
		SHORT(fid);
		break;

	case Tstat:
		SHORT(fid);
		break;

	case Twstat:
		SHORT(fid);
		STRING(stat, sizeof(f->stat));
		break;

	case Tclwalk:
		SHORT(fid);
		SHORT(newfid);
		STRING(name, sizeof(f->name));
		break;
/*
 */
	case Rnop:
		break;

	case Rsession:
		break;

	case Rerror:
		STRING(ename, sizeof(f->ename));
		break;

	case Rflush:
		break;

	case Rattach:
		SHORT(fid);
		LONG(qid.path);
		LONG(qid.vers);
		break;

	case Rauth:
		SHORT(fid);
		STRING(chal, 8+8+7+7);
		break;

	case Rclone:
		SHORT(fid);
		break;

	case Rwalk:
	case Rclwalk:
		SHORT(fid);
		LONG(qid.path);
		LONG(qid.vers);
		break;

	case Ropen:
		SHORT(fid);
		LONG(qid.path);
		LONG(qid.vers);
		break;

	case Rcreate:
		SHORT(fid);
		LONG(qid.path);
		LONG(qid.vers);
		break;

	case Rread:
		SHORT(fid);
		SHORT(count);
		p++;	/* pad(1) */
		f->data = (char*)p; p += f->count;
		break;

	case Rwrite:
		SHORT(fid);
		SHORT(count);
		break;

	case Rclunk:
		SHORT(fid);
		break;

	case Rremove:
		SHORT(fid);
		break;

	case Rstat:
		SHORT(fid);
		STRING(stat, sizeof(f->stat));
		break;

	case Rwstat:
		SHORT(fid);
		break;
	}
	if((uchar*)ap+n == p)
		return n;
	return 0;
}

int
convM2D(char *ap, Dir *f)
{
	uchar *p;

	p = (uchar*)ap;
	STRING(name, sizeof(f->name));
	STRING(uid, sizeof(f->uid));
	STRING(gid, sizeof(f->gid));
	LONG(qid.path);
	LONG(qid.vers);
	LONG(mode);
	LONG(atime);
	LONG(mtime);
	VLONG(length);
	SHORT(type);
	SHORT(dev);
	return p - (uchar*)ap;
}

M power/fptrap.c => power/fptrap.c +15 -11
@@ 22,28 22,33 @@ enum	/* op */
};

static int	fpunimp(ulong);
static ulong	branch(Ureg*, ulong);
static ulong	branch(Ureg*, ulong, ulong);

void
fptrap(Ureg *ur)
{
	ulong iw, npc;
	ulong iw, iw_4, npc;

	if((u->fpsave.fpstatus&(1<<17)) == 0)
		return;

print("fpt: %d %s %lux\n", u->p->pid, u->p->text, u->fpsave.fpstatus);
print("fpt: %d %s %lux %lux\n", u->p->pid, u->p->text, u->fpsave.fpstatus, ur->pc);

	if(ur->cause & (1<<31))
	if(tlbp(ur->pc) == 0)
		panic("not in tlb %lux\n", ur->pc);
	iw = *(ulong*)ur->pc;
	iw_4 = iw;
	if(ur->cause & (1<<31)){
		if(tlbp(ur->pc+4) == 0)
			panic("not in tlb %lux\n", ur->pc+4);
		iw = *(ulong*)(ur->pc+4);
	else
		iw = *(ulong*)ur->pc;
	}

	if(fpunimp(iw) == 0)
		return;

	if(ur->cause & (1<<31)){
		npc = branch(ur, u->fpsave.fpstatus);
		npc = branch(ur, iw_4, u->fpsave.fpstatus);
		if(npc == 0)
			return;
		ur->pc = npc;


@@ 51,7 56,7 @@ print("fpt: %d %s %lux\n", u->p->pid, u->p->text, u->fpsave.fpstatus);
	else
		ur->pc += 4;

	u->fpsave.fpstatus = u->fpsave.fpstatus & ~(1<<17);
	u->fpsave.fpstatus &= ~(1<<17);
}

static void


@@ 188,11 193,10 @@ reg(Ureg *ur, int regno)
}

static ulong
branch(Ureg *ur, ulong fcr31)
branch(Ureg *ur, ulong iw, ulong fcr31)
{
	ulong iw, npc, rs, rt, rd, offset;
	ulong npc, rs, rt, rd, offset;

	iw = *(ulong*)ur->pc;
	rs = (iw>>21) & 0x1F;
	if(rs)
		rs = *reg(ur, rs);

M power/l.s => power/l.s +11 -1
@@ 229,9 229,19 @@ TEXT	puttlbx(SB), $0
	RET

TEXT	tlbp(SB), $0
	MOVW	M(TLBVIRT), R2
	AND	$(~(BY2PG-1)), R1, R4	/* get the VPN */
	AND	$((NTLBPID-1)<<6), R2	/* get the pid */
	OR	R4, R2
	MOVW	R2, M(TLBVIRT)
	NOOP
	TLBP
	NOOP
	MOVW	M(INDEX), R1
	MOVW	M(INDEX), R2
	MOVW	R0, R1
	BLTZ	R2, bad
	MOVW	$1, R1
bad:
	RET
	
TEXT	tlbvirt(SB), $0