Browse Source

Goodbye NFS at all

Fixed sam/build.json
Fixed samterm/build.json
Fixed acme/build.json
Fixed games/build.json
Fixed bzip2/lib/libbzip2.json

Tested, restoring general build to ok state.

Change-Id: I1ec3a3fa32ca4198978b51a6e195b3af5222e5e0
Elbing Miss 8 years ago
parent
commit
a2d77d8b1e
57 changed files with 173 additions and 9078 deletions
  1. 0 97
      sys/src/cmd/9nfs/9auth.c
  2. 0 30
      sys/src/cmd/9nfs/9nfs.json
  3. 0 193
      sys/src/cmd/9nfs/9p.c
  4. 0 25
      sys/src/cmd/9nfs/all.h
  5. 0 40
      sys/src/cmd/9nfs/auth.c
  6. 0 186
      sys/src/cmd/9nfs/authhostowner.c
  7. 0 140
      sys/src/cmd/9nfs/chat.c
  8. 0 282
      sys/src/cmd/9nfs/dat.h
  9. 0 75
      sys/src/cmd/9nfs/fns.h
  10. 0 28
      sys/src/cmd/9nfs/listalloc.c
  11. 0 194
      sys/src/cmd/9nfs/mport.c
  12. 0 108
      sys/src/cmd/9nfs/nametest.c
  13. 0 481
      sys/src/cmd/9nfs/nfs.c
  14. 0 53
      sys/src/cmd/9nfs/nfs.h
  15. 0 343
      sys/src/cmd/9nfs/nfsmount.c
  16. 0 665
      sys/src/cmd/9nfs/nfsserver.c
  17. 0 189
      sys/src/cmd/9nfs/pcnfsd.c
  18. 0 20
      sys/src/cmd/9nfs/pcnfsd.json
  19. 0 181
      sys/src/cmd/9nfs/portmapper.c
  20. 0 16
      sys/src/cmd/9nfs/portmapper.json
  21. 0 323
      sys/src/cmd/9nfs/rpc.c
  22. 0 95
      sys/src/cmd/9nfs/rpc.h
  23. 0 604
      sys/src/cmd/9nfs/server.c
  24. 0 114
      sys/src/cmd/9nfs/string.c
  25. 0 41
      sys/src/cmd/9nfs/strparse.c
  26. 0 43
      sys/src/cmd/9nfs/system.c
  27. 0 8
      sys/src/cmd/9nfs/testit
  28. 0 331
      sys/src/cmd/9nfs/unixnames.c
  29. 0 115
      sys/src/cmd/9nfs/xfile.c
  30. 22 85
      sys/src/cmd/acme/build.json
  31. 0 2
      sys/src/cmd/aux/aux.json
  32. 0 343
      sys/src/cmd/aux/nfsmount.c
  33. 0 213
      sys/src/cmd/aux/portmap.c
  34. 1 1
      sys/src/cmd/bzip2/bzip2.json
  35. 0 1
      sys/src/cmd/cmd.json
  36. 0 1
      sys/src/cmd/cmds.json
  37. 3 65
      sys/src/cmd/sam/build.json
  38. 2 63
      sys/src/cmd/samterm/build.json
  39. 140 0
      sys/src/cmd/samterm/mesg.h
  40. 5 5
      sys/src/games/games.json
  41. 0 1
      sys/src/libs.json
  42. 0 29
      sys/src/libsunrpc/COPYING
  43. 0 69
      sys/src/libsunrpc/authunix.c
  44. 0 492
      sys/src/libsunrpc/client.c
  45. 0 43
      sys/src/libsunrpc/emalloc.c
  46. 0 46
      sys/src/libsunrpc/error.c
  47. 0 116
      sys/src/libsunrpc/fd.c
  48. 0 73
      sys/src/libsunrpc/fmt.c
  49. 0 25
      sys/src/libsunrpc/libsunrpc.json
  50. 0 753
      sys/src/libsunrpc/mount3.c
  51. 0 66
      sys/src/libsunrpc/net.c
  52. 0 507
      sys/src/libsunrpc/portmap.c
  53. 0 86
      sys/src/libsunrpc/prog.c
  54. 0 542
      sys/src/libsunrpc/rpc.c
  55. 0 286
      sys/src/libsunrpc/server.c
  56. 0 23
      sys/src/libsunrpc/suncall.c
  57. 0 122
      sys/src/libsunrpc/udp.c

+ 0 - 97
sys/src/cmd/9nfs/9auth.c

@@ -1,97 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-
-#define	NETCHLEN	16		/* max network challenge length	*/
-
-char *	argv0;
-int	debug;
-int	delete;
-
-char *	root = "/n/emelie";
-char *	user;
-char	file[64];
-char	challenge[NETCHLEN];
-char	response[NETCHLEN];
-
-void
-usage(void)
-{
-	printf("usage: %s [-d] username\n", argv0);
-	exit(1);
-}
-
-void
-main(int argc, char **argv)
-{
-	int fd, n;
-
-	for(argv0=*argv++,--argc; argc>0; ++argv,--argc){
-		if(argv[0][0] != '-' || argv[0][1] == '-')
-			break;
-		switch(argv[0][1]){
-		case 'D':
-			++debug;
-			break;
-		case 'd':
-			++delete;
-			break;
-		case 'r':
-			root = argv[0][2] ? &argv[0][2] : (--argc, *++argv);
-			break;
-		default:
-			usage();
-			break;
-		}
-	}
-	if(argc != 1)
-		usage();
-	user = argv[0];
-	snprintf(file, sizeof file, "%s/#%s", root, user);
-	if(debug)
-		printf("debug=%d, file=%s\n", debug, file);
-	if(delete){
-		fd = creat(file, 0600);
-		if(fd < 0){
-			perror(file);
-			exit(1);
-		}
-		exit(0);
-	}
-	fd = open(file, 2);
-	if(fd < 0){
-		perror(file);
-		exit(1);
-	}
-	n = read(fd, challenge, NETCHLEN);
-	if(debug)
-		printf("read %d\n", n);
-	if(n <= 0){
-		printf("read %d: ", n);
-		perror("");
-		exit(1);
-	}
-	printf("challenge: %s\n", challenge);
-	write(1, "response: ", 10);
-	read(0, response, NETCHLEN-1);
-	lseek(fd, 0, 0);
-	n = write(fd, response, NETCHLEN);
-	if(debug)
-		printf("write %d\n", n);
-	if(n <= 0){
-		printf("write %d: ", n);
-		perror("");
-		exit(1);
-	}
-	exit(0);
-}

+ 0 - 30
sys/src/cmd/9nfs/9nfs.json

@@ -1,30 +0,0 @@
-{
-	"nfsserver": {
-		"Include": [
-			"../cmd.json"
-		],
-		"Install": "/$ARCH/bin/aux",
-		"Program": "nfsserver",
-		"Projects": [
-			"portmapper.json",
-			"pcnfsd.json"
-		],
-		"SourceFiles": [
-			"9p.c",
-			"auth.c",
-			"authhostowner.c",
-			"nfs.c",
-			"nfsmount.c",
-			"nfsserver.c",
-			"xfile.c",
-			"chat.c",
-			"rpc.c",
-			"string.c",
-			"strparse.c",
-			"system.c",
-			"listalloc.c",
-			"server.c",
-			"unixnames.c"
-		]
-	}
-}

+ 0 - 193
sys/src/cmd/9nfs/9p.c

@@ -1,193 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-static char *tnames[] = {
-	[Tversion]	"version",
-	[Tauth]		"auth",
-	[Tattach]	"attach",
-	[Tflush]	"flush",
-	[Twalk]		"walk",
-	[Topen]		"open",
-	[Tcreate]	"create",
-	[Tread]		"read",
-	[Twrite]	"write",
-	[Tclunk]	"clunk",
-	[Tremove]	"remove",
-	[Tstat]		"stat",
-	[Twstat]	"wstat",
-};
-
-int	messagesize = IOHDRSZ+Maxfdata;
-
-int
-xmesg(Session *s, int t)
-{
-	int n;
-
-	if(chatty){
-		if(0 <= t && t < nelem(tnames) && tnames[t])
-			chat("T%s...", tnames[t]);
-		else
-			chat("T%d...", t);
-	}
-	s->f.type = t;
-	s->f.tag = ++s->tag;
-	if(p9debug)
-		fprint(2, "xmseg\tsend %F\n", &s->f);
-	n = convS2M(&s->f, s->data, messagesize);
-	if(niwrite(s->fd, s->data, n) != n){
-		clog("xmesg write error on %d: %r\n", s->fd);
-		return -1;
-	}
-again:
-	n = read9pmsg(s->fd, s->data, messagesize);
-	if(n < 0){
-		clog("xmesg read error: %r\n");
-		return -1;
-	}
-	if(convM2S(s->data, n, &s->f) <= 0){
-		clog("xmesg bad convM2S %d %.2x %.2x %.2x %.2x\n",
-			n, ((uint8_t*)s->data)[0], ((uint8_t*)s->data)[1],
-			((uint8_t*)s->data)[2], ((uint8_t*)s->data)[3]);
-		return -1;
-	}
-	if(p9debug)
-		fprint(2, "\trecv %F\n", &s->f);
-	if(s->f.tag != s->tag){
-		clog("xmesg tag %d for %d\n", s->f.tag, s->tag);
-		goto again;
-	}
-	if(s->f.type == Rerror){
-		if(t == Tclunk)
-			clog("xmesg clunk: %s", s->f.ename);
-		chat("xmesg %d error %s...", t, s->f.ename);
-		return -1;
-	}
-	if(s->f.type != t+1){
-		clog("xmesg type mismatch: %d, expected %d\n", s->f.type, t+1);
-		return -1;
-	}
-	return 0;
-}
-
-int
-clunkfid(Session *s, Fid *f)
-{
-	putfid(s, f);
-	if(s == 0 || f == 0)
-		return 0;
-	s->f.fid = f - s->fids;
-	return xmesg(s, Tclunk);
-}
-
-#define	UNLINK(p)	((p)->prev->next = (p)->next, (p)->next->prev = (p)->prev)
-
-#define	LINK(h, p)	((p)->next = (h)->next, (p)->prev = (h), \
-			 (h)->next->prev = (p), (h)->next = (p))
-
-#define	TOFRONT(h, p)	((h)->next != (p) ? (UNLINK(p), LINK(h,p)) : 0)
-
-Fid *
-newfid(Session *s)
-{
-	Fid *f, *fN;
-
-	chat("newfid..");
-	if(s->list.prev == 0){
-		chat("init..");
-		s->list.prev = &s->list;
-		s->list.next = &s->list;
-		s->free = s->fids;
-		if(0 && chatty)
-			fN = &s->fids[25];
-		else
-			fN = &s->fids[nelem(s->fids)];
-		for(f=s->fids; f<fN; f++){
-			f->owner = 0;
-			f->prev = 0;
-			f->next = f+1;
-		}
-		(f-1)->next = 0;
-	}
-	if(s->free){
-		f = s->free;
-		s->free = f->next;
-		LINK(&s->list, f);
-	}else{
-		for(f=s->list.prev; f!=&s->list; f=f->prev)
-			if(f->owner)
-				break;
-		if(f == &s->list){
-			clog("fid leak");
-			return 0;
-		}
-		setfid(s, f);
-		if(xmesg(s, Tclunk) < 0){
-			clog("clunk failed, no fids?");
-			/*return 0;*/
-		}
-		*(f->owner) = 0;
-		f->owner = 0;
-	}
-	chat("%ld...", f - s->fids);
-	f->tstale = nfstime + staletime;
-	return f;
-}
-
-void
-setfid(Session *s, Fid *f)
-{
-	/*
-	 * TOFRONT(&s->list, f);
-	 */
-	if(s->list.next != f){
-		UNLINK(f);
-		LINK(&s->list, f);
-	}
-
-	f->tstale = nfstime + staletime;
-	s->f.fid = f - s->fids;
-}
-
-void
-putfid(Session *s, Fid *f)
-{
-	chat("putfid %ld...", f-s->fids);
-	if(s == 0 || f == 0){
-		clog("putfid(0x%p, 0x%p) %s", s, f, (s ? s->service : "?"));
-		return;
-	}
-	UNLINK(f);
-	if(f->owner)
-		*(f->owner) = 0;
-	f->owner = 0;
-	f->prev = 0;
-	f->next = s->free;
-	s->free = f;
-}
-
-void
-fidtimer(Session *s, int32_t now)
-{
-	Fid *f, *t;
-	int n;
-
-	f = s->list.next;
-	n = 0;
-	while(f != &s->list){
-		t = f;
-		f = f->next;
-		if(t->owner && now >= t->tstale)
-			++n, clunkfid(s, t);
-	}
-	if(n > 0)
-		chat("fidtimer %s\n", s->service);
-}

+ 0 - 25
sys/src/cmd/9nfs/all.h

@@ -1,25 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <ip.h>
-#include <bio.h>
-#include <auth.h>
-#include <authsrv.h>
-#include <fcall.h>
-#include <regexp.h>
-#include "dat.h"
-#include "fns.h"
-#include "rpc.h"
-#include "nfs.h"
-#pragma	varargck	type	"I"	uint32_t
-#pragma	varargck	argpos	chat	1
-#pragma	varargck	argpos	clog	1
-#pragma	varargck	argpos	panic	1

+ 0 - 40
sys/src/cmd/9nfs/auth.c

@@ -1,40 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-/* this is all stubbed out; the NFS authentication stuff is now disabled - rob */
-
-Xfid *
-xfauth(Xfile *x, String *s)
-{
-	return 0;
-}
-
-int32_t
-xfauthread(Xfid *xf, int32_t i, uint8_t *n, int32_t l)
-{
-
-	chat("xfauthread %s...", xf->uid);
-	return 0;
-}
-
-int32_t
-xfauthwrite(Xfid *xf, int32_t i, uint8_t *n, int32_t l)
-{
-	chat("xfauthwrite %s...", xf->uid);
-	return 0;
-}
-
-int
-xfauthremove(Xfid *x, char *c)
-{
-	chat("authremove...");
-	return -1;
-}

+ 0 - 186
sys/src/cmd/9nfs/authhostowner.c

@@ -1,186 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-enum {
-	ARgiveup = 100,
-};
-
-static int
-dorpc(AuthRpc *rpc, char *verb, char *val, int len, AuthGetkey *getkey)
-{
-	int ret;
-
-	for(;;){
-		if((ret = auth_rpc(rpc, verb, val, len)) != ARneedkey && ret != ARbadkey)
-			return ret;
-		if(getkey == nil)
-			return ARgiveup;	/* don't know how */
-		if((*getkey)(rpc->arg) < 0)
-			return ARgiveup;	/* user punted */
-	}
-}
-
-static int
-doread(Session *s, Fid *f, void *buf, int n)
-{
-	s->f.fid = f - s->fids;
-	s->f.offset = 0;
-	s->f.count = n;
-	if(xmesg(s, Tread) < 0)
-		return -1;
-	n = s->f.count;
-	memmove(buf, s->f.data, n);
-	return n;
-}
-
-static int
-dowrite(Session *s, Fid *f, void *buf, int n)
-{
-	s->f.fid = f - s->fids;
-	s->f.offset = 0;
-	s->f.count = n;
-	s->f.data = (char *)buf;
-	if(xmesg(s, Twrite) < 0)
-		return -1;
-	return n;
-}
-
-/*
- *  this just proxies what the factotum tells it to.
- */
-AuthInfo*
-authproto(Session *s, Fid *f, AuthRpc *rpc, AuthGetkey *getkey,
-	  char *params)
-{
-	char *buf;
-	int m, n, ret;
-	AuthInfo *a;
-	char oerr[ERRMAX];
-
-	rerrstr(oerr, sizeof oerr);
-	werrstr("UNKNOWN AUTH ERROR");
-
-	if(dorpc(rpc, "start", params, strlen(params), getkey) != ARok){
-		werrstr("fauth_proxy start: %r");
-		return nil;
-	}
-
-	buf = malloc(AuthRpcMax);
-	if(buf == nil)
-		return nil;
-	for(;;){
-		switch(dorpc(rpc, "read", nil, 0, getkey)){
-		case ARdone:
-			free(buf);
-			a = auth_getinfo(rpc);
-			errstr(oerr, sizeof oerr);	/* no error, restore whatever was there */
-			return a;
-		case ARok:
-			if(dowrite(s, f, rpc->arg, rpc->narg) != rpc->narg){
-				werrstr("auth_proxy write fd: %r");
-				goto Error;
-			}
-			break;
-		case ARphase:
-			n = 0;
-			memset(buf, 0, AuthRpcMax);
-			while((ret = dorpc(rpc, "write", buf, n, getkey)) == ARtoosmall){
-				if(atoi(rpc->arg) > AuthRpcMax)
-					break;
-				m = doread(s, f, buf+n, atoi(rpc->arg)-n);
-				if(m <= 0){
-					if(m == 0)
-						werrstr("auth_proxy short read: %s", buf);
-					goto Error;
-				}
-				n += m;
-			}
-			if(ret != ARok){
-				werrstr("auth_proxy rpc write: %s: %r", buf);
-				goto Error;
-			}
-			break;
-		default:
-			werrstr("auth_proxy rpc: %r");
-			goto Error;
-		}
-	}
-Error:
-	free(buf);
-	return nil;
-}
-
-/* returns 0 if auth succeeded (or unneeded), -1 otherwise */
-int
-authhostowner(Session *s)
-{
-	Fid *af, *f;
-	int rv = -1;
-	int afd;
-	AuthInfo *ai;
-	AuthRpc *rpc;
-
-	/* get a fid to authenticate over */
-	f = nil;
-	af = newfid(s);
-	s->f.afid = af - s->fids;
-	s->f.uname = getuser();
-	s->f.aname = s->spec;
-	if(xmesg(s, Tauth)){
-		/* not needed */
-		rv = 0;
-		goto out;
-	}
-
-	quotefmtinstall();	/* just in case */
-
-	afd = open("/mnt/factotum/rpc", ORDWR);
-	if(afd < 0){
-		werrstr("opening /mnt/factotum/rpc: %r");
-		goto out;
-	}
-
-	rpc = auth_allocrpc(afd);
-	if(rpc == nil)
-		goto out;
-
-	ai = authproto(s, af, rpc, auth_getkey, "proto=p9any role=client");
-	if(ai != nil){
-		rv = 0;
-		auth_freeAI(ai);
-	}
-	auth_freerpc(rpc);
-	close(afd);
-
-	/* try attaching with the afid */
-	chat("attaching as hostowner...");
-	f = newfid(s);
-	s->f.fid = f - s->fids;
-	s->f.afid = af - s->fids;;
-	s->f.uname = getuser();
-	s->f.aname = s->spec;
-	if(xmesg(s, Tattach) == 0)
-		rv = 0;
-out:
-	if(af != nil){
-		putfid(s, af);
-		s->f.fid = af - s->fids;
-		xmesg(s, Tclunk);
-	}
-	if(f != nil){
-		putfid(s, f);
-		s->f.fid = f - s->fids;
-		xmesg(s, Tclunk);
-	}
-
-	return rv;
-}
-

+ 0 - 140
sys/src/cmd/9nfs/chat.c

@@ -1,140 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-#define	SIZE	1024
-
-int		chatty;
-int		conftime;
-
-#define	NSIZE	128
-
-static char	nbuf[NSIZE];
-static int	chatpid;
-
-static void
-killchat(void)
-{
-	char buf[NSIZE];
-	int fd;
-
-	remove(nbuf);
-	snprint(buf, sizeof buf, "/proc/%d/note", chatpid);
-	fd = open(buf, OWRITE);
-	write(fd, "kill\n", 5);
-	close(fd);
-}
-
-void
-chatsrv(char *name)
-{
-	int n, sfd, pfd[2];
-	char *p, buf[256];
-
-	if(name && *name)
-		snprint(nbuf, sizeof nbuf, "/srv/%s", name);
-	else{
-		if(p = strrchr(argv0, '/'))	/* assign = */
-			name = p+1;
-		else
-			name = argv0;
-		snprint(nbuf, sizeof nbuf, "/srv/%s.chat", name);
-	}
-	remove(nbuf);
-	if(pipe(pfd) < 0)
-		panic("chatsrv pipe");
-	sfd = create(nbuf, OWRITE, 0600);
-	if(sfd < 0)
-		panic("chatsrv create %s", nbuf);
-	chatpid = rfork(RFPROC|RFMEM);
-	switch(chatpid){
-	case -1:
-		panic("chatsrv fork");
-	case 0:
-		break;
-	default:
-		atexit(killchat);
-		return;
-	}
-	fprint(sfd, "%d", pfd[1]);
-	close(sfd);
-	close(pfd[1]);
-	for(;;){
-		n = read(pfd[0], buf, sizeof(buf)-1);
-		if(n < 0)
-			break;
-		if(n == 0)
-			continue;
-		buf[n] = 0;
-		if(buf[0] == 'c')
-			conftime = 999;
-		chatty = strtol(buf, 0, 0);
-		if(abs(chatty) < 2)
-			rpcdebug = 0;
-		else
-			rpcdebug = abs(chatty) - 1;
-		fprint(2, "%s: chatty=%d, rpcdebug=%d, conftime=%d\n",
-			nbuf, chatty, rpcdebug, conftime);
-	}
-	_exits(0);
-}
-
-void
-chat(char *fmt, ...)
-{
-	char buf[SIZE];
-	va_list arg;
-	Fmt f;
-
-	if(!chatty)
-		return;
-
-	fmtfdinit(&f, 2, buf, sizeof buf);
-	va_start(arg, fmt);
-	fmtvprint(&f, fmt, arg);
-	va_end(arg);
-	fmtfdflush(&f);
-}
-
-void
-clog(char *fmt, ...)
-{
-	char buf[SIZE];
-	va_list arg;
-	int n;
-
-	va_start(arg, fmt);
-	vseprint(buf, buf+SIZE, fmt, arg);
-	va_end(arg);
-	n = strlen(buf);
-	if(chatty || rpcdebug)
-		write(2, buf, n);
-	if(chatty <= 0){
-		if(n>0 && buf[n-1] == '\n')
-			buf[n-1] = 0;
-		syslog(0, "nfs", buf);
-	}
-}
-
-void
-panic(char *fmt, ...)
-{
-	char buf[SIZE];
-	va_list arg;
-
-	va_start(arg, fmt);
-	vseprint(buf, buf+SIZE, fmt, arg);
-	va_end(arg);
-	if(chatty || rpcdebug)
-		fprint(2, "%s %d: %s: %r\n", argv0, getpid(), buf);
-	if(chatty <= 0)
-		syslog(0, "nfs", buf);
-	exits("panic");
-}

+ 0 - 282
sys/src/cmd/9nfs/dat.h

@@ -1,282 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-enum
-{
-	FHSIZE	= 32
-};
-
-typedef struct Accept	Accept;
-typedef struct Auth	Auth;
-typedef struct Authunix	Authunix;
-typedef struct Chalstuff Chalstuff;
-typedef unsigned char		Fhandle[FHSIZE];
-typedef struct Fid	Fid;
-typedef struct Procmap	Procmap;
-typedef struct Progmap	Progmap;
-typedef struct Reject	Reject;
-typedef struct Rpccall	Rpccall;
-typedef struct Rpccache	Rpccache;
-typedef struct Sattr	Sattr;
-typedef struct Session	Session;
-typedef struct String	String;
-typedef struct Strnode	Strnode;
-typedef struct Unixid	Unixid;
-typedef struct Unixidmap Unixidmap;
-typedef struct Unixmap	Unixmap;
-typedef struct Unixscmap Unixscmap;
-typedef struct Xfid	Xfid;
-typedef struct Xfile	Xfile;
-
-struct String
-{
-	uint32_t	n;
-	char *	s;
-};
-
-struct Progmap
-{
-	int	progno;
-	int	vers;
-	void	(*init)(int, char**);
-	Procmap *pmap;
-};
-
-struct Procmap
-{
-	int	procno;
-	int	(*procp)(int, Rpccall*, Rpccall*);
-};
-
-struct Auth
-{
-	uint32_t	flavor;
-	uint32_t	count;
-	void *	data;
-};
-
-struct Authunix
-{
-	uint32_t	stamp;
-	String	mach;
-	uint32_t	uid;
-	uint32_t	gid;
-	int	gidlen;
-	uint32_t	gids[10];
-};
-
-struct Accept
-{
-	Auth	averf;
-	uint32_t	astat;
-	union{
-		void *	results;	/* SUCCESS */
-		struct{			/* PROG_MISMATCH */
-			uint32_t	plow;	/* acceptable version numbers */
-			uint32_t	phigh;
-		};
-	};
-};
-
-struct Reject
-{
-	uint32_t	rstat;
-	union{
-		struct{			/* RPC_MISMATCH */
-			uint32_t	rlow;	/* acceptable  rpc version numbers */
-			uint32_t	rhigh;
-		};
-		uint32_t	authstat;	/* AUTH_ERROR */
-	};
-};
-
-struct Rpccall
-{
-	/* corresponds to Udphdr */
-	unsigned char	prefix0[12];
-	uint32_t	host;		/* ipv4 subset: prefixed to RPC message */
-	unsigned char	prefix1[12];
-	uint32_t	lhost;		/* ipv4 subset: prefixed to RPC message */
-	/* ignore ifcaddr */
-	uint32_t	port;		/* prefixed to RPC message */
-	uint32_t	lport;		/* prefixed to RPC message */
-
-	uint32_t	xid;		/* transaction id */
-	uint32_t	mtype;		/* CALL or REPLY */
-	union{
-		struct{		/* CALL */
-			uint32_t	rpcvers;	/* must be equal to two (2) */
-			uint32_t	prog;		/* program number */
-			uint32_t	vers;		/* program version */
-			uint32_t	proc;		/* procedure number */
-			Auth	cred;		/* authentication credentials */
-			Auth	verf;		/* authentication verifier */
-			Unixidmap *up;
-			char *	user;
-			void *	args;		/* procedure-specific */
-		};
-		struct{		/* REPLY */
-			uint32_t	stat;		/* MSG_ACCEPTED or MSG_DENIED */
-			union{
-				Accept;
-				Reject;
-			};
-		};
-	};
-};
-
-struct Rpccache
-{
-	Rpccache *prev;
-	Rpccache *next;
-	uint32_t	host;
-	uint32_t	port;
-	uint32_t	xid;
-	int	n;
-	unsigned char	data[4];
-};
-
-struct Sattr
-{
-	uint32_t	mode;
-	uint32_t	uid;
-	uint32_t	gid;
-	uint32_t	size;
-	uint32_t	atime;		/* sec's */
-	uint32_t	ausec;		/* microsec's */
-	uint32_t	mtime;
-	uint32_t	musec;
-};
-
-struct Strnode
-{
-	Strnode *next;	/* in hash bucket */
-	char	str[4];
-};
-
-struct Unixid
-{
-	Unixid *next;
-	char *	name;
-	int	id;
-};
-
-struct Unixmap
-{
-	char *	file;
-	int	style;
-	int32_t	timestamp;
-	Unixid *ids;
-};
-
-struct Unixidmap
-{
-	Unixidmap *next;
-	int	flag;
-	char *	server;
-	char *	client;
-	Reprog *sexp;
-	Reprog *cexp;
-	Unixmap	u;
-	Unixmap	g;
-};
-
-struct Unixscmap
-{
-	Unixscmap *next;
-	char *	server;
-	uint32_t	clientip;
-	Unixidmap *map;
-};
-
-struct Xfile
-{
-	Xfile *	next;		/* hash chain */
-	Session	*s;
-	Qid		qid;	/* from stat */
-	Xfile *	parent;
-	Xfile *	child;		/* if directory */
-	Xfile *	sib;		/* siblings */
-	char *	name;		/* path element */
-	Xfid *	users;
-};
-
-enum
-{
-	Oread	= 1,
-	Owrite	= 2,
-	Open	= 3,
-	Trunc	= 4
-};
-
-struct Xfid
-{
-	Xfid *	next;		/* Xfile's user list */
-	Xfile *	xp;
-	char *	uid;
-	Fid *	urfid;
-	Fid *	opfid;
-	uint32_t	mode;		/* open mode, if opfid is non-zero */
-	uint32_t	offset;
-};
-
-struct Fid
-{
-	Fid **	owner;		/* null for root fids */
-	Fid *	prev;
-	Fid *	next;
-	int32_t	tstale;		/* auto-clunk */
-};
-
-enum
-{
-	Maxfdata = 8192,
-	Maxstatdata = 2048,
-};
-
-struct Session
-{
-	Session *next;
-	char *	service;		/* for dial */
-	int	fd;
-#define CHALLEN 1
-	char	cchal[CHALLEN];		/* client challenge */
-	char	schal[CHALLEN];		/* server challenge */
-	char	authid[ANAMELEN];	/* server encryption uid */
-	char	authdom[DOMLEN];	/* server encryption domain */
-	char *	spec;			/* for attach */
-	Xfile *	root;			/* to answer mount rpc */
-	uint16_t	tag;
-	Fcall	f;
-	unsigned char	data[IOHDRSZ+Maxfdata];
-	unsigned char	statbuf[Maxstatdata];
-	Fid *	free;			/* available */
-	Fid	list;			/* active, most-recently-used order */
-	Fid	fids[1000];
-	int	noauth;
-};
-
-struct Chalstuff
-{
-	Chalstuff *next;
-	Xfid *	xf;
-	int32_t	tstale;
-	Chalstate;
-};
-
-extern int	rpcdebug;
-extern int	p9debug;
-extern int	chatty;
-extern void	(*rpcalarm)(void);
-extern int32_t	starttime;
-extern int32_t	nfstime;
-extern char *	config;
-extern int	staletime;
-extern int	messagesize;
-extern char *	commonopts;

+ 0 - 75
sys/src/cmd/9nfs/fns.h

@@ -1,75 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-int	argopt(int c);
-int	auth2unix(Auth*, Authunix*);
-int	authhostowner(Session*);
-int	canlock(Lock*);
-void	chat(char*, ...);
-void	chatsrv(char*);
-int	checkreply(Session*, char*);
-int	checkunixmap(Unixmap*);
-void	clog(char*, ...);
-int	clunkfid(Session*, Fid*);
-int	convM2sattr(void*, Sattr*);
-int	dir2fattr(Unixidmap*, Dir*, void*);
-int	error(Rpccall*, int);
-void	fidtimer(Session*, int32_t);
-int	garbage(Rpccall*, char*);
-int	getdom(uint32_t, char*, int);
-int	getticket(Session*, char*);
-char*	id2name(Unixid**, int);
-void	idprint(int, Unixid*);
-void*	listalloc(int32_t, int32_t);
-void	lock(Lock*);
-void	mnttimer(int32_t);
-int	name2id(Unixid**, char*);
-Fid*	newfid(Session*);
-int32_t	niwrite(int, void*, int32_t);
-Unixidmap*	pair2idmap(char*, uint32_t);
-void	panic(char*, ...);
-void	putfid(Session*, Fid*);
-int	readunixidmaps(char*);
-Unixid*	readunixids(char*, int);
-Xfid*	rpc2xfid(Rpccall*, Dir*);
-int	rpcM2S(void*, Rpccall*, int);
-int	rpcS2M(Rpccall*, int, void*);
-void	rpcprint(int, Rpccall*);
-void	server(int argc, char *argv[], int, Progmap*);
-void	setfid(Session*, Fid*);
-Xfid*	setuser(Xfile*, char*);
-void	showauth(Auth*);
-void	srvinit(int, char*, char*);
-char*	strfind(char*);
-int	string2S(void*, String*);
-int	strparse(char*, int, char**);
-void	strprint(int);
-char*	strstore(char*);
-Waitmsg	*system(char*, char**);
-Waitmsg	*systeml(char*, ...);
-void	unlock(Lock*);
-int	xfattach(Session*, char*, int);
-Xfid*	xfauth(Xfile*, String*);
-void	xfauthclose(Xfid*);
-int32_t	xfauthread(Xfid*, int32_t, unsigned char*, int32_t);
-int	xfauthremove(Xfid*, char*);
-int32_t	xfauthwrite(Xfid*, int32_t, unsigned char*, int32_t);
-void	xfclear(Xfid*);
-void	xfclose(Xfid*);
-Xfid*	xfid(char*, Xfile*, int);
-Xfile*	xfile(Qid*, void*, int);
-int	xfopen(Xfid*, int);
-int	xfpurgeuid(Session*, char*);
-Xfile*	xfroot(char*, int);
-int	xfstat(Xfid*, Dir*);
-Xfid*	xfwalkcr(int, Xfid*, String*, int32_t);
-int	xfwstat(Xfid*, Dir*);
-int	xmesg(Session*, int);
-int	xp2fhandle(Xfile*, Fhandle);
-void	xpclear(Xfile*);

+ 0 - 28
sys/src/cmd/9nfs/listalloc.c

@@ -1,28 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-
-void*	listalloc(int32_t, int32_t);
-
-void *
-listalloc(int32_t n, int32_t size)
-{
-	char *p, *base;
-
-	size = (size+sizeof(uint32_t)-1)/sizeof(uint32_t)*sizeof(uint32_t);
-	p = base = malloc(n*size);
-	while(--n > 0){
-		*(char**)p = p+size;
-		p += size;
-	}
-	*(char**)p = 0;
-	return base;
-}

