~kris/9p

9hist

01bc072ba508d802b1a233f1b4b11d970027d242 — David du Colombier 30 years ago d38dfbf
Plan 9 from Bell Labs 1996-02-23
M carrera/devrtc.c => carrera/devrtc.c +0 -1
@@ 4,7 4,6 @@
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"
#include	"devtab.h"
#include	"io.h"

/*

M carrera/kbd.c => carrera/kbd.c +0 -1
@@ 6,7 6,6 @@
#include	"io.h"
#include	"../port/error.h"

#include	"devtab.h"

enum
{

M pc/devastar.c => pc/devastar.c +0 -1
@@ 6,7 6,6 @@
#include	"io.h"
#include	"../port/error.h"

#include	"devtab.h"

/*
 *  Stargate's Avanstar serial board.  There are ISA, EISA, microchannel

M pc/devata.c => pc/devata.c +0 -1
@@ 10,7 10,6 @@
#include	"io.h"
#include	"../port/error.h"

#include	"devtab.h"

#define DPRINT if(0)print
#define XPRINT if(0)print

D pc/devconfig.c => pc/devconfig.c +0 -207
@@ 1,207 0,0 @@
#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"
#include	"../port/error.h"

#include	<libg.h>
#include	"devtab.h"
#include	"vga.h"

/*
 *  Driver for various VGA cards
 */

char	vgacard[NAMELEN];	/* vga card type */
struct screeninfo {
	int	maxx, maxy;	/* current bits per screen */
	int	packed;		/* 0=planar, 1=packed */
	int	interlaced;	/* != 0 if interlaced */
} screeninfo;

enum {
	Qdir=		0,
	Qvgasize=	1,
	Qvgatype=	2,
	Qvgaport=	3,
	Nvga=		4,
};

Dirtab vgadir[]={
	"vgatype",	{Qvgatype},	0,		0666,
	"vgasize",	{Qvgasize},	0,		0666,
	"vgaport",	{Qvgaport},	0,		0666,
};

/* a routine from ../port/devcons.c */
extern	int readstr(ulong, char *, ulong, char *);

void
configsetup(void) {
}

void
configreset(void) {
	strcpy(vgacard, "generic");
	screeninfo.maxx = 640;
	screeninfo.maxy = 480;
	screeninfo.packed = 0;
	screeninfo.interlaced = 0;
}

void
configinit(void)
{
}

Chan*
configattach(char *upec)
{
	return devattach('v', upec);
}

Chan*
configclone(Chan *c, Chan *nc)
{
	return devclone(c, nc);
}

int
configwalk(Chan *c, char *name)
{
	return devwalk(c, name, vgadir, Nvga, devgen);
}

void
configstat(Chan *c, char *dp)
{
	devstat(c, dp, vgadir, Nvga, devgen);
}

Chan*
configopen(Chan *c, int omode)
{
	return devopen(c, omode, vgadir, Nvga, devgen);
}

void
configcreate(Chan*, char*, int, ulong)
{
	error(Eperm);
}

void
configclose(Chan *c)
{
	USED(c);
}

long
configread(Chan *c, void *buf, long n, ulong offset)
{
	int port;
	uchar *cp = buf;

	switch(c->qid.path&~CHDIR){
	case Qdir:
		return devdirread(c, buf, n, vgadir, Nvga, devgen);
	case Qvgatype:
		return readstr(offset, buf, n, vgacard);
	case Qvgaport:
		if (offset + n >= 0x8000)
			error(Ebadarg);
		for (port=offset; port<offset+n; port++)
			*cp++ = inb(port);
		return n;
	}
	error(Eperm);
	return 0;
}

Block*
configbread(Chan *c, long n, ulong offset)
{
	return devbread(c, n, offset);
}

