[9fans] Re: So, once I've got the OS up how do I... (fwd)

Jim Choate ravage at einstein.ssz.com
Wed Feb 7 18:33:44 PST 2001




    ____________________________________________________________________

           Before a larger group can see the virtue of an idea, a
           smaller group must first understand it.

                                           "Stranger Suns"
                                           George Zebrowski

       The Armadillo Group       ,::////;::-.          James Choate
       Austin, Tx               /:'///// ``::>/|/      ravage at ssz.com
       www.ssz.com            .',  ||||    `/( e\      512-451-7087
                           -====~~mm-'`-```-mm --'-
    --------------------------------------------------------------------

---------- Forwarded message ----------
Date: Wed, 7 Feb 2001 21:21:31 -0500
From: Russ Cox <rsc at plan9.bell-labs.com>
Reply-To: 9fans at cse.psu.edu
To: 9fans at cse.psu.edu
Subject: Re: [9fans] Re: So, once I've got the OS up how do I...

Regarding Plan 9 <-> Unix as far as file systems,
Plan 9 has an NFS server that Unix systems may
use to mount Plan 9 file systems.  It works pretty
well.  We had someone working almost exclusively
over the NFS server two summers ago.

U9fs is a 9P server that Plan 9 systems may use to
mount Unix file systems.  It too works pretty well.
As I type this, I have two such file systems mounted
in my namespace.  I'm also booting a Plan 9 box
entirely over an ethernet with a FreeBSD machine
serving as both file and authentication server.
I'm using u9fs (rewritten for 9P2000 but pretty much
the same) for file service and a port of auth.srv for
authentication.  It works.

Neither is blazingly fast, but that's not the goal.
They work well for providing interoperability.

The amazing thing is how simple they are.

    1527    3657   27203 u9fs/u9fs.c
     326     792    6457 9auth/9authsrv.c

The rest is mostly supporting routines pulled in
from the Plan 9 C library, like doprint and convM2S.

That's a full file server in 1500 lines of code,
and an authentication server in 300.  The reason this
works is that 9P is so simple.  If you want to drive the
point home, put up the rot13fs below (inspired by a
French intro to Plan 9 that appeared a few years ago;
I'd credit further except not knowing French, I got
by reading only the examples).

The whole guts of the filter is right here:

	while(n=sizeof buf, getS(rd, buf, &f, &n) == nil){
		if(f.type == Ropen)
			isdir[f.fid] = f.qid.path&CHDIR;
		if((f.type == Twrite || f.type == Rread) && !isdir[f.fid])
			rot13(f.data, f.count);
		n = convS2M(&f, wbuf);
		write(wr, wbuf, n);
	}

and that's it.  9P is simple.  Compare this with the hoops
being jumped through to do encrypted file systems on Unix
by having fake NFS servers or kernel vnode-layer replacements
or what-have-you.

Russ


#include <u.h>
#include <libc.h>
#include <auth.h>
#include <fcall.h>
#include <ctype.h>

void
rot13(char *p, int n)
{
	char *ep;

	for(ep=p+n; p<ep; p++)
		if(isalpha(*p))
			if(tolower(*p) <= 'm')
				*p += 13;
			else
				*p -= 13;
}

int isdir[65536];
void
filter(int rd, int wr)
{
	char buf[MAXMSG+MAXFDATA], wbuf[MAXMSG+MAXFDATA];
	Fcall f;
	long n;

	while(n=sizeof buf, getS(rd, buf, &f, &n) == nil){
		if(f.type == Ropen)
			isdir[f.fid] = f.qid.path&CHDIR;
		if((f.type == Twrite || f.type == Rread) && !isdir[f.fid])
			rot13(f.data, f.count);
		n = convS2M(&f, wbuf);
		write(wr, wbuf, n);
	}
	postnote(PNGROUP, getpid(), "die");
}

void
main(int argc, char **argv)
{
	int sfd, p[2];

	rfork(RFNOTEG);

	if(argc != 1+2){
		fprint(2, "usage: rot13fs service-in mountpoint\n");
		exits("usage");
	}

	if((sfd = open(argv[1], ORDWR)) < 0)
		sysfatal("cannot open %s: %r\n", argv[1]);

	if(pipe(p) < 0)
		sysfatal("pipe fails: %r\n");

	switch(rfork(RFNAMEG|RFPROC|RFFDG|RFMEM)){
	case -1:
		sysfatal("rfork fails: %r\n");
	case 0:
		close(p[0]);
		switch(fork()){
		case -1:
			sysfatal("rfork fails: %r\n");
		case 0:
			filter(sfd, p[1]);
			break;
		default:
			filter(p[1], sfd);
			break;
		}
		_exits(0);
	default:
		close(p[1]);
		if(amount(p[0], argv[2], MREPL, "") < 0)
			sysfatal("mount fails: %r\n");
		exits(0);
	}
}





More information about the cypherpunks-legacy mailing list