+ 0 - 194
sys/src/cmd/9nfs/mport.c

@@ -1,194 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-typedef struct Rpcconn	Rpcconn;
-
-struct Rpcconn
-{
-	int	data;
-	int	ctl;
-	Rpccall	cmd;
-	Rpccall	reply;
-	uint8_t	rpcbuf[8192];
-	uint8_t	argbuf[8192];
-};
-
-void	putauth(char*, Auth*);
-int	rpccall(Rpcconn*, int);
-
-int	rpcdebug;
-
-Rpcconn	r;
-char *	mach;
-
-void
-main(int argc, char **argv)
-{
-	char addr[64], dir[64], name[128];
-	char buf[33], *p;
-	unsigned char *dataptr, *argptr;
-	int i, fd, n, remport;
-
-	ARGBEGIN{
-	case 'm':
-		mach = ARGF();
-		break;
-	case 'D':
-		++rpcdebug;
-		break;
-	}ARGEND
-	if(argc != 1)
-		exits("usage");
-
-	snprint(addr, sizeof addr, "udp!%s!111", argv[0]);
-	r.data = dial(addr, 0, dir, &r.ctl);
-	if(r.data < 0){
-		fprint(2, "dial %s: %r\n", addr);
-		exits("dial");
-	}
-	if(rpcdebug)
-		fprint(2, "dial %s: dir=%s\n", addr, dir);
-	if(fprint(r.ctl, "headers") < 0){
-		fprint(2, "can't set header mode: %r\n");
-		exits("headers");
-	}
-	sprint(name, "%s/remote", dir);
-	fd = open(name, OREAD);
-	if(fd < 0){
-		fprint(2, "can't open %s: %r\n", name);
-		exits("remote");
-	}
-	n = read(fd, buf, sizeof buf-1);
-	if(n < 0){
-		fprint(2, "can't read %s: %r\n", name);
-		exits("remote");
-	}
-	close(fd);
-	buf[n] = 0;
-	p = buf;
-	r.cmd.host = 0;
-	for(i=0; i<4; i++, p++)
-		r.cmd.host = (r.cmd.host<<8)|strtol(p, &p, 10);
-	r.cmd.port = strtol(p, 0, 10);
-	fprint(2, "host=%ld.%ld.%ld.%ld, port=%lud\n",
-		(r.cmd.host>>24)&0xff, (r.cmd.host>>16)&0xff,
-		(r.cmd.host>>8)&0xff, r.cmd.host&0xff, r.cmd.port);
-	fprint(r.ctl, "disconnect");
-
-	r.cmd.xid = time(0);
-	r.cmd.mtype = CALL;
-	r.cmd.rpcvers = 2;
-	r.cmd.args = r.argbuf;
-	if(mach)
-		putauth(mach, &r.cmd.cred);
-
-	r.cmd.prog = 100000;	/* portmapper */
-	r.cmd.vers = 2;		/* vers */
-	r.cmd.proc = 3;		/* getport */
-	dataptr = r.cmd.args;
-
-	PLONG(100005);		/* mount */
-	PLONG(1);		/* vers */
-	PLONG(IPPROTO_UDP);
-	PLONG(0);
-
-	i = rpccall(&r, dataptr-(unsigned char*)r.cmd.args);
-	if(i != 4)
-		exits("trouble");
-	argptr = r.reply.results;
-	remport = GLONG();
-	fprint(2, "remote port = %d\n", remport);
-
-	r.cmd.port = remport;
-	r.cmd.prog = 100005;	/* mount */
-	r.cmd.vers = 1;		/* vers */
-	r.cmd.proc = 0;		/* null */
-	dataptr = r.cmd.args;
-
-	i = rpccall(&r, dataptr-(unsigned char*)r.cmd.args);
-	if(i != 0)
-		exits("trouble");
-	fprint(2, "OK ping mount\n");
-
-	r.cmd.prog = 100005;	/* mount */
-	r.cmd.vers = 1;		/* vers */
-	r.cmd.proc = 5;		/* export */
-	dataptr = r.cmd.args;
-
-	i = rpccall(&r, dataptr-(unsigned char*)r.cmd.args);
-	fprint(2, "export: %d bytes returned\n", i);
-	argptr = r.reply.results;
-	while (GLONG() != 0) {
-		n = GLONG();
-		p = GPTR(n);
-		print("%.*s\n", utfnlen(p, n), p);
-		while (GLONG() != 0) {
-			n = GLONG();
-			p = GPTR(n);
-			print("\t%.*s\n", utfnlen(p, n), p);
-		}
-	}
-
-	exits(0);
-}
-
-void
-putauth(char *mach, Auth *a)
-{
-	uint8_t *dataptr;
-	int32_t stamp = time(0);
-	int n = strlen(mach);
-
-	dataptr = realloc(a->data, 2*4+ROUNDUP(n)+4*4);
-	a->data = dataptr;
-	a->flavor = AUTH_UNIX;
-	PLONG(stamp);
-	PLONG(n);
-	PPTR(mach, n);
-	PLONG(0);
-	PLONG(1);
-	PLONG(1);
-	PLONG(0);
-	a->count = dataptr - (uint8_t*)a->data;
-}
-
-int
-rpccall(Rpcconn *r, int narg)
-{
-	int n;
-
-	r->cmd.xid++;
-	n = rpcS2M(&r->cmd, narg, r->rpcbuf);
-	if(rpcdebug)
-		rpcprint(2, &r->cmd);
-	if(write(r->data, r->rpcbuf, n) < 0){
-		fprint(2, "rpc write: %r\n");
-		exits("rpc");
-	}
-	n = read(r->data, r->rpcbuf, sizeof r->rpcbuf);
-	if(n < 0){
-		fprint(2, "rpc read: %r\n");
-		exits("rpc");
-	}
-	if(rpcM2S(r->rpcbuf, &r->reply, n) != 0){
-		fprint(2, "rpc reply format error\n");
-		exits("rpc");
-	}
-	if(rpcdebug)
-		rpcprint(2, &r->reply);
-	if(r->reply.mtype != REPLY || r->reply.stat != MSG_ACCEPTED ||
-	   r->reply.astat != SUCCESS){
-		fprint(2, "rpc mtype, stat, astat = %ld, %ld, %ld\n",
-			r->reply.mtype, r->reply.stat, r->reply.astat);
-		exits("rpc");
-	}
-	return n - (((uint8_t *)r->reply.results) - r->rpcbuf);
-}

+ 0 - 108
sys/src/cmd/9nfs/nametest.c

@@ -1,108 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-void	mapinit(char*, char*);
-
-int	debug;
-int	rpcdebug;
-int	style = 'u';
-Biobuf *in;
-Unixid *ids;
-Unixid **pids;
-Unixidmap *mp;
-
-void
-main(int argc, char **argv)
-{
-	int id, arc; char *arv[4];
-	char *l, *name;
-
-	chatty = 1;
-	ARGBEGIN{
-	case '9':
-	case 'u':
-		style = ARGC();
-		break;
-	case 'D':
-		++debug;
-		break;
-	}ARGEND
-	if(argc <= 0){
-		ids = readunixids("/fd/0", style);
-		if(ids)
-			idprint(1, ids);
-		exits(ids ? 0 : "readunixids");
-	}
-	mapinit(argv[0], 0);
-	in = Bopen("/fd/0", OREAD);
-	while(l = Brdline(in, '\n')){	/* assign = */
-		l[Blinelen(in)-1] = 0;
-		arc = strparse(l, nelem(arv), arv);
-		if(arc <= 0)
-			continue;
-		switch(arv[0][0]){
-		case 'r':
-			if(arc < 2)
-				continue;
-			mapinit(arv[1], arv[2]);
-			break;
-		case 'i':
-			if(arc < 2)
-				continue;
-			id = strtol(arv[1], 0, 10);
-			name = id2name(pids, id);
-			print("%d -> %s\n", id, name);
-			break;
-		case 'n':
-			if(arc < 2)
-				continue;
-			name = arv[1];
-			id = name2id(pids, name);
-			print("%s -> %d\n", name, id);
-			break;
-		case 'p':
-			print("server=%s, client=%s\n", mp->server, mp->client);
-			break;
-		case 'P':
-			idprint(1, *pids);
-			break;
-		case 'u':
-			pids = &mp->u.ids;
-			print("users...\n");
-			break;
-		case 'g':
-			pids = &mp->g.ids;
-			print("groups...\n");
-			break;
-		}
-	}
-	exits(0);
-}
-
-void
-mapinit(char *file, char *client)
-{
-	if(file){
-		print("reading %s...\n", file);
-		if(readunixidmaps(file) < 0)
-			exits("readunixidmaps");
-		if(!client)
-		client = "nslocum.research.bell-labs.com";
-	}
-	print("client = %s...\n", client);
-	mp = pair2idmap("bootes", client, 0);
-	if(mp == 0){
-		fprint(2, "%s: pair2idmap failed\n", argv0);
-		exits("pair2idmap");
-	}
-	pids = &mp->u.ids;
-	print("[users...]\n");
-}

+ 0 - 481
sys/src/cmd/9nfs/nfs.c

@@ -1,481 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-extern uint8_t buf[];
-
-Xfid *
-rpc2xfid(Rpccall *cmd, Dir *dp)
-{
-	char *argptr = cmd->args;
-	Xfile *xp;
-	Xfid *xf;
-	Session *s;
-	char *service;
-	Authunix au;
-	Qid qid;
-	char client[256], *user;
-	Unixidmap *m;
-	int i;
-	uint64_t x1, x2;
-
-	chat("rpc2xfid %.8lux %.8lux %p %p\n", *((uint32_t*)argptr),
-	     *((uint32_t*)argptr+1), buf, argptr);
-	if(argptr[0] == 0 && argptr[1] == 0){	/* root */
-		chat("root...");
-		xp = xfroot(&argptr[2], 0);
-		s = xp ? xp->s : 0;
-	}else{
-		uint32_t ul;
-		chat("noroot %.8lux...", *((uint32_t*)argptr));
-		if((ul=GLONG()) != starttime){
-			chat("bad tag %lux %lux...", ul, starttime);
-			return 0;
-		}
-		s = (Session *)(int64_t)GLONG();
-		x1 = GLONG();
-		x2 = GLONG();
-		qid.path = x1 | (x2<<32);
-		qid.vers = 0;
-		qid.type = GBYTE();
-		xp = xfile(&qid, s, 0);
-	}
-	if(xp == 0){
-		chat("no xfile...");
-		return 0;
-	}
-	if(auth2unix(&cmd->cred, &au) != 0){
-		chat("auth flavor=%ld, count=%ld\n",
-			cmd->cred.flavor, cmd->cred.count);
-		for(i=0; i<cmd->cred.count; i++)
-			chat(" %.2ux", ((uint8_t *)cmd->cred.data)[i]);
-		chat("...");
-		return 0;
-	}else{
-/*		chat("auth: %d %.*s u=%d g=%d",
- *			au.stamp, utfnlen(au.mach.s, au.mach.n), au.mach.s, au.uid, au.gid);
- *		for(i=0; i<au.gidlen; i++)
- *			chat(", %d", au.gids[i]);
- *		chat("...");
- */
-		char *p = memchr(au.mach.s, '.', au.mach.n);
-		chat("%ld@%.*s...", au.uid, utfnlen(au.mach.s, (p ? p-au.mach.s : au.mach.n)), au.mach.s);
-	}
-	if(au.mach.n >= sizeof client){
-		chat("client name too int32_t...");
-		return 0;
-	}
-	memcpy(client, au.mach.s, au.mach.n);
-	client[au.mach.n] = 0;
-	service = xp->parent->s->service;
-	cmd->up = m = pair2idmap(service, cmd->host);
-	if(m == 0){
-		chat("no map for pair (%s,%s)...", service, client);
-		/*chat("getdom %d.%d.%d.%d", cmd->host&0xFF, (cmd->host>>8)&0xFF,
-			(cmd->host>>16)&0xFF, (cmd->host>>24)&0xFF);*/
-		/*if(getdom(cmd->host, client, sizeof(client))<0)
-			return 0;*/
-		return 0;
-	}
-	/*chat("map=(%s,%s)...", m->server, m->client);*/
-	cmd->user = user = id2name(&m->u.ids, au.uid);
-	if(user == 0){
-		chat("no user for id %ld...", au.uid);
-		return 0;
-	}
-	chat("user=%s...", user);/**/
-	xf = 0;
-	if(s == xp->parent->s){
-		if(!s->noauth)
-			xf = setuser(xp, user);
-		if(xf == 0)
-			xf = setuser(xp, "none");
-		if(xf == 0)
-			chat("can't set user none...");
-	}else
-		xf = xp->users;
-	if(xf)
-		chat("uid=%s...", xf->uid);
-	if(xf && dp && xfstat(xf, dp) < 0){
-		chat("can't stat %s...", xp->name);
-		return 0;
-	}
-	return xf;
-}
-
-Xfid *
-setuser(Xfile *xp, char *user)
-{
-	Xfid *xf, *xpf;
-	Session *s;
-
-	xf = xfid(user, xp, 1);
-	if(xf->urfid)
-		return xf;
-	if(xp->parent==xp || !(xpf = setuser(xp->parent, user))) /* assign = */
-		return xfid(user, xp, -1);
-	s = xp->s;
-	xf->urfid = newfid(s);
-	xf->urfid->owner = &xf->urfid;
-	setfid(s, xpf->urfid);
-	s->f.newfid = xf->urfid - s->fids;
-	s->f.nwname = 1;
-	s->f.wname[0] = xp->name;
-	if(xmesg(s, Twalk) || s->f.nwqid != 1)
-		return xfid(user, xp, -1);
-	return xf;
-}
-
-int
-xfstat(Xfid *xf, Dir *dp)
-{
-	Xfile *xp;
-	Session *s;
-	char buf[128];
-
-	xp = xf->xp;
-	s = xp->s;
-	if(s != xp->parent->s){
-		seprint(buf, buf+sizeof buf, "#%s", xf->uid);
-		dp->name = strstore(buf);
-		dp->uid = xf->uid;
-		dp->gid = xf->uid;
-		dp->muid = xf->uid;
-		dp->qid.path = (uint64_t)xf->uid;
-		dp->qid.type = QTFILE;
-		dp->qid.vers = 0;
-		dp->mode = 0666;
-		dp->atime = time(0);
-		dp->mtime = dp->atime;
-		dp->length = NETCHLEN;
-		dp->type = 0;
-		dp->type = 0;
-		return 0;
-	}
-	setfid(s, xf->urfid);
-	if(xmesg(s, Tstat) == 0){
-		convM2D(s->f.stat, s->f.nstat, dp, (char*)s->statbuf);
-		if(xp->qid.path == dp->qid.path){
-			xp->name = strstore(dp->name);
-			return 0;
-		}
-		/* not reached ? */
-		chat("xp->qid.path=0x%.16llux, dp->qid.path=0x%.16llux name=%s...",
-			xp->qid.path, dp->qid.path, dp->name);
-	}
-	if(xp != xp->parent)
-		xpclear(xp);
-	else
-		clog("can't stat root: %s",
-			s->f.type == Rerror ? s->f.ename : "??");
-	return -1;
-}
-
-int
-xfwstat(Xfid *xf, Dir *dp)
-{
-	Xfile *xp;
-	Session *s;
-
-	xp = xf->xp;
-	s = xp->s;
-
-	/*
-	 * xf->urfid can be zero because some DOS NFS clients
-	 * try to do wstat on the #user authentication files on close.
-	 */
-	if(s == 0 || xf->urfid == 0)
-		return -1;
-	setfid(s, xf->urfid);
-	s->f.stat = s->statbuf;
-	convD2M(dp, s->f.stat, Maxstatdata);
-	if(xmesg(s, Twstat))
-		return -1;
-	xp->name = strstore(dp->name);
-	return 0;
-}
-
-int
-xfopen(Xfid *xf, int flag)
-{
-	static int modes[] = {
-		[Oread] OREAD, [Owrite] OWRITE, [Oread|Owrite] ORDWR,
-	};
-	Xfile *xp;
-	Session *s;
-	Fid *opfid;
-	int omode;
-
-	if(xf->opfid && (xf->mode & flag & Open) == flag)
-		return 0;
-	omode = modes[(xf->mode|flag) & Open];
-	if(flag & Trunc)
-		omode |= OTRUNC;
-	xp = xf->xp;
-	chat("open(\"%s\", %d)...", xp->name, omode);
-	s = xp->s;
-	opfid = newfid(s);
-	setfid(s, xf->urfid);
-	s->f.newfid = opfid - s->fids;
-	s->f.nwname = 0;
-	if(xmesg(s, Twalk)){
-		putfid(s, opfid);
-		return -1;
-	}
-	setfid(s, opfid);
-	s->f.mode = omode;
-	if(xmesg(s, Topen)){
-		clunkfid(s, opfid);
-		return -1;
-	}
-	if(xf->opfid)
-		clunkfid(s, xf->opfid);
-	xf->mode |= flag & Open;
-	xf->opfid = opfid;
-	opfid->owner = &xf->opfid;
-	xf->offset = 0;
-	return 0;
-}
-
-void
-xfclose(Xfid *xf)
-{
-	Xfile *xp;
-
-	if(xf->mode & Open){
-		xp = xf->xp;
-		chat("close(\"%s\")...", xp->name);
-		if(xf->opfid)
-			clunkfid(xp->s, xf->opfid);
-		xf->mode &= ~Open;
-		xf->opfid = 0;
-	}
-}
-
-void
-xfclear(Xfid *xf)
-{
-	Xfile *xp = xf->xp;
-
-	if(xf->opfid){
-		clunkfid(xp->s, xf->opfid);
-		xf->opfid = 0;
-	}
-	if(xf->urfid){
-		clunkfid(xp->s, xf->urfid);
-		xf->urfid = 0;
-	}
-	xfid(xf->uid, xp, -1);
-}
-
-Xfid *
-xfwalkcr(int type, Xfid *xf, String *elem, int32_t perm)
-{
-	Session *s;
-	Xfile *xp, *newxp;
-	Xfid *newxf;
-	Fid *nfid;
-
-	chat("xf%s(\"%s\")...", type==Tcreate ? "create" : "walk", elem->s);
-	xp = xf->xp;
-	s = xp->s;
-	nfid = newfid(s);
-	setfid(s, xf->urfid);
-	s->f.newfid = nfid - s->fids;
-	if(type == Tcreate){
-		s->f.nwname = 0;
-		if(xmesg(s, Twalk)){
-			putfid(s, nfid);
-			return 0;
-		}
-		s->f.fid = nfid - s->fids;
-	}
-	if(type == Tcreate){
-		s->f.name = elem->s;
-		s->f.perm = perm;
-		s->f.mode = (perm&DMDIR) ? OREAD : ORDWR;
-		if(xmesg(s, type)){
-			clunkfid(s, nfid);
-			return 0;
-		}
-	}else{	/* Twalk */
-		s->f.nwname = 1;
-		s->f.wname[0] = elem->s;
-		if(xmesg(s, type) || s->f.nwqid!=1){
-			putfid(s, nfid);
-			return 0;
-		}
-		s->f.qid = s->f.wqid[0];	/* only one element */
-	}
-	chat("fid=%d,qid=0x%llux,%ld,%.2ux...", s->f.fid, s->f.qid.path, s->f.qid.vers, s->f.qid.type);
-	newxp = xfile(&s->f.qid, s, 1);
-	if(newxp->parent == 0){
-		chat("new xfile...");
-		newxp->parent = xp;
-		newxp->sib = xp->child;
-		xp->child = newxp;
-	}
-	newxf = xfid(xf->uid, newxp, 1);
-	if(type == Tcreate){
-		newxf->mode = (perm&DMDIR) ? Oread : (Oread|Owrite);
-		newxf->opfid = nfid;
-		nfid->owner = &newxf->opfid;
-		nfid = newfid(s);
-		setfid(s, xf->urfid);
-		s->f.newfid = nfid - s->fids;
-		s->f.nwname = 1;
-		s->f.wname[0] = elem->s;
-		if(xmesg(s, Twalk) || s->f.nwqid!=1){
-			putfid(s, nfid);
-			xpclear(newxp);
-			return 0;
-		}
-		newxf->urfid = nfid;
-		nfid->owner = &newxf->urfid;
-	}else if(newxf->urfid){
-		chat("old xfid %ld...", newxf->urfid-s->fids);
-		clunkfid(s, nfid);
-	}else{
-		newxf->urfid = nfid;
-		nfid->owner = &newxf->urfid;
-	}
-	newxp->name = strstore(elem->s);
-	return newxf;
-}
-
-void
-xpclear(Xfile *xp)
-{
-	Session *s;
-	Xfid *xf;
-	Xfile *xnp;
-
-	s = xp->s;
-	while(xf = xp->users)	/* assign = */
-		xfclear(xf);
-	while(xnp = xp->child){	/* assign = */
-		xp->child = xnp->sib;
-		xnp->parent = 0;
-		xpclear(xnp);
-		xfile(&xnp->qid, s, -1);
-	}
-	if(xnp = xp->parent){	/* assign = */
-		if(xnp->child == xp)
-			xnp->child = xp->sib;
-		else{
-			xnp = xnp->child;
-			while(xnp->sib != xp)
-				xnp = xnp->sib;
-			xnp->sib = xp->sib;
-		}
-		xfile(&xp->qid, s, -1);
-	}
-}
-
-int
-xp2fhandle(Xfile *xp, Fhandle fh)
-{
-	unsigned char *dataptr = fh;
-	uint32_t x;
-	int n;
-
-	memset(fh, 0, FHSIZE);
-	if(xp == xp->parent){	/* root */
-		dataptr[0] = 0;
-		dataptr[1] = 0;
-		n = strlen(xp->s->service);
-		if(n > FHSIZE-3)
-			n = FHSIZE-3;
-		memmove(&dataptr[2], xp->s->service, n);
-		dataptr[2+n] = 0;
-	}else{
-		PLONG(starttime);
-		PLONG((uint32_t)(uintptr)xp->s);
-		x = xp->qid.path;
-		PLONG(x);
-		x = xp->qid.path>>32;
-		PLONG(x);
-		PBYTE(xp->qid.type);
-		USED(dataptr);
-	}
-	return FHSIZE;
-}
-
-int
-dir2fattr(Unixidmap *up, Dir *dp, void *mp)
-{
-	uint8_t *dataptr = mp;
-	int32_t length;
-	int r;
-
-	r = dp->mode & 0777;
-	if (dp->mode & DMDIR)
-		length = 1024;
-	else
-		length = dp->length;
-	if((dp->mode & DMDIR) && dp->type == '/' && dp->dev == 0)
-		r |= 0555;
-	if(dp->mode & DMDIR){
-		PLONG(NFDIR);	/* type */
-		r |= S_IFDIR;
-		PLONG(r);	/* mode */
-		PLONG(3);	/* nlink */
-	}else{
-		PLONG(NFREG);	/* type */
-		r |= S_IFREG;
-		PLONG(r);	/* mode */
-		PLONG(1);	/* nlink */
-	}
-	r = name2id(&up->u.ids, dp->uid);
-	if(r < 0){
-		r = name2id(&up->u.ids, "daemon");
-		if(r < 0)
-			r = 1;
-	}
-	PLONG(r);		/* uid */
-	r = name2id(&up->g.ids, dp->gid);
-	if(r < 0){
-		r = name2id(&up->g.ids, "user");
-		if(r < 0)
-			r = 1;
-	}
-	PLONG(r);		/* gid */
-	PLONG(length);		/* size */
-	PLONG(2048);		/* blocksize */
-	PLONG(0);		/* rdev */
-	r = (length+2047)/2048;
-	PLONG(r);		/* blocks */
-	r = (dp->type<<16) | dp->dev;
-	PLONG(r);		/* fsid */
-	PLONG(dp->qid.path);	/* fileid */
-	PLONG(dp->atime);	/* atime */
-	PLONG(0);
-	PLONG(dp->mtime);	/* mtime */
-	PLONG(0);
-	PLONG(dp->mtime);	/* ctime */
-	PLONG(0);
-	return dataptr - (uint8_t *)mp;
-}
-
-int
-convM2sattr(void *mp, Sattr *sp)
-{
-	uint8_t *argptr = mp;
-
-	sp->mode = GLONG();
-	sp->uid = GLONG();
-	sp->gid = GLONG();
-	sp->size = GLONG();
-	sp->atime = GLONG();
-	sp->ausec = GLONG();
-	sp->mtime = GLONG();
-	sp->musec = GLONG();
-	return argptr - (uint8_t *)mp;
-}

+ 0 - 53
sys/src/cmd/9nfs/nfs.h

@@ -1,53 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-/*
- *	Cf. /lib/rfc/rfc1094
- */
-
-enum NFS_stat
-{
-	NFS_OK		= 0,
-	NFSERR_PERM	= 1,
-	NFSERR_NOENT	= 2,
-	NFSERR_IO	= 5,
-	NFSERR_NXIO	= 6,
-	NFSERR_ACCES	= 13,
-	NFSERR_EXIST	= 17,
-	NFSERR_NODEV	= 19,
-	NFSERR_NOTDIR	= 20,
-	NFSERR_ISDIR	= 21,
-	NFSERR_FBIG	= 27,
-	NFSERR_NOSPC	= 28,
-	NFSERR_ROFS	= 30,
-	NFSERR_NAMETOOLONG	= 63,
-	NFSERR_NOTEMPTY	= 66,
-	NFSERR_DQUOT	= 69,
-	NFSERR_STALE	= 70,
-	NFSERR_WFLUSH	= 99
-};
-
-enum NFS_ftype
-{
-	NFNON	= 0,
-	NFREG	= 1,
-	NFDIR	= 2,
-	NFBLK	= 3,
-	NFCHR	= 4,
-	NFLNK	= 5
-};
-
-enum NFS_mode
-{
-	S_IFMT	= 0170000,	/* mask */
-	S_IFDIR	= 0040000,	/* directory */
-	S_IFREG	= 0100000	/* regular */
-};
-
-#define	NOATTR	0xffffffff

+ 0 - 343
sys/src/cmd/9nfs/nfsmount.c

@@ -1,343 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-/*
- *	Cf. /lib/rfc/rfc1094
- */
-
-static int	mntnull(int, Rpccall*, Rpccall*);
-static int	mntmnt(int, Rpccall*, Rpccall*);
-static int	mntdump(int, Rpccall*, Rpccall*);
-static int	mntumnt(int, Rpccall*, Rpccall*);
-static int	mntumntall(int, Rpccall*, Rpccall*);
-static int	mntexport(int, Rpccall*, Rpccall*);
-
-Procmap mntproc[] = {
-	0, mntnull,
-	1, mntmnt,
-	2, mntdump,
-	3, mntumnt,
-	4, mntumntall,
-	5, mntexport,
-	0, 0
-};
-
-int32_t		starttime;
-static int	noauth;
-char *		config;
-Session *	head;
-Session *	tail;
-int staletime = 10*60;
-
-void
-mnttimer(int32_t now)
-{
-	Session *s;
-
-	for(s=head; s; s=s->next)
-		fidtimer(s, now);
-}
-
-static void
-usage(void)
-{
-	sysfatal("usage: %s %s [-ns] [-a dialstring] [-c uidmap] [-f srvfile] "
-		"[-T staletime]", argv0, commonopts);
-}
-
-void
-mntinit(int argc, char **argv)
-{
-	int tries;
-
-	config = "config";
-	starttime = time(0);
-	clog("nfs mount server init, starttime = %lud\n", starttime);
-	tries = 0;
-	ARGBEGIN{
-	case 'a':
-		++tries;
-		srvinit(-1, 0, EARGF(usage()));
-		break;
-	case 'c':
-		config = EARGF(usage());
-		break;
-	case 'f':
-		++tries;
-		srvinit(-1, EARGF(usage()), 0);
-		break;
-	case 'n':
-		++noauth;
-		break;
-	case 's':
-		++tries;
-		srvinit(1, 0, 0);
-		break;
-	case 'T':
-		staletime = atoi(EARGF(usage()));
-		break;
-	default:
-		if(argopt(ARGC()) < 0)
-			sysfatal("usage: %s %s [-ns] [-a dialstring] "
-				"[-c uidmap] [-f srvfile] [-T staletime]",
-				argv0, commonopts);
-		break;
-	}ARGEND
-noauth=1;	/* ZZZ */
-	if(tries == 0 && head == 0)
-		srvinit(-1, 0, "tcp!fs");
-	if(head == 0)
-		panic("can't initialize services");
-	readunixidmaps(config);
-}
-
-void
-srvinit(int fd, char *file, char *addr)
-{
-	char fdservice[16], *naddr;
-	Session *s;
-	Xfile *xp;
-	Xfid *xf;
-	Fid *f;
-
-	s = calloc(1, sizeof(Session));
-	s->spec = "";
-	s->fd = -1;
-	if(fd >= 0){
-		s->fd = fd;
-		sprint(fdservice, "/fd/%d", s->fd);
-		s->service = strstore(fdservice);
-		chat("fd = %d\n", s->fd);
-	}else if(file){
-		chat("file = \"%s\"\n", file);
-		s->service = file;
-		s->fd = open(file, ORDWR);
-		if(s->fd < 0){
-			clog("can't open %s: %r\n", file);
-			goto error;
-		}
-	}else if(addr){
-		chat("addr = \"%s\"\n", addr);
-		naddr = netmkaddr(addr, 0, "9fs");
-		s->service = addr;
-		s->fd = dial(naddr, 0, 0, 0);
-		if(s->fd < 0){
-			clog("can't dial %s: %r\n", naddr);
-			goto error;
-		}
-	}
-
-	chat("version...");
-	s->tag = NOTAG-1;
-	s->f.msize = Maxfdata+IOHDRSZ;
-	s->f.version = "9P2000";
-	xmesg(s, Tversion);
-	messagesize = IOHDRSZ+s->f.msize;
-	chat("version spec %s size %d\n", s->f.version, s->f.msize);
-
-	s->tag = 0;
-
-	chat("authenticate...");
-	if(authhostowner(s) < 0){
-		clog("auth failed %r\n");
-		goto error;
-	}
-
-	chat("attach as none...");
-	f = newfid(s);
-	s->f.fid = f - s->fids;
-	s->f.afid = (int64_t)~0x0UL;
-	s->f.uname = "none";
-	s->f.aname = s->spec;
-	if(xmesg(s, Tattach)){
-		clog("attach failed\n");
-		goto error;
-	}
-
-	xp = xfile(&s->f.qid, s, 1);
-	s->root = xp;
-	xp->parent = xp;
-	xp->name = "/";
-	xf = xfid("none", xp, 1);
-	xf->urfid = f;
-	clog("service=%s uid=%s fid=%ld\n",
-		s->service, xf->uid, xf->urfid - s->fids);
-	if(tail)
-		tail->next = s;
-	else
-		head = s;
-	tail = s;
-	return;
-
-error:
-	if(s->fd >= 0)
-		close(s->fd);
-	free(s);
-}
-
-static int
-mntnull(int n, Rpccall *cmd, Rpccall *reply)
-{
-	USED(n); USED(cmd); USED(reply);
-	chat("mntnull\n");
-	return 0;
-}
-
-/*
-static char*
-Str2str(String s, char *buf, int nbuf)
-{
-	int i;
-	i = s.n;
-	if(i >= nbuf)
-		i = nbuf-1;
-	memmove(buf, s.s, i);
-	buf[i] = 0;
-	return buf;
-}
-*/
-static int
-mntmnt(int n, Rpccall *cmd, Rpccall *reply)
-{
-	int i;
-	char dom[64];
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-	Authunix au;
-	Xfile *xp;
-	String root;
-
-	chat("mntmnt...\n");
-	if(n < 8)
-		return garbage(reply, "n too small");
-	argptr += string2S(argptr, &root);
-	if(argptr != &((uint8_t *)cmd->args)[n])
-		return garbage(reply, "bad count");
-	clog("host=%I, port=%ld, root=\"%.*s\"...",
-		cmd->host, cmd->port, utfnlen(root.s, root.n), root.s);
-	if(auth2unix(&cmd->cred, &au) != 0){
-		chat("auth flavor=%ld, count=%ld\n",
-			cmd->cred.flavor, cmd->cred.count);
-		for(i=0; i<cmd->cred.count; i++)
-			chat(" %.2ux", ((uint8_t *)cmd->cred.data)[i]);
-		chat("\n");
-		clog("auth: bad credentials");
-		return error(reply, 1);
-	}
-	clog("auth: %ld %.*s u=%ld g=%ld",
-		au.stamp, utfnlen(au.mach.s, au.mach.n), au.mach.s, au.uid, au.gid);
-	for(i=0; i<au.gidlen; i++)
-		chat(", %ld", au.gids[i]);
-	chat("...");
-	if(getdom(cmd->host, dom, sizeof(dom))<0){
-		clog("auth: unknown ip address");
-		return error(reply, 1);
-	}
-	chat("dom=%s...", dom);
-	xp = xfroot(root.s, root.n);
-	if(xp == 0){
-		chat("xp=0...");
-		clog("mntmnt: no fs");
-		return error(reply, 3);
-	}
-
-	PLONG(0);
-	dataptr += xp2fhandle(xp, dataptr);
-	chat("OK\n");
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-mntdump(int n, Rpccall *cmd, Rpccall *reply)
-{
-	if(n != 0)
-		return garbage(reply, "mntdump");
-	USED(cmd);
-	chat("mntdump...");
-	return error(reply, FALSE);
-}
-
-static int
-mntumnt(int n, Rpccall *cmd, Rpccall *reply)
-{
-	if(n <= 0)
-		return garbage(reply, "mntumnt");
-	USED(cmd);
-	chat("mntumnt\n");
-	return 0;
-}
-
-static int
-mntumntall(int n, Rpccall *cmd, Rpccall *reply)
-{
-	if(n != 0)
-		return garbage(reply, "mntumntall");
-	USED(cmd);
-	chat("mntumntall\n");
-	return 0;
-}
-
-static int
-mntexport(int n, Rpccall *cmd, Rpccall *reply)
-{
-	uint8_t *dataptr = reply->results;
-	Authunix au;
-	int i;
-
-	chat("mntexport...");
-	if(n != 0)
-		return garbage(reply, "mntexport");
-	if(auth2unix(&cmd->cred, &au) != 0){
-		chat("auth flavor=%ld, count=%ld\n",
-			cmd->cred.flavor, cmd->cred.count);
-		for(i=0; i<cmd->cred.count; i++)
-			chat(" %.2ux", ((uint8_t *)cmd->cred.data)[i]);
-		chat("...");
-		au.mach.n = 0;
-	}else
-		chat("%ld@%.*s...", au.uid, utfnlen(au.mach.s, au.mach.n), au.mach.s);
-	PLONG(TRUE);
-	PLONG(1);
-	PPTR("/", 1);
-	if(au.mach.n > 0){
-		PLONG(TRUE);
-		PLONG(au.mach.n);
-		PPTR(au.mach.s, au.mach.n);
-	}
-	PLONG(FALSE);
-	PLONG(FALSE);
-	chat("OK\n");
-	return dataptr - (uint8_t *)reply->results;
-}
-
-Xfile *
-xfroot(char *name, int n)
-{
-	Session *s;
-	char *p;
-
-	if(n <= 0)
-		n = strlen(name);
-	chat("xfroot: %.*s...", utfnlen(name, n), name);
-	if(n == 1 && name[0] == '/')
-		return head->root;
-	for(s=head; s; s=s->next){
-		if(strncmp(name, s->service, n) == 0)
-			return s->root;
-		p = strrchr(s->service, '!');	/* for -a tcp!foo */
-		if(p && strncmp(name, p+1, n) == 0)
-			return s->root;
-		p = strrchr(s->service, '/');	/* for -f /srv/foo */
-		if(p && strncmp(name, p+1, n) == 0)
-			return s->root;
-	}
-	return 0;
-}

+ 0 - 665
sys/src/cmd/9nfs/nfsserver.c

@@ -1,665 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-/*
- *	Cf. /lib/rfc/rfc1094
- */
-
-static int	nfsnull(int, Rpccall*, Rpccall*);
-static int	nfsgetattr(int, Rpccall*, Rpccall*);
-static int	nfssetattr(int, Rpccall*, Rpccall*);
-static int	nfsroot(int, Rpccall*, Rpccall*);
-static int	nfslookup(int, Rpccall*, Rpccall*);
-static int	nfsreadlink(int, Rpccall*, Rpccall*);
-static int	nfsread(int, Rpccall*, Rpccall*);
-static int	nfswritecache(int, Rpccall*, Rpccall*);
-static int	nfswrite(int, Rpccall*, Rpccall*);
-static int	nfscreate(int, Rpccall*, Rpccall*);
-static int	nfsremove(int, Rpccall*, Rpccall*);
-static int	nfsrename(int, Rpccall*, Rpccall*);
-static int	nfslink(int, Rpccall*, Rpccall*);
-static int	nfssymlink(int, Rpccall*, Rpccall*);
-static int	nfsmkdir(int, Rpccall*, Rpccall*);
-static int	nfsrmdir(int, Rpccall*, Rpccall*);
-static int	nfsreaddir(int, Rpccall*, Rpccall*);
-static int	nfsstatfs(int, Rpccall*, Rpccall*);
-
-Procmap nfsproc[] = {
-	0, nfsnull,	/* void */
-	1, nfsgetattr,	/* Fhandle */
-	2, nfssetattr,	/* Fhandle, Sattr */
-	3, nfsroot,	/* void */
-	4, nfslookup,	/* Fhandle, String */
-	5, nfsreadlink,	/* Fhandle */
-	6, nfsread,	/* Fhandle, int32_t, int32_t, int32_t */
-	7, nfswritecache,/* void */
-	8, nfswrite,	/* Fhandle, int32_t, int32_t, int32_t, String */
-	9, nfscreate,	/* Fhandle, String, Sattr */
-	10, nfsremove,	/* Fhandle, String */
-	11, nfsrename,	/* Fhandle, String, Fhandle, String */
-	12, nfslink,	/* Fhandle, Fhandle, String */
-	13, nfssymlink,	/* Fhandle, String, String, Sattr */
-	14, nfsmkdir,	/* Fhandle, String, Sattr */
-	15, nfsrmdir,	/* Fhandle, String */
-	16, nfsreaddir,	/* Fhandle, int32_t, int32_t */
-	17, nfsstatfs,	/* Fhandle */
-	0, 0
-};
-
-void	nfsinit(int, char**);
-extern void	mntinit(int, char**);
-extern Procmap	mntproc[];
-
-Progmap progmap[] = {
-	100005, 1, mntinit, mntproc,
-	100003, 2, nfsinit, nfsproc,
-	0, 0, 0,
-};
-
-int	myport = 2049;
-int32_t	nfstime;
-int	conftime;
-
-void
-main(int argc, char *argv[])
-{
-	server(argc, argv, myport, progmap);
-}
-
-static void
-doalarm(void)
-{
-	nfstime = time(0);
-	mnttimer(nfstime);
-	if(conftime+5*60 < nfstime){
-		conftime = nfstime;
-		readunixidmaps(config);
-	}
-}
-
-void
-nfsinit(int argc, char **argv)
-{
-	/*
-	 * mntinit will have already parsed our options.
-	 */
-	USED(argc); USED(argv);
-	clog("nfs file server init\n");
-	rpcalarm = doalarm;
-	nfstime = time(0);
-}
-
-static int
-nfsnull(int n, Rpccall *cmd, Rpccall *reply)
-{
-	USED(n); USED(reply);
-	chat("nfsnull...");
-	showauth(&cmd->cred);
-	chat("OK\n");
-	return 0;
-}
-
-static int
-nfsgetattr(int n, Rpccall *cmd, Rpccall *reply)
-{
-	Xfid *xf;
-	Dir dir;
-	uint8_t *dataptr = reply->results;
-
-	chat("getattr...");
-	if(n != FHSIZE)
-		return garbage(reply, "bad count");
-	xf = rpc2xfid(cmd, &dir);
-	if(xf == 0)
-		return error(reply, NFSERR_STALE);
-	chat("%s...", xf->xp->name);
-	PLONG(NFS_OK);
-	dataptr += dir2fattr(cmd->up, &dir, dataptr);
-	chat("OK\n");
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-nfssetattr(int n, Rpccall *cmd, Rpccall *reply)
-{
-	Xfid *xf;
-	Dir dir, nd;
-	Sattr sattr;
-	int r;
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-
-	chat("setattr...");
-	if(n <= FHSIZE)
-		return garbage(reply, "count too small");
-	xf = rpc2xfid(cmd, &dir);
-	argptr += FHSIZE;
-	argptr += convM2sattr(argptr, &sattr);
-	if(argptr != &((uint8_t *)cmd->args)[n])
-		return garbage(reply, "bad count");
-	chat("mode=0%lo,u=%ld,g=%ld,size=%ld,atime=%ld,mtime=%ld...",
-		sattr.mode, sattr.uid, sattr.gid, sattr.size,
-		sattr.atime, sattr.mtime);
-	if(xf == 0)
-		return error(reply, NFSERR_STALE);
-	if(sattr.uid != NOATTR || sattr.gid != NOATTR)
-		return error(reply, NFSERR_PERM);
-	if(sattr.size == 0){
-		if(xf->xp->s != xf->xp->parent->s){
-			if(xfauthremove(xf, cmd->user) < 0)
-				return error(reply, NFSERR_PERM);
-		}else if(dir.length && xfopen(xf, Trunc|Oread|Owrite) < 0)
-			return error(reply, NFSERR_PERM);
-	}else if(sattr.size != NOATTR)
-		return error(reply, NFSERR_PERM);
-	r = 0;
-	nulldir(&nd);
-	if(sattr.mode != NOATTR)
-		++r, nd.mode = (dir.mode & ~0777) | (sattr.mode & 0777);
-	if(sattr.atime != NOATTR)
-		++r, nd.atime = sattr.atime;
-	if(sattr.mtime != NOATTR)
-		++r, nd.mtime = sattr.mtime;
-	chat("sattr.mode=%luo dir.mode=%luo nd.mode=%luo...", sattr.mode, dir.mode, nd.mode);
-	if(r){
-		r = xfwstat(xf, &nd);
-		if(r < 0)
-			return error(reply, NFSERR_PERM);
-	}
-	if(xfstat(xf, &dir) < 0)
-		return error(reply, NFSERR_STALE);
-	PLONG(NFS_OK);
-	dataptr += dir2fattr(cmd->up, &dir, dataptr);
-	chat("OK\n");
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-nfsroot(int n, Rpccall *cmd, Rpccall *reply)
-{
-	USED(n); USED(reply);
-	chat("nfsroot...");
-	showauth(&cmd->cred);
-	chat("OK\n");
-	return 0;
-}
-
-static int
-nfslookup(int n, Rpccall *cmd, Rpccall *reply)
-{
-	Xfile *xp;
-	Xfid *xf, *newxf;
-	String elem;
-	Dir dir;
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-
-	chat("lookup...");
-	if(n <= FHSIZE)
-		return garbage(reply, "count too small");
-	xf = rpc2xfid(cmd, 0);
-	argptr += FHSIZE;
-	argptr += string2S(argptr, &elem);
-	if(argptr != &((uint8_t *)cmd->args)[n])
-		return garbage(reply, "bad count");
-	if(xf == 0)
-		return error(reply, NFSERR_STALE);
-	xp = xf->xp;
-	if(!(xp->qid.type & QTDIR))
-		return error(reply, NFSERR_NOTDIR);
-	chat("%s -> \"%.*s\"...", xp->name, utfnlen(elem.s, elem.n), elem.s);
-	if(xp->s->noauth == 0 && xp->parent == xp && elem.s[0] == '#')
-		newxf = xfauth(xp, &elem);
-	else
-		newxf = xfwalkcr(Twalk, xf, &elem, 0);
-	if(newxf == 0)
-		return error(reply, NFSERR_NOENT);
-	if(xfstat(newxf, &dir) < 0)
-		return error(reply, NFSERR_IO);
-	PLONG(NFS_OK);
-	dataptr += xp2fhandle(newxf->xp, dataptr);
-	dataptr += dir2fattr(cmd->up, &dir, dataptr);
-	chat("OK\n");
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-nfsreadlink(int n, Rpccall *cmd, Rpccall *reply)
-{
-	USED(n); USED(reply);
-	chat("readlink...");
-	showauth(&cmd->cred);
-	return error(reply, NFSERR_NOENT);
-}
-
-static int
-nfsread(int n, Rpccall *cmd, Rpccall *reply)
-{
-	Session *s;
-	Xfid *xf;
-	Dir dir;
-	int offset, count;
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-	uint8_t *readptr = dataptr + 4 + 17*4 + 4;
-
-	chat("read...");
-	if(n != FHSIZE+12)
-		return garbage(reply, "bad count");
-	xf = rpc2xfid(cmd, 0);
-	argptr += FHSIZE;
-	offset = GLONG();
-	count = GLONG();
-	if(xf == 0)
-		return error(reply, NFSERR_STALE);
-	chat("%s %d %d...", xf->xp->name, offset, count);
-	if(xf->xp->s != xf->xp->parent->s){
-		count = xfauthread(xf, offset, readptr, count);
-	}else{
-		if(xfopen(xf, Oread) < 0)
-			return error(reply, NFSERR_PERM);
-		if(count > 8192)
-			count = 8192;
-		s = xf->xp->s;
-		setfid(s, xf->opfid);
-		xf->opfid->tstale = nfstime + 60;
-		s->f.offset = offset;
-		s->f.count = count;
-		if(xmesg(s, Tread) < 0)
-			return error(reply, NFSERR_IO);
-		count = s->f.count;
-		memmove(readptr, s->f.data, count);
-	}
-	if(xfstat(xf, &dir) < 0)
-		return error(reply, NFSERR_IO);
-	PLONG(NFS_OK);
-	dataptr += dir2fattr(cmd->up, &dir, dataptr);
-	PLONG(count);
-	dataptr += ROUNDUP(count);
-	chat("%d OK\n", count);
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-nfswritecache(int n, Rpccall *cmd, Rpccall *reply)
-{
-	USED(n); USED(reply);
-	chat("writecache...");
-	showauth(&cmd->cred);
-	chat("OK\n");
-	return 0;
-}
-
-static int
-nfswrite(int n, Rpccall *cmd, Rpccall *reply)
-{
-	Session *s;
-	Xfid *xf;
-	Dir dir;
-	int offset, count;
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-
-	chat("write...");
-	if(n < FHSIZE+16)
-		return garbage(reply, "count too small");
-	xf = rpc2xfid(cmd, 0);
-	argptr += FHSIZE + 4;
-	offset = GLONG();
-	argptr += 4;
-	count = GLONG();
-	if(xf == 0)
-		return error(reply, NFSERR_STALE);
-	chat("%s %d %d...", xf->xp->name, offset, count);
-	if(xf->xp->s != xf->xp->parent->s){
-		if(xfauthwrite(xf, offset, argptr, count) < 0)
-			return error(reply, NFSERR_IO);
-	}else{
-		if(xfopen(xf, Owrite) < 0)
-			return error(reply, NFSERR_PERM);
-		s = xf->xp->s;
-		setfid(s, xf->opfid);
-		xf->opfid->tstale = nfstime + 60;
-		s->f.offset = offset;
-		s->f.count = count;
-		s->f.data = (char *)argptr;
-		if(xmesg(s, Twrite) < 0)
-			return error(reply, NFSERR_IO);
-	}
-	if(xfstat(xf, &dir) < 0)
-		return error(reply, NFSERR_IO);
-	PLONG(NFS_OK);
-	dataptr += dir2fattr(cmd->up, &dir, dataptr);
-	chat("OK\n");
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-creat(int n, Rpccall *cmd, Rpccall *reply, int chdir)
-{
-	Xfid *xf, *newxf;
-	Xfile *xp;
-	String elem;
-	Dir dir; Sattr sattr;
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-	int trunced;
-
-	if(n <= FHSIZE)
-		return garbage(reply, "count too small");
-	xf = rpc2xfid(cmd, 0);
-	argptr += FHSIZE;
-	argptr += string2S(argptr, &elem);
-	argptr += convM2sattr(argptr, &sattr);
-	if(argptr != &((uint8_t *)cmd->args)[n])
-		return garbage(reply, "bad count");
-	if(xf == 0)
-		return error(reply, NFSERR_STALE);
-	xp = xf->xp;
-	if(!(xp->qid.type & QTDIR))
-		return error(reply, NFSERR_NOTDIR);
-	chat("%s/%.*s...", xp->name, utfnlen(elem.s, elem.n), elem.s);
-	trunced = 0;
-	if(xp->parent == xp && elem.s[0] == '#'){
-		newxf = xfauth(xp, &elem);
-		if(newxf == 0)
-			return error(reply, NFSERR_PERM);
-		if(xfauthremove(newxf, cmd->user) < 0)
-			return error(reply, NFSERR_PERM);
-		trunced = 1;
-	}else
-		newxf = xfwalkcr(Twalk, xf, &elem, 0);
-	if(newxf == 0){
-		newxf = xfwalkcr(Tcreate, xf, &elem, chdir|(sattr.mode&0777));
-		if(newxf)
-			trunced = 1;
-		else
-			newxf = xfwalkcr(Twalk, xf, &elem, 0);
-	}
-	if(newxf == 0)
-		return error(reply, NFSERR_PERM);
-	if(!trunced && chdir)
-		return error(reply, NFSERR_EXIST);
-	if(!trunced && xfopen(newxf, Trunc|Oread|Owrite) < 0)
-		return error(reply, NFSERR_PERM);
-	if(xfstat(newxf, &dir) < 0)
-		return error(reply, NFSERR_IO);
-
-	PLONG(NFS_OK);
-	dataptr += xp2fhandle(newxf->xp, dataptr);
-	dataptr += dir2fattr(cmd->up, &dir, dataptr);
-	chat("OK\n");
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-nfscreate(int n, Rpccall *cmd, Rpccall *reply)
-{
-	chat("create...");
-	return creat(n, cmd, reply, 0);
-}
-
-static int
-remov(int n, Rpccall *cmd, Rpccall *reply)
-{
-	Session *s;
-	Xfile *xp;
-	Xfid *xf, *newxf;
-	String elem;
-	Fid *nfid;
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-
-	if(n <= FHSIZE)
-		return garbage(reply, "count too small");
-	xf = rpc2xfid(cmd, 0);
-	argptr += FHSIZE;
-	argptr += string2S(argptr, &elem);
-	if(argptr != &((uint8_t *)cmd->args)[n])
-		return garbage(reply, "bad count");
-	if(xf == 0)
-		return error(reply, NFSERR_STALE);
-	xp = xf->xp;
-	if(!(xp->qid.type & QTDIR))
-		return error(reply, NFSERR_NOTDIR);
-	chat("%s/%.*s...", xp->name, utfnlen(elem.s, elem.n), elem.s);
-	if(xp->s->noauth == 0 && xp->parent == xp && elem.s[0] == '#')
-		return error(reply, NFSERR_PERM);
-	newxf = xfwalkcr(Twalk, xf, &elem, 0);
-	if(newxf == 0)
-		return error(reply, NFSERR_NOENT);
-	s = xp->s;
-	nfid = newfid(s);
-	setfid(s, newxf->urfid);
-	s->f.newfid = nfid - s->fids;
-	s->f.nwname = 0;
-	if(xmesg(s, Twalk) < 0){
-		putfid(s, nfid);
-		return error(reply, NFSERR_IO);
-	}
-	s->f.fid = nfid - s->fids;
-	if(xmesg(s, Tremove) < 0){
-		putfid(s, nfid);
-		return error(reply, NFSERR_PERM);
-	}
-	putfid(s, nfid);
-	xpclear(newxf->xp);
-	PLONG(NFS_OK);
-	chat("OK\n");
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-nfsremove(int n, Rpccall *cmd, Rpccall *reply)
-{
-	chat("remove...");
-	return remov(n, cmd, reply);
-}
-
-static int
-nfsrename(int n, Rpccall *cmd, Rpccall *reply)
-{
-	Xfid *xf, *newxf;
-	Xfile *xp;
-	uint8_t *fromdir, *todir;
-	String fromelem, toelem;
-	Dir dir;
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-
-	chat("rename...");
-	if(n <= FHSIZE)
-		return garbage(reply, "count too small");
-	xf = rpc2xfid(cmd, 0);
-	fromdir = argptr;
-	argptr += FHSIZE;
-	argptr += string2S(argptr, &fromelem);
-	todir = argptr;
-	argptr += FHSIZE;
-	argptr += string2S(argptr, &toelem);
-	if(argptr != &((uint8_t *)cmd->args)[n])
-		return garbage(reply, "bad count");
-	if(xf == 0)
-		return error(reply, NFSERR_STALE);
-	xp = xf->xp;
-	if(!(xp->qid.type & QTDIR))
-		return error(reply, NFSERR_NOTDIR);
-	if(memcmp(fromdir, todir, FHSIZE) != 0)
-		return error(reply, NFSERR_NXIO);
-	newxf = xfwalkcr(Twalk, xf, &fromelem, 0);
-	if(newxf == 0)
-		return error(reply, NFSERR_NOENT);
-	if(xfstat(newxf, &dir) < 0)
-		return error(reply, NFSERR_IO);
-
-	if(xp->parent == xp && toelem.s[0] == '#')
-		return error(reply, NFSERR_PERM);
-	nulldir(&dir);
-	dir.name = toelem.s;
-	if(xfwstat(newxf, &dir) < 0)
-		return error(reply, NFSERR_PERM);
-	PLONG(NFS_OK);
-	chat("OK\n");
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-nfslink(int n, Rpccall *cmd, Rpccall *reply)
-{
-	USED(n); USED(reply);
-	chat("link...");
-	showauth(&cmd->cred);
-	return error(reply, NFSERR_NOENT);
-}
-
-static int
-nfssymlink(int n, Rpccall *cmd, Rpccall *reply)
-{
-	USED(n); USED(reply);
-	chat("symlink...");
-	showauth(&cmd->cred);
-	return error(reply, NFSERR_NOENT);
-}
-
-static int
-nfsmkdir(int n, Rpccall *cmd, Rpccall *reply)
-{
-	chat("mkdir...");
-	return creat(n, cmd, reply, DMDIR);
-}
-
-static int
-nfsrmdir(int n, Rpccall *cmd, Rpccall *reply)
-{
-	chat("rmdir...");
-	return remov(n, cmd, reply);
-}
-
-static int
-nfsreaddir(int n, Rpccall *cmd, Rpccall *reply)
-{
-	Session *s;
-	Xfid *xf;
-	Dir dir;
-	char *rdata;
-	int k, offset, count, sfcount, entries, dsize;
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-
-	chat("readdir...");
-	if(n != FHSIZE+8)
-		return garbage(reply, "bad count");
-	xf = rpc2xfid(cmd, 0);
-	argptr += FHSIZE;
-	offset = GLONG();
-	count = GLONG();
-	if(xf == 0)
-		return error(reply, NFSERR_STALE);
-	chat("%s (%ld) %d %d...", xf->xp->name, xf->offset, offset, count);
-	s = xf->xp->s;
-	if((xf->mode & Open) && xf->offset > offset)
-		xfclose(xf);
-	if(xfopen(xf, Oread) < 0)
-		return error(reply, NFSERR_PERM);
-	while(xf->offset < offset){	/* if we reopened, xf->offset will be zero */
-		sfcount = offset - xf->offset;
-		if(sfcount > messagesize-IOHDRSZ)
-			sfcount = messagesize-IOHDRSZ;
-		setfid(s, xf->opfid);
-		s->f.offset = xf->offset;
-		s->f.count = sfcount;
-		if(xmesg(s, Tread) < 0){
-			xfclose(xf);
-			return error(reply, NFSERR_IO);
-		}
-		if(s->f.count <= BIT16SZ)
-			break;
-		xf->offset += s->f.count;
-	}
-	if(count > messagesize-IOHDRSZ)
-		count = messagesize-IOHDRSZ;
-	PLONG(NFS_OK);
-	entries = 0;
-	while(count > 16){	/* at least 16 bytes required; we don't know size of name */
-chat("top of loop\n");
-		setfid(s, xf->opfid);
-		s->f.offset = xf->offset;
-		s->f.count = count;	/* as good a guess as any */
-		if(xmesg(s, Tread) < 0){
-			xfclose(xf);
-			return error(reply, NFSERR_IO);
-		}
-		sfcount = s->f.count;
-		if(sfcount <= BIT16SZ)
-			break;
-		xf->offset += sfcount;
-chat("count %d data 0x%p\n", s->f.count, s->f.data);
-		rdata = s->f.data;
-		/* now have a buffer of Plan 9 directories; unpack into NFS thingies */
-		while(sfcount >= 0){
-			dsize = convM2D((uint8_t*)rdata, sfcount, &dir,
-					(char*)s->statbuf);
-			if(dsize <= BIT16SZ){
-				count = 0;	/* force break from outer loop */
-				break;
-			}
-			offset += dsize;
-			k = strlen(dir.name);
-			if(count < 16+ROUNDUP(k)){
-				count = 0;	/* force break from outer loop */
-				break;
-			}
-			PLONG(TRUE);
-			PLONG(dir.qid.path);
-			PLONG(k);
-			PPTR(dir.name, k);
-			PLONG(offset);
-			count -= 16+ROUNDUP(k);
-			rdata += dsize;
-			sfcount -= dsize;
-		}
-	}
-	PLONG(FALSE);
-	if(s->f.count <= 0){
-		xfclose(xf);
-		chat("eof...");
-		PLONG(TRUE);
-	}else
-		PLONG(FALSE);
-	chat("%d OK\n", entries);
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-nfsstatfs(int n, Rpccall *cmd, Rpccall *reply)
-{
-	uint8_t *dataptr = reply->results;
-	enum {
-		Xfersize = 2048,
-		Maxint32_t = (int32_t)((1ULL<<31) - 1),
-		Maxfreeblks = Maxint32_t / Xfersize,
-	};
-
-	chat("statfs...");
-	showauth(&cmd->cred);
-	if(n != FHSIZE)
-		return garbage(reply, "bad count");
-	PLONG(NFS_OK);
-	PLONG(4096);		/* tsize (fs block size) */
-	PLONG(Xfersize);	/* bsize (optimal transfer size) */
-	PLONG(Maxfreeblks);	/* blocks in fs */
-	PLONG(Maxfreeblks);	/* bfree to root*/
-	PLONG(Maxfreeblks);	/* bavail (free to mortals) */
-	chat("OK\n");
-	/*conftime = 0;
-	readunixidmaps(config);*/
-	return dataptr - (uint8_t *)reply->results;
-}

+ 0 - 189
sys/src/cmd/9nfs/pcnfsd.c

@@ -1,189 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-static void	pcinit(int, char**);
-static int	pcnull(int, Rpccall*, Rpccall*);
-static int	pcinfo(int, Rpccall*, Rpccall*);
-static int	pcauth(int, Rpccall*, Rpccall*);
-static int	pc1auth(int, Rpccall*, Rpccall*);
-static int	pcfacilities[15];
-static char	no_comment[] = "Trust me.";
-static char	pc_vers[] = "@(#)pcnfsd_v2.c	1.6 - rpc.pcnfsd V2.0 (c) 1994 P9, GmbH";
-static char	pc_home[] = "merrimack:/";
-
-static Procmap pcproc[] = {	/* pcnfsd v2 */
-	0, pcnull,
-	1, pcinfo,
-	13, pcauth,
-	0, 0
-};
-
-static Procmap pc1proc[] = { 	/* pc-nfsd v1 */
-	0, pcnull,
-	1, pc1auth,
-	0, 0
-};
-
-int	myport = 1111;
-
-Progmap progmap[] = {
-	150001, 2, pcinit, pcproc,
-	150001, 1, 0, pc1proc,
-	0, 0, 0,
-};
-
-void
-main(int argc, char *argv[])
-{
-	server(argc, argv, myport, progmap);
-}
-
-static void
-pcinit(int argc, char **argv)
-{
-	Procmap *p;
-	int i;
-	char *config = "config";
-
-	ARGBEGIN{
-	case 'c':
-		config = ARGF();
-		break;
-	default:
-		if(argopt(ARGC()) < 0)
-			sysfatal("usage: %s %s [-c config]", argv0, commonopts);
-		break;
-	}ARGEND;
-	clog("pc init\n");
-
-	for(i=0; i<nelem(pcfacilities); i++)
-		pcfacilities[i] = -1;
-	for(p=pcproc; p->procp; p++)
-		pcfacilities[p->procno] = 100;
-	readunixidmaps(config);
-}
-
-static int
-pcnull(int n, Rpccall *cmd, Rpccall *reply)
-{
-	USED(n); USED(cmd); USED(reply);
-	return 0;
-}
-
-static void
-scramble(String *x)
-{
-	int i;
-
-	for(i=0; i<x->n; i++)
-		x->s[i] = (x->s[i] ^ 0x5b) & 0x7f;
-}
-
-static int
-pcinfo(int n, Rpccall *cmd, Rpccall *reply)
-{
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-	String vers, cm;
-	int i;
-
-	chat("host=%I, port=%ld: pcinfo...",
-		cmd->host, cmd->port);
-	if(n <= 16)
-		return garbage(reply, "count too small");
-	argptr += string2S(argptr, &vers);
-	argptr += string2S(argptr, &cm);
-	if(argptr != &((uint8_t *)cmd->args)[n])
-		return garbage(reply, "bad count");
-	chat("\"%.*s\",\"%.*s\"\n", utfnlen(vers.s, vers.n), vers.s, utfnlen(cm.s, cm.n), cm.s);
-	PLONG(sizeof(pc_vers)-1);
-	PPTR(pc_vers, sizeof(pc_vers)-1);
-	PLONG(sizeof(no_comment)-1);
-	PPTR(no_comment, sizeof(no_comment)-1);
-	PLONG(nelem(pcfacilities));
-	for(i=0; i<nelem(pcfacilities); i++)
-		PLONG(pcfacilities[i]);
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-pc1auth(int n, Rpccall *cmd, Rpccall *reply)
-{
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-	String id, pw;
-	Unixidmap *m;
-	int uid;
-
-	chat("host=%I, port=%ld: pcauth...",
-		cmd->host, cmd->port);
-	if(n <= 8)
-		return garbage(reply, "count too small");
-	argptr += string2S(argptr, &id);
-	argptr += string2S(argptr, &pw);
-	if(argptr != &((uint8_t*)cmd->args)[n])
-		return garbage(reply, "bad count");
-	scramble(&id);
-	scramble(&pw);
-	m = pair2idmap("pcnfsd", cmd->host);
-	uid = -1;
-	if(m)
-		uid = name2id(&m->u.ids, id.s);
-	if(uid < 0)
-		uid = 1;
-	chat("\"%.*s\",\"%.*s\" uid=%d\n", utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, uid);
-	PLONG(0);	/* status */
-	PLONG(uid);	/* uid */
-	PLONG(uid);	/* gid */
-	return dataptr - (uint8_t*)reply->results;
-}
-
-static int
-pcauth(int n, Rpccall *cmd, Rpccall *reply)
-{
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-	String sys, id, pw, cm;
-	Unixidmap *m;
-	int uid;
-
-	chat("host=%I, port=%ld: pcauth...",
-		cmd->host, cmd->port);
-	if(n <= 16)
-		return garbage(reply, "count too small");
-	argptr += string2S(argptr, &sys);
-	argptr += string2S(argptr, &id);
-	argptr += string2S(argptr, &pw);
-	argptr += string2S(argptr, &cm);
-	if(argptr != &((uint8_t *)cmd->args)[n])
-		return garbage(reply, "bad count");
-	scramble(&id);
-	scramble(&pw);
-
-	m = pair2idmap("pcnfsd", cmd->host);
-	uid = -1;
-	if(m)
-		uid = name2id(&m->u.ids, id.s);
-	if(uid < 0)
-		uid = 1;
-	chat("\"%.*s\",\"%.*s\",\"%.*s\",\"%.*s\"\n", utfnlen(sys.s, sys.n), sys.s,
-		utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, utfnlen(cm.s, cm.n), cm.s);
-	PLONG(0);	/* status - OK */
-	PLONG(uid);
-	PLONG(uid);	/* gid */
-	PLONG(0);	/* ngids */
-	PLONG(sizeof(pc_home)-1);
-	PPTR(pc_home, sizeof(pc_home)-1);
-	PLONG(0);	/* umask */
-	PLONG(sizeof(no_comment)-1);
-	PPTR(no_comment, sizeof(no_comment)-1);
-	return dataptr - (uint8_t *)reply->results;
-}

+ 0 - 20
sys/src/cmd/9nfs/pcnfsd.json

@@ -1,20 +0,0 @@
-{
-	"pcnfsd": {
-		"Include": [
-			"../cmd.json"
-		],
-		"Install": "/$ARCH/bin/aux",
-		"Program": "pcnfsd",
-		"SourceFiles": [
-			"pcnfsd.c",
-			"unixnames.c",
-			"chat.c",
-			"rpc.c",
-			"server.c",
-			"string.c",
-			"listalloc.c",
-			"strparse.c",
-			"system.c"
-		]
-	}
-}

+ 0 - 181
sys/src/cmd/9nfs/portmapper.c

@@ -1,181 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-/*
- * sunrpc portmapper
- */
-#include "all.h"
-
-typedef struct Portmap	Portmap;
-struct Portmap
-{
-	int	prog;
-	int	vers;
-	int	protocol;
-	int	port;
-};
-
-Portmap map[] = {
-	100003, 2, IPPROTO_UDP, 2049,	/* nfs v2 */
-//	100003, 3, IPPROTO_UDP, 2049,	/* nfs v3 */
-	100005, 1, IPPROTO_UDP, 2049,	/* mount */
-	150001, 2, IPPROTO_UDP, 1111,	/* pcnfsd v2 */
-	150001, 1, IPPROTO_UDP, 1111,	/* pcnfsd v1 */
-	0, 0, 0, 0,
-};
-
-static void	pmapinit(int, char**);
-static int	pmapnull(int, Rpccall*, Rpccall*);
-static int	pmapset(int, Rpccall*, Rpccall*);
-static int	pmapunset(int, Rpccall*, Rpccall*);
-static int	pmapgetport(int, Rpccall*, Rpccall*);
-static int	pmapdump(int, Rpccall*, Rpccall*);
-static int	pmapcallit(int, Rpccall*, Rpccall*);
-
-static Procmap pmapproc[] = {
-	0, pmapnull,
-	1, pmapset,
-	2, pmapunset,
-	3, pmapgetport,
-	4, pmapdump,
-	5, pmapcallit,
-	0, 0
-};
-
-int	myport = 111;
-
-Progmap progmap[] = {
-	100000, 2, pmapinit, pmapproc,
-	0, 0, 0,
-};
-
-void
-main(int argc, char *argv[])
-{
-	server(argc, argv, myport, progmap);
-}
-
-static
-void
-pmapinit(int argc, char **argv)
-{
-	ARGBEGIN{
-	default:
-		if(argopt(ARGC()) < 0)
-			sysfatal("usage: %s %s", argv0, commonopts);
-		break;
-	}ARGEND;
-	clog("portmapper init\n");
-}
-
-static int
-pmapnull(int n, Rpccall *cmd, Rpccall *reply)
-{
-	USED(n); USED(cmd); USED(reply);
-	return 0;
-}
-
-static int
-pmapset(int n, Rpccall *cmd, Rpccall *reply)
-{
-	uint8_t *dataptr = reply->results;
-
-	if(n != 16)
-		return garbage(reply, "bad count");
-	USED(cmd);
-	PLONG(FALSE);
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-pmapunset(int n, Rpccall *cmd, Rpccall *reply)
-{
-	uint8_t *dataptr = reply->results;
-
-	if(n != 16)
-		return garbage(reply, "bad count");
-	USED(cmd);
-	PLONG(TRUE);
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-pmapgetport(int n, Rpccall *cmd, Rpccall *reply)
-{
-	int prog, vers, prot;
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-	Portmap *mp;
-
-	clog("get port\n");
-
-	if(n != 16)
-		return garbage(reply, "bad count");
-	prog = GLONG();
-	vers = GLONG();
-	prot = GLONG();
-	chat("host=%I, port=%ld: ", cmd->host, cmd->port);
-	chat("getport: %d, %d, %d...", prog, vers, prot);
-	for(mp=map; mp->prog>0; mp++)
-		if(prog == mp->prog && vers == mp->vers &&
-		   prot == mp->protocol)
-			break;
-	chat("%d\n", mp->port);
-	PLONG(mp->port);
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-pmapdump(int n, Rpccall *cmd, Rpccall *reply)
-{
-	uint8_t *dataptr = reply->results;
-	Portmap *mp;
-
-	if(n != 0)
-		return garbage(reply, "bad count");
-	USED(cmd);
-	for(mp=map; mp->prog>0; mp++){
-		PLONG(1);
-		PLONG(mp->prog);
-		PLONG(mp->vers);
-		PLONG(mp->protocol);
-		PLONG(mp->port);
-	}
-	PLONG(0);
-	return dataptr - (uint8_t *)reply->results;
-}
-
-static int
-pmapcallit(int n, Rpccall *cmd, Rpccall *reply)
-{
-	int prog, vers, proc;
-	uint8_t *argptr = cmd->args;
-	uint8_t *dataptr = reply->results;
-	Portmap *mp;
-
-	if(n < 12)
-		return garbage(reply, "bad count");
-	prog = GLONG();
-	vers = GLONG();
-	proc = GLONG();
-	chat("host=%I, port=%ld: ", cmd->host, cmd->port);
-	chat("callit: %d, %d, %d...", prog, vers, proc);
-	for(mp=map; mp->prog>0; mp++)
-		if(prog == mp->prog && vers == mp->vers &&
-		   proc == 0)
-			break;
-	if(mp->port == 0){
-		chat("ignored\n");
-		return -1;
-	}
-	chat("%d\n", mp->port);
-	PLONG(mp->port);
-	PLONG(0);
-	return dataptr - (uint8_t *)reply->results;
-}

+ 0 - 16
sys/src/cmd/9nfs/portmapper.json

@@ -1,16 +0,0 @@
-{
-	"portmapper": {
-		"Include": [
-			"../cmd.json"
-		],
-		"Install": "/$ARCH/bin/aux",
-		"Program": "portmapper",
-		"SourceFiles": [
-			"portmapper.c",
-			"rpc.c",
-			"chat.c",
-			"server.c",
-			"string.c"
-		]
-	}
-}

+ 0 - 323
sys/src/cmd/9nfs/rpc.c

@@ -1,323 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-#define	SHORT(x)	r->x = (p[1] | (p[0]<<8)); p += 2
-#define	LONG(x)		r->x = (p[3] | (p[2]<<8) |\
-				(p[1]<<16) | (p[0]<<24)); p += 4
-#define SKIPLONG	p += 4
-#define	PTR(x, n)	r->x = (void *)(p); p += ROUNDUP(n)
-
-int
-rpcM2S(void *ap, Rpccall *r, int n)
-{
-	int k;
-	uint8_t *p;
-	Udphdr *up;
-
-	/* copy IPv4 header fields from Udphdr */
-	up = ap;
-	p = &up->raddr[IPaddrlen - IPv4addrlen];
-	LONG(host);
-	USED(p);
-	p = &up->laddr[IPaddrlen - IPv4addrlen];
-	LONG(lhost);
-	USED(p);
-	/* ignore up->ifcaddr */
-	p = up->rport;
-	SHORT(port);
-	SHORT(lport);
-
-	LONG(xid);
-	LONG(mtype);
-	switch(r->mtype){
-	case CALL:
-		LONG(rpcvers);
-		if(r->rpcvers != 2)
-			break;
-		LONG(prog);
-		LONG(vers);
-		LONG(proc);
-		LONG(cred.flavor);
-		LONG(cred.count);
-		PTR(cred.data, r->cred.count);
-		LONG(verf.flavor);
-		LONG(verf.count);
-		PTR(verf.data, r->verf.count);
-		r->up = 0;
-		k = n - (p - (uint8_t *)ap);
-		if(k < 0)
-			break;
-		PTR(args, k);
-		break;
-	case REPLY:
-		LONG(stat);
-		switch(r->stat){
-		case MSG_ACCEPTED:
-			LONG(averf.flavor);
-			LONG(averf.count);
-			PTR(averf.data, r->averf.count);
-			LONG(astat);
-			switch(r->astat){
-			case SUCCESS:
-				k = n - (p - (uint8_t *)ap);
-				if(k < 0)
-					break;
-				PTR(results, k);
-				break;
-			case PROG_MISMATCH:
-				LONG(plow);
-				LONG(phigh);
-				break;
-			}
-			break;
-		case MSG_DENIED:
-			LONG(rstat);
-			switch(r->rstat){
-			case RPC_MISMATCH:
-				LONG(rlow);
-				LONG(rhigh);
-				break;
-			case AUTH_ERROR:
-				LONG(authstat);
-				break;
-			}
-			break;
-		}
-		break;
-	}
-	n -= p - (uint8_t *)ap;
-	return n;
-}
-
-int
-auth2unix(Auth *arg, Authunix *r)
-{
-	int i, n;
-	uint8_t *p;
-
-	if(arg->flavor != AUTH_UNIX)
-		return -1;
-	p = arg->data;
-	LONG(stamp);
-	LONG(mach.n);
-	PTR(mach.s, r->mach.n);
-	LONG(uid);
-	LONG(gid);
-	LONG(gidlen);
-	n = r->gidlen;
-	for(i=0; i<n && i < nelem(r->gids); i++){
-		LONG(gids[i]);
-	}
-	for(; i<n; i++){
-		SKIPLONG;
-	}
-	return arg->count - (p - (uint8_t *)arg->data);
-}
-
-int
-string2S(void *arg, String *r)
-{
-	uint8_t *p;
-	char *s;
-
-	p = arg;
-	LONG(n);
-	PTR(s, r->n);
-	/* must NUL terminate */
-	s = malloc(r->n+1);
-	if(s == nil)
-		panic("malloc(%ld) failed in string2S\n", r->n+1);
-	memmove(s, r->s, r->n);
-	s[r->n] = '\0';
-	r->s = strstore(s);
-	free(s);
-	return p - (uint8_t *)arg;
-}
-
-#undef	SHORT
-#undef	LONG
-#undef	PTR
-
-#define	SHORT(x)	p[1] = r->x; p[0] = r->x>>8; p += 2
-#define	LONG(x)		p[3] = r->x; p[2] = r->x>>8; p[1] = r->x>>16; p[0] = r->x>>24; p += 4
-
-#define	PTR(x,n)	memmove(p, r->x, n); p += ROUNDUP(n)
-
-int
-rpcS2M(Rpccall *r, int ndata, void *ap)
-{
-	uint8_t *p;
-	Udphdr *up;
-
-	/* copy header fields to Udphdr */
-	up = ap;
-	memmove(up->raddr, v4prefix, IPaddrlen);
-	p = &up->raddr[IPaddrlen - IPv4addrlen];
-	LONG(host);
-	USED(p);
-	memmove(up->laddr, v4prefix, IPaddrlen);
-	p = &up->laddr[IPaddrlen - IPv4addrlen];
-	LONG(lhost);
-	USED(p);
-	memmove(up->ifcaddr, IPnoaddr, sizeof up->ifcaddr);
-	p = up->rport;
-	SHORT(port);
-	SHORT(lport);
-
-	LONG(xid);
-	LONG(mtype);
-	switch(r->mtype){
-	case CALL:
-		LONG(rpcvers);
-		LONG(prog);
-		LONG(vers);
-		LONG(proc);
-		LONG(cred.flavor);
-		LONG(cred.count);
-		PTR(cred.data, r->cred.count);
-		LONG(verf.flavor);
-		LONG(verf.count);
-		PTR(verf.data, r->verf.count);
-		PTR(args, ndata);
-		break;
-	case REPLY:
-		LONG(stat);
-		switch(r->stat){
-		case MSG_ACCEPTED:
-			LONG(averf.flavor);
-			LONG(averf.count);
-			PTR(averf.data, r->averf.count);
-			LONG(astat);
-			switch(r->astat){
-			case SUCCESS:
-				PTR(results, ndata);
-				break;
-			case PROG_MISMATCH:
-				LONG(plow);
-				LONG(phigh);
-				break;
-			}
-			break;
-		case MSG_DENIED:
-			LONG(rstat);
-			switch(r->rstat){
-			case RPC_MISMATCH:
-				LONG(rlow);
-				LONG(rhigh);
-				break;
-			case AUTH_ERROR:
-				LONG(authstat);
-				break;
-			}
-			break;
-		}
-		break;
-	}
-	return p - (uint8_t *)ap;
-}
-
-#undef	SHORT
-#undef	LONG
-#undef	PTR
-
-#define	LONG(m, x)	fprint(fd, "%s = %ld\n", m, r->x)
-
-#define	PTR(m, count)	fprint(fd, "%s [%ld]\n", m, count)
-
-void
-rpcprint(int fd, Rpccall *r)
-{
-	fprint(fd, "%s: host = %I, port = %ld\n", 
-		argv0, r->host, r->port);
-	LONG("xid", xid);
-	LONG("mtype", mtype);
-	switch(r->mtype){
-	case CALL:
-		LONG("rpcvers", rpcvers);
-		LONG("prog", prog);
-		LONG("vers", vers);
-		LONG("proc", proc);
-		LONG("cred.flavor", cred.flavor);
-		PTR("cred.data", r->cred.count);
-		LONG("verf.flavor", verf.flavor);
-		PTR("verf.data", r->verf.count);
-		fprint(fd, "args...\n");
-		break;
-	case REPLY:
-		LONG("stat", stat);
-		switch(r->stat){
-		case MSG_ACCEPTED:
-			LONG("averf.flavor", averf.flavor);
-			PTR("averf.data", r->averf.count);
-			LONG("astat", astat);
-			switch(r->astat){
-			case SUCCESS:
-				fprint(fd, "results...\n");
-				break;
-			case PROG_MISMATCH:
-				LONG("plow", plow);
-				LONG("phigh", phigh);
-				break;
-			}
-			break;
-		case MSG_DENIED:
-			LONG("rstat", rstat);
-			switch(r->rstat){
-			case RPC_MISMATCH:
-				LONG("rlow", rlow);
-				LONG("rhigh", rhigh);
-				break;
-			case AUTH_ERROR:
-				LONG("authstat", authstat);
-				break;
-			}
-			break;
-		}
-	}
-}
-
-void
-showauth(Auth *ap)
-{
-	Authunix au;
-	int i;
-
-	if(auth2unix(ap, &au) != 0){
-		chat("auth flavor=%ld, count=%ld",
-			ap->flavor, ap->count);
-		for(i=0; i<ap->count; i++)
-			chat(" %.2ux", ((uint8_t *)ap->data)[i]);
-	}else{
-		chat("auth: %ld %.*s u=%ld g=%ld",
-			au.stamp, utfnlen(au.mach.s, au.mach.n), au.mach.s, au.uid, au.gid);
-		for(i=0; i<au.gidlen; i++)
-			chat(", %ld", au.gids[i]);
-	}
-	chat("...");
-}
-
-int
-garbage(Rpccall *reply, char *msg)
-{
-	chat("%s\n", msg ? msg : "garbage");
-	reply->astat = GARBAGE_ARGS;
-	return 0;
-}
-
-int
-error(Rpccall *reply, int errno)
-{
-	uint8_t *dataptr = reply->results;
-
-	chat("error %d\n", errno);
-	PLONG(errno);
-	return dataptr - (uint8_t *)reply->results;
-}

+ 0 - 95
sys/src/cmd/9nfs/rpc.h

@@ -1,95 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-/*
- *	Cf. /lib/rfc/rfc1014, /lib/rfc/rfc1050
- */
-
-enum Bool
-{
-	FALSE	= 0,
-	TRUE	= 1
-};
-
-enum Auth_flavor
-{
-	AUTH_NULL	= 0,
-	AUTH_UNIX	= 1,
-	AUTH_SHORT	= 2,
-	AUTH_DES	= 3
-};
-
-enum Msg_type
-{
-	CALL	= 0,
-	REPLY	= 1
-};
-
-/*
- * A reply to a call message can take on two forms:
- * The message was either accepted or rejected.
- */
-
-enum Reply_stat
-{
-	MSG_ACCEPTED	= 0,
-	MSG_DENIED	= 1
-};
-
-/*
- * Given that a call message was accepted, the following is the
- * status of an attempt to call a remote procedure.
- */
-enum Accept_stat
-{
-	SUCCESS		= 0,	/* RPC executed successfully       */
-	PROG_UNAVAIL	= 1,	/* remote hasn't exported program  */
-	PROG_MISMATCH	= 2,	/* remote can't support version #  */
-	PROC_UNAVAIL	= 3,	/* program can't support procedure */
-	GARBAGE_ARGS	= 4	/* procedure can't decode params   */
-};
-
-/*
- * Reasons why a call message was rejected:
- */
-enum Reject_stat
-{
-	RPC_MISMATCH	= 0,	/* RPC version number != 2          */
-	AUTH_ERROR	= 1	/* remote can't authenticate caller */
-};
-
-/*
- * Why authentication failed:
- */
-enum Auth_stat
-{
-	AUTH_BADCRED		= 1,	/* bad credentials (seal broken) */
-	AUTH_REJECTEDCRED	= 2,	/* client must begin new session */
-	AUTH_BADVERF		= 3,	/* bad verifier (seal broken)    */
-	AUTH_REJECTEDVERF	= 4,	/* verifier expired or replayed  */
-	AUTH_TOOWEAK		= 5	/* rejected for security reasons */
-};
-
-enum
-{
-	IPPROTO_TCP	= 6,	/* protocol number for TCP/IP */
-	IPPROTO_UDP	= 17	/* protocol number for UDP/IP */
-};
-
-#define	ROUNDUP(n)	((n) + ((-(n))&3))
-
-/* shift to unsigned char */
-#define SHUC(x, n) (((uint32_t)(x)>>n) & 0xff)
-#define	PLONG(x)	(dataptr[3] = SHUC(x,0), dataptr[2] = SHUC(x,8), dataptr[1] = SHUC(x,16), dataptr[0] = SHUC(x,24), dataptr += 4)
-#define	PPTR(x, n)	(memmove(dataptr, (x), n), dataptr += ROUNDUP(n))
-#define	PBYTE(x)	(*dataptr++ = (x))
-
-#define	GLONG()		(argptr += 4, (((unsigned char*)argptr)[-1] | (((unsigned char*)argptr)[-2]<<8) | (((unsigned char*)argptr)[-3]<<16) | (((unsigned char*)argptr)[-4]<<24)))
-#define	GPTR(n)		(void *)(argptr); argptr += ROUNDUP(n)
-#define	GBYTE()	(argptr++, ((unsigned char*)argptr)[-1])

+ 0 - 604
sys/src/cmd/9nfs/server.c

@@ -1,604 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-#include <ndb.h>
-
-static int	alarmflag;
-
-static int	Iconv(Fmt*);
-//static void	openudp(int);
-static void	cachereply(Rpccall*, void*, int);
-static int	replycache(int, Rpccall*, int32_t (*)(int, void*, int32_t));
-static void	udpserver(int, Progmap*);
-static void	tcpserver(int, Progmap*);
-static void	getendpoints(Udphdr*, char*);
-static int32_t	readtcp(int, void*, int32_t);
-static int32_t	writetcp(int, void*, int32_t);
-static int	servemsg(int, int32_t (*)(int, void*, int32_t),
-			   int32_t (*)(int, void*, int32_t),
-		int, Progmap*);
-void	(*rpcalarm)(void);
-int	rpcdebug;
-int	rejectall;
-int	p9debug;
-
-int	nocache;
-
-uint8_t	buf[9000];
-uint8_t	rbuf[9000];
-uint8_t	resultbuf[9000];
-
-static int tcp;
-
-char *commonopts = "[-9CDrtv]";			/* for usage() messages */
-
-/*
- * this recognises common, nominally rcp-related options.
- * they may not take arguments.
- */
-int
-argopt(int c)
-{
-	switch(c){
-	case '9':
-		++p9debug;
-		return 0;
-	case 'C':
-		++nocache;
-		return 0;
-	case 'D':
-		++rpcdebug;
-		return 0;
-	case 'r':
-		++rejectall;
-		return 0;
-	case 't':
-		tcp = 1;
-		return 0;
-	case 'v':
-		++chatty;
-		return 0;
-	default:
-		return -1;
-	}
-}
-
-/*
- * all option parsing is now done in (*pg->init)(), which can call back
- * here to argopt for common options.
- */
-void
-server(int argc, char **argv, int myport, Progmap *progmap)
-{
-	Progmap *pg;
-
-	fmtinstall('I', Iconv);
-	fmtinstall('F', fcallfmt);
-	fmtinstall('D', dirfmt);
-
-	switch(rfork(RFNOWAIT|RFENVG|RFNAMEG|RFNOTEG|RFFDG|RFPROC)){
-	case -1:
-		panic("fork");
-	default:
-		_exits(0);
-	case 0:
-		break;
-	}
-
-	switch(rfork(RFMEM|RFPROC)){
-	case 0:
-		for(;;){
-			sleep(30*1000);
-			alarmflag = 1;
-		}
-	case -1:
-		sysfatal("rfork: %r");
-	}
-
-	for(pg=progmap; pg->init; pg++)
-		(*pg->init)(argc, argv);
-	if(tcp)
-		tcpserver(myport, progmap);
-	else
-		udpserver(myport, progmap);
-}
-
-static void
-udpserver(int myport, Progmap *progmap)
-{
-	char service[128];
-	char data[128];
-	char devdir[40];
-	int ctlfd, datafd;
-
-	snprint(service, sizeof service, "udp!*!%d", myport);
-	ctlfd = announce(service, devdir);
-	if(ctlfd < 0)
-		panic("can't announce %s: %r\n", service);
-	if(fprint(ctlfd, "headers") < 0)
-		panic("can't set header mode: %r\n");
-
-	snprint(data, sizeof data, "%s/data", devdir);
-	datafd = open(data, ORDWR);
-	if(datafd < 0)
-		panic("can't open udp data: %r\n");
-	close(ctlfd);
-
-	chatsrv(0);
-	clog("%s: listening to port %d\n", argv0, myport);
-	while (servemsg(datafd, read, (void *)write, myport, progmap) >= 0)
-		continue;
-	exits(0);
-}
-
-static void
-tcpserver(int myport, Progmap *progmap)
-{
-	char adir[40];
-	char ldir[40];
-	char ds[40];
-	int actl, lctl, data;
-
-	snprint(ds, sizeof ds, "tcp!*!%d", myport);
-	chatsrv(0);
-	actl = -1;
-	for(;;){
-		if(actl < 0){
-			actl = announce(ds, adir);
-			if(actl < 0){
-				clog("%s: listening to tcp port %d\n",
-					argv0, myport);
-				clog("announcing: %r");
-				break;
-			}
-		}
-		lctl = listen(adir, ldir);
-		if(lctl < 0){
-			close(actl);
-			actl = -1;
-			continue;
-		}
-		switch(fork()){
-		case -1:
-			clog("%s!%d: %r\n", argv0, myport);
-			/* fall through */
-		default:
-			close(lctl);
-			continue;
-		case 0:
-			close(actl);
-			data = accept(lctl, ldir);
-			close(lctl);
-			if(data < 0)
-				exits(0);
-
-			/* pretend it's udp; fill in Udphdr */
-			getendpoints((Udphdr*)buf, ldir);
-
-			while (servemsg(data, readtcp, writetcp, myport,
-			    progmap) >= 0)
-				continue;
-			close(data);
-			exits(0);
-		}
-	}
-	exits(0);
-}
-
-static int
-servemsg(int fd, int32_t (*readmsg)(int, void*, int32_t),
-	 int32_t (*writemsg)(int, void*, int32_t),
-		int myport, Progmap * progmap)
-{
-	int i, n, nreply;
-	Rpccall rcall, rreply;
-	int vlo, vhi;
-	Progmap *pg;
-	Procmap *pp;
-	char errbuf[ERRMAX];
-
-	if(alarmflag){
-		alarmflag = 0;
-		if(rpcalarm)
-			(*rpcalarm)();
-	}
-	n = (*readmsg)(fd, buf, sizeof buf);
-	if(n < 0){
-		errstr(errbuf, sizeof errbuf);
-		if(strcmp(errbuf, "interrupted") == 0)
-			return 0;
-		clog("port %d: error: %s\n", myport, errbuf);
-		return -1;
-	}
-	if(n == 0){
-		clog("port %d: EOF\n", myport);
-		return -1;
-	}
-	if(rpcdebug == 1)
-		fprint(2, "%s: rpc from %d.%d.%d.%d/%d\n",
-			argv0, buf[12], buf[13], buf[14], buf[15],
-			(buf[32]<<8)|buf[33]);
-	i = rpcM2S(buf, &rcall, n);
-	if(i != 0){
-		clog("udp port %d: message format error %d\n",
-			myport, i);
-		return 0;
-	}
-	if(rpcdebug > 1)
-		rpcprint(2, &rcall);
-	if(rcall.mtype != CALL)
-		return 0;
-	if(replycache(fd, &rcall, writemsg))
-		return 0;
-	nreply = 0;
-	rreply.host = rcall.host;
-	rreply.port = rcall.port;
-	rreply.lhost = rcall.lhost;
-	rreply.lport = rcall.lport;
-	rreply.xid = rcall.xid;
-	rreply.mtype = REPLY;
-	if(rcall.rpcvers != 2){
-		rreply.stat = MSG_DENIED;
-		rreply.rstat = RPC_MISMATCH;
-		rreply.rlow = 2;
-		rreply.rhigh = 2;
-		goto send_reply;
-	}
-	if(rejectall){
-		rreply.stat = MSG_DENIED;
-		rreply.rstat = AUTH_ERROR;
-		rreply.authstat = AUTH_TOOWEAK;
-		goto send_reply;
-	}
-	i = n - (((uint8_t *)rcall.args) - buf);
-	if(rpcdebug > 1)
-		fprint(2, "arg size = %d\n", i);
-	rreply.stat = MSG_ACCEPTED;
-	rreply.averf.flavor = 0;
-	rreply.averf.count = 0;
-	rreply.results = resultbuf;
-	vlo = 0x7fffffff;
-	vhi = -1;
-	for(pg=progmap; pg->pmap; pg++){
-		if(pg->progno != rcall.prog)
-			continue;
-		if(pg->vers == rcall.vers)
-			break;
-		if(pg->vers < vlo)
-			vlo = pg->vers;
-		if(pg->vers > vhi)
-			vhi = pg->vers;
-	}
-	if(pg->pmap == 0){
-		if(vhi < 0)
-			rreply.astat = PROG_UNAVAIL;
-		else{
-			rreply.astat = PROG_MISMATCH;
-			rreply.plow = vlo;
-			rreply.phigh = vhi;
-		}
-		goto send_reply;
-	}
-	for(pp = pg->pmap; pp->procp; pp++)
-		if(rcall.proc == pp->procno){
-			if(rpcdebug > 1)
-				fprint(2, "process %d\n", pp->procno);
-			rreply.astat = SUCCESS;
-			nreply = (*pp->procp)(i, &rcall, &rreply);
-			goto send_reply;
-		}
-	rreply.astat = PROC_UNAVAIL;
-send_reply:
-	if(nreply >= 0){
-		i = rpcS2M(&rreply, nreply, rbuf);
-		if(rpcdebug > 1)
-			rpcprint(2, &rreply);
-		(*writemsg)(fd, rbuf, i);
-		cachereply(&rreply, rbuf, i);
-	}
-	return 0;
-}
-
-static void
-getendpoint(char *dir, char *file, uint8_t *addr, uint8_t *port)
-{
-	int fd, n;
-	char buf[128];
-	char *sys, *serv;
-
-	sys = serv = 0;
-
-	snprint(buf, sizeof buf, "%s/%s", dir, file);
-	fd = open(buf, OREAD);
-	if(fd >= 0){
-		n = read(fd, buf, sizeof(buf)-1);
-		if(n>0){
-			buf[n-1] = 0;
-			serv = strchr(buf, '!');
-			if(serv){
-				*serv++ = 0;
-				serv = strdup(serv);
-			}
-			sys = strdup(buf);
-		}
-		close(fd);
-	}
-	if(serv == 0)
-		serv = strdup("unknown");
-	if(sys == 0)
-		sys = strdup("unknown");
-	parseip(addr, sys);
-	n = atoi(serv);
-	hnputs(port, n);
-}
-
-/* set Udphdr values from protocol dir local & remote files */
-static void
-getendpoints(Udphdr *ep, char *dir)
-{
-	getendpoint(dir, "local", ep->laddr, ep->lport);
-	getendpoint(dir, "remote", ep->raddr, ep->rport);
-}
-
-static int32_t
-readtcp(int fd, void *vbuf, int32_t blen)
-{
-	uint8_t mk[4];
-	int n, m, sofar;
-	uint32_t done;
-	char *buf;
-
-	buf = vbuf;
-	buf += Udphdrsize;
-	blen -= Udphdrsize;
-
-	done = 0;
-	for(sofar = 0; !done; sofar += n){
-		m = readn(fd, mk, 4);
-		if(m < 4)
-			return 0;
-		done = (mk[0]<<24)|(mk[1]<<16)|(mk[2]<<8)|mk[3];
-		m = done & 0x7fffffff;
-		done &= 0x80000000;
-		if(m > blen-sofar)
-			return -1;
-		n = readn(fd, buf+sofar, m);
-		if(m != n)
-			return 0;
-	}
-	return sofar + Udphdrsize;
-}
-
-static int32_t
-writetcp(int fd, void *vbuf, int32_t len)
-{
-	char *buf;
-
-	buf = vbuf;
-	buf += Udphdrsize;
-	len -= Udphdrsize;
-
-	buf -= 4;
-	buf[0] = 0x80 | (len>>24);
-	buf[1] = len>>16;
-	buf[2] = len>>8;
-	buf[3] = len;
-	len += 4;
-	return write(fd, buf, len);
-}
-/*
- *int32_t
- *niwrite(int fd, void *buf, int32_t count)
- *{
- *	char errbuf[ERRLEN];
- *	int32_t n;
- *
- *	for(;;){
- *		n = write(fd, buf, count);
- *		if(n < 0){
- *			errstr(errbuf);
- *			if(strcmp(errbuf, "interrupted") == 0)
- *				continue;
- *			clog("niwrite error: %s\n", errbuf);
- *			werrstr(errbuf);
- *		}
- *		break;
- *	}
- *	return n;
- *}
- */
-int32_t
-niwrite(int fd, void *buf, int32_t n)
-{
-//	int savalarm;
-
-// 	savalarm = alarm(0);
-	n = write(fd, buf, n);
-// 	if(savalarm > 0)
-//		alarm(savalarm);
-	return n;
-}
-
-typedef struct Namecache	Namecache;
-struct Namecache {
-	char dom[256];
-	uint32_t ipaddr;
-	Namecache *next;
-};
-
-Namecache *dnscache;
-
-static Namecache*
-iplookup(uint32_t ip)
-{
-	Namecache *n, **ln;
-
-	for(ln=&dnscache, n=*ln; n; ln=&(*ln)->next, n=*ln) {
-		if(n->ipaddr == ip) {
-			*ln = n->next;
-			n->next = dnscache;
-			dnscache = n;
-			return n;
-		}
-	}
-	return nil;
-}
-
-static Namecache*
-addcacheentry(void *name, int len, uint32_t ip)
-{
-	Namecache *n;
-
-	if(len >= sizeof(n->dom))
-		return nil;
-
-	n = malloc(sizeof(*n));
-	if(n == nil)
-		return nil;
-	strncpy(n->dom, name, len);
-	n->dom[len] = 0;
-	n->ipaddr = ip;
-	n->next = dnscache;
-	dnscache = n;
-	return nil;
-}
-
-int
-getdnsdom(uint32_t ip, char *name, int len)
-{
-	char buf[128];
-	Namecache *nc;
-	char *p;
-
-	if(nc=iplookup(ip)) {
-		strncpy(name, nc->dom, len);
-		name[len-1] = 0;
-		return 0;
-	}
-	clog("getdnsdom: %I\n", ip);
-	snprint(buf, sizeof buf, "%I", ip);
-	p = csgetvalue("/net", "ip", buf, "dom", nil);
-	if(p == nil)
-		return -1;
-	strncpy(name, p, len-1);
-	name[len] = 0;
-	free(p);
-	addcacheentry(name, strlen(name), ip);
-	return 0;
-}
-
-int
-getdom(uint32_t ip, char *dom, int len)
-{
-	int i;
-	static char *prefix[] = { "", "gate-", "fddi-", "u-", 0 };
-	char **pr;
-
-	if(getdnsdom(ip, dom, len)<0)
-		return -1;
-
-	for(pr=prefix; *pr; pr++){
-		i = strlen(*pr);
-		if(strncmp(dom, *pr, i) == 0) {
-			memmove(dom, dom+i, len-i);
-			break;
-		}
-	}
-	return 0;
-}
-
-#define	MAXCACHE	64
-
-static Rpccache *head, *tail;
-static int	ncache;
-
-static void
-cachereply(Rpccall *rp, void *buf, int len)
-{
-	Rpccache *cp;
-
-	if(nocache)
-		return;
-
-	if(ncache >= MAXCACHE){
-		if(rpcdebug)
-			fprint(2, "%s: drop  %I/%ld, xid %uld, len %d\n",
-				argv0, tail->host,
-				tail->port, tail->xid, tail->n);
-		tail = tail->prev;
-		free(tail->next);
-		tail->next = 0;
-		--ncache;
-	}
-	cp = malloc(sizeof(Rpccache)+len-4);
-	if(cp == 0){
-		clog("cachereply: malloc %d failed\n", len);
-		return;
-	}
-	++ncache;
-	cp->prev = 0;
-	cp->next = head;
-	if(head)
-		head->prev = cp;
-	else
-		tail = cp;
-	head = cp;
-	cp->host = rp->host;
-	cp->port = rp->port;
-	cp->xid = rp->xid;
-	cp->n = len;
-	memmove(cp->data, buf, len);
-	if(rpcdebug)
-		fprint(2, "%s: cache %I/%ld, xid %uld, len %d\n",
-			argv0, cp->host, cp->port, cp->xid, cp->n);
-}
-
-static int
-replycache(int fd, Rpccall *rp, int32_t (*writemsg)(int, void*, int32_t))
-{
-	Rpccache *cp;
-
-	for(cp=head; cp; cp=cp->next)
-		if(cp->host == rp->host &&
-		   cp->port == rp->port &&
-		   cp->xid == rp->xid)
-			break;
-	if(cp == 0)
-		return 0;
-	if(cp->prev){	/* move to front */
-		cp->prev->next = cp->next;
-		if(cp->next)
-			cp->next->prev = cp->prev;
-		else
-			tail = cp->prev;
-		cp->prev = 0;
-		cp->next = head;
-		head->prev = cp;
-		head = cp;
-	}
-	(*writemsg)(fd, cp->data, cp->n);
-	if(rpcdebug)
-		fprint(2, "%s: reply %I/%ld, xid %uld, len %d\n",
-			argv0, cp->host, cp->port, cp->xid, cp->n);
-	return 1;
-}
-
-static int
-Iconv(Fmt *f)
-{
-	char buf[16];
-	uint32_t h;
-
-	h = va_arg(f->args, uint32_t);
-	snprint(buf, sizeof buf, "%ld.%ld.%ld.%ld",
-		(h>>24)&0xff, (h>>16)&0xff,
-		(h>>8)&0xff, h&0xff);
-	return fmtstrcpy(f, buf);
-}

+ 0 - 114
sys/src/cmd/9nfs/string.c

@@ -1,114 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-#define STRHASH	509	/* prime */
-
-static Strnode *	stab[STRHASH];
-
-static int32_t	hashfun(void*);
-static Strnode*	nalloc(int);
-
-char *
-strfind(char *a)
-{
-	Strnode **bin, *x, *xp;
-
-	bin = &stab[hashfun(a) % STRHASH];
-	for(xp=0, x=*bin; x; xp=x, x=x->next)
-		if(x->str[0] == a[0] && strcmp(x->str, a) == 0)
-			break;
-	if(x == 0)
-		return 0;
-	if(xp){
-		xp->next = x->next;
-		x->next = *bin;
-		*bin = x;
-	}
-	return x->str;
-}
-
-char *
-strstore(char *a)
-{
-	Strnode **bin, *x, *xp;
-	int n;
-
-	bin = &stab[hashfun(a) % STRHASH];
-	for(xp=0, x=*bin; x; xp=x, x=x->next)
-		if(x->str[0] == a[0] && strcmp(x->str, a) == 0)
-			break;
-	if(x == 0){
-		n = strlen(a)+1;
-		x = nalloc(n);
-		memmove(x->str, a, n);
-		x->next = *bin;
-		*bin = x;
-	}else if(xp){
-		xp->next = x->next;
-		x->next = *bin;
-		*bin = x;
-	}
-	return x->str;
-}
-
-void
-strprint(int fd)
-{
-	Strnode **bin, *x;
-
-	for(bin = stab; bin < stab+STRHASH; bin++)
-		for(x=*bin; x; x=x->next)
-			fprint(fd, "%ld %s\n", bin-stab, x->str);
-}
-
-static int32_t
-hashfun(void *v)
-{
-	uint32_t a = 0, b;
-	uint8_t *s = v;
-
-	while(*s){
-		a = (a << 4) + *s++;
-		if(b = a&0xf0000000){	/* assign = */
-			a ^= b >> 24;
-			a ^= b;
-		}
-	}
-	return a;
-}
-
-#define STRSIZE	1000
-
-static Strnode *
-nalloc(int n)	/* get permanent storage for Strnode */
-{
-	static char *curstp;
-	static int nchleft;
-	int k;
-	char *p;
-
-	if(n < 4)
-		n = 4;
-	else if(k = n&3)	/* assign = */
-		n += 4-k;
-	n += sizeof(Strnode)-4;
-	if(n > nchleft){
-		nchleft = STRSIZE;
-		while(nchleft < n)
-			nchleft *= 2;
-		if((curstp = malloc(nchleft)) == 0)
-			panic("malloc(%d) failed in nalloc\n", nchleft);
-	}
-	p = curstp;
-	curstp += n;
-	nchleft -= n;
-	return (Strnode*)p;
-}

+ 0 - 41
sys/src/cmd/9nfs/strparse.c

@@ -1,41 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-
-int	strcomment = '#';
-
-int
-strparse(char *p, int arsize, char **arv)
-{
-	int arc = 0;
-
-	/*print("parse: 0x%lux = \"%s\"\n", p, p);*/
-	while(p){
-		while(*p == ' ' || *p == '\t')
-			p++;
-		if(*p == 0 || *p == strcomment)
-			break;
-		if(arc >= arsize-1)
-			break;
-		arv[arc++] = p;
-		while(*p && *p != ' ' && *p != '\t')
-			p++;
-		if(*p == 0)
-			break;
-		*p++ = 0;
-	}
-	arv[arc] = 0;
-	/*while(*arv){
-		print("\t0x%lux = \"%s\"\n", *arv, *arv);
-		++arv;
-	}*/
-	return arc;
-}

+ 0 - 43
sys/src/cmd/9nfs/system.c

@@ -1,43 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-
-Waitmsg*
-system(char *name, char **argv)
-{
-	char err[ERRMAX];
-	Waitmsg *w;
-	int pid;
-
-	switch(pid = fork()){	/* assign = */
-	case -1:
-		return nil;
-	case 0:
-		exec(name, argv);
-		errstr(err, sizeof err);
-		_exits(err);
-	}
-	for(;;){
-		w = wait();
-		if(w == nil)
-			break;
-		if(w->pid == pid)
-			return w;
-		free(w);
-	}
-	return nil;
-}
-
-Waitmsg*
-systeml(char *name, ...)
-{
-	return system(name, &name+1);
-}

+ 0 - 8
sys/src/cmd/9nfs/testit

@@ -1,8 +0,0 @@
-#!/bin/rc
-9fs nslocum
-Kill 8.portmapper|rc
-Kill 8.nfsserver|rc
-rm -f /srv/nfsserver.chat /srv/portmapper.chat
-8.nfsserver -a il!emelie -c /lib/ndb/nfs >[2] /tmp/nfsserver
-8.portmapper >[2] /tmp/portmapper
-# on unix: mount -t nfs -o nfsv2 edith:/ /mnt

+ 0 - 331
sys/src/cmd/9nfs/unixnames.c

@@ -1,331 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-static void	uxfree(Unixid*);
-
-static Unixid *	xfree;
-
-Unixidmap *idhead, *idtail;
-
-Unixscmap *scmap;
-
-#define	UNUSED	0x7FFFFFFF
-
-/*
- * Sadly we have to use the IP address, since some systems (FreeBSD in particular)
- * do not believe it to be safe to depend on the hostname and so refuse to send it.
- * I dislike making this IP-centric, but so be it.
- * We keep a cache of host names in getdom.
- */
-Unixidmap *
-pair2idmap(char *server, uint32_t clientip)
-{
-	Resub match;
-	Unixscmap *m, *mp;
-	Unixidmap *r;
-	char dom[256];
-
-	for(mp=0,m=scmap; m; mp=m,m=m->next){
-		if(m->server[0] != server[0])
-			continue;
-		if(strcmp(m->server, server))
-			continue;
-		if(m->clientip != clientip)
-			continue;
-		if(mp){
-			mp->next = m->next;
-			m->next = scmap;
-			scmap = m;
-		}
-		r = m->map;
-		if(r->u.timestamp != 0 && r->g.timestamp != 0)
-			return r;
-		scmap = m->next;
-		free(m);
-		break;
-	}
-	if(rpcdebug)
-		fprint(2, "looking for %lux\n", clientip);
-	if(getdom(clientip, dom, sizeof dom)<0){
-		clog("auth: unknown ip address");
-		return nil;
-	}
-	if(rpcdebug)
-		fprint(2, "dom is %s\n", dom);
-	for(r=idhead; r; r=r->next){
-		if(r->u.timestamp == 0 || r->g.timestamp == 0)
-			continue;
-		match.sp = match.ep = 0;
-		if(regexec(r->sexp, server, &match, 1) == 0)
-			continue;
-		if(match.sp != server || match.ep <= match.sp || *match.ep)
-			continue;
-		match.sp = match.ep = 0;
-		if(regexec(r->cexp, dom, &match, 1) == 0)
-			continue;
-		if(match.sp != dom || match.ep <= match.sp || *match.ep)
-			continue;
-		m = malloc(sizeof(Unixscmap));
-		m->next = scmap;
-		scmap = m;
-		m->server = strstore(server);
-		m->clientip = clientip;
-		m->map = r;
-		break;
-	}
-	return r;
-}
-
-int
-readunixidmaps(char *file)
-{
-	Waitmsg *w;
-	Biobuf *in;
-	Unixidmap *m;
-	int i, arc; char *arv[16], buf[256];
-	char *l;
-// 	int32_t savalarm;
-
-// 	savalarm = alarm(0);
-	in = Bopen(file, OREAD);
-	if(in == 0){
-		clog("readunixidmaps can't open %s: %r\n", file);
-//		alarm(savalarm);
-		return -1;
-	}
-	for(m=idhead; m; m=m->next)
-		m->flag = 0;
-	while(l = Brdline(in, '\n')){	/* assign = */
-		l[Blinelen(in)-1] = 0;
-		arc = strparse(l, nelem(arv), arv);
-		if(arc > 0 && arv[0][0] == '!'){
-			++arv[0];
-			snprint(buf, sizeof buf, "/bin/%s", arv[0]);
-			if(chatty){
-				chat("!");
-				for(i=0; i<arc; i++)
-					chat(" %s", arv[i]);
-				chat("...");
-			}
-			w = system(buf, arv);
-			if(w == nil)
-				chat("err: %r\n");
-			else if(w->msg && w->msg[0])
-				chat("status: %s\n", w->msg);
-			else
-				chat("OK\n");
-			free(w);
-			continue;
-		}
-		if(arc != 4)
-			continue;
-		for(m=idhead; m; m=m->next)
-			if(strcmp(arv[0], m->server) == 0 &&
-			   strcmp(arv[1], m->client) == 0)
-				break;
-		if(m == 0){
-			m = malloc(sizeof(Unixidmap));
-			if(idtail)
-				idtail->next = m;
-			else
-				idhead = m;
-			idtail = m;
-			m->next = 0;
-			m->server = strstore(arv[0]);
-			m->client = strstore(arv[1]);
-			m->sexp = regcomp(m->server);
-			m->cexp = regcomp(m->client);
-			m->u.file = strstore(arv[2]);
-			m->u.style = 'u';
-			m->u.timestamp = 0;
-			m->u.ids = 0;
-			m->g.file = strstore(arv[3]);
-			m->g.style = 'u';
-			m->g.timestamp = 0;
-			m->g.ids = 0;
-		}else{
-			if(!m->u.file || strcmp(m->u.file, arv[2]) != 0){
-				m->u.file = strstore(arv[2]);
-				m->u.timestamp = 0;
-			}
-			if(!m->g.file || strcmp(m->g.file, arv[3]) != 0){
-				m->g.file = strstore(arv[3]);
-				m->g.timestamp = 0;
-			}
-		}
-		m->flag = 1;
-		checkunixmap(&m->u);
-		checkunixmap(&m->g);
-	}
-	Bterm(in);
-	for(m=idhead; m; m=m->next)
-		if(m->flag == 0){
-			m->u.file = 0;
-			m->u.timestamp = 0;
-			uxfree(m->u.ids);
-			m->u.ids = 0;
-			m->g.file = 0;
-			m->g.timestamp = 0;
-			uxfree(m->g.ids);
-			m->g.ids = 0;
-		}
-// 	alarm(savalarm);
-	return 0;
-}
-
-static void
-uxfree(Unixid *x)
-{
-	Unixid *tail;
-	int count=0;
-
-	if(x){
-		tail = x;
-		if(tail->id < 0)
-			abort();
-		tail->id = UNUSED;
-		while(tail->next){
-			tail = tail->next;
-			++count;
-			if(tail->id == UNUSED)
-				abort();
-			tail->id = UNUSED;
-		}
-		tail->next = xfree;
-		xfree = x;
-	}
-}
-
-int
-checkunixmap(Unixmap *u)
-{
-	Dir *dir;
-
-	dir = dirstat(u->file);
-	if(dir == nil){
-		clog("checkunixmap can't stat %s: %r\n", u->file);
-		return -1;
-	}
-	if(u->timestamp > dir->mtime){
-		free(dir);
-		return 0;
-	}
-	uxfree(u->ids);
-	u->ids = readunixids(u->file, u->style);
-	u->timestamp = time(0);
-	free(dir);
-	return 1;
-}
-
-int
-name2id(Unixid **list, char *name)
-{
-	Unixid *x, *xp;
-
-	for(xp=0,x=*list; x; xp=x,x=x->next){
-		if(x->name[0] == name[0] && strcmp(x->name, name) == 0){
-			if(xp){
-				xp->next = x->next;
-				x->next = *list;
-				*list = x;
-			}
-			return x->id;
-		}
-	}
-	return -1;
-}
-
-char *
-id2name(Unixid **list, int id)
-{
-	Unixid *x, *xp;
-
-	for(xp=0,x=*list; x; xp=x,x=x->next){
-		if(x->id == id){
-			if(xp){
-				xp->next = x->next;
-				x->next = *list;
-				*list = x;
-			}
-			return x->name;
-		}
-	}
-	return "none";
-}
-
-void
-idprint(int fd, Unixid *xp)
-{
-	while(xp){
-		fprint(fd, "%d\t%s\n", xp->id, xp->name);
-		xp = xp->next;
-	}
-}
-
-/*
- *	style '9': 3:tom:tom:
- *	style 'u': sysadm:*:0:0:System-Administrator:/usr/admin:/bin/sh
- */
-
-Unixid *
-readunixids(char *file, int style)
-{
-	Biobuf *in;
-	char *l, *name = 0;
-	Unixid *x, *xp = 0;
-	int id = 0;
-
-	in = Bopen(file, OREAD);
-	if(in == 0){
-		clog("readunixids can't open %s: %r\n", file);
-		return 0;
-	}
-	while(l = Brdline(in, '\n')){	/* assign = */
-		l[Blinelen(in)-1] = 0;
-		switch(style){
-		case '9':
-			id = strtol(l, &l, 10);
-			if(*l != ':')
-				continue;
-			name = ++l;
-			l = strchr(l, ':');
-			if(l == 0)
-				continue;
-			*l = 0;
-			break;
-		case 'u':
-			name = l;
-			l = strchr(l, ':');
-			if(l == 0)
-				continue;
-			*l++ = 0;
-			/* skip password */
-			l = strchr(l, ':');
-			if(l == 0)
-				continue;
-			id = strtol(l+1, 0, 10);
-			break;
-		default:
-			panic("unknown unixid style %d\n", style);
-		}
-		if(id == UNUSED)
-			id = -1;	/* any value will do */
-		if(!(x = xfree))	/* assign = */
-			x = listalloc(1024/sizeof(Unixid), sizeof(Unixid));
-		xfree = x->next;
-		x->id = id;
-		x->name = strstore(name);
-		x->next = xp;
-		xp = x;
-	}
-	Bterm(in);
-	return xp;
-}

+ 0 - 115
sys/src/cmd/9nfs/xfile.c

@@ -1,115 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "all.h"
-
-static Xfile *	xflfree;
-static Xfid *	xfdfree;
-
-#define	FIDMOD	127	/* prime */
-
-static Xfile	*xfiles[FIDMOD];
-static Lock	xlocks[FIDMOD];
-
-Xfile *
-xfile(Qid *qid, void *s, int new)
-{
-	int k;
-	Xfile **hp, *f, *pf;
-
-	k = ((uint32_t)qid->path ^ (((uint32_t)(uintptr)s)<<24))%FIDMOD;
-	hp = &xfiles[k];
-
-	lock(&xlocks[k]);
-	for(f=*hp, pf=0; f; pf=f, f=f->next)
-		if(f->qid.path == qid->path 
-		&& (uint32_t)(uintptr)f->s == (uint32_t)(uintptr)s)
-			break;
-	if(f && pf){
-		pf->next = f->next;
-		f->next = *hp;
-		*hp = f;
-	}
-	if(new < 0 && f){
-		*hp = f->next;
-		f->next = xflfree;
-		xflfree = f;
-		f = 0;
-	}
-	if(new > 0 && !f){
-		if(!(f = xflfree))	/* assign = */
-			f = listalloc(1024/sizeof(Xfile), sizeof(Xfile));
-		xflfree = f->next;
-		memset(f, 0, sizeof(Xfile));
-		f->next = *hp;
-		*hp = f;
-		f->qid = *qid;
-		f->s = s;
-	}
-	unlock(&xlocks[k]);
-	return f;
-}
-
-Xfid *
-xfid(char *uid, Xfile *xp, int new)
-{
-	Xfid *f, *pf;
-
-	for(f=xp->users, pf=0; f; pf=f, f=f->next)
-		if(f->uid[0] == uid[0] && strcmp(f->uid, uid) == 0)
-			break;
-	if(f && pf){
-		pf->next = f->next;
-		f->next = xp->users;
-		xp->users = f;
-	}
-	if(new < 0 && f){
-		if(f->urfid)
-			clunkfid(xp->s, f->urfid);
-		if(f->opfid)
-			clunkfid(xp->s, f->opfid);
-		xp->users = f->next;
-		f->next = xfdfree;
-		xfdfree = f;
-		f = 0;
-	}
-	if(new > 0 && !f){
-		if(!(f = xfdfree))	/* assign = */
-			f = listalloc(1024/sizeof(Xfid), sizeof(Xfid));
-		xfdfree = f->next;
-		memset(f, 0, sizeof(Xfid));
-		f->next = xp->users;
-		xp->users = f;
-		f->xp = xp;
-		f->uid = strstore(uid);
-		f->urfid = 0;
-		f->opfid = 0;
-	}
-	return f;
-}
-
-int
-xfpurgeuid(Session *s, char *uid)
-{
-	Xfile **hp, *f;
-	Xfid *xf;
-	int k, count=0;
-
-	for(k=0; k<FIDMOD; k++){
-		lock(&xlocks[k]);
-		hp=&xfiles[k];
-		for(f=*hp; f; f=f->next)
-			if(f->s == s && (xf = xfid(uid, f, 0))){ /* assign = */
-				xfclear(xf);
-				++count;
-			}
-		unlock(&xlocks[k]);
-	}
-	return count;
-}

+ 22 - 85
sys/src/cmd/acme/build.json

@@ -1,94 +1,31 @@
 {
 	"acme": {
-		"Cflags": [
-			"-ffreestanding",
-			"-fno-builtin",
-			"-fno-omit-frame-pointer",
-			"-fplan9-extensions",
-			"-fvar-tracking",
-			"-fvar-tracking-assignments",
-			"-g",
-			"-gdwarf-2",
-			"-ggdb",
-			"-mcmodel=small",
-			"-mno-red-zone",
-			"-O0",
-			"-static",
-			"-Wall",
-			"-Wno-missing-braces",
-			"-Wno-parentheses",
-		    "-Wno-pointer-sign",
-			"-Wno-unknown-pragmas"
+		"Include": [
+			"../cmd.json"
 		],
 		"Install": "/$ARCH/bin",
-		"Post": [
-			"rm *.o"
-		],
-		"Oflags": [
-			"-static",
-			"-e_main",
-			"-lavl",
-			"-lcomplete",
-			"-lcontrol",
-			"-ldisk",
-			"-lflate",
-			"-lframe",
-			"-lgeometry",
-			"-lhttpd",
-			"-lbin",
-			"-llex",
-			"-lmemdraw",
-			"-lmemlayer",
-			"-lmemdraw",
-			"-ldraw",
-			"-lplumb",
-			"-lregexp",
-			"-lstdio",
-			"-lString",
-			"-lsunrpc",
-			"-loventi",
-			"-l9p",
-			"-lauth",
-			"-lauthsrv",
-			"-lndb",
-			"-lip",
-			"-lventi",
-			"-lsec",
-			"-lauth",
-			"-lmp",
-			"-lthread",
-			"-lmach",
-			"-lbio",
-			"-lc"
-		],
-		"Post": [
-			"rm -f *.o"
-		],
-		"Pre": [
-			"rm -f *.tag.*"
-		],
 		"Program": "acme",
 	 	"SourceFiles": [
-	"acme.c",
-	"addr.c",
-	"buff.c",
-	"cols.c",
-	"disk.c",
-	"ecmd.c",
-	"edit.c",
-	"elog.c",
-	"exec.c",
-	"file.c",
-	"fsys.c",
-	"look.c",
-	"regx.c",
-	"rows.c",
-	"scrl.c",
-	"text.c",
-	"time.c",
-	"util.c",
-	"wind.c",
-	"xfid.c"
+			"acme.c",
+			"addr.c",
+			"buff.c",
+			"cols.c",
+			"disk.c",
+			"ecmd.c",
+			"edit.c",
+			"elog.c",
+			"exec.c",
+			"file.c",
+			"fsys.c",
+			"look.c",
+			"regx.c",
+			"rows.c",
+			"scrl.c",
+			"text.c",
+			"time.c",
+			"util.c",
+			"wind.c",
+			"xfid.c"
 		]
 	}
 }

+ 0 - 2
sys/src/cmd/aux/aux.json

@@ -36,10 +36,8 @@
 			"msexceltables.c",
 			"mswordstrings.c",
 			"mouse.c",
-			"nfsmount.c",
 			"olefs.c",
 			"pcmcia.c",
-			"portmap.c",
 			"rdwr.c",
 			"reboot.c",
 			"searchfs.c",

+ 0 - 343
sys/src/cmd/aux/nfsmount.c

@@ -1,343 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-/* Copyright © 2003 Russ Cox, MIT; see /sys/src/libsunrpc/COPYING */
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-#include <nfs3.h>
-
-int chatty;
-SunClient *client;
-
-void
-usage(void)
-{
-	fprint(2, "usage: nfsmount address [cmd]\n"
-		"cmd is one of:\n"
-		"\tnull\n"
-		"\tmnt path\n"
-		"\tdump\n"
-		"\tumnt path\n"
-		"\tumntall\n"
-		"\texport (default)\n");
-	threadexitsall("usage");
-}
-
-void
-portCall(SunCall *c, PortCallType type)
-{
-	c->rpc.prog = PortProgram;
-	c->rpc.vers = PortVersion;
-	c->rpc.proc = type>>1;
-	c->rpc.iscall = !(type&1);
-	c->type = type;
-}
-
-int
-getport(SunClient *client, uint prog, uint vers, uint prot, uint *port)
-{
-	PortTGetport tx;
-	PortRGetport rx;
-
-	memset(&tx, 0, sizeof tx);
-	portCall(&tx.call, PortCallTGetport);
-	tx.map.prog = prog;
-	tx.map.vers = vers;
-	tx.map.prot = prot;
-
-	memset(&rx, 0, sizeof rx);
-	portCall(&rx.call, PortCallRGetport);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
-		return -1;
-	*port = rx.port;
-	return 0;
-}
-
-uint8_t unixauth[] = {
-	0x12, 0x23, 0x34, 0x45,	/* stamp */
-	0x00, 0x00, 0x00, 0x04,	/* gnot */
-	0x67, 0x6e, 0x6f, 0x74,
-	0x00, 0x00, 0x03, 0xE9,	/* 1001 */
-	0x00, 0x00, 0x03, 0xE9,	/* 1001 */
-	0x00, 0x00, 0x00, 0x00,	/* gid list */
-};
-void
-mountCall(SunCall *c, NfsMount3CallType type)
-{
-	c->rpc.prog = NfsMount3Program;
-	c->rpc.vers = NfsMount3Version;
-	c->rpc.proc = type>>1;
-	c->rpc.iscall = !(type&1);
-	if(c->rpc.iscall){
-		c->rpc.cred.flavor = SunAuthSys;
-		c->rpc.cred.data = unixauth;
-		c->rpc.cred.ndata = sizeof unixauth;
-	}
-	c->type = type;
-}
-
-void
-tnull(char **argv)
-{
-	NfsMount3TNull tx;
-	NfsMount3RNull rx;
-
-	USED(argv);
-
-	memset(&tx, 0, sizeof tx);
-	mountCall(&tx.call, NfsMount3CallTNull);
-
-	memset(&rx, 0, sizeof rx);
-	mountCall(&rx.call, NfsMount3CallRNull);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
-		sysfatal("rpc: %r");
-}
-
-void
-tmnt(char **argv)
-{
-	int i;
-	NfsMount3TMnt tx;
-	NfsMount3RMnt rx;
-
-	memset(&tx, 0, sizeof tx);
-	mountCall(&tx.call, NfsMount3CallTMnt);
-	tx.path = argv[0];
-
-	memset(&rx, 0, sizeof rx);
-	mountCall(&rx.call, NfsMount3CallRMnt);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
-		sysfatal("rpc: %r");
-
-	if(rx.status != 0){
-		nfs3Errstr(rx.status);
-		sysfatal("mnt: %r");
-	}
-
-	print("handle %.*H\n", rx.len, rx.handle);
-	print("auth:");
-	for(i=0; i<rx.nauth; i++)
-		print(" %ud", (uint)rx.auth[i]);
-	print("\n");
-}
-
-void
-tdump(char **argv)
-{
-	uint8_t *p, *ep;
-	NfsMount3TDump tx;
-	NfsMount3RDump rx;
-	NfsMount3Entry e;
-
-	memset(&tx, 0, sizeof tx);
-	mountCall(&tx.call, NfsMount3CallTDump);
-	USED(argv);
-
-	memset(&rx, 0, sizeof rx);
-	mountCall(&rx.call, NfsMount3CallRDump);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
-		sysfatal("rpc: %r");
-
-	p = rx.data;
-	ep = p+rx.count;
-	while(p < ep){
-		if(nfsMount3EntryUnpack(p, ep, &p, &e) < 0)
-			sysfatal("unpack entry structure failed");
-		print("%s %s\n", e.host, e.path);
-	}
-}
-
-void
-tumnt(char **argv)
-{
-	NfsMount3TUmnt tx;
-	NfsMount3RUmnt rx;
-
-	memset(&tx, 0, sizeof tx);
-	mountCall(&tx.call, NfsMount3CallTUmnt);
-	tx.path = argv[0];
-
-	memset(&rx, 0, sizeof rx);
-	mountCall(&rx.call, NfsMount3CallRUmnt);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
-		sysfatal("rpc: %r");
-
-	print("\n");
-}
-
-void
-tumntall(char **argv)
-{
-	NfsMount3TUmntall tx;
-	NfsMount3RUmntall rx;
-
-	memset(&tx, 0, sizeof tx);
-	mountCall(&tx.call, NfsMount3CallTUmntall);
-	USED(argv);
-
-	memset(&rx, 0, sizeof rx);
-	mountCall(&rx.call, NfsMount3CallRUmntall);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
-		sysfatal("rpc: %r");
-
-	print("\n");
-}
-
-void
-texport(char **argv)
-{
-	uint8_t *p, *ep, *tofree;
-	char **g, **gg;
-	int ng, i, n;
-	NfsMount3TDump tx;
-	NfsMount3RDump rx;
-	NfsMount3Export e;
-
-	memset(&tx, 0, sizeof tx);
-	mountCall(&tx.call, NfsMount3CallTExport);
-	USED(argv);
-
-	memset(&rx, 0, sizeof rx);
-	mountCall(&rx.call, NfsMount3CallRExport);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, &tofree) < 0)
-		sysfatal("rpc: %r");
-
-	p = rx.data;
-	ep = p+rx.count;
-	g = nil;
-	ng = 0;
-	while(p < ep){
-		n = nfsMount3ExportGroupSize(p);
-		if(n > ng){
-			ng = n;
-			g = erealloc(g, sizeof(g[0])*ng);
-		}
-		if(nfsMount3ExportUnpack(p, ep, &p, g, &gg, &e) < 0)
-			sysfatal("unpack export structure failed");
-		print("%s", e.path);
-		for(i=0; i<e.ng; i++)
-			print(" %s", e.g[i]);
-		print("\n");
-	}
-	free(tofree);
-}
-
-static struct {
-	char *cmd;
-	int narg;
-	void (*fn)(char**);
-} tab[] = {
-	"null",	0,	tnull,
-	"mnt",	1,	tmnt,
-	"dump",	0,	tdump,
-	"umnt",	1,	tumnt,
-	"umntall",	1,	tumntall,
-	"export",	0,	texport,
-};
-
-char*
-netchangeport(char *addr, char *port)
-{
-	static char buf[256];
-	char *r;
-
-	strecpy(buf, buf+sizeof buf, addr);
-	r = strrchr(buf, '!');
-	if(r == nil)
-		return nil;
-	r++;
-	strecpy(r, buf+sizeof buf, port);
-	return buf;
-}
-
-void
-threadmain(int argc, char **argv)
-{
-	char *dflt[] = { "export", };
-	char *addr, *cmd;
-	int i, proto;
-	uint port;
-	char buf[32];
-	int mapit;
-
-	mapit = 1;
-	ARGBEGIN{
-	case 'R':
-		chatty++;
-		break;
-	case 'm':
-		mapit = 0;
-		break;
-	}ARGEND
-
-	if(argc < 1)
-		usage();
-
-	fmtinstall('B', sunRpcFmt);
-	fmtinstall('C', sunCallFmt);
-	fmtinstall('H', encodefmt);
-	sunFmtInstall(&portProg);
-	sunFmtInstall(&nfsMount3Prog);
-
-	addr = netmkaddr(argv[0], "udp", "portmap");
-	if(mapit){
-		/* translate with port mapper */
-		fprint(2, "connecting to %s\n", addr);
-		if((client = sunDial(addr)) == nil)
-			sysfatal("dial %s: %r", addr);
-		client->chatty = chatty;
-		sunClientProg(client, &portProg);
-		if(strstr(addr, "udp!"))
-			proto = PortProtoUdp;
-		else
-			proto = PortProtoTcp;
-		if(getport(client, NfsMount3Program, NfsMount3Version, proto, &port) < 0)
-			sysfatal("getport: %r");
-		snprint(buf, sizeof buf, "%ud!r", port);
-		addr = netchangeport(addr, buf);
-		sunClientClose(client);
-	}
-
-	fprint(2, "connecting to %s\n", addr);
-	if((client = sunDial(addr)) == nil)
-		sysfatal("dial %s: %r", addr);
-
-	client->chatty = chatty;
-	sunClientProg(client, &nfsMount3Prog);
-
-	argv++;
-	argc--;
-
-	if(argc == 0){
-		argc = 1;
-		argv = dflt;
-	}
-	cmd = argv[0];
-	argv++;
-	argc--;
-
-	for(i=0; i<nelem(tab); i++){
-		if(strcmp(tab[i].cmd, cmd) == 0){
-			if(tab[i].narg != argc)
-				usage();
-			(*tab[i].fn)(argv);
-			threadexitsall(nil);
-		}
-	}
-	usage();
-}

+ 0 - 213
sys/src/cmd/aux/portmap.c

@@ -1,213 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-/* Copyright © 2003 Russ Cox, MIT; see /sys/src/libsunrpc/COPYING */
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-int chatty;
-SunClient *client;
-
-void
-usage(void)
-{
-	fprint(2, "usage: portmap address [cmd]\n"
-		"cmd is one of:\n"
-		"\tnull\n"
-		"\tset prog vers proto port\n"
-		"\tunset prog vers proto port\n"
-		"\tgetport prog vers proto\n"
-		"\tdump (default)\n");
-	threadexitsall("usage");
-}
-
-void
-portCall(SunCall *c, PortCallType type)
-{
-	c->rpc.prog = PortProgram;
-	c->rpc.vers = PortVersion;
-	c->rpc.proc = type>>1;
-	c->rpc.iscall = !(type&1);
-	c->type = type;
-}
-
-void
-tnull(char **argv)
-{
-	PortTNull tx;
-	PortRNull rx;
-
-	USED(argv);
-
-	memset(&tx, 0, sizeof tx);
-	portCall(&tx.call, PortCallTNull);
-
-	memset(&rx, 0, sizeof rx);
-	portCall(&rx.call, PortCallRNull);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
-		sysfatal("rpc: %r");
-}
-
-void
-tset(char **argv)
-{
-	PortTSet tx;
-	PortRSet rx;
-
-	memset(&tx, 0, sizeof tx);
-	portCall(&tx.call, PortCallTSet);
-	tx.map.prog = strtol(argv[0], 0, 0);
-	tx.map.vers = strtol(argv[1], 0, 0);
-	tx.map.prot = strtol(argv[2], 0, 0);
-	tx.map.port = strtol(argv[3], 0, 0);
-
-	memset(&rx, 0, sizeof rx);
-	portCall(&rx.call, PortCallRSet);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
-		sysfatal("rpc: %r");
-
-	if(rx.b == 0)
-		print("rejected\n");
-}
-
-void
-tunset(char **argv)
-{
-	PortTUnset tx;
-	PortRUnset rx;
-
-	memset(&tx, 0, sizeof tx);
-	portCall(&tx.call, PortCallTUnset);
-	tx.map.prog = strtol(argv[0], 0, 0);
-	tx.map.vers = strtol(argv[1], 0, 0);
-	tx.map.prot = strtol(argv[2], 0, 0);
-	tx.map.port = strtol(argv[3], 0, 0);
-
-	memset(&rx, 0, sizeof rx);
-	portCall(&rx.call, PortCallRUnset);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
-		sysfatal("rpc: %r");
-
-	if(rx.b == 0)
-		print("rejected\n");
-}
-
-void
-tgetport(char **argv)
-{
-	PortTGetport tx;
-	PortRGetport rx;
-
-	memset(&tx, 0, sizeof tx);
-	portCall(&tx.call, PortCallTGetport);
-	tx.map.prog = strtol(argv[0], 0, 0);
-	tx.map.vers = strtol(argv[1], 0, 0);
-	tx.map.prot = strtol(argv[2], 0, 0);
-
-	memset(&rx, 0, sizeof rx);
-	portCall(&rx.call, PortCallRGetport);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
-		sysfatal("rpc: %r");
-
-	print("%d\n", rx.port);
-}
-
-void
-tdump(char **argv)
-{
-	int i;
-	uint8_t *p;
-	PortTDump tx;
-	PortRDump rx;
-	PortMap *m;
-
-	USED(argv);
-
-	memset(&tx, 0, sizeof tx);
-	portCall(&tx.call, PortCallTDump);
-
-	memset(&rx, 0, sizeof rx);
-	portCall(&rx.call, PortCallRDump);
-
-	if(sunClientRpc(client, 0, &tx.call, &rx.call, &p) < 0)
-		sysfatal("rpc: %r");
-
-	for(i=0, m=rx.map; i<rx.nmap; i++, m++)
-		print("%ud %ud %ud %ud\n", (uint)m->prog, (uint)m->vers, (uint)m->prot, (uint)m->port);
-
-	free(p);
-}
-
-static struct {
-	char *cmd;
-	int narg;
-	void (*fn)(char**);
-} tab[] = {
-	"null",	0,	tnull,
-	"set",	4,	tset,
-	"unset",	4,	tunset,
-	"getport",	3,	tgetport,
-	"dump",	0,	tdump,
-};
-
-void
-threadmain(int argc, char **argv)
-{
-	char *dflt[] = { "dump", };
-	char *addr, *cmd;
-	int i;
-
-	ARGBEGIN{
-	case 'R':
-		chatty++;
-		break;
-	}ARGEND
-
-	if(argc < 1)
-		usage();
-
-	fmtinstall('B', sunRpcFmt);
-	fmtinstall('C', sunCallFmt);
-	fmtinstall('H', encodefmt);
-	sunFmtInstall(&portProg);
-
-	addr = netmkaddr(argv[0], "udp", "portmap");
-	if((client = sunDial(addr)) == nil)
-		sysfatal("dial %s: %r", addr);
-
-	client->chatty = chatty;
-	sunClientProg(client, &portProg);
-
-	argv++;
-	argc--;
-
-	if(argc == 0){
-		argc = 1;
-		argv = dflt;
-	}
-	cmd = argv[0];
-	argv++;
-	argc--;
-
-	for(i=0; i<nelem(tab); i++){
-		if(strcmp(tab[i].cmd, cmd) == 0){
-			if(tab[i].narg != argc)
-				usage();
-			(*tab[i].fn)(argv);
-			threadexitsall(nil);
-		}
-	}
-	usage();
-}

+ 1 - 1
sys/src/cmd/bzip2/bzip2.json

@@ -7,7 +7,7 @@
 			"../cmd.json"
 		],
 		"Libs": [
-			"lib/libbzip2.a"
+			"/sys/src/cmd/bzip2/lib/libbzip2.a"
 		],
 		"Install": "/$ARCH/bin",
 		"Post": [

+ 0 - 1
sys/src/cmd/cmd.json

@@ -24,7 +24,6 @@
 			"-lregexp",
 			"-lstdio",
 			"-lString",
-			"-lsunrpc",
 			"-loventi",
 			"-l9p",
 			"-lauth",

+ 0 - 1
sys/src/cmd/cmds.json

@@ -132,7 +132,6 @@
 		"Install": "/$ARCH/bin/",
 		"Projects": [
 			"9660srv/9660srv.json",
-			"9nfs/9nfs.json",
 			"acme/build.json",
 			"astro/astro.json",
 			"auth/auth.json",

+ 3 - 65
sys/src/cmd/sam/build.json

@@ -1,71 +1,9 @@
 {
 	"sam": {
-		"Cflags": [
-			"-ffreestanding",
-			"-fno-builtin",
-			"-fno-omit-frame-pointer",
-			"-fplan9-extensions",
-			"-fvar-tracking",
-			"-fvar-tracking-assignments",
-			"-g",
-			"-gdwarf-2",
-			"-ggdb",
-			"-mcmodel=small",
-			"-mno-red-zone",
-			"-Wpedantic",
-			"-O0",
-			"-static",
-			"-Wall",
-			"-Wno-missing-braces",
-			"-Wno-parentheses",
-		    "-Wno-pointer-sign",
-			"-Wno-unknown-pragmas"
-		],
-		"Install": "/$ARCH/bin",
-		"Post": [
-			"rm *.o",
-			"OBJDUMP=objdump; $TOOLPREFIX$OBJDUMP -S $HARVEY/$ARCH/bin/sam > sam.asm" 
-		],
-		"Oflags": [
-			"-static",
-			"-e_main",
-			"-lavl",
-			"-lcomplete",
-			"-lcontrol",
-			"-ldisk",
-			"-lflate",
-			"-lframe",
-			"-lgeometry",
-			"-lhttpd",
-			"-lbin",
-			"-llex",
-			"-lmemdraw",
-			"-lmemlayer",
-			"-lmemdraw",
-			"-ldraw",
-			"-lplumb",
-			"-lregexp",
-			"-lstdio",
-			"-lString",
-			"-lsunrpc",
-			"-loventi",
-			"-l9p",
-			"-lauth",
-			"-lauthsrv",
-			"-lndb",
-			"-lip",
-			"-lventi",
-			"-lsec",
-			"-lauth",
-			"-lmp",
-			"-lthread",
-			"-lmach",
-			"-lbio",
-			"-lc"
-		],
-		"Pre": [
-			"rm -f *.tag.*"
+		"Include": [
+			"../cmd.json"
 		],
+		"Install": "/$ARCH/bin/",
 		"Program": "sam",
 	 	"SourceFiles": [
 			"address.c",

+ 2 - 63
sys/src/cmd/samterm/build.json

@@ -1,70 +1,9 @@
 {
 	"samterm": {
-		"Cflags": [
-			"-ffreestanding",
-			"-fno-builtin",
-			"-fno-omit-frame-pointer",
-			"-fplan9-extensions",
-			"-fvar-tracking",
-			"-fvar-tracking-assignments",
-			"-g",
-			"-gdwarf-2",
-			"-ggdb",
-			"-mcmodel=small",
-			"-mno-red-zone",
-			"-O2",
-			"-I../sam",
-			"-static",
-			"-Wall",
-			"-Wno-missing-braces",
-			"-Wno-parentheses",
-			"-Wno-pointer-sign",
-			"-Wno-unknown-pragmas"
+		"Include": [
+			"../cmd.json"
 		],
 		"Install": "/$ARCH/bin/aux",
-		"Post": [
-			"rm *.o"
-		],
-		"Oflags": [
-			"-static",
-			"-e_main",
-			"-lavl",
-			"-lcomplete",
-			"-lcontrol",
-			"-ldisk",
-			"-lflate",
-			"-lframe",
-			"-lgeometry",
-			"-lhttpd",
-			"-lbin",
-			"-llex",
-			"-lmemdraw",
-			"-lmemlayer",
-			"-lmemdraw",
-			"-ldraw",
-			"-lplumb",
-			"-lregexp",
-			"-lstdio",
-			"-lString",
-			"-lsunrpc",
-			"-loventi",
-			"-l9p",
-			"-lauth",
-			"-lauthsrv",
-			"-lndb",
-			"-lip",
-			"-lventi",
-			"-lsec",
-			"-lauth",
-			"-lmp",
-			"-lthread",
-			"-lmach",
-			"-lbio",
-			"-lc"
-		],
-		"Pre": [
-			"rm -f *.tag.*"
-		],
 		"Program": "samterm",
 	 	"SourceFiles": [
 			"flayer.c",

+ 140 - 0
sys/src/cmd/samterm/mesg.h

@@ -0,0 +1,140 @@
+/* 
+ * This file is part of the UCB release of Plan 9. It is subject to the license
+ * terms in the LICENSE file found in the top-level directory of this
+ * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
+ * part of the UCB release of Plan 9, including this file, may be copied,
+ * modified, propagated, or distributed except according to the terms contained
+ * in the LICENSE file.
+ */
+
+/* VERSION 1 introduces plumbing
+	2 increases SNARFSIZE from 4096 to 32000
+ */
+#define	VERSION	2
+
+#define	TBLOCKSIZE 512		  /* largest piece of text sent to terminal */
+#define	DATASIZE  (UTFmax*TBLOCKSIZE+30) /* ... including protocol header stuff */
+#define	SNARFSIZE 32000		/* maximum length of exchanged snarf buffer, must fit in 15 bits */
+/*
+ * Messages originating at the terminal
+ */
+typedef enum Tmesg
+{
+	Tversion,	/* version */
+	Tstartcmdfile,	/* terminal just opened command frame */
+	Tcheck,		/* ask host to poke with Hcheck */
+	Trequest,	/* request data to fill a hole */
+	Torigin,	/* gimme an Horigin near here */
+	Tstartfile,	/* terminal just opened a file's frame */
+	Tworkfile,	/* set file to which commands apply */
+	Ttype,		/* add some characters, but terminal already knows */
+	Tcut,
+	Tpaste,
+	Tsnarf,
+	Tstartnewfile,	/* terminal just opened a new frame */
+	Twrite,		/* write file */
+	Tclose,		/* terminal requests file close; check mod. status */
+	Tlook,		/* search for literal current text */
+	Tsearch,	/* search for last regular expression */
+	Tsend,		/* pretend he typed stuff */
+	Tdclick,	/* double click */
+	Tstartsnarf,	/* initiate snarf buffer exchange */
+	Tsetsnarf,	/* remember string in snarf buffer */
+	Tack,		/* acknowledge Hack */
+	Texit,		/* exit */
+	Tplumb,		/* send plumb message */
+	TMAX,
+}Tmesg;
+/*
+ * Messages originating at the host
+ */
+typedef enum Hmesg
+{
+	Hversion,	/* version */
+	Hbindname,	/* attach name[0] to text in terminal */
+	Hcurrent,	/* make named file the typing file */
+	Hnewname,	/* create "" name in menu */
+	Hmovname,	/* move file name in menu */
+	Hgrow,		/* insert space in rasp */
+	Hcheck0,	/* see below */
+	Hcheck,		/* ask terminal to check whether it needs more data */
+	Hunlock,	/* command is finished; user can do things */
+	Hdata,		/* store this data in previously allocated space */
+	Horigin,	/* set origin of file/frame in terminal */
+	Hunlockfile,	/* unlock file in terminal */
+	Hsetdot,	/* set dot in terminal */
+	Hgrowdata,	/* Hgrow + Hdata folded together */
+	Hmoveto,	/* scrolling, context search, etc. */
+	Hclean,		/* named file is now 'clean' */
+	Hdirty,		/* named file is now 'dirty' */
+	Hcut,		/* remove space from rasp */
+	Hsetpat,	/* set remembered regular expression */
+	Hdelname,	/* delete file name from menu */
+	Hclose,		/* close file and remove from menu */
+	Hsetsnarf,	/* remember string in snarf buffer */
+	Hsnarflen,	/* report length of implicit snarf */
+	Hack,		/* request acknowledgement */
+	Hexit,
+	Hplumb,		/* return plumb message to terminal - version 1 */
+	HMAX,
+}Hmesg;
+typedef struct Header{
+	uchar	type;		/* one of the above */
+	uchar	count0;		/* low bits of data size */
+	uchar	count1;		/* high bits of data size */
+	uchar	data[1];	/* variable size */
+}Header;
+
+/*
+ * File transfer protocol schematic, a la Holzmann
+ * #define N	6
+ * 
+ * chan h = [4] of { mtype };
+ * chan t = [4] of { mtype };
+ * 
+ * mtype = {	Hgrow, Hdata,
+ * 		Hcheck, Hcheck0,
+ * 		Trequest, Tcheck,
+ * 	};
+ * 
+ * active proctype host()
+ * {	byte n;
+ * 
+ * 	do
+ * 	:: n <  N -> n++; t!Hgrow
+ * 	:: n == N -> n++; t!Hcheck0
+ * 
+ * 	:: h?Trequest -> t!Hdata
+ * 	:: h?Tcheck   -> t!Hcheck
+ * 	od
+ * }
+ * 
+ * active proctype term()
+ * {
+ * 	do
+ * 	:: t?Hgrow   -> h!Trequest
+ * 	:: t?Hdata   -> skip
+ * 	:: t?Hcheck0 -> h!Tcheck
+ * 	:: t?Hcheck  ->
+ * 		if
+ * 		:: h!Trequest -> progress: h!Tcheck
+ * 		:: break
+ * 		fi
+ * 	od;
+ * 	printf("term exits\n")
+ * }
+ *
+ * From: gerard@research.bell-labs.com
+ * Date: Tue Jul 17 13:47:23 EDT 2001
+ * To: rob@research.bell-labs.com
+ * 
+ * spin -c 	(or -a) spec
+ * pcc -DNP -o pan pan.c
+ * pan -l
+ * 
+ * proves that there are no non-progress cycles
+ * (infinite executions *not* passing through
+ * the statement marked with a label starting
+ * with the prefix "progress")
+ * 
+ */

+ 5 - 5
sys/src/games/games.json

@@ -14,11 +14,11 @@
 		]
 	},
 	"Dirs": {
-                "Include": [
-                        "../cmd/cmd.json"
-                ],               
-                "Install": "/$ARCH/bin/",
-                "Projects": [           
+		"Include": [
+			"../cmd/cmd.json"
+		],
+		"Install": "/$ARCH/bin/",
+		"Projects": [
 			"sokoban/sokoban.json",
 			"sudoku/sudoku.json",
 			"mahjongg/mahjongg.json"

+ 0 - 1
sys/src/libs.json

@@ -29,7 +29,6 @@
 			"/sys/src/libregexp/libregexp.json",
 			"/sys/src/libsec/libsec.json",
 			"/sys/src/libstdio/libstdio.json",
-			"/sys/src/libsunrpc/libsunrpc.json",
 			"/sys/src/libthread/libthread.json",
 			"/sys/src/libusb",
 			"/sys/src/libventi/libventi.json"

+ 0 - 29
sys/src/libsunrpc/COPYING

@@ -1,29 +0,0 @@
-
-This software was developed as part of a project at MIT:
-	/sys/src/libsunrpc/*
-	/sys/src/cmd/nfs.c
-	/sys/src/cmd/aux/nfsmount.c
-	/sys/src/cmd/aux/portmap.c
-
-Copyright (c) 2003 Russ Cox,
-                   Massachusetts Institute of Technology
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-

+ 0 - 69
sys/src/libsunrpc/authunix.c

@@ -1,69 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-uint
-sunAuthUnixSize(SunAuthUnix *x)
-{
-	return 4 + sunStringSize(x->sysname) + 4 + 4 + 4 + 4*x->ng;
-}
-int
-sunAuthUnixUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, SunAuthUnix *x)
-{
-	int i;
-
-	if(sunUint32Unpack(a, ea, &a, &x->stamp) < 0) goto Err;
-	if(sunStringUnpack(a, ea, &a, &x->sysname, 256) < 0) goto Err;
-	if(sunUint32Unpack(a, ea, &a, &x->uid) < 0) goto Err;
-	if(sunUint32Unpack(a, ea, &a, &x->gid) < 0) goto Err;
-	if(sunUint32Unpack(a, ea, &a, &x->ng) < 0 || x->ng > nelem(x->g)) goto Err;
-	for(i=0; i<x->ng; i++)
-		if(sunUint32Unpack(a, ea, &a, &x->g[i]) < 0) goto Err;
-
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-int
-sunAuthUnixPack(uint8_t *a, uint8_t *ea, uint8_t **pa, SunAuthUnix *x)
-{
-	int i;
-
-	if(sunUint32Pack(a, ea, &a, &x->stamp) < 0) goto Err;
-	if(sunStringPack(a, ea, &a, &x->sysname, 256) < 0) goto Err;
-	if(sunUint32Pack(a, ea, &a, &x->uid) < 0) goto Err;
-	if(sunUint32Pack(a, ea, &a, &x->gid) < 0) goto Err;
-	if(sunUint32Pack(a, ea, &a, &x->ng) < 0 || x->ng > nelem(x->g)) goto Err;
-	for(i=0; i<x->ng; i++)
-		if(sunUint32Pack(a, ea, &a, &x->g[i]) < 0) goto Err;
-
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-void
-sunAuthUnixPrint(Fmt *fmt, SunAuthUnix *x)
-{
-	int i;
-	fmtprint(fmt, "unix %.8lux %s %lud %lud (", (uint32_t)x->stamp,
-		x->sysname, (uint32_t)x->uid, (uint32_t)x->gid);
-	for(i=0; i<x->ng; i++)
-		fmtprint(fmt, "%s%lud", i ? " ":"", (uint32_t)x->g[i]);
-	fmtprint(fmt, ")");
-}

+ 0 - 492
sys/src/libsunrpc/client.c

@@ -1,492 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-/*
- * Sun RPC client.
- */
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-typedef struct Out Out;
-struct Out
-{
-	char err[ERRMAX];	/* error string */
-	Channel *creply;	/* send to finish rpc */
-	uint8_t *p;			/* pending request packet */
-	int n;				/* size of request */
-	uint32_t tag;			/* flush tag of pending request */
-	uint32_t xid;			/* xid of pending request */
-	uint32_t st;			/* first send time */
-	uint32_t t;			/* resend time */
-	int nresend;		/* number of resends */
-	SunRpc rpc;		/* response rpc */
-};
-
-static void
-udpThread(void *v)
-{
-	uint8_t *p, *buf;
-	Ioproc *io;
-	int n;
-	SunClient *cli;
-	enum { BufSize = 65536 };
-
-	cli = v;
-	buf = emalloc(BufSize);
-	io = ioproc();
-	p = nil;
-	for(;;){
-		n = ioread(io, cli->fd, buf, BufSize);
-		if(n <= 0)
-			break;
-		p = emalloc(4+n);
-		memmove(p+4, buf, n);
-		p[0] = n>>24;
-		p[1] = n>>16;
-		p[2] = n>>8;
-		p[3] = n;
-		if(sendp(cli->readchan, p) == 0)
-			break;
-		p = nil;
-	}
-	free(p);
-	closeioproc(io);
-	while(send(cli->dying, nil) == -1)
-		;
-}
-
-static void
-netThread(void *v)
-{
-	uint8_t *p, buf[4];
-	Ioproc *io;
-	uint n, tot;
-	int done;
-	SunClient *cli;
-
-	cli = v;
-	io = ioproc();
-	tot = 0;
-	p = nil;
-	for(;;){
-		n = ioreadn(io, cli->fd, buf, 4);
-		if(n != 4)
-			break;
-		n = (buf[0]<<24)|(buf[1]<<16)|(buf[2]<<8)|buf[3];
-		if(cli->chatty)
-			fprint(2, "%.8ux...", n);
-		done = n&0x80000000;
-		n &= ~0x80000000;
-		if(tot == 0){
-			p = emalloc(4+n);
-			tot = 4;
-		}else
-			p = erealloc(p, tot+n);
-		if(ioreadn(io, cli->fd, p+tot, n) != n)
-			break;
-		tot += n;
-		if(done){
-			p[0] = tot>>24;
-			p[1] = tot>>16;
-			p[2] = tot>>8;
-			p[3] = tot;
-			if(sendp(cli->readchan, p) == 0)
-				break;
-			p = nil;
-			tot = 0;
-		}
-	}
-	free(p);
-	closeioproc(io);
-	while(send(cli->dying, 0) == -1)
-		;
-}
-
-static void
-timerThread(void *v)
-{
-	Ioproc *io;
-	SunClient *cli;
-
-	cli = v;
-	io = ioproc();
-	for(;;){
-		if(iosleep(io, 200) < 0)
-			break;
-		if(sendul(cli->timerchan, 0) == 0)
-			break;
-	}
-	closeioproc(io);
-	while(send(cli->dying, 0) == -1)
-		;
-}
-
-static uint32_t
-msec(void)
-{
-	return nsec()/1000000;
-}
-
-static uint32_t
-twait(uint32_t rtt, int nresend)
-{
-	uint32_t t;
-
-	t = rtt;
-	if(nresend <= 1)
-		{}
-	else if(nresend <= 3)
-		t *= 2;
-	else if(nresend <= 18)
-		t <<= nresend-2;
-	else
-		t = 60*1000;
-	if(t > 60*1000)
-		t = 60*1000;
-
-	return t;
-}
-
-static void
-rpcMuxThread(void *v)
-{
-	uint8_t *buf, *p, *ep;
-	int i, n, nout, mout;
-	uint32_t t, xidgen, tag;
-	Alt a[5];
-	Out *o, **out;
-	SunRpc rpc;
-	SunClient *cli;
-
-	cli = v;
-	mout = 16;
-	nout = 0;
-	out = emalloc(mout*sizeof(out[0]));
-	xidgen = truerand();
-
-	a[0].op = CHANRCV;
-	a[0].c = cli->rpcchan;
-	a[0].v = &o;
-	a[1].op = CHANNOP;
-	a[1].c = cli->timerchan;
-	a[1].v = nil;
-	a[2].op = CHANRCV;
-	a[2].c = cli->flushchan;
-	a[2].v = &tag;
-	a[3].op = CHANRCV;
-	a[3].c = cli->readchan;
-	a[3].v = &buf;
-	a[4].op = CHANEND;
-
-	for(;;){
-		switch(alt(a)){
-		case 0:	/* o = <-rpcchan */
-			if(o == nil)
-				goto Done;
-			cli->nsend++;
-			/* set xid */
-			o->xid = ++xidgen;
-			if(cli->needcount)
-				p = o->p+4;
-			else
-				p = o->p;
-			p[0] = xidgen>>24;
-			p[1] = xidgen>>16;
-			p[2] = xidgen>>8;
-			p[3] = xidgen;
-			if(write(cli->fd, o->p, o->n) != o->n){
-				free(o->p);
-				o->p = nil;
-				snprint(o->err, sizeof o->err, "write: %r");
-				sendp(o->creply, 0);
-				break;
-			}
-			if(nout >= mout){
-				mout *= 2;
-				out = erealloc(out, mout*sizeof(out[0]));
-			}
-			o->st = msec();
-			o->nresend = 0;
-			o->t = o->st + twait(cli->rtt.avg, 0);
-if(cli->chatty) fprint(2, "send %lux %lud %lud\n", o->xid, o->st, o->t);
-			out[nout++] = o;
-			a[1].op = CHANRCV;
-			break;
-
-		case 1:	/* <-timerchan */
-			t = msec();
-			for(i=0; i<nout; i++){
-				o = out[i];
-				if((int)(t - o->t) > 0){
-if(cli->chatty) fprint(2, "resend %lux %lud %lud\n", o->xid, t, o->t);
-					if(cli->maxwait && t - o->st >= cli->maxwait){
-						free(o->p);
-						o->p = nil;
-						strcpy(o->err, "timeout");
-						sendp(o->creply, 0);
-						out[i--] = out[--nout];
-						continue;
-					}
-					cli->nresend++;
-					o->nresend++;
-					o->t = t + twait(cli->rtt.avg, o->nresend);
-					if(write(cli->fd, o->p, o->n) != o->n){
-						free(o->p);
-						o->p = nil;
-						snprint(o->err, sizeof o->err, "rewrite: %r");
-						sendp(o->creply, 0);
-						out[i--] = out[--nout];
-						continue;
-					}
-				}
-			}
-			/* stop ticking if no work; rpcchan will turn it back on */
-			if(nout == 0)
-				a[1].op = CHANNOP;
-			break;
-			
-		case 2:	/* tag = <-flushchan */
-			for(i=0; i<nout; i++){
-				o = out[i];
-				if(o->tag == tag){
-					out[i--] = out[--nout];
-					strcpy(o->err, "flushed");
-					free(o->p);
-					o->p = nil;
-					sendp(o->creply, 0);
-				}
-			}
-			break;
-
-		case 3:	/* buf = <-readchan */
-			p = buf;
-			n = (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
-			p += 4;
-			ep = p+n;
-			if(sunRpcUnpack(p, ep, &p, &rpc) < 0){
-				fprint(2, "in: %.*H unpack failed\n", n, buf+4);
-				free(buf);
-				break;
-			}
-			if(cli->chatty)
-				fprint(2, "in: %B\n", &rpc);
-			if(rpc.iscall){
-				fprint(2, "did not get reply\n");
-				free(buf);
-				break;
-			}
-			o = nil;
-			for(i=0; i<nout; i++){
-				o = out[i];
-				if(o->xid == rpc.xid)
-					break;
-			}
-			if(i==nout){
-				if(cli->chatty) fprint(2, "did not find waiting request\n");
-				free(buf);
-				break;
-			}
-			out[i] = out[--nout];
-			free(o->p);
-			o->p = nil;
-			if(rpc.status == SunSuccess){
-				o->p = buf;
-				o->rpc = rpc;
-			}else{
-				o->p = nil;
-				free(buf);
-				sunErrstr(rpc.status);
-				rerrstr(o->err, sizeof o->err);
-			}
-			sendp(o->creply, 0);
-			break;
-		}
-	}
-Done:
-	free(out);
-	sendp(cli->dying, 0);
-}
-
-SunClient*
-sunDial(char *address)
-{
-	int fd;
-	SunClient *cli;
-
-	if((fd = dial(address, 0, 0, 0)) < 0)
-		return nil;
-
-	cli = emalloc(sizeof(SunClient));
-	cli->fd = fd;
-	cli->maxwait = 15000;
-	cli->rtt.avg = 1000;
-	cli->dying = chancreate(sizeof(void*), 0);
-	cli->rpcchan = chancreate(sizeof(Out*), 0);
-	cli->timerchan = chancreate(sizeof(uint32_t), 0);
-	cli->flushchan = chancreate(sizeof(uint32_t), 0);
-	cli->readchan = chancreate(sizeof(uint8_t*), 0);
-	if(strstr(address, "udp!")){
-		cli->needcount = 0;
-		cli->nettid = threadcreate(udpThread, cli, SunStackSize);
-		cli->timertid = threadcreate(timerThread, cli, SunStackSize);
-	}else{
-		cli->needcount = 1;
-		cli->nettid = threadcreate(netThread, cli, SunStackSize);
-		/* assume reliable: don't need timer */
-		/* BUG: netThread should know how to redial */
-	}
-	threadcreate(rpcMuxThread, cli, SunStackSize);
-
-	return cli;
-}
-
-void
-sunClientClose(SunClient *cli)
-{
-	int n;
-
-	/*
-	 * Threadints get you out of any stuck system calls
-	 * or thread rendezvouses, but do nothing if the thread
-	 * is in the ready state.  Keep interrupting until it takes.
-	 */
-	n = 0;
-	if(!cli->timertid)
-		n++;
-	while(n < 2){
-		threadint(cli->nettid);
-		if(cli->timertid)
-			threadint(cli->timertid);
-		yield();
-		while(nbrecv(cli->dying, nil) == 1)
-			n++;
-	}
-
-	sendp(cli->rpcchan, 0);
-	recvp(cli->dying);
-
-	/* everyone's gone: clean up */
-	close(cli->fd);
-	chanfree(cli->flushchan);
-	chanfree(cli->readchan);
-	chanfree(cli->timerchan);
-	free(cli);
-}
-	
-void
-sunClientFlushRpc(SunClient *cli, uint32_t tag)
-{
-	sendul(cli->flushchan, tag);
-}
-
-void
-sunClientProg(SunClient *cli, SunProg *p)
-{
-	if(cli->nprog%16 == 0)
-		cli->prog = erealloc(cli->prog, (cli->nprog+16)*sizeof(cli->prog[0]));
-	cli->prog[cli->nprog++] = p;
-}
-
-int
-sunClientRpc(SunClient *cli, uint32_t tag, SunCall *tx, SunCall *rx,
-	     uint8_t **tofree)
-{
-	uint8_t *bp, *p, *ep;
-	int i, n1, n2, n, nn;
-	Out o;
-	SunProg *prog;
-	SunStatus ok;
-
-	for(i=0; i<cli->nprog; i++)
-		if(cli->prog[i]->prog == tx->rpc.prog && cli->prog[i]->vers == tx->rpc.vers)
-			break;
-	if(i==cli->nprog){
-		werrstr("unknown sun rpc program %d version %d", tx->rpc.prog, tx->rpc.vers);
-		return -1;
-	}
-	prog = cli->prog[i];
-
-	if(cli->chatty){
-		fprint(2, "out: %B\n", &tx->rpc);
-		fprint(2, "\t%C\n", tx);
-	}
-
-	n1 = sunRpcSize(&tx->rpc);
-	n2 = sunCallSize(prog, tx);
-
-	n = n1+n2;
-	if(cli->needcount)
-		n += 4;
-
-	bp = emalloc(n);
-	ep = bp+n;
-	p = bp;
-	if(cli->needcount){
-		nn = n-4;
-		p[0] = (nn>>24)|0x80;
-		p[1] = nn>>16;
-		p[2] = nn>>8;
-		p[3] = nn;
-		p += 4;
-	}
-	if((ok = sunRpcPack(p, ep, &p, &tx->rpc)) != SunSuccess
-	|| (ok = sunCallPack(prog, p, ep, &p, tx)) != SunSuccess){
-		sunErrstr(ok);
-		free(bp);
-		return -1;
-	}
-	if(p != ep){
-		werrstr("rpc: packet size mismatch");
-		free(bp);
-		return -1;
-	}
-
-	memset(&o, 0, sizeof o);
-	o.creply = chancreate(sizeof(void*), 0);
-	o.tag = tag;
-	o.p = bp;
-	o.n = n;
-
-	sendp(cli->rpcchan, &o);
-	recvp(o.creply);
-	chanfree(o.creply);
-
-	if(o.p == nil){
-		werrstr("%s", o.err);
-		return -1;
-	}
-
-	p = o.rpc.data;
-	ep = p+o.rpc.ndata;
-	rx->rpc = o.rpc;
-	rx->rpc.proc = tx->rpc.proc;
-	rx->rpc.prog = tx->rpc.prog;
-	rx->rpc.vers = tx->rpc.vers;
-	rx->type = (rx->rpc.proc<<1)|1;
-	if((ok = sunCallUnpack(prog, p, ep, &p, rx)) != SunSuccess){
-		sunErrstr(ok);
-		werrstr("unpack: %r");
-		free(o.p);
-		return -1;
-	}
-
-	if(cli->chatty){
-		fprint(2, "in: %B\n", &rx->rpc);
-		fprint(2, "in:\t%C\n", rx);
-	}
-
-	if(tofree)
-		*tofree = o.p;
-	else
-		free(o.p);
-
-	return 0;
-}

+ 0 - 43
sys/src/libsunrpc/emalloc.c

@@ -1,43 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-void*
-emalloc(uint32_t n)
-{
-	void *v;
-
-	v = mallocz(n, 1);
-	if(v == nil)
-{
-abort();
-		sysfatal("out of memory");
-}
-	setmalloctag(v, getcallerpc(&n));
-	return v;
-}
-
-void*
-erealloc(void *v, uint32_t n)
-{
-	v = realloc(v, n);
-	if(v == nil)
-{
-abort();
-		sysfatal("out of memory");
-}
-	setrealloctag(v, getcallerpc(&n));
-	return v;
-}
-
-

+ 0 - 46
sys/src/libsunrpc/error.c

@@ -1,46 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-static struct {
-	SunStatus status;
-	char *msg;
-} tab[] = {
-	SunProgUnavail,	"program unavailable",
-	SunProgMismatch,	"program mismatch",
-	SunProcUnavail,	"procedure unavailable",
-	SunGarbageArgs,	"garbage args",
-	SunSystemErr,		"system error",
-	SunRpcMismatch,	"rpc mismatch",
-	SunAuthBadCred,	"bad auth cred",
-	SunAuthRejectedCred,	"rejected auth cred",
-	SunAuthBadVerf,	"bad auth verf",
-	SunAuthRejectedVerf,	"rejected auth verf",
-	SunAuthTooWeak,	"auth too weak",
-	SunAuthInvalidResp,	"invalid auth response",
-	SunAuthFailed,		"auth failed",
-};
-
-void
-sunErrstr(SunStatus status)
-{
-	int i;
-
-	for(i=0; i<nelem(tab); i++){
-		if(tab[i].status == status){
-			werrstr(tab[i].msg);
-			return;
-		}
-	}
-	werrstr("unknown sun error %d", (int)status);
-}

+ 0 - 116
sys/src/libsunrpc/fd.c

@@ -1,116 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-enum
-{
-	MaxRead = 17000,
-};
-
-typedef struct SunMsgFd SunMsgFd;
-struct SunMsgFd
-{
-	SunMsg msg;
-	int fd;
-};
-
-typedef struct Arg Arg;
-struct Arg
-{
-	SunSrv *srv;
-	Channel *creply;
-	Channel *csync;
-	int fd;
-};
-
-static void
-sunFdRead(void *v)
-{
-	uint n, tot;
-	int done;
-	uint8_t buf[4], *p;
-	Arg arg = *(Arg*)v;
-	SunMsgFd *msg;
-
-	sendp(arg.csync, 0);
-
-	p = nil;
-	tot = 0;
-	for(;;){
-		n = readn(arg.fd, buf, 4);
-		if(n != 4)
-			break;
-		n = (buf[0]<<24)|(buf[1]<<16)|(buf[2]<<8)|buf[3];
-if(arg.srv->chatty) fprint(2, "%.8ux...", n);
-		done = n&0x80000000;
-		n &= ~0x80000000;
-		p = erealloc(p, tot+n);
-		if(readn(arg.fd, p+tot, n) != n)
-			break;
-		tot += n;
-		if(done){
-			msg = emalloc(sizeof(SunMsgFd));
-			msg->msg.data = p;
-			msg->msg.count = tot;
-			msg->msg.creply = arg.creply;
-			sendp(arg.srv->crequest, msg);
-			p = nil;
-			tot = 0;
-		}
-	}
-}
-
-static void
-sunFdWrite(void *v)
-{
-	uint8_t buf[4];
-	uint32_t n;
-	Arg arg = *(Arg*)v;
-	SunMsgFd *msg;
-
-	sendp(arg.csync, 0);
-
-	while((msg = recvp(arg.creply)) != nil){
-		n = msg->msg.count;
-		buf[0] = (n>>24)|0x80;
-		buf[1] = n>>16;
-		buf[2] = n>>8;
-		buf[3] = n;
-		if(write(arg.fd, buf, 4) != 4
-		|| write(arg.fd, msg->msg.data, msg->msg.count) != msg->msg.count)
-			fprint(2, "sunFdWrite: %r\n");
-		free(msg->msg.data);
-		free(msg);
-	}
-}
-
-int
-sunSrvFd(SunSrv *srv, int fd)
-{
-	Arg *arg;
-
-	arg = emalloc(sizeof(Arg));
-	arg->fd = fd;
-	arg->srv = srv;
-	arg->csync = chancreate(sizeof(void*), 0);
-	arg->creply = chancreate(sizeof(SunMsg*), 10);
-
-	proccreate(sunFdRead, arg, SunStackSize);
-	proccreate(sunFdWrite, arg, SunStackSize);
-	recvp(arg->csync);
-	recvp(arg->csync);
-
-	chanfree(arg->csync);
-	free(arg);
-	return 0;
-}

+ 0 - 73
sys/src/libsunrpc/fmt.c

@@ -1,73 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-/*
- * print formatters
- */
-int
-sunRpcFmt(Fmt *f)
-{
-	SunRpc *rpc;
-
-	rpc = va_arg(f->args, SunRpc*);
-	sunRpcPrint(f, rpc);
-	return 0;
-}
-
-static SunProg **fmtProg;
-static int nfmtProg;
-static RWLock fmtLock;
-
-void
-sunFmtInstall(SunProg *p)
-{
-	int i;
-
-	wlock(&fmtLock);
-	for(i=0; i<nfmtProg; i++){
-		if(fmtProg[i] == p){
-			wunlock(&fmtLock);
-			return;
-		}
-	}
-	if(nfmtProg%16 == 0)
-		fmtProg = erealloc(fmtProg, sizeof(fmtProg[0])*(nfmtProg+16));
-	fmtProg[nfmtProg++] = p;
-	wunlock(&fmtLock);
-}
-
-int
-sunCallFmt(Fmt *f)
-{
-	int i;
-	void (*fmt)(Fmt*, SunCall*);
-	SunCall *c;
-	SunProg *p;
-
-	c = va_arg(f->args, SunCall*);
-	rlock(&fmtLock);
-	for(i=0; i<nfmtProg; i++){
-		p = fmtProg[i];
-		if(p->prog == c->rpc.prog && p->vers == c->rpc.vers){
-			runlock(&fmtLock);
-			if(c->type < 0 || c->type >= p->nproc || (fmt=p->proc[c->type].fmt) == nil)
-				return fmtprint(f, "unknown proc %c%d", "TR"[c->type&1], c->type>>1);
-			(*fmt)(f, c);
-			return 0;
-		}
-	}
-	runlock(&fmtLock);
-	fmtprint(f, "<sunrpc %d %d %c%d>", c->rpc.prog, c->rpc.vers, "TR"[c->type&1], c->type>>1);
-	return 0;
-}

+ 0 - 25
sys/src/libsunrpc/libsunrpc.json

@@ -1,25 +0,0 @@
-{
-	"libsunrpc": {
-		"Include": [
-			"../lib.json"
-		],
-		"Install": "/$ARCH/lib/",
-		"Library": "libsunrpc.a",
-		"SourceFiles": [
-			"mount3.c",
-			"portmap.c",
-			"authunix.c",
-			"client.c",
-			"emalloc.c",
-			"error.c",
-			"fd.c",
-			"fmt.c",
-			"net.c",
-			"prog.c",
-			"rpc.c",
-			"server.c",
-			"suncall.c",
-			"udp.c"
-		]
-	}
-}

+ 0 - 753
sys/src/libsunrpc/mount3.c

@@ -1,753 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-/*
- * SUN NFSv3 Mounter.  See RFC 1813
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-#include <nfs3.h>
-
-void
-nfsMount3TNullPrint(Fmt *fmt, NfsMount3TNull *x)
-{
-	USED(x);
-	fmtprint(fmt, "%s\n", "NfsMount3TNull");
-}
-uint
-nfsMount3TNullSize(NfsMount3TNull *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	return a;
-}
-int
-nfsMount3TNullPack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3TNull *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-int
-nfsMount3TNullUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		     NfsMount3TNull *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-void
-nfsMount3RNullPrint(Fmt *fmt, NfsMount3RNull *x)
-{
-	USED(x);
-	fmtprint(fmt, "%s\n", "NfsMount3RNull");
-}
-uint
-nfsMount3RNullSize(NfsMount3RNull *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	return a;
-}
-int
-nfsMount3RNullPack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3RNull *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-int
-nfsMount3RNullUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		     NfsMount3RNull *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-void
-nfsMount3TMntPrint(Fmt *fmt, NfsMount3TMnt *x)
-{
-	fmtprint(fmt, "%s\n", "NfsMount3TMnt");
-	fmtprint(fmt, "\t%s=", "path");
-	fmtprint(fmt, "\"%s\"", x->path);
-	fmtprint(fmt, "\n");
-}
-uint
-nfsMount3TMntSize(NfsMount3TMnt *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + sunStringSize(x->path);
-	return a;
-}
-int
-nfsMount3TMntPack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3TMnt *x)
-{
-	if(sunStringPack(a, ea, &a, &x->path, 1024) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-int
-nfsMount3TMntUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3TMnt *x)
-{
-	if(sunStringUnpack(a, ea, &a, &x->path, 1024) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-void
-nfsMount3RMntPrint(Fmt *fmt, NfsMount3RMnt *x)
-{
-	fmtprint(fmt, "%s\n", "NfsMount3RMnt");
-	fmtprint(fmt, "\t%s=", "status");
-	fmtprint(fmt, "%ud", x->status);
-	fmtprint(fmt, "\n");
-	switch(x->status){
-	case 0:
-		fmtprint(fmt, "\t%s=", "handle");
-		fmtprint(fmt, "%.*H", x->len, x->handle);
-		fmtprint(fmt, "\n");
-		break;
-	}
-}
-uint
-nfsMount3RMntSize(NfsMount3RMnt *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + 4;
-	switch(x->status){
-	case 0:
-		a = a + sunVarOpaqueSize(x->len);
-		a = a + 4 + 4 * x->nauth;
-		break;
-	}
-	a = a;
-	return a;
-}
-uint
-nfsMount1RMntSize(NfsMount3RMnt *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + 4;
-	switch(x->status){
-	case 0:
-		a = a + NfsMount1HandleSize;
-		break;
-	}
-	return a;
-}
-
-int
-nfsMount3RMntPack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3RMnt *x)
-{
-	int i;
-	if(sunUint32Pack(a, ea, &a, &x->status) < 0) goto Err;
-	switch(x->status){
-	case 0:
-		if(sunVarOpaquePack(a, ea, &a, &x->handle, &x->len, NfsMount3MaxHandleSize) < 0) goto Err;
-		if(sunUint32Pack(a, ea, &a, &x->nauth) < 0) goto Err;
-		for(i=0; i<x->nauth; i++)
-			if(sunUint32Pack(a, ea, &a, &x->auth[i]) < 0) goto Err;
-		break;
-	}
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-int
-nfsMount1RMntPack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3RMnt *x)
-{
-	if(sunUint32Pack(a, ea, &a, &x->status) < 0) goto Err;
-	switch(x->status){
-	case 0:
-		if(x->len != NfsMount1HandleSize)
-			goto Err;
-		if(sunFixedOpaquePack(a, ea, &a, x->handle, NfsMount1HandleSize) < 0) goto Err;
-		if(x->nauth != 0)
-			goto Err;
-		break;
-	}
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-int
-nfsMount1RMntUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3RMnt *x)
-{
-	if(sunUint32Unpack(a, ea, &a, &x->status) < 0) goto Err;
-	switch(x->status){
-	case 0:
-		x->len = NfsMount1HandleSize;
-		x->nauth = 0;
-		x->auth = 0;
-		if(sunFixedOpaqueUnpack(a, ea, &a, x->handle, NfsMount1HandleSize) < 0) goto Err;
-		if(x->nauth != 0)
-			goto Err;
-		break;
-	}
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-
-int
-nfsMount3RMntUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3RMnt *x)
-{
-	int i;
-
-	if(sunUint32Unpack(a, ea, &a, &x->status) < 0) goto Err;
-	switch(x->status){
-	case 0:
-		if(sunVarOpaqueUnpack(a, ea, &a, &x->handle, &x->len, NfsMount3MaxHandleSize) < 0) goto Err;
-		if(sunUint32Unpack(a, ea, &a, &x->nauth) < 0) goto Err;
-		x->auth = (uint32_t*)a;
-		for(i=0; i<x->nauth; i++)
-			if(sunUint32Unpack(a, ea, &a, &x->auth[i]) < 0) goto Err;
-		break;
-	}
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-void
-nfsMount3TDumpPrint(Fmt *fmt, NfsMount3TDump *x)
-{
-	USED(x);
-	fmtprint(fmt, "%s\n", "NfsMount3TDump");
-}
-uint
-nfsMount3TDumpSize(NfsMount3TDump *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	return a;
-}
-int
-nfsMount3TDumpPack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3TDump *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-int
-nfsMount3TDumpUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		     NfsMount3TDump *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-void
-nfsMount3EntryPrint(Fmt *fmt, NfsMount3Entry *x)
-{
-	fmtprint(fmt, "%s\n", "NfsMount3Entry");
-	fmtprint(fmt, "\t%s=", "host");
-	fmtprint(fmt, "\"%s\"", x->host);
-	fmtprint(fmt, "\n");
-	fmtprint(fmt, "\t%s=", "path");
-	fmtprint(fmt, "\"%s\"", x->path);
-	fmtprint(fmt, "\n");
-}
-uint
-nfsMount3EntrySize(NfsMount3Entry *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + sunStringSize(x->host) + sunStringSize(x->path);
-	return a;
-}
-int
-nfsMount3EntryPack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3Entry *x)
-{
-	u1int one;
-
-	one = 1;
-	if(sunUint1Pack(a, ea, &a, &one) < 0) goto Err;
-	if(sunStringPack(a, ea, &a, &x->host, 255) < 0) goto Err;
-	if(sunStringPack(a, ea, &a, &x->path, 1024) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-int
-nfsMount3EntryUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		     NfsMount3Entry *x)
-{
-	u1int one;
-
-	if(sunUint1Unpack(a, ea, &a, &one) < 0 || one != 1) goto Err;
-	if(sunStringUnpack(a, ea, &a, &x->host, NfsMount3MaxNameSize) < 0) goto Err;
-	if(sunStringUnpack(a, ea, &a, &x->path, NfsMount3MaxPathSize) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-void
-nfsMount3RDumpPrint(Fmt *fmt, NfsMount3RDump *x)
-{
-	USED(x);
-	fmtprint(fmt, "%s\n", "NfsMount3RDump");
-}
-uint
-nfsMount3RDumpSize(NfsMount3RDump *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	a += x->count;
-	a += 4;
-	return a;
-}
-int
-nfsMount3RDumpPack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3RDump *x)
-{
-	u1int zero;
-
-	zero = 0;
-	if(a+x->count > ea) goto Err;
-	memmove(a, x->data, x->count);
-	a += x->count;
-	if(sunUint1Pack(a, ea, &a, &zero) < 0)
-		goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-int
-nfsMount3RDumpUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		     NfsMount3RDump *x)
-{
-	int i;
-	uint8_t *oa;
-	u1int u1;
-	uint32_t u32;
-
-	oa = a;
-	for(i=0;; i++){
-		if(sunUint1Unpack(a, ea, &a, &u1) < 0)
-			goto Err;
-		if(u1 == 0)
-			break;
-		if(sunUint32Unpack(a, ea, &a, &u32) < 0
-		|| u32 > NfsMount3MaxNameSize
-		|| (a+=u32) >= ea
-		|| sunUint32Unpack(a, ea, &a, &u32) < 0
-		|| u32 > NfsMount3MaxPathSize
-		|| (a+=u32) >= ea)
-			goto Err;
-	}
-	x->count = (a-4) - oa;
-	x->data = oa;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-void
-nfsMount3TUmntPrint(Fmt *fmt, NfsMount3TUmnt *x)
-{
-	fmtprint(fmt, "%s\n", "NfsMount3TUmnt");
-	fmtprint(fmt, "\t%s=", "path");
-	fmtprint(fmt, "\"%s\"", x->path);
-	fmtprint(fmt, "\n");
-}
-uint
-nfsMount3TUmntSize(NfsMount3TUmnt *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + sunStringSize(x->path);
-	return a;
-}
-int
-nfsMount3TUmntPack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3TUmnt *x)
-{
-	if(sunStringPack(a, ea, &a, &x->path, 1024) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-int
-nfsMount3TUmntUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		     NfsMount3TUmnt *x)
-{
-	if(sunStringUnpack(a, ea, &a, &x->path, 1024) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-void
-nfsMount3RUmntPrint(Fmt *fmt, NfsMount3RUmnt *x)
-{
-	USED(x);
-	fmtprint(fmt, "%s\n", "NfsMount3RUmnt");
-}
-uint
-nfsMount3RUmntSize(NfsMount3RUmnt *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	return a;
-}
-int
-nfsMount3RUmntPack(uint8_t *a, uint8_t *ea, uint8_t **pa, NfsMount3RUmnt *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-int
-nfsMount3RUmntUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		     NfsMount3RUmnt *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-void
-nfsMount3TUmntallPrint(Fmt *fmt, NfsMount3TUmntall *x)
-{
-	USED(x);
-	fmtprint(fmt, "%s\n", "NfsMount3TUmntall");
-}
-uint
-nfsMount3TUmntallSize(NfsMount3TUmntall *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	return a;
-}
-int
-nfsMount3TUmntallPack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		      NfsMount3TUmntall *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-int
-nfsMount3TUmntallUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-			NfsMount3TUmntall *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-void
-nfsMount3RUmntallPrint(Fmt *fmt, NfsMount3RUmntall *x)
-{
-	USED(x);
-	fmtprint(fmt, "%s\n", "NfsMount3RUmntall");
-}
-uint
-nfsMount3RUmntallSize(NfsMount3RUmntall *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	return a;
-}
-int
-nfsMount3RUmntallPack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		      NfsMount3RUmntall *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-int
-nfsMount3RUmntallUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-			NfsMount3RUmntall *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-void
-nfsMount3TExportPrint(Fmt *fmt, NfsMount3TExport *x)
-{
-	USED(x);
-	fmtprint(fmt, "%s\n", "NfsMount3TExport");
-}
-uint
-nfsMount3TExportSize(NfsMount3TExport *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	return a;
-}
-int
-nfsMount3TExportPack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		     NfsMount3TExport *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-int
-nfsMount3TExportUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		       NfsMount3TExport *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-void
-nfsMount3RExportPrint(Fmt *fmt, NfsMount3RExport *x)
-{
-	USED(x);
-	fmtprint(fmt, "%s\n", "NfsMount3RExport");
-	fmtprint(fmt, "\n");
-}
-uint
-nfsMount3RExportSize(NfsMount3RExport *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	a += x->count;
-	a += 4;	/* end of export list */
-	return a;
-}
-int
-nfsMount3RExportPack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		     NfsMount3RExport *x)
-{
-	u1int zero;
-
-	zero = 0;
-	if(a+x->count > ea) goto Err;
-	memmove(a, x->data, x->count);
-	a += x->count;
-	if(sunUint1Pack(a, ea, &a, &zero) < 0)
-		goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-int
-nfsMount3RExportUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		       NfsMount3RExport *x)
-{
-	int ng, ne;
-	uint8_t *oa;
-	u1int u1;
-	uint32_t u32;
-
-	oa = a;
-	ng = 0;
-	for(ne=0;; ne++){
-		if(sunUint1Unpack(a, ea, &a, &u1) < 0)
-			goto Err;
-		if(u1 == 0)
-			break;
-		if(sunUint32Unpack(a, ea, &a, &u32) < 0
-		|| (a += (u32+3)&~3) >= ea)
-			goto Err;
-		for(;; ng++){
-			if(sunUint1Unpack(a, ea, &a, &u1) < 0)
-				goto Err;
-			if(u1 == 0)
-				break;
-			if(sunUint32Unpack(a, ea, &a, &u32) < 0
-			|| (a += (u32+3)&~3) >= ea)
-				goto Err;
-		}
-	}
-	x->data = oa;
-	x->count = (a-4) - oa;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-uint
-nfsMount3ExportGroupSize(uint8_t *a)
-{
-	int ng;
-	u1int have;
-	uint32_t n;
-
-	a += 4;
-	sunUint32Unpack(a, a+4, &a, &n);
-	a += (n+3)&~3;
-	ng = 0;
-	for(;;){
-		sunUint1Unpack(a, a+4, &a, &have);
-		if(have == 0)
-			break;
-		ng++;
-		sunUint32Unpack(a, a+4, &a, &n);
-		a += (n+3)&~3;
-	}
-	return ng;
-}
-int
-nfsMount3ExportUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, char **gp,
-		      char ***pgp, NfsMount3Export *x)
-{
-	int ng;
-	u1int u1;
-
-	if(sunUint1Unpack(a, ea, &a, &u1) < 0 || u1 != 1) goto Err;
-	if(sunStringUnpack(a, ea, &a, &x->path, NfsMount3MaxPathSize) < 0) goto Err;
-	x->g = gp;
-	ng = 0;
-	for(;;){
-		if(sunUint1Unpack(a, ea, &a, &u1) < 0) goto Err;
-		if(u1 == 0)
-			break;
-		if(sunStringUnpack(a, ea, &a, &gp[ng++], NfsMount3MaxNameSize) < 0) goto Err;
-	}
-	x->ng = ng;
-	*pgp = gp+ng;
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-uint
-nfsMount3ExportSize(NfsMount3Export *x)
-{
-	int i;
-	uint a;
-
-	a = 4 + sunStringSize(x->path);
-	for(i=0; i<x->ng; i++)
-		a += 4 + sunStringSize(x->g[i]);
-	a += 4;
-	return a;
-}
-int
-nfsMount3ExportPack(uint8_t *a, uint8_t *ea, uint8_t **pa,
-		    NfsMount3Export *x)
-{
-	int i;
-	u1int u1;
-
-	u1 = 1;
-	if(sunUint1Pack(a, ea, &a, &u1) < 0) goto Err;
-	if(sunStringPack(a, ea, &a, &x->path, NfsMount3MaxPathSize) < 0) goto Err;
-	for(i=0; i<x->ng; i++){
-		if(sunUint1Pack(a, ea, &a, &u1) < 0) goto Err;
-		if(sunStringPack(a, ea, &a, &x->g[i], NfsMount3MaxNameSize) < 0) goto Err;
-	}
-	u1 = 0;
-	if(sunUint1Pack(a, ea, &a, &u1) < 0) goto Err;
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-
-typedef int (*P)(uint8_t*, uint8_t*, uint8_t**, SunCall*);
-typedef void (*F)(Fmt*, SunCall*);
-typedef uint (*S)(SunCall*);
-
-static SunProc proc3[] = {
-	(P)nfsMount3TNullPack, (P)nfsMount3TNullUnpack, (S)nfsMount3TNullSize, (F)nfsMount3TNullPrint, sizeof(NfsMount3TNull),
-	(P)nfsMount3RNullPack, (P)nfsMount3RNullUnpack, (S)nfsMount3RNullSize, (F)nfsMount3RNullPrint, sizeof(NfsMount3RNull),
-	(P)nfsMount3TMntPack, (P)nfsMount3TMntUnpack, (S)nfsMount3TMntSize, (F)nfsMount3TMntPrint, sizeof(NfsMount3TMnt),
-	(P)nfsMount3RMntPack, (P)nfsMount3RMntUnpack, (S)nfsMount3RMntSize, (F)nfsMount3RMntPrint, sizeof(NfsMount3RMnt),
-	(P)nfsMount3TDumpPack, (P)nfsMount3TDumpUnpack, (S)nfsMount3TDumpSize, (F)nfsMount3TDumpPrint, sizeof(NfsMount3TDump),
-	(P)nfsMount3RDumpPack, (P)nfsMount3RDumpUnpack, (S)nfsMount3RDumpSize, (F)nfsMount3RDumpPrint, sizeof(NfsMount3RDump),
-	(P)nfsMount3TUmntPack, (P)nfsMount3TUmntUnpack, (S)nfsMount3TUmntSize, (F)nfsMount3TUmntPrint, sizeof(NfsMount3TUmnt),
-	(P)nfsMount3RUmntPack, (P)nfsMount3RUmntUnpack, (S)nfsMount3RUmntSize, (F)nfsMount3RUmntPrint, sizeof(NfsMount3RUmnt),
-	(P)nfsMount3TUmntallPack, (P)nfsMount3TUmntallUnpack, (S)nfsMount3TUmntallSize, (F)nfsMount3TUmntallPrint, sizeof(NfsMount3TUmntall),
-	(P)nfsMount3RUmntallPack, (P)nfsMount3RUmntallUnpack, (S)nfsMount3RUmntallSize, (F)nfsMount3RUmntallPrint, sizeof(NfsMount3RUmntall),
-	(P)nfsMount3TExportPack, (P)nfsMount3TExportUnpack, (S)nfsMount3TExportSize, (F)nfsMount3TExportPrint, sizeof(NfsMount3TExport),
-	(P)nfsMount3RExportPack, (P)nfsMount3RExportUnpack, (S)nfsMount3RExportSize, (F)nfsMount3RExportPrint, sizeof(NfsMount3RExport),
-};
-
-static SunProc proc1[] = {
-	(P)nfsMount3TNullPack, (P)nfsMount3TNullUnpack, (S)nfsMount3TNullSize, (F)nfsMount3TNullPrint, sizeof(NfsMount3TNull),
-	(P)nfsMount3RNullPack, (P)nfsMount3RNullUnpack, (S)nfsMount3RNullSize, (F)nfsMount3RNullPrint, sizeof(NfsMount3RNull),
-	(P)nfsMount3TMntPack, (P)nfsMount3TMntUnpack, (S)nfsMount3TMntSize, (F)nfsMount3TMntPrint, sizeof(NfsMount3TMnt),
-	(P)nfsMount1RMntPack, (P)nfsMount1RMntUnpack, (S)nfsMount1RMntSize, (F)nfsMount3RMntPrint, sizeof(NfsMount3RMnt),
-	(P)nfsMount3TDumpPack, (P)nfsMount3TDumpUnpack, (S)nfsMount3TDumpSize, (F)nfsMount3TDumpPrint, sizeof(NfsMount3TDump),
-	(P)nfsMount3RDumpPack, (P)nfsMount3RDumpUnpack, (S)nfsMount3RDumpSize, (F)nfsMount3RDumpPrint, sizeof(NfsMount3RDump),
-	(P)nfsMount3TUmntPack, (P)nfsMount3TUmntUnpack, (S)nfsMount3TUmntSize, (F)nfsMount3TUmntPrint, sizeof(NfsMount3TUmnt),
-	(P)nfsMount3RUmntPack, (P)nfsMount3RUmntUnpack, (S)nfsMount3RUmntSize, (F)nfsMount3RUmntPrint, sizeof(NfsMount3RUmnt),
-	(P)nfsMount3TUmntallPack, (P)nfsMount3TUmntallUnpack, (S)nfsMount3TUmntallSize, (F)nfsMount3TUmntallPrint, sizeof(NfsMount3TUmntall),
-	(P)nfsMount3RUmntallPack, (P)nfsMount3RUmntallUnpack, (S)nfsMount3RUmntallSize, (F)nfsMount3RUmntallPrint, sizeof(NfsMount3RUmntall),
-	(P)nfsMount3TExportPack, (P)nfsMount3TExportUnpack, (S)nfsMount3TExportSize, (F)nfsMount3TExportPrint, sizeof(NfsMount3TExport),
-	(P)nfsMount3RExportPack, (P)nfsMount3RExportUnpack, (S)nfsMount3RExportSize, (F)nfsMount3RExportPrint, sizeof(NfsMount3RExport),
-};
-
-SunProg nfsMount3Prog = 
-{
-	NfsMount3Program,
-	NfsMount3Version,
-	proc3,
-	nelem(proc3),
-};
-
-SunProg nfsMount1Prog =
-{
-	NfsMount1Program,
-	NfsMount1Version,
-	proc1,
-	nelem(proc1),
-};

+ 0 - 66
sys/src/libsunrpc/net.c

@@ -1,66 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-typedef struct Arg Arg;
-struct Arg
-{
-	int fd;
-	char adir[40];
-	SunSrv *srv;
-};
-
-static void
-sunNetListen(void *v)
-{
-	int fd, lcfd;
-	char ldir[40];
-	Arg *a = v;
-
-	for(;;){
-		lcfd = listen(a->adir, ldir);
-		if(lcfd < 0)
-			break;
-		fd = accept(lcfd, ldir);
-		close(lcfd);
-		if(fd < 0)
-			continue;
-		if(!sunSrvFd(a->srv, fd))
-			close(fd);
-	}
-	free(a);
-	close(a->fd);
-}
-
-int
-sunSrvNet(SunSrv *srv, char *addr)
-{
-	Arg *a;
-
-	a = emalloc(sizeof(Arg));
-	if((a->fd = announce(addr, a->adir)) < 0)
-		return -1;
-	a->srv = srv;
-
-	proccreate(sunNetListen, a, SunStackSize);
-	return 0;
-}
-
-int
-sunSrvAnnounce(SunSrv *srv, char *addr)
-{
-	if(strstr(addr, "udp!"))
-		return sunSrvUdp(srv, addr);
-	else
-		return sunSrvNet(srv, addr);
-}

+ 0 - 507
sys/src/libsunrpc/portmap.c

@@ -1,507 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-static void
-portMapPrint(Fmt *fmt, PortMap *x)
-{
-	fmtprint(fmt, "[%ud %ud %ud %ud]", x->prog, x->vers, x->prot, x->port);
-}
-static uint
-portMapSize(PortMap *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + 4 + 4 + 4 + 4;
-	return a;
-}
-static int
-portMapPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortMap *x)
-{
-	if(sunUint32Pack(a, ea, &a, &x->prog) < 0) goto Err;
-	if(sunUint32Pack(a, ea, &a, &x->vers) < 0) goto Err;
-	if(sunUint32Pack(a, ea, &a, &x->prot) < 0) goto Err;
-	if(sunUint32Pack(a, ea, &a, &x->port) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static int
-portMapUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortMap *x)
-{
-	if(sunUint32Unpack(a, ea, &a, &x->prog) < 0) goto Err;
-	if(sunUint32Unpack(a, ea, &a, &x->vers) < 0) goto Err;
-	if(sunUint32Unpack(a, ea, &a, &x->prot) < 0) goto Err;
-	if(sunUint32Unpack(a, ea, &a, &x->port) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static void
-portTNullPrint(Fmt *fmt, PortTNull *x)
-{
-	USED(x);
-	fmtprint(fmt, "%s", "PortTNull");
-}
-static uint
-portTNullSize(PortTNull *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	return a;
-}
-static int
-portTNullPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTNull *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-static int
-portTNullUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTNull *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-static void
-portRNullPrint(Fmt *fmt, PortRNull *x)
-{
-	USED(x);
-	fmtprint(fmt, "%s", "PortRNull");
-}
-static uint
-portRNullSize(PortRNull *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	return a;
-}
-static int
-portRNullPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRNull *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-static int
-portRNullUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRNull *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-static void
-portTSetPrint(Fmt *fmt, PortTSet *x)
-{
-	fmtprint(fmt, "PortTSet ");
-	portMapPrint(fmt, &x->map);
-}
-static uint
-portTSetSize(PortTSet *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + portMapSize(&x->map);
-	return a;
-}
-static int
-portTSetPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTSet *x)
-{
-	if(portMapPack(a, ea, &a, &x->map) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static int
-portTSetUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTSet *x)
-{
-	if(portMapUnpack(a, ea, &a, &x->map) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static void
-portRSetPrint(Fmt *fmt, PortRSet *x)
-{
-	fmtprint(fmt, "PortRSet %ud", x->b);
-}
-static uint
-portRSetSize(PortRSet *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + 4;
-	return a;
-}
-static int
-portRSetPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRSet *x)
-{
-	if(sunUint1Pack(a, ea, &a, &x->b) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static int
-portRSetUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRSet *x)
-{
-	if(sunUint1Unpack(a, ea, &a, &x->b) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static void
-portTUnsetPrint(Fmt *fmt, PortTUnset *x)
-{
-	fmtprint(fmt, "PortTUnset ");
-	portMapPrint(fmt, &x->map);
-}
-static uint
-portTUnsetSize(PortTUnset *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + portMapSize(&x->map);
-	return a;
-}
-static int
-portTUnsetPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTUnset *x)
-{
-	if(portMapPack(a, ea, &a, &x->map) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static int
-portTUnsetUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTUnset *x)
-{
-	if(portMapUnpack(a, ea, &a, &x->map) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static void
-portRUnsetPrint(Fmt *fmt, PortRUnset *x)
-{
-	fmtprint(fmt, "PortRUnset %ud", x->b);
-}
-static uint
-portRUnsetSize(PortRUnset *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + 4;
-	return a;
-}
-static int
-portRUnsetPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRUnset *x)
-{
-	if(sunUint1Pack(a, ea, &a, &x->b) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static int
-portRUnsetUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRUnset *x)
-{
-	if(sunUint1Unpack(a, ea, &a, &x->b) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static void
-portTGetportPrint(Fmt *fmt, PortTGetport *x)
-{
-	fmtprint(fmt, "PortTGetport ");
-	portMapPrint(fmt, &x->map);
-}
-static uint
-portTGetportSize(PortTGetport *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + portMapSize(&x->map);
-	return a;
-}
-static int
-portTGetportPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTGetport *x)
-{
-	if(portMapPack(a, ea, &a, &x->map) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static int
-portTGetportUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTGetport *x)
-{
-	if(portMapUnpack(a, ea, &a, &x->map) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static void
-portRGetportPrint(Fmt *fmt, PortRGetport *x)
-{
-	fmtprint(fmt, "PortRGetport %ud", x->port);
-}
-static uint
-portRGetportSize(PortRGetport *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + 4;
-	return a;
-}
-static int
-portRGetportPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRGetport *x)
-{
-	if(sunUint32Pack(a, ea, &a, &x->port) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static int
-portRGetportUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRGetport *x)
-{
-	if(sunUint32Unpack(a, ea, &a, &x->port) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static void
-portTDumpPrint(Fmt *fmt, PortTDump *x)
-{
-	USED(x);
-	fmtprint(fmt, "PortTDump");
-}
-static uint
-portTDumpSize(PortTDump *x)
-{
-	uint a;
-	USED(x);
-	a = 0;
-	return a;
-}
-static int
-portTDumpPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTDump *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-static int
-portTDumpUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTDump *x)
-{
-	USED(ea);
-	USED(x);
-	*pa = a;
-	return 0;
-}
-static void
-portRDumpPrint(Fmt *fmt, PortRDump *x)
-{
-	int i;
-
-	fmtprint(fmt, "PortRDump");
-	for(i=0; i<x->nmap; i++){
-		fmtprint(fmt, " ");
-		portMapPrint(fmt, &x->map[i]);
-	}
-}
-static uint
-portRDumpSize(PortRDump *x)
-{
-	return (5*4*x->nmap) + 4;
-}
-static int
-portRDumpPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRDump *x)
-{
-	int i;
-	uint32_t zero, one;
-
-	zero = 0;
-	one = 1;
-	for(i=0; i<x->nmap; i++){
-		if(sunUint32Pack(a, ea, &a, &one) < 0
-		|| portMapPack(a, ea, &a, &x->map[i]) < 0)
-			goto Err;
-	}
-	if(sunUint32Pack(a, ea, &a, &zero) < 0)
-		goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static int
-portRDumpUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRDump *x)
-{
-	int i;
-	u1int u1;
-	PortMap *m;
-
-	m = (PortMap*)a;
-	for(i=0;; i++){
-		if(sunUint1Unpack(a, ea, &a, &u1) < 0)
-			goto Err;
-		if(u1 == 0)
-			break;
-		if(portMapUnpack(a, ea, &a, &m[i]) < 0)
-			goto Err;
-	}
-	x->nmap = i;
-	x->map = m;
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-static void
-portTCallitPrint(Fmt *fmt, PortTCallit *x)
-{
-	fmtprint(fmt, "PortTCallit [%ud,%ud,%ud] %ud", x->prog, x->vers, x->proc, x->count);
-}
-static uint
-portTCallitSize(PortTCallit *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + 4 + 4 + 4 + sunVarOpaqueSize(x->count);
-	return a;
-}
-static int
-portTCallitPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTCallit *x)
-{
-	if(sunUint32Pack(a, ea, &a, &x->prog) < 0) goto Err;
-	if(sunUint32Pack(a, ea, &a, &x->vers) < 0) goto Err;
-	if(sunUint32Pack(a, ea, &a, &x->proc) < 0) goto Err;
-	if(sunVarOpaquePack(a, ea, &a, &x->data, &x->count, -1) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static int
-portTCallitUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortTCallit *x)
-{
-	if(sunUint32Unpack(a, ea, &a, &x->prog) < 0) goto Err;
-	if(sunUint32Unpack(a, ea, &a, &x->vers) < 0) goto Err;
-	if(sunUint32Unpack(a, ea, &a, &x->proc) < 0) goto Err;
-	if(sunVarOpaqueUnpack(a, ea, &a, &x->data, &x->count, -1) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static void
-portRCallitPrint(Fmt *fmt, PortRCallit *x)
-{
-	fmtprint(fmt, "PortRCallit %ud %ud", x->port, x->count);
-}
-static uint
-portRCallitSize(PortRCallit *x)
-{
-	uint a;
-	USED(x);
-	a = 0 + 4 + sunVarOpaqueSize(x->count);
-	return a;
-}
-static int
-portRCallitPack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRCallit *x)
-{
-	if(sunUint32Pack(a, ea, &a, &x->port) < 0) goto Err;
-	if(sunVarOpaquePack(a, ea, &a, &x->data, &x->count, -1) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-static int
-portRCallitUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, PortRCallit *x)
-{
-	if(sunUint32Unpack(a, ea, &a, &x->port) < 0) goto Err;
-	if(sunVarOpaqueUnpack(a, ea, &a, &x->data, &x->count, -1) < 0) goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-
-typedef int (*P)(uint8_t*, uint8_t*, uint8_t**, SunCall*);
-typedef void (*F)(Fmt*, SunCall*);
-typedef uint (*S)(SunCall*);
-
-static SunProc proc[] = {
-	(P)portTNullPack, (P)portTNullUnpack, (S)portTNullSize, (F)portTNullPrint, sizeof(PortTNull),
-	(P)portRNullPack, (P)portRNullUnpack, (S)portRNullSize, (F)portRNullPrint, sizeof(PortRNull),
-	(P)portTSetPack, (P)portTSetUnpack, (S)portTSetSize, (F)portTSetPrint, sizeof(PortTSet),
-	(P)portRSetPack, (P)portRSetUnpack, (S)portRSetSize, (F)portRSetPrint, sizeof(PortRSet),
-	(P)portTUnsetPack, (P)portTUnsetUnpack, (S)portTUnsetSize, (F)portTUnsetPrint, sizeof(PortTUnset),
-	(P)portRUnsetPack, (P)portRUnsetUnpack, (S)portRUnsetSize, (F)portRUnsetPrint, sizeof(PortRUnset),
-	(P)portTGetportPack, (P)portTGetportUnpack, (S)portTGetportSize, (F)portTGetportPrint, sizeof(PortTGetport),
-	(P)portRGetportPack, (P)portRGetportUnpack, (S)portRGetportSize, (F)portRGetportPrint, sizeof(PortRGetport),
-	(P)portTDumpPack, (P)portTDumpUnpack, (S)portTDumpSize, (F)portTDumpPrint, sizeof(PortTDump),
-	(P)portRDumpPack, (P)portRDumpUnpack, (S)portRDumpSize, (F)portRDumpPrint, sizeof(PortRDump),
-	(P)portTCallitPack, (P)portTCallitUnpack, (S)portTCallitSize, (F)portTCallitPrint, sizeof(PortTCallit),
-	(P)portRCallitPack, (P)portRCallitUnpack, (S)portRCallitSize, (F)portRCallitPrint, sizeof(PortRCallit),
-};
-
-SunProg portProg = 
-{
-	PortProgram,
-	PortVersion,
-	proc,
-	nelem(proc),
-};

+ 0 - 86
sys/src/libsunrpc/prog.c

@@ -1,86 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-SunStatus
-sunCallPack(SunProg *prog, uint8_t *a, uint8_t *ea, uint8_t **pa,
-	    SunCall *c)
-{
-	uint8_t *x;
-	int (*pack)(uint8_t*, uint8_t*, uint8_t**, SunCall*);
-
-	if(pa == nil)
-		pa = &x;
-	if(c->type < 0 || c->type >= prog->nproc || (pack=prog->proc[c->type].pack) == nil)
-		return SunProcUnavail;
-	if((*pack)(a, ea, pa, c) < 0)
-		return SunGarbageArgs;
-	return SunSuccess;
-}
-
-SunStatus
-sunCallUnpack(SunProg *prog, uint8_t *a, uint8_t *ea, uint8_t **pa,
-	      SunCall *c)
-{
-	uint8_t *x;
-	int (*unpack)(uint8_t*, uint8_t*, uint8_t**, SunCall*);
-
-	if(pa == nil)
-		pa = &x;
-	if(c->type < 0 || c->type >= prog->nproc || (unpack=prog->proc[c->type].unpack) == nil)
-		return SunProcUnavail;
-	if((*unpack)(a, ea, pa, c) < 0){
-		fprint(2, "in: %.*H unpack failed\n", (int)(ea-a), a);
-		return SunGarbageArgs;
-	}
-	return SunSuccess;
-}
-
-SunStatus
-sunCallUnpackAlloc(SunProg *prog, SunCallType type, uint8_t *a, uint8_t *ea,
-		   uint8_t **pa, SunCall **pc)
-{
-	uint8_t *x;
-	uint size;
-	int (*unpack)(uint8_t*, uint8_t*, uint8_t**, SunCall*);
-	SunCall *c;
-
-	if(pa == nil)
-		pa = &x;
-	if(type < 0 || type >= prog->nproc || (unpack=prog->proc[type].unpack) == nil)
-		return SunProcUnavail;
-	size = prog->proc[type].sizeoftype;
-	if(size == 0)
-		return SunProcUnavail;
-	c = mallocz(size, 1);
-	if(c == nil)
-		return SunSystemErr;
-	c->type = type;
-	if((*unpack)(a, ea, pa, c) < 0){
-		fprint(2, "in: %.*H unpack failed\n", (int)(ea-a), a);
-		free(c);
-		return SunGarbageArgs;
-	}
-	*pc = c;
-	return SunSuccess;
-}
-
-uint
-sunCallSize(SunProg *prog, SunCall *c)
-{
-	uint (*size)(SunCall*);
-
-	if(c->type < 0 || c->type >= prog->nproc || (size=prog->proc[c->type].size) == nil)
-		return ~0;
-	return (*size)(c);
-}

+ 0 - 542
sys/src/libsunrpc/rpc.c

@@ -1,542 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-/*
- * RPC protocol constants
- */
-enum
-{
-	RpcVersion = 2,
-
-	/* msg type */
-	MsgCall = 0,
-	MsgReply = 1,
-
-	/* reply stat */
-	MsgAccepted = 0,
-	MsgDenied = 1,
-
-	/* accept stat */
-	MsgSuccess = 0,
-	MsgProgUnavail = 1,
-	MsgProgMismatch = 2,
-	MsgProcUnavail = 3,
-	MsgGarbageArgs = 4,
-	MsgSystemErr = 5,
-
-	/* reject stat */
-	MsgRpcMismatch = 0,
-	MsgAuthError = 1,
-
-	/* msg auth xxx */
-	MsgAuthOk = 0,
-	MsgAuthBadCred = 1,
-	MsgAuthRejectedCred = 2,
-	MsgAuthBadVerf = 3,
-	MsgAuthRejectedVerf = 4,
-	MsgAuthTooWeak = 5,
-	MsgAuthInvalidResp = 6,
-	MsgAuthFailed = 7,
-};
-
-SunStatus
-sunRpcPack(uint8_t *a, uint8_t *ea, uint8_t **pa, SunRpc *rpc)
-{
-	uint32_t x;
-
-	if(sunUint32Pack(a, ea, &a, &rpc->xid) < 0)
-		goto Err;
-	if(rpc->iscall){
-		if(sunUint32Pack(a, ea, &a, (x=MsgCall, &x)) < 0
-		|| sunUint32Pack(a, ea, &a, (x=RpcVersion, &x)) < 0
-		|| sunUint32Pack(a, ea, &a, &rpc->prog) < 0
-		|| sunUint32Pack(a, ea, &a, &rpc->vers) < 0
-		|| sunUint32Pack(a, ea, &a, &rpc->proc) < 0
-		|| sunAuthInfoPack(a, ea, &a, &rpc->cred) < 0
-		|| sunAuthInfoPack(a, ea, &a, &rpc->verf) < 0
-		|| sunFixedOpaquePack(a, ea, &a, rpc->data, rpc->ndata) < 0)
-			goto Err;
-	}else{
-		if(sunUint32Pack(a, ea, &a, (x=MsgReply, &x)) < 0)
-			goto Err;
-		switch(rpc->status&0xF0000){
-		case 0:
-		case SunAcceptError:
-			if(sunUint32Pack(a, ea, &a, (x=MsgAccepted, &x)) < 0
-			|| sunAuthInfoPack(a, ea, &a, &rpc->verf) < 0)
-				goto Err;
-			break;
-		default:
-			if(sunUint32Pack(a, ea, &a, (x=MsgDenied, &x)) < 0)
-				goto Err;
-			break;
-		}
-
-		switch(rpc->status){
-		case SunSuccess:
-			if(sunUint32Pack(a, ea, &a, (x=MsgSuccess, &x)) < 0
-			|| sunFixedOpaquePack(a, ea, &a, rpc->data, rpc->ndata) < 0)
-				goto Err;
-			break;
-		case SunRpcMismatch:
-		case SunProgMismatch:
-			if(sunUint32Pack(a, ea, &a, (x=rpc->status&0xFFFF, &x)) < 0
-			|| sunUint32Pack(a, ea, &a, &rpc->low) < 0
-			|| sunUint32Pack(a, ea, &a, &rpc->high) < 0)
-				goto Err;
-			break;
-		default:
-			if(sunUint32Pack(a, ea, &a, (x=rpc->status&0xFFFF, &x)) < 0)
-				goto Err;
-			break;
-		}
-	}
-	*pa = a;
-	return SunSuccess;
-
-Err:
-	*pa = ea;
-	return SunGarbageArgs;
-}
-
-uint
-sunRpcSize(SunRpc *rpc)
-{
-	uint a;
-
-	a = 4;
-	if(rpc->iscall){
-		a += 5*4;
-		a += sunAuthInfoSize(&rpc->cred);
-		a += sunAuthInfoSize(&rpc->verf);
-		a += sunFixedOpaqueSize(rpc->ndata);
-	}else{
-		a += 4;
-		switch(rpc->status&0xF0000){
-		case 0:
-		case SunAcceptError:
-			a += 4+sunAuthInfoSize(&rpc->verf);
-			break;
-		default:
-			a += 4;
-			break;
-		}
-
-		switch(rpc->status){
-		case SunSuccess:
-			a += 4+sunFixedOpaqueSize(rpc->ndata);
-			break;
-		case SunRpcMismatch:
-		case SunProgMismatch:
-			a += 3*4;
-		default:
-			a += 4;
-		}
-	}
-	return a;
-}
-
-SunStatus
-sunRpcUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, SunRpc *rpc)
-{
-	uint32_t x;
-
-	memset(rpc, 0, sizeof *rpc);
-	if(sunUint32Unpack(a, ea, &a, &rpc->xid) < 0
-	|| sunUint32Unpack(a, ea, &a, &x) < 0)
-		goto Err;
-
-	switch(x){
-	default:
-		goto Err;
-	case MsgCall:
-		rpc->iscall = 1;
-		if(sunUint32Unpack(a, ea, &a, &x) < 0 || x != RpcVersion
-		|| sunUint32Unpack(a, ea, &a, &rpc->prog) < 0
-		|| sunUint32Unpack(a, ea, &a, &rpc->vers) < 0
-		|| sunUint32Unpack(a, ea, &a, &rpc->proc) < 0
-		|| sunAuthInfoUnpack(a, ea, &a, &rpc->cred) < 0
-		|| sunAuthInfoUnpack(a, ea, &a, &rpc->verf) < 0)
-			goto Err;
-		rpc->ndata = ea-a;
-		rpc->data = a;
-		a = ea;
-		break;
-
-	case MsgReply:
-		rpc->iscall = 0;
-		if(sunUint32Unpack(a, ea, &a, &x) < 0)
-			goto Err;
-		switch(x){
-		default:
-			goto Err;
-		case MsgAccepted:
-			if(sunAuthInfoUnpack(a, ea, &a, &rpc->verf) < 0
-			|| sunUint32Unpack(a, ea, &a, &x) < 0)
-				goto Err;
-			switch(x){
-			case MsgSuccess:
-				rpc->status = SunSuccess;
-				rpc->ndata = ea-a;
-				rpc->data = a;
-				a = ea;
-				break;
-			case MsgProgUnavail:
-			case MsgProcUnavail:
-			case MsgGarbageArgs:
-			case MsgSystemErr:
-				rpc->status = SunAcceptError | x;
-				break;
-			case MsgProgMismatch:
-				rpc->status = SunAcceptError | x;
-				if(sunUint32Unpack(a, ea, &a, &rpc->low) < 0
-				|| sunUint32Unpack(a, ea, &a, &rpc->high) < 0)
-					goto Err;
-				break;
-			}
-			break;
-		case MsgDenied:
-			if(sunUint32Unpack(a, ea, &a, &x) < 0)
-				goto Err;
-			switch(x){
-			default:
-				goto Err;
-			case MsgAuthError:
-				if(sunUint32Unpack(a, ea, &a, &x) < 0)
-					goto Err;
-				rpc->status = SunAuthError | x;
-				break;
-			case MsgRpcMismatch:
-				rpc->status = SunRejectError | x;
-				if(sunUint32Unpack(a, ea, &a, &rpc->low) < 0
-				|| sunUint32Unpack(a, ea, &a, &rpc->high) < 0)
-					goto Err;
-				break;
-			}
-			break;
-		}
-	}
-	*pa = a;
-	return SunSuccess;
-
-Err:
-	*pa = ea;
-	return SunGarbageArgs;
-}
-
-void
-sunRpcPrint(Fmt *fmt, SunRpc *rpc)
-{
-	fmtprint(fmt, "xid=%#ux", rpc->xid);
-	if(rpc->iscall){
-		fmtprint(fmt, " prog %#ux vers %#ux proc %#ux [", rpc->prog, rpc->vers, rpc->proc);
-		sunAuthInfoPrint(fmt, &rpc->cred);
-		fmtprint(fmt, "] [");
-		sunAuthInfoPrint(fmt, &rpc->verf);
-		fmtprint(fmt, "]");
-	}else{
-		fmtprint(fmt, " status %#ux [", rpc->status);
-		sunAuthInfoPrint(fmt, &rpc->verf);
-		fmtprint(fmt, "] low %#ux high %#ux", rpc->low, rpc->high);
-	}
-}
-
-void
-sunAuthInfoPrint(Fmt *fmt, SunAuthInfo *ai)
-{
-	switch(ai->flavor){
-	case SunAuthNone:
-		fmtprint(fmt, "none");
-		break;
-	case SunAuthShort:
-		fmtprint(fmt, "short");
-		break;
-	case SunAuthSys:
-		fmtprint(fmt, "sys");
-		break;
-	default:
-		fmtprint(fmt, "%#ux", ai->flavor);
-		break;
-	}
-//	if(ai->ndata)
-//		fmtprint(fmt, " %.*H", ai->ndata, ai->data);
-}
-
-uint
-sunAuthInfoSize(SunAuthInfo *ai)
-{
-	return 4 + sunVarOpaqueSize(ai->ndata);
-}
-
-int
-sunAuthInfoPack(uint8_t *a, uint8_t *ea, uint8_t **pa, SunAuthInfo *ai)
-{
-	if(sunUint32Pack(a, ea, &a, &ai->flavor) < 0
-	|| sunVarOpaquePack(a, ea, &a, &ai->data, &ai->ndata, 400) < 0)
-		goto Err;
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-
-int
-sunAuthInfoUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, SunAuthInfo *ai)
-{
-	if(sunUint32Unpack(a, ea, &a, &ai->flavor) < 0
-	|| sunVarOpaqueUnpack(a, ea, &a, &ai->data, &ai->ndata, 400) < 0)
-		goto Err;
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-
-int
-sunEnumPack(uint8_t *a, uint8_t *ea, uint8_t **pa, int *e)
-{
-	uint32_t x;
-
-	x = *e;
-	return sunUint32Pack(a, ea, pa, &x);
-}
-
-int
-sunUint1Pack(uint8_t *a, uint8_t *ea, uint8_t **pa, u1int *u)
-{
-	uint32_t x;
-
-	x = *u;
-	return sunUint32Pack(a, ea, pa, &x);
-}
-
-int
-sunUint32Pack(uint8_t *a, uint8_t *ea, uint8_t **pa, uint32_t *u)
-{
-	uint32_t x;
-
-	if(ea-a < 4)
-		goto Err;
-
-	x = *u;
-	*a++ = x>>24;
-	*a++ = x>>16;
-	*a++ = x>>8;
-	*a++ = x;
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-
-int
-sunEnumUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, int *e)
-{
-	uint32_t x;
-	if(sunUint32Unpack(a, ea, pa, &x) < 0)
-		return -1;
-	*e = x;
-	return 0;
-}
-
-int
-sunUint1Unpack(uint8_t *a, uint8_t *ea, uint8_t **pa, u1int *u)
-{
-	uint32_t x;
-	if(sunUint32Unpack(a, ea, pa, &x) < 0 || (x!=0 && x!=1)){
-		*pa = ea;
-		return -1;
-	}
-	*u = x;
-	return 0;
-}
-
-int
-sunUint32Unpack(uint8_t *a, uint8_t *ea, uint8_t **pa, uint32_t *u)
-{
-	uint32_t x;
-
-	if(ea-a < 4)
-		goto Err;
-	x = *a++ << 24;
-	x |= *a++ << 16;
-	x |= *a++ << 8;
-	x |= *a++;
-	*pa = a;
-	*u = x;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-
-int
-sunUint64Unpack(uint8_t *a, uint8_t *ea, uint8_t **pa, uint64_t *u)
-{
-	uint32_t x, y;
-
-	if(sunUint32Unpack(a, ea, &a, &x) < 0
-	|| sunUint32Unpack(a, ea, &a, &y) < 0)
-		goto Err;
-	*u = ((uint64_t)x<<32) | y;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-
-int
-sunUint64Pack(uint8_t *a, uint8_t *ea, uint8_t **pa, uint64_t *u)
-{
-	uint32_t x, y;
-
-	x = *u >> 32;
-	y = *u;
-	if(sunUint32Pack(a, ea, &a, &x) < 0
-	|| sunUint32Pack(a, ea, &a, &y) < 0)
-		goto Err;
-	*pa = a;
-	return 0;
-Err:
-	*pa = ea;
-	return -1;
-}
-
-uint
-sunStringSize(char *s)
-{
-	return (4+strlen(s)+3) & ~3;
-}
-
-int
-sunStringUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, char **s,
-		uint32_t max)
-{
-	uint8_t *dat;
-	uint32_t n;
-
-	if(sunVarOpaqueUnpack(a, ea, pa, &dat, &n, max) < 0)
-		goto Err;
-	/* slide string down over length to make room for NUL */
-	memmove(dat-1, dat, n);
-	dat[-1+n] = 0;
-	*s = (char*)(dat-1);
-	return 0;
-Err:
-	return -1;
-}
-
-int
-sunStringPack(uint8_t *a, uint8_t *ea, uint8_t **pa, char **s, uint32_t max)
-{
-	uint32_t n;
-
-	n = strlen(*s);
-	return sunVarOpaquePack(a, ea, pa, (uint8_t**)s, &n, max);
-}
-
-uint
-sunVarOpaqueSize(uint32_t n)
-{
-	return (4+n+3) & ~3;
-}
-
-int
-sunVarOpaquePack(uint8_t *a, uint8_t *ea, uint8_t **pa, uint8_t **dat,
-		 uint32_t *ndat, uint32_t max)
-{
-	if(*ndat > max || sunUint32Pack(a, ea, &a, ndat) < 0
-	|| sunFixedOpaquePack(a, ea, &a, *dat, *ndat) < 0)
-		goto Err;
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-
-int
-sunVarOpaqueUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, uint8_t **dat,
-		   uint32_t *ndat, uint32_t max)
-{
-	if(sunUint32Unpack(a, ea, &a, ndat) < 0
-	|| *ndat > max)
-		goto Err;
-	*dat = a;
-	a += (*ndat+3)&~3;
-	if(a > ea)
-		goto Err;
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-
-uint
-sunFixedOpaqueSize(uint32_t n)
-{
-	return (n+3) & ~3;
-}
-
-int
-sunFixedOpaquePack(uint8_t *a, uint8_t *ea, uint8_t **pa, uint8_t *dat,
-		   uint32_t n)
-{
-	uint nn;
-
-	nn = (n+3)&~3;
-	if(a+nn > ea)
-		goto Err;
-	memmove(a, dat, n);
-	if(nn > n)
-		memset(a+n, 0, nn-n);
-	a += nn;
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-
-int
-sunFixedOpaqueUnpack(uint8_t *a, uint8_t *ea, uint8_t **pa, uint8_t *dat,
-		     uint32_t n)
-{
-	uint nn;
-
-	nn = (n+3)&~3;
-	if(a+nn > ea)
-		goto Err;
-	memmove(dat, a, n);
-	a += nn;
-	*pa = a;
-	return 0;
-
-Err:
-	*pa = ea;
-	return -1;
-}
-

+ 0 - 286
sys/src/libsunrpc/server.c

@@ -1,286 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-/*
- * Sun RPC server; for now, no reply cache
- */
-
-static void sunRpcProc(void*);
-static void sunRpcRequestThread(void*);
-static void sunRpcReplyThread(void*);
-static void sunRpcForkThread(void*);
-static SunProg *sunFindProg(SunSrv*, SunMsg*, SunRpc*, Channel**);
-
-typedef struct Targ Targ;
-struct Targ
-{
-	void (*fn)(void*);
-	void *arg;
-};
-
-SunSrv*
-sunSrv(void)
-{
-	SunSrv *srv;
-
-	srv = emalloc(sizeof(SunSrv));
-	srv->chatty = 0;
-	srv->crequest = chancreate(sizeof(SunMsg*), 16);
-	srv->creply = chancreate(sizeof(SunMsg*), 16);
-	srv->cthread = chancreate(sizeof(Targ), 4);
-
-	proccreate(sunRpcProc, srv, SunStackSize);
-	return srv;
-}
-
-void
-sunSrvProg(SunSrv *srv, SunProg *prog, Channel *c)
-{
-	if(srv->nprog%16 == 0){
-		srv->prog = erealloc(srv->prog, (srv->nprog+16)*sizeof(srv->prog[0]));
-		srv->cdispatch = erealloc(srv->cdispatch, (srv->nprog+16)*sizeof(srv->cdispatch[0]));
-	}
-	srv->prog[srv->nprog] = prog;
-	srv->cdispatch[srv->nprog] = c;
-	srv->nprog++;
-}
-
-static void
-sunRpcProc(void *v)
-{
-	threadcreate(sunRpcReplyThread, v, SunStackSize);
-	threadcreate(sunRpcRequestThread, v, SunStackSize);
-	threadcreate(sunRpcForkThread, v, SunStackSize);
-
-}
-
-static void
-sunRpcForkThread(void *v)
-{
-	SunSrv *srv = v;
-	Targ t;
-
-	while(recv(srv->cthread, &t) == 1)
-		threadcreate(t.fn, t.arg, SunStackSize);
-}
-
-void
-sunSrvThreadCreate(SunSrv *srv, void (*fn)(void*), void *arg)
-{
-	Targ t;
-
-	t.fn = fn;
-	t.arg = arg;
-	send(srv->cthread, &t);
-}
-
-static void
-sunRpcRequestThread(void *v)
-{
-	uint8_t *p, *ep;
-	Channel *c;
-	SunSrv *srv = v;
-	SunMsg *m;
-	SunProg *pg;
-	SunStatus ok;
-
-	while((m = recvp(srv->crequest)) != nil){
-		/* could look up in cache here? */
-
-if(srv->chatty) fprint(2, "sun msg %p count %d\n", m, m->count);
-		m->srv = srv;
-		p = m->data;
-		ep = p+m->count;
-		if(sunRpcUnpack(p, ep, &p, &m->rpc) != SunSuccess){
-			fprint(2, "in: %.*H unpack failed\n", m->count, m->data);
-			sunMsgDrop(m);
-			continue;
-		}
-		if(srv->chatty)
-			fprint(2, "in: %B\n", &m->rpc);
-
-		if(srv->alwaysReject){
-			if(srv->chatty)
-				fprint(2, "\trejecting\n");
-			sunMsgReplyError(m, SunAuthTooWeak);
-			continue;
-		}
-
-		if(!m->rpc.iscall){
-			sunMsgReplyError(m, SunGarbageArgs);
-			continue;
-		}
-
-		if((pg = sunFindProg(srv, m, &m->rpc, &c)) == nil){
-			/* sunFindProg sent error */
-			continue;
-		}
-
-		p = m->rpc.data;
-		ep = p+m->rpc.ndata;
-		m->call = nil;
-		if((ok = sunCallUnpackAlloc(pg, m->rpc.proc<<1, p, ep, &p, &m->call)) != SunSuccess){
-			sunMsgReplyError(m, ok);
-			continue;
-		}
-		m->call->rpc = m->rpc;
-
-		if(srv->chatty)
-			fprint(2, "\t%C\n", m->call);
-
-		m->pg = pg;
-		sendp(c, m);
-	}
-}
-
-static SunProg*
-sunFindProg(SunSrv *srv, SunMsg *m, SunRpc *rpc, Channel **pc)
-{
-	int i, vlo, vhi;
-	SunProg *pg;
-
-	vlo = 0x7fffffff;
-	vhi = -1;
-
-	for(i=0; i<srv->nprog; i++){
-		pg = srv->prog[i];
-		if(pg->prog != rpc->prog)
-			continue;
-		if(pg->vers == rpc->vers){
-			*pc = srv->cdispatch[i];
-			return pg;
-		}
-		/* right program, wrong version: record range */
-		if(pg->vers < vlo)
-			vlo = pg->vers;
-		if(pg->vers > vhi)
-			vhi = pg->vers;
-	}
-	if(vhi == -1){
-		if(srv->chatty)
-			fprint(2, "\tprogram %ud unavailable\n", rpc->prog);
-		sunMsgReplyError(m, SunProgUnavail);
-	}else{
-		/* putting these in rpc is a botch */
-		rpc->low = vlo;
-		rpc->high = vhi;
-		if(srv->chatty)
-			fprint(2, "\tversion %ud unavailable; have %d-%d\n", rpc->vers, vlo, vhi);
-		sunMsgReplyError(m, SunProgMismatch);
-	}
-	return nil;
-}
-
-static void
-sunRpcReplyThread(void *v)
-{
-	SunMsg *m;
-	SunSrv *srv = v;
-
-	while((m = recvp(srv->creply)) != nil){
-		/* could record in cache here? */
-		sendp(m->creply, m);
-	}	
-}
-
-int
-sunMsgReplyError(SunMsg *m, SunStatus error)
-{
-	uint8_t *p, *bp, *ep;
-	int n;
-
-	m->rpc.status = error;
-	m->rpc.iscall = 0;
-	m->rpc.verf.flavor = SunAuthNone;
-	m->rpc.data = nil;
-	m->rpc.ndata = 0;
-
-	if(m->srv->chatty)
-		fprint(2, "out: %B\n", &m->rpc);
-
-	n = sunRpcSize(&m->rpc);
-	bp = emalloc(n);
-	ep = bp+n;
-	p = bp;
-	if(sunRpcPack(p, ep, &p, &m->rpc) < 0){
-		fprint(2, "sunRpcPack failed\n");
-		sunMsgDrop(m);
-		return 0;
-	}
-	if(p != ep){
-		fprint(2, "sunMsgReplyError: rpc sizes didn't work out\n");
-		sunMsgDrop(m);
-		return 0;
-	}
-	free(m->data);
-	m->data = bp;
-	m->count = n;
-	sendp(m->srv->creply, m);
-	return 0;
-}
-
-int
-sunMsgReply(SunMsg *m, SunCall *c)
-{
-	int n1, n2;
-	uint8_t *bp, *p, *ep;
-
-	c->type = m->call->type+1;
-	c->rpc.iscall = 0;
-	c->rpc.prog = m->rpc.prog;
-	c->rpc.vers = m->rpc.vers;
-	c->rpc.proc = m->rpc.proc;
-	c->rpc.xid = m->rpc.xid;
-
-	if(m->srv->chatty){
-		fprint(2, "out: %B\n", &c->rpc);
-		fprint(2, "\t%C\n", c);
-	}
-
-	n1 = sunRpcSize(&c->rpc);
-	n2 = sunCallSize(m->pg, c);
-
-	bp = emalloc(n1+n2);
-	ep = bp+n1+n2;
-	p = bp;
-	if(sunRpcPack(p, ep, &p, &c->rpc) != SunSuccess){
-		fprint(2, "sunRpcPack failed\n");
-		return sunMsgDrop(m);
-	}
-	if(sunCallPack(m->pg, p, ep, &p, c) != SunSuccess){
-		fprint(2, "pg->pack failed\n");
-		return sunMsgDrop(m);
-	}
-	if(p != ep){
-		fprint(2, "sunMsgReply: sizes didn't work out\n");
-		return sunMsgDrop(m);
-	}
-	free(m->data);
-	m->data = bp;
-	m->count = n1+n2;
-
-	sendp(m->srv->creply, m);
-	return 0;
-}
-
-int
-sunMsgDrop(SunMsg *m)
-{
-	free(m->data);
-	free(m->call);
-	memset(m, 0xFB, sizeof *m);
-	free(m);
-	return 0;
-}
-

+ 0 - 23
sys/src/libsunrpc/suncall.c

@@ -1,23 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-void
-sunCallSetup(SunCall *c, SunProg *prog, uint proc)
-{
-	c->rpc.prog = prog->prog;
-	c->rpc.vers = prog->vers;
-	c->rpc.proc = proc>>1;
-	c->rpc.iscall = !(proc&1);
-	c->type = proc;
-}

+ 0 - 122
sys/src/libsunrpc/udp.c

@@ -1,122 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <ip.h>
-#include <thread.h>
-#include <sunrpc.h>
-
-typedef struct SunMsgUdp SunMsgUdp;
-struct SunMsgUdp
-{
-	SunMsg	msg;
-	Udphdr	udp;
-};
-
-typedef struct Arg Arg;
-struct Arg
-{
-	SunSrv	*srv;
-	Channel	*creply;
-	Channel	*csync;
-	int 	fd;
-};
-
-enum
-{
-	UdpMaxRead = 65536+Udphdrsize
-};
-
-static void
-sunUdpRead(void *v)
-{
-	int n;
-	uint8_t *buf;
-	Arg arg = *(Arg*)v;
-	SunMsgUdp *msg;
-
-	sendp(arg.csync, 0);
-
-	buf = emalloc(UdpMaxRead);
-	while((n = read(arg.fd, buf, UdpMaxRead)) > 0){
-		if(arg.srv->chatty)
-			fprint(2, "udp got %d (%d)\n", n, Udphdrsize);
-		msg = emalloc(sizeof(SunMsgUdp));
-		memmove(&msg->udp, buf, Udphdrsize);
-		msg->msg.data = emalloc(n);
-		msg->msg.count = n-Udphdrsize;
-		memmove(msg->msg.data, buf+Udphdrsize, n-Udphdrsize);
-		memmove(&msg->udp, buf, Udphdrsize);
-		msg->msg.creply = arg.creply;
-		if(arg.srv->chatty)
-			fprint(2, "message %p count %d\n", msg, msg->msg.count);
-		sendp(arg.srv->crequest, msg);
-	}
-}
-
-static void
-sunUdpWrite(void *v)
-{
-	uint8_t *buf;
-	Arg arg = *(Arg*)v;
-	SunMsgUdp *msg;
-
-	sendp(arg.csync, 0);
-
-	buf = emalloc(UdpMaxRead);
-	while((msg = recvp(arg.creply)) != nil){
-		memmove(buf+Udphdrsize, msg->msg.data, msg->msg.count);
-		memmove(buf, &msg->udp, Udphdrsize);
-		msg->msg.count += Udphdrsize;
-		if(write(arg.fd, buf, msg->msg.count) != msg->msg.count)
-			fprint(2, "udpWrite: %r\n");
-		free(msg->msg.data);
-		free(msg);
-	}
-}
-
-int
-sunSrvUdp(SunSrv *srv, char *address)
-{
-	int acfd, fd;
-	char adir[40], data[60];
-	Arg *arg;
-
-	acfd = announce(address, adir);
-	if(acfd < 0)
-		return -1;
-	if(write(acfd, "headers", 7) < 0){
-		werrstr("setting headers: %r");
-		close(acfd);
-		return -1;
-	}
-	snprint(data, sizeof data, "%s/data", adir);
-	if((fd = open(data, ORDWR)) < 0){
-		werrstr("open %s: %r", data);
-		close(acfd);
-		return -1;
-	}
-	close(acfd); 
-	
-	arg = emalloc(sizeof(Arg));
-	arg->fd = fd;
-	arg->srv = srv;
-	arg->creply = chancreate(sizeof(SunMsg*), 10);
-	arg->csync =  chancreate(sizeof(void*), 10);
-
-	proccreate(sunUdpRead, arg, SunStackSize);
-	proccreate(sunUdpWrite, arg, SunStackSize);
-	recvp(arg->csync);
-	recvp(arg->csync);
-	chanfree(arg->csync);
-	free(arg);
-
-	return 0;
-}