long
configwrite(Chan *c, void *buf, long n, ulong offset)
{
	char cbuf[20], *cp;
	int port, maxx, maxy, ldepth;

	switch(c->qid.path&~CHDIR){
	case Qdir:
		error(Eperm);
	case Qvgatype:
		error(Eperm);
	case Qvgasize:
		if(offset != 0)
			error(Ebadarg);
		if(n >= sizeof(cbuf))
			n = sizeof(cbuf) - 1;
		memmove(cbuf, buf, n);
		cbuf[n] = 0;
		cp = cbuf;
		maxx = strtoul(cp, &cp, 0);
		if(*cp!=0)
			cp++;
		maxy = strtoul(cp, &cp, 0);
		if(*cp!=0)
			cp++;
		switch(strtoul(cp, &cp, 0)){
		case 1:
			ldepth = 0;
			break;
		case 2:
			ldepth = 1;
			break;
		case 4:
			ldepth = 2;
			break;
		case 8:
			ldepth = 3;
			break;
		default:
			ldepth = -1;
		}
		if(maxx == 0 || maxy == 0
		|| maxx > 1280 || maxy > 1024
		|| ldepth > 3 || ldepth < 0)
			error(Ebadarg);
		setscreen(maxx, maxy, ldepth);
		return n;
	case Qvgaport:
		cp = buf;
		if (offset + n >= 0x8000)
			error(Ebadarg);
		for (port=offset; port<offset+n; port++) {
			outb(port, *cp++);
		}
		return n;
	}
	error(Eperm);
	return 0;
}

long
configbwrite(Chan *c, Block *bp, ulong offset)
{
	return devbwrite(c, bp, offset);
}

void
configremove(Chan *c)
{
	USED(c);
	error(Eperm);
}

void
configwstat(Chan *c, char *dp)
{
	USED(c, dp);
	error(Eperm);
}

M pc/devfloppy.c => pc/devfloppy.c +0 -1
@@ 5,7 5,6 @@
#include	"fns.h"
#include	"io.h"
#include	"../port/error.h"
#include	"devtab.h"

/* Intel 82077A (8272A compatible) floppy controller */


M pc/devrtc.c => pc/devrtc.c +0 -1
@@ 4,7 4,6 @@
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"
#include	"devtab.h"

/*
 *  real time clock and non-volatile ram

M port/cache.c => port/cache.c +0 -1
@@ 4,7 4,6 @@
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"
#include	"devtab.h"

Image	fscache;


M port/dev.c => port/dev.c +0 -1
@@ 4,7 4,6 @@
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"
#include	"devtab.h"

extern ulong	kerndate;


M port/devXXX.c => port/devXXX.c +0 -1
@@ 9,7 9,6 @@
#include	"fns.h"
#include	"../port/error.h"

#include	"devtab.h"

enum{
	Qdir,

M port/devaudio.c => port/devaudio.c +0 -1
@@ 7,7 7,6 @@
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"
#include	"devtab.h"
#include	"io.h"
#include	"audio.h"


M port/devboot.c => port/devboot.c +0 -1
@@ 4,7 4,6 @@
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"
#include	"devtab.h"

enum{
	Qdir,

M port/devcons.c => port/devcons.c +0 -1
@@ 5,7 5,6 @@
#include	"fns.h"
#include	"../port/error.h"

#include	"devtab.h"

Queue	*mouseq;
Queue	*kbdq;		/* unprocessed console input */

M port/devdup.c => port/devdup.c +0 -1
@@ 5,7 5,6 @@
#include	"fns.h"
#include	"../port/error.h"

#include	"devtab.h"


int

M port/devenv.c => port/devenv.c +0 -1
@@ 5,7 5,6 @@
#include	"fns.h"
#include	"../port/error.h"

#include	"devtab.h"

enum
{

M port/devkprof.c => port/devkprof.c +0 -1
@@ 5,7 5,6 @@
#include	"fns.h"
#include	"../port/error.h"

#include	"devtab.h"

#define	LRES	3		/* log of PC resolution */
#define	SZ	4		/* sizeof of count cell; well known as 4 */

M port/devmnt.c => port/devmnt.c +0 -1
@@ 4,7 4,6 @@
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"
#include	"devtab.h"

struct Mntrpc
{

M port/devmouse.c => port/devmouse.c +0 -1
@@ 6,7 6,6 @@
#include	"fns.h"
#include	"../port/error.h"

#include	"devtab.h"
#include	"screen.h"

typedef struct Mouseinfo	Mouseinfo;

M port/devns16552.c => port/devns16552.c +0 -1
@@ 6,7 6,6 @@
#include	"io.h"
#include	"../port/error.h"

#include	"devtab.h"
#include	"../port/netif.h"

/*

M port/devpipe.c => port/devpipe.c +0 -1
@@ 5,7 5,6 @@
#include	"fns.h"
#include	"../port/error.h"

#include	"devtab.h"
#include	"netif.h"

typedef struct Pipe	Pipe;

M port/devproc.c => port/devproc.c +0 -1
@@ 6,7 6,6 @@
#include	"../port/error.h"
#include	"ureg.h"

#include	"devtab.h"

enum
{

M port/devroot.c => port/devroot.c +0 -1
@@ 4,7 4,6 @@
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"
#include	"devtab.h"

enum{
	Qdir=	0,

M port/devsd.c => port/devsd.c +0 -1
@@ 7,7 7,6 @@
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"
#include	"devtab.h"

enum
{

M port/devsrv.c => port/devsrv.c +0 -1
@@ 5,7 5,6 @@
#include	"fns.h"
#include	"../port/error.h"

#include	"devtab.h"

typedef struct Srv Srv;
struct Srv

M port/devssl.c => port/devssl.c +105 -106
@@ 10,7 10,6 @@
#include	"../port/error.h"
#include	<libcrypt.h>

#include	"devtab.h"

typedef struct OneWay OneWay;
struct OneWay


@@ 191,32 190,6 @@ sslclose(Chan *c)
	}
}

long
sslread(Chan *c, void *a, long n, ulong offset)
{
	Block *b;

	switch(c->qid.path & ~CHDIR){
	case Qdir:
		return devdirread(c, a, n, digesttab, Ndigesttab, devgen);
	}

	b = sslbread(c, n, offset);

	if(waserror()){
		freeb(b);
		nexterror();
	}

	n = BLEN(b);
	memmove(a, b->rp, n);
	freeb(b);

	poperror();

	return n;
}

Block*
sslbread(Chan *c, long n, ulong offset)
{


@@ 301,94 274,28 @@ sslbread(Chan *c, long n, ulong offset)
}

long
sslwrite(Chan *c, void *a, long n, ulong offset)
sslread(Chan *c, void *a, long n, ulong offset)
{
	Dstate *s;
	Block *b;
	int m;
	char *p, *e, buf[32];

	switch(c->qid.path & ~CHDIR){
	case Qclone:
		break;
	default:
		error(Ebadusefd);
	case Qdir:
		return devdirread(c, a, n, digesttab, Ndigesttab, devgen);
	}

	s = c->aux;
	if(s == 0)
		error(Ebadusefd);
	b = sslbread(c, n, offset);

	switch(s->state){
	case Algwait:
		/* get algorithm */
		if(n >= sizeof(buf))
			error(Ebadarg);
		strncpy(buf, a, n);
		buf[n] = 0;
		s->blocklen = 1;
		s->diglen = 0;
		if(strcmp(buf, "md5") == 0){
			s->hf = md5;
			s->diglen = MD5dlen;
		} else if(strcmp(buf, "sha") == 0){
			s->hf = sha;
			s->diglen = SHAdlen;
		} else if(strcmp(buf, "descbc") == 0){
			s->encryptalg = DESCBC;
			s->blocklen = 8;
		} else if(strcmp(buf, "desecb") == 0){
			s->encryptalg = DESECB;
			s->blocklen = 8;
		} else
			error(Ebadarg);
		s->state = Fdwait;
		break;
	case Fdwait:
		/* get communications channel */
		s->c = buftochan(a, n);
		s->state = Secretinwait;
		break;
	case Secretinwait:
		/* get secret for incoming messages */
		setsecret(s, &s->in, a, n);
		s->state = Secretoutwait;
		break;
	case Secretoutwait:
		/* get secret for outgoing messages */
		setsecret(s, &s->out, a, n);
		if(s->blocklen != 1){
			s->max = (1<<15) - s->diglen;
			s->max -= s->max % s->blocklen;
			s->maxpad = (1<<14) - s->diglen;
			s->maxpad -= s->maxpad % s->blocklen;
		} else
			s->maxpad = s->max = (1<<15) - s->diglen;
		s->state = Established;
		break;
	case Established:
		p = a;
		for(e = p + n; p < e; p += m){
			m = e - p;
			if(m > s->max)
				m = s->max;
	
			b = allocb(m);
			if(waserror()){
				freeb(b);
				nexterror();
			}
			memmove(b->wp, p, m);
			poperror();
			b->wp += m;
	
			sslbwrite(c, b, offset);
		}
		break;
	default:
		error(Ebadusefd);
	if(waserror()){
		freeb(b);
		nexterror();
	}

	n = BLEN(b);
	memmove(a, b->rp, n);
	freeb(b);

	poperror();

	return n;
}



@@ 485,6 392,98 @@ sslbwrite(Chan *c, Block *b, ulong offset)
	return rv;
}

long
sslwrite(Chan *c, void *a, long n, ulong offset)
{
	Dstate *s;
	Block *b;
	int m;
	char *p, *e, buf[32];

	switch(c->qid.path & ~CHDIR){
	case Qclone:
		break;
	default:
		error(Ebadusefd);
	}

	s = c->aux;
	if(s == 0)
		error(Ebadusefd);

	switch(s->state){
	case Algwait:
		/* get algorithm */
		if(n >= sizeof(buf))
			error(Ebadarg);
		strncpy(buf, a, n);
		buf[n] = 0;
		s->blocklen = 1;
		s->diglen = 0;
		if(strcmp(buf, "md5") == 0){
			s->hf = md5;
			s->diglen = MD5dlen;
		} else if(strcmp(buf, "sha") == 0){
			s->hf = sha;
			s->diglen = SHAdlen;
		} else if(strcmp(buf, "descbc") == 0){
			s->encryptalg = DESCBC;
			s->blocklen = 8;
		} else if(strcmp(buf, "desecb") == 0){
			s->encryptalg = DESECB;
			s->blocklen = 8;
		} else
			error(Ebadarg);
		s->state = Fdwait;
		break;
	case Fdwait:
		/* get communications channel */
		s->c = buftochan(a, n);
		s->state = Secretinwait;
		break;
	case Secretinwait:
		/* get secret for incoming messages */
		setsecret(s, &s->in, a, n);
		s->state = Secretoutwait;
		break;
	case Secretoutwait:
		/* get secret for outgoing messages */
		setsecret(s, &s->out, a, n);
		if(s->blocklen != 1){
			s->max = (1<<15) - s->diglen;
			s->max -= s->max % s->blocklen;
			s->maxpad = (1<<14) - s->diglen;
			s->maxpad -= s->maxpad % s->blocklen;
		} else
			s->maxpad = s->max = (1<<15) - s->diglen;
		s->state = Established;
		break;
	case Established:
		p = a;
		for(e = p + n; p < e; p += m){
			m = e - p;
			if(m > s->max)
				m = s->max;
	
			b = allocb(m);
			if(waserror()){
				freeb(b);
				nexterror();
			}
			memmove(b->wp, p, m);
			poperror();
			b->wp += m;
	
			sslbwrite(c, b, offset);
		}
		break;
	default:
		error(Ebadusefd);
	}

	return n;
}

/*
 *  make sure we have at least 'n' bytes in list 'l'
 */

M port/devtinyfs.c => port/devtinyfs.c +0 -1
@@ 9,7 9,6 @@
#include	"fns.h"
#include	"../port/error.h"

#include	"devtab.h"

enum{
	Qdir,

M power/devduart.c => power/devduart.c +0 -1
@@ 6,7 6,6 @@
#include	"io.h"
#include	"../port/error.h"

#include	"devtab.h"
#include	"../port/netif.h"

/*

M power/devrtc.c => power/devrtc.c +0 -1
@@ 4,7 4,6 @@
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"
#include	"devtab.h"

#include	"io.h"