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

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


## diffname port/devroot.c 1990/0227
## diff -e /dev/null /n/bootesdump/1990/0227/sys/src/9/mips/devroot.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"errno.h"
#include	"devtab.h"

enum{
	Qdir,
	Qbin,
	Qboot,
	Qdev,
	Qenv,
	Qproc,
};

Dirtab rootdir[]={
	"bin",		Qbin|CHDIR,	0,			0700,
	"boot",		Qboot,		0,			0700,
	"dev",		Qdev|CHDIR,	0,			0700,
	"env",		Qenv|CHDIR,	0,			0700,
	"proc",		Qproc|CHDIR,	0,			0700,
};

#define	NROOT	(sizeof rootdir/sizeof(Dirtab))

void
rootreset(void)
{
}

void
rootinit(void)
{
}

Chan*
rootattach(char *spec)
{
	return devattach('/', spec);
}

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

int	 
rootwalk(Chan *c, char *name)
{
	return devwalk(c, name, rootdir, NROOT, devgen);
}

void	 
rootstat(Chan *c, char *dp)
{
	devstat(c, dp, rootdir, NROOT, devgen);
}

Chan*
rootopen(Chan *c, int omode)
{
	return devopen(c, omode, rootdir, NROOT, devgen);
}

void	 
rootcreate(Chan *c, char *name, int omode, ulong perm)
{
	error(0, Eperm);
}

/*
 * sysremove() knows this is a nop
 */
void	 
rootclose(Chan *c)
{
}

#include	"boot.h"

long	 
rootread(Chan *c, void *buf, long n)
{

	switch(c->qid & ~CHDIR){
	case Qdir:
		return devdirread(c, buf, n, rootdir, NROOT, devgen);

	case Qboot:		/* boot */
		if(c->offset >= sizeof bootcode)
			return 0;
		if(c->offset+n > sizeof bootcode)
			n = sizeof bootcode - c->offset;
		memcpy(buf, ((char*)bootcode)+c->offset, n);
		return n;

	case Qdev:
		return 0;
	}
	error(0, Egreg);
	return 0;
}

long	 
rootwrite(Chan *c, void *buf, long n)
{
	error(0, Egreg);
}

void	 
rootremove(Chan *c)
{
	error(0, Eperm);
}

void	 
rootwstat(Chan *c, char *dp)
{
	error(0, Eperm);
}

void
rootuserstr(Error *e, char *buf)
{
	consuserstr(e, buf);
}

#include "errstr.h"

void	 
rooterrstr(Error *e, char *buf)
{
	if(e->code<0 || e->code>=sizeof errstrtab/sizeof(char*))
		strcpy(buf, "no such error");
	else
		strcpy(buf, errstrtab[e->code]);
}
.
## diffname port/devroot.c 1990/11211
## diff -e /n/bootesdump/1990/0227/sys/src/9/mips/devroot.c /n/bootesdump/1990/11211/sys/src/9/mips/devroot.c
122,139c
	error(Eperm);
.
116c
	error(Eperm);
.
110c
	error(Egreg);
.
103c
	error(Egreg);
.
88c
	switch(c->qid.path & ~CHDIR){
.
71c
	error(Eperm);
.
19,23c
	"bin",		{Qbin|CHDIR},	0,			0700,
	"boot",		{Qboot},	0,			0700,
	"dev",		{Qdev|CHDIR},	0,			0700,
	"env",		{Qenv|CHDIR},	0,			0700,
	"proc",		{Qproc|CHDIR},	0,			0700,
.
## diffname port/devroot.c 1991/0110
## diff -e /n/bootesdump/1990/1210/sys/src/9/mips/devroot.c /n/bootesdump/1991/0110/sys/src/9/port/devroot.c
97a
ck("2");
.
96a
ck("1");
.
## diffname port/devroot.c 1991/0111
## diff -e /n/bootesdump/1991/0110/sys/src/9/port/devroot.c /n/bootesdump/1991/0111/sys/src/9/port/devroot.c
99d
97d
## diffname port/devroot.c 1991/0214
## diff -e /n/bootesdump/1991/0111/sys/src/9/port/devroot.c /n/bootesdump/1991/0214/sys/src/9/port/devroot.c
97a
		return n;

	case Qcfs:		/* boot */
		if(c->offset >= cfslen)
			return 0;
		if(c->offset+n > cfslen)
			n = cfslen - c->offset;
		memcpy(buf, ((char*)cfscode)+c->offset, n);
.
90c
		return devdirread(c, buf, n, rootdir, nroot, devgen);
.
65c
	return devopen(c, omode, rootdir, nroot, devgen);
.
59c
	devstat(c, dp, rootdir, nroot, devgen);
.
53c
	return devwalk(c, name, rootdir, nroot, devgen);
.
30a
	nroot = (cfslen > 0) ? NROOT : NROOT-1;
.
26a
int	nroot;
.
23a
	"cfs",		{Qcfs},		0,			0700,
.
17a
extern long	cfslen;
extern ulong	*cfscode;


.
12a
	Qcfs,
.
## diffname port/devroot.c 1991/0216
## diff -e /n/bootesdump/1991/0214/sys/src/9/port/devroot.c /n/bootesdump/1991/0216/sys/src/9/port/devroot.c
20c
extern ulong	cfscode[];
.
## diffname port/devroot.c 1991/0312
## diff -e /n/bootesdump/1991/0216/sys/src/9/port/devroot.c /n/bootesdump/1991/0312/sys/src/9/port/devroot.c
108c
	case Qcfs:		/* cfs */
.
## diffname port/devroot.c 1991/0318
## diff -e /n/bootesdump/1991/0312/sys/src/9/port/devroot.c /n/bootesdump/1991/0318/sys/src/9/port/devroot.c
113c
		memmove(buf, ((char*)cfscode)+c->offset, n);
.
105c
		memmove(buf, ((char*)bootcode)+c->offset, n);
.
## diffname port/devroot.c 1991/0411
## diff -e /n/bootesdump/1991/0318/sys/src/9/port/devroot.c /n/bootesdump/1991/0411/sys/src/9/port/devroot.c
124c
rootwrite(Chan *c, void *buf, long n, ulong offset)
.
111,113c
		if(offset+n > cfslen)
			n = cfslen - offset;
		memmove(buf, ((char*)cfscode)+offset, n);
.
109c
		if(offset >= cfslen)
.
103,105c
		if(offset+n > sizeof bootcode)
			n = sizeof bootcode - offset;
		memmove(buf, ((char*)bootcode)+offset, n);
.
101c
		if(offset >= sizeof bootcode)
.
93c
rootread(Chan *c, void *buf, long n, ulong offset)
.
## diffname port/devroot.c 1991/0419
## diff -e /n/bootesdump/1991/0411/sys/src/9/port/devroot.c /n/bootesdump/1991/0419/sys/src/9/port/devroot.c
63a
Chan*
rootclwalk(Chan *c, char *name)
{
	return devclwalk(c, name);
}

.
## diffname port/devroot.c 1991/0427
## diff -e /n/bootesdump/1991/0419/sys/src/9/port/devroot.c /n/bootesdump/1991/0427/sys/src/9/port/devroot.c
64,69d
## diffname port/devroot.c 1991/0613
## diff -e /n/bootesdump/1991/0427/sys/src/9/port/devroot.c /n/bootesdump/1991/0613/sys/src/9/port/devroot.c
113a
		return n;

	case Qcryptfs:		/* cryptfs */
		if(offset >= cryptfslen)
			return 0;
		if(offset+n > cryptfslen)
			n = cryptfslen - offset;
		memmove(buf, ((char*)cryptfscode)+offset, n);
.
28a
	"cryptfs",	{Qcryptfs},	0,			0700,
.
22a

.
21a
extern long	cryptfslen;
extern ulong	cryptfscode[];
.
13a
	Qcryptfs,
.
## diffname port/devroot.c 1991/0615
## diff -e /n/bootesdump/1991/0613/sys/src/9/port/devroot.c /n/bootesdump/1991/0615/sys/src/9/port/devroot.c
103c
		return devdirread(c, buf, n, rootdir, nroot, rootgen);
.
78c
	return devopen(c, omode, rootdir, nroot, rootgen);
.
72c
	devstat(c, dp, rootdir, nroot, rootgen);
.
66c
	return devwalk(c, name, rootdir, nroot, rootgen);
.
43c
	int i;

	i = 0;
	if(cfslen)
		rootmap[i++] = &rootpdir[0];
	if(cryptfslen)
		rootmap[i++] = &rootpdir[1];
	nroot = NROOT + i;
.
39a
int
rootgen(Chan *c, Dirtab *tab, int ntab, int i, Dir *dp)
{
	if(tab==0 || i>=ntab)
		return -1;
	if(i < NROOT)
		tab += i;
	else
		tab = rootmap[i - NROOT];
	devdir(c, tab->qid, tab->name, tab->length, tab->perm, dp);
	return 1;
}

.
37a
Dirtab rootpdir[]={
	"cfs",		{Qcfs},		0,			0700,
	"cryptfs",	{Qcryptfs},	0,			0700,
};
Dirtab *rootmap[sizeof rootpdir/sizeof(Dirtab)];
.
36d
33,34d
26d
22d
## diffname port/devroot.c 1991/0910
## diff -e /n/bootesdump/1991/0615/sys/src/9/port/devroot.c /n/bootesdump/1991/0910/sys/src/9/port/devroot.c
138a
		return n;

	case Qkfs:		/* kfs */
		if(offset >= kfslen)
			return 0;
		if(offset+n > kfslen)
			n = kfslen - offset;
		memmove(buf, ((char*)kfscode)+offset, n);
.
62a
	if(kfslen)
		rootmap[i++] = &rootpdir[2];
.
35a
	"kfs",		{Qkfs},		0,			0700,
.
21a
extern long	kfslen;
extern ulong	kfscode[];
.
16a
	Qkfs,
.
## diffname port/devroot.c 1991/0913
## diff -e /n/bootesdump/1991/0910/sys/src/9/port/devroot.c /n/bootesdump/1991/0913/sys/src/9/port/devroot.c
153,160d
68c
		rootmap[i++] = &rootpdir[1];
.
65,66d
38d
25,26d
14d
## diffname port/devroot.c 1991/1109
## diff -e /n/bootesdump/1991/0913/sys/src/9/port/devroot.c /n/bootesdump/1991/1109/sys/src/9/port/devroot.c
49c
	devdir(c, tab->qid, tab->name, tab->length, eve, tab->perm, dp);
.
## diffname port/devroot.c 1991/1112
## diff -e /n/bootesdump/1991/1109/sys/src/9/port/devroot.c /n/bootesdump/1991/1112/sys/src/9/port/devroot.c
34,35c
	"cfs",		{Qcfs},		0,			0777,
	"kfs",		{Qkfs},		0,			0777,
.
26,30c
	"bin",		{Qbin|CHDIR},	0,			0777,
	"boot",		{Qboot},	0,			0777,
	"dev",		{Qdev|CHDIR},	0,			0777,
	"env",		{Qenv|CHDIR},	0,			0777,
	"proc",		{Qproc|CHDIR},	0,			0777,
.
## diffname port/devroot.c 1991/1115
## diff -e /n/bootesdump/1991/1112/sys/src/9/port/devroot.c /n/bootesdump/1991/1115/sys/src/9/port/devroot.c
170a
	USED(c, dp);
.
164a
	USED(c);
.
158a
	USED(c, buf, n, offset);
.
112a
	USED(c);
.
103a
	USED(c, name, omode, perm);
.
## diffname port/devroot.c 1991/1206
## diff -e /n/bootesdump/1991/1115/sys/src/9/port/devroot.c /n/bootesdump/1991/1206/sys/src/9/port/devroot.c
130,131c
		if(offset+n > bootlen)
			n = bootlen - offset;
.
128c
		if(offset >= bootlen)
.
117,118d
85a
	if(strcmp(name, "..") == 0) {
		c->qid.path = Qdir|CHDIR;
		return 1;
	}
.
23a
extern ulong	bootlen;
extern ulong	bootcode[];
.
17a

	Qboot,
	Qcfs,
	Qkfs,
.
16d
12,13d
## diffname port/devroot.c 1992/0111
## diff -e /n/bootesdump/1991/1206/sys/src/9/port/devroot.c /n/bootesdump/1992/0111/sys/src/9/port/devroot.c
6c
#include	"../port/error.h"
.
## diffname port/devroot.c 1992/0213
## diff -e /n/bootesdump/1992/0111/sys/src/9/port/devroot.c /n/bootesdump/1992/0213/sys/src/9/port/devroot.c
33a
	"net",		{Qnet|CHDIR},	0,			0777,
.
14a
	Qnet,
.
## diffname port/devroot.c 1992/0215
## diff -e /n/bootesdump/1992/0213/sys/src/9/port/devroot.c /n/bootesdump/1992/0215/sys/src/9/port/devroot.c
161d
## diffname port/devroot.c 1992/0225
## diff -e /n/bootesdump/1992/0215/sys/src/9/port/devroot.c /n/bootesdump/1992/0225/sys/src/9/port/devroot.c
94a
	if((c->qid.path & ~CHDIR) != Qdir)
		error(Enonexist);
.
53a

.
51c
		tab = &rootdir[i];
.
49a

.
48c
	if(i >= nroot)
.
## diffname port/devroot.c 1992/0226
## diff -e /n/bootesdump/1992/0225/sys/src/9/port/devroot.c /n/bootesdump/1992/0226/sys/src/9/port/devroot.c
98c
		return 0;
.
## diffname port/devroot.c 1992/0321
## diff -e /n/bootesdump/1992/0226/sys/src/9/port/devroot.c /n/bootesdump/1992/0321/sys/src/9/port/devroot.c
2c
#include	"../port/lib.h"
.
## diffname port/devroot.c 1992/0520
## diff -e /n/bootesdump/1992/0321/sys/src/9/port/devroot.c /n/bootesdump/1992/0520/sys/src/9/port/devroot.c
172a
	return 0;	/* not reached */
.
## diffname port/devroot.c 1992/0711
## diff -e /n/bootesdump/1992/0520/sys/src/9/port/devroot.c /n/bootesdump/1992/0711/sys/src/9/port/devroot.c
47a
	USED(ntab);

.
## diffname port/devroot.c 1992/0902
## diff -e /n/bootesdump/1992/0711/sys/src/9/port/devroot.c /n/bootesdump/1992/0902/sys/src/9/port/devroot.c
159,161c
		if(offset+n > fslen)
			n = fslen - offset;
		memmove(buf, ((char*)fscode)+offset, n);
.
156,157c
	case Qfs:		/* fs */
		if(offset >= fslen)
.
145c
		memmove(buf, bootcode+offset, n);
.
70c
	if(fslen)
.
40c
	"fs",		{Qfs},		0,			0777,
.
27c
extern uchar	bootcode[];
.
24,25c
extern long	fslen;
extern ulong	fscode[];
.
19c
	Qfs,
.
## diffname port/devroot.c 1993/0501
## diff -e /n/bootesdump/1992/0902/sys/src/9/port/devroot.c /n/fornaxdump/1993/0501/sys/src/brazil/port/devroot.c
189a
}

void
rootrecover(Path *p, char *mntname)
{
	int i;
	Recover *r;
	char buf[256];

	r = malloc(sizeof(Recover));
	i = ptpath(p, buf, sizeof(buf));
	r->req = smalloc(i+strlen(mntname)+2);
	sprint(r->req, "%s %s", buf, mntname);
	lock(&reclist);
	r->next = reclist.q;
	reclist.q = r;
	unlock(&reclist);
	wakeup(&reclist);
.
173,175c
	char tmp[256];

	USED(offset);
	switch(c->qid.path & ~CHDIR){
	default:
		error(Egreg);
	case Qrecover:
		if(n > sizeof(tmp)-1)
			error(Etoosmall);
		/* Nul terminate */
		memmove(tmp, buf, n);
		tmp[n] = '\0';
		mntrepl(tmp);
		return n;
	}
	return 0;
.
163a
	case Qrecover:
		qlock(&reclist);
		if(waserror()) {
			qunlock(&reclist);
			nexterror();
		}

		sleep(&reclist, rdrdy, 0);

		lock(&reclist);
		r = reclist.q;
		reclist.q = r->next;
		unlock(&reclist);

		qunlock(&reclist);

		poperror();
		if(n < r->len)
			n = r->len;
		memmove(buf, r->req, n);
		free(r->req);
		free(r);
		return n;

.
134a
	Recover *r;
.
131a
int
rdrdy(void *a)
{
	USED(a);
	return reclist.q != 0;
}

.
112a
	switch(c->qid.path & ~CHDIR) {
	default:
		break;
	case Qrecover:
		if(strcmp(up->user, eve) != 0)
			error(Eperm);
		break;
	}

.
44a
typedef struct Recover Recover;
struct Recover
{
	int	len;
	char	*req;
	Recover	*next;
};

struct 
{
	Lock;
	QLock;
	Rendez;
	Recover	*q;
}reclist;

.
35a
	"recover",	{Qrecover},	0,			0777,
.
15a
	Qrecover,
.
9c
enum
{
.
## diffname port/devroot.c 1993/0724
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/port/devroot.c /n/fornaxdump/1993/0724/sys/src/brazil/port/devroot.c
226,227c

	d = &rootdir[t-1];
	data = rootdata[t-1];
	if(offset >= d->length)
		return 0;
	if(offset+n > d->length)
		n = d->length - offset;
	memmove(buf, data+offset, n);
	return n;
.
224c
	if(t < Qboot)
.
222a
	}
.
174,199c
		return devdirread(c, buf, n, rootdir, nroot, devgen);
.
172c
	t = c->qid.path & ~CHDIR;
	switch(t){
.
169a
	ulong t;
	Dirtab *d;
	uchar *data;
.
141c
	return devopen(c, omode, rootdir, nroot, devgen);
.
126c
	devstat(c, dp, rootdir, nroot, devgen);
.
120c
	return devwalk(c, name, rootdir, nroot, devgen);
.
84,91c
	addrootfile("boot", bootcode, bootlen);	/* always have a boot file */
.
69,78c
	if(nroot >= Nfiles)
		panic("too many root files");
	rootdata[nroot] = contents;
	d = &rootdir[nroot];
	strcpy(d->name, name);
	d->length = len;
	d->perm = 0555;
	d->qid.path = nroot+1;
	nroot++;
.
67c
	Dirtab *d;
	
.
64,65c
/*
 *  add a root file
 */
void
addrootfile(char *name, uchar *contents, ulong len)
.
47a
static uchar	*rootdata[Nfiles];
static int	nroot = Qboot - 1;

.
40,46d
31,38c
Dirtab rootdir[Nfiles]={
	"bin",		{Qbin|CHDIR},	0,	0777,
	"dev",		{Qdev|CHDIR},	0,	0777,
	"env",		{Qenv|CHDIR},	0,	0777,
	"proc",		{Qproc|CHDIR},	0,	0777,
	"net",		{Qnet|CHDIR},	0,	0777,
	"recover",	{Qrecover},	0,	0777,
.
24,27d
19,21c
	Nfiles=13,	/* max root files */	
.
17a
	Qboot,		/* readable files */
.
9,11c
enum{
	Qdir=	0,
.
## diffname port/devroot.c 1993/1031
## diff -e /n/fornaxdump/1993/0724/sys/src/brazil/port/devroot.c /n/fornaxdump/1993/1031/sys/src/brazil/port/devroot.c
142a
	switch(c->qid.path) {
	default:
		break;
	case Qrecover:
		if(c->flag&COPEN)
			recovbusy = 0;
		break;
	}
.
122a
		recovbusy = 1;
.
120a
		if(recovbusy)
			error(Einuse);		
.
35a
static int	recovbusy;
.
## diffname port/devroot.c 1995/0108
## diff -e /n/fornaxdump/1993/1031/sys/src/brazil/port/devroot.c /n/fornaxdump/1995/0108/sys/src/brazil/port/devroot.c
232a
}

long
rootbwrite(Chan *c, Block *bp, ulong offset)
{
	return devbwrite(c, bp, offset);
.
213a
Block*
rootbread(Chan *c, long n, ulong offset)
{
	return devbread(c, n, offset);
}

.
## diffname port/devroot.c 1995/0804
## diff -e /n/fornaxdump/1995/0108/sys/src/brazil/port/devroot.c /n/fornaxdump/1995/0804/sys/src/brazil/port/devroot.c
257d
255c
rootwstat(Chan*, char*)
.
250d
248c
rootremove(Chan*)
.
225d
221c
rootwrite(Chan *c, void *buf, long n, ulong)
.
160d
158c
rdrdy(void*)
.
146d
136d
134c
rootcreate(Chan*, char*, int, ulong)
.
## diffname port/devroot.c 1995/1114
## diff -e /n/fornaxdump/1995/0804/sys/src/brazil/port/devroot.c /n/fornaxdump/1995/1114/sys/src/brazil/port/devroot.c
30a
	"net.alt",	{Qnetalt|CHDIR},	0,	0777,
.
15a
	Qnetalt,
.
## diffname port/devroot.c 1996/0223
## diff -e /n/fornaxdump/1995/1114/sys/src/brazil/port/devroot.c /n/fornaxdump/1996/0223/sys/src/brazil/port/devroot.c
7d
## diffname port/devroot.c 1997/0327
## diff -e /n/fornaxdump/1996/0223/sys/src/brazil/port/devroot.c /n/emeliedump/1997/0327/sys/src/brazil/port/devroot.c
238,254c
Dev rootdevtab = {
	rootreset,
	devinit,
	rootattach,
	devclone,
	rootwalk,
	rootstat,
	rootopen,
	devcreate,
	rootclose,
	rootread,
	devbread,
	rootwrite,
	devbwrite,
	devremove,
	devwstat,
};
.
212,218c
static long	 
.
162c
static long	 
.
156c
static int
.
143c
static void	 
.
134,139d
116c
static Chan*
.
110c
static void	 
.
92,98c
static int	 
.
81,86c
static Chan*
.
75c
static void
.
## diffname port/devroot.c 1997/0408
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/port/devroot.c /n/emeliedump/1997/0408/sys/src/brazil/port/devroot.c
215a
	'/',
	"root",

.
## diffname port/devroot.c 1998/0319
## diff -e /n/emeliedump/1997/0408/sys/src/brazil/port/devroot.c /n/emeliedump/1998/0319/sys/src/brazil/port/devroot.c
196c
rootwrite(Chan *c, void *buf, long n, vlong)
.
151a
	ulong offset = off;
.
146c
rootread(Chan *c, void *buf, long n, vlong off)
.
## diffname port/devroot.c 1998/0512
## diff -e /n/emeliedump/1998/0319/sys/src/brazil/port/devroot.c /n/emeliedump/1998/0512/sys/src/brazil/port/devroot.c
196c
static long
.
145c
static long
.
126c
static void
.
113c
			error(Einuse);
.
99c
static void
.
87c
static int
.
63a

.
62d
47c
struct
.
19c
	Nfiles=13,	/* max root files */
.
## diffname port/devroot.c 1999/0316
## diff -e /n/emeliedump/1998/0512/sys/src/brazil/port/devroot.c /n/emeliedump/1999/0316/sys/src/brazil/port/devroot.c
32a
	"root",		{Qroot|CHDIR},	0,	0777,
.
16a
	Qroot,		/* boot root */

	// add new entries above this
.
## diffname port/devroot.c 1999/0629
## diff -e /n/emeliedump/1999/0316/sys/src/brazil/port/devroot.c /n/emeliedump/1999/0629/sys/src/brazil/port/devroot.c
249,251c
	r->req = smalloc(c->name->len+strlen(mntname)+2);
	sprint(r->req, "%s %s", c->name->s, mntname);
.
246d
244d
242c
rootrecover(Chan *c, char *mntname)
.
## diffname port/devroot.c 1999/0729
## diff -e /n/emeliedump/1999/0629/sys/src/brazil/port/devroot.c /n/emeliedump/1999/0729/sys/src/brazil/port/devroot.c
231c
	rootcreate,
.
219a
static void
rootcreate(Chan *c, char *name, int mode, ulong perm)
{
	if(!iseve())
		error(Eperm);
	if(c->qid.path != (CHDIR|Qdir))
		error(Eperm);
	perm &= 0777|CHDIR;
	if((perm & CHDIR) == 0)
		error(Eperm);
	c->flag |= COPEN;
	c->mode = mode & ~OWRITE;
}

.
79a
addrootdir(char *name)
{
	Dirtab *d;

	if(nroot >= Nfiles)
		panic("too many root files");
	rootdata[nroot] = nil;
	d = &rootdir[nroot];
	strcpy(d->name, name);
	d->length = 0;
	d->perm = 0;
	d->qid.path = nroot+1;
	nroot++;
}

static void
.
78a
/*
 *  add a root file
 */
.
## diffname port/devroot.c 1999/0730
## diff -e /n/emeliedump/1999/0729/sys/src/brazil/port/devroot.c /n/emeliedump/1999/0730/sys/src/brazil/port/devroot.c
248a
	addrootdir(name);
.
## diffname port/devroot.c 1999/0731
## diff -e /n/emeliedump/1999/0730/sys/src/brazil/port/devroot.c /n/emeliedump/1999/0731/sys/src/brazil/port/devroot.c
251c
	c->mode = OREAD;
.
244,248d
242c
	if(!iseve() || c->qid.path != (CHDIR|Qdir) ||
	   (perm & CHDIR) == 0 || mode != OREAD)
.
206,208d
100a
	addrootdir("bin");
	addrootdir("dev");
	addrootdir("env");
	addrootdir("proc");
	addrootdir("net");
	addrootdir("net.alt");
	addrootdir("root");
	addrootdir("srv");
	addrootdir("xsrv");

.
85,95c
	addroot(name, nil, 0, CHDIR);
.
81a
void
addrootfile(char *name, uchar *contents, ulong len)
{
	addroot(name, contents, len, 0555);
}

/*
 *  add a root file
 */
.
75a
	if(perm & CHDIR)
		d->qid.path |= CHDIR;
.
74c
	d->perm = perm;
.
67d
62,63c
static void
addroot(char *name, uchar *contents, ulong len, int perm)
.
40c
static int	nroot = 1;
.
36d
28,34c
Dirtab rootdir[Nfiles]=
{
.
19,22c
	Nfiles=32,	/* max root files */
.
17d
10,15d
## diffname port/devroot.c 1999/0803
## diff -e /n/emeliedump/1999/0731/sys/src/brazil/port/devroot.c /n/emeliedump/1999/0803/sys/src/brazil/port/devroot.c
79c
	addroot(name, nil, 0, CHDIR|0555);
.
## diffname port/devroot.c 1999/1105
## diff -e /n/emeliedump/1999/0803/sys/src/brazil/port/devroot.c /n/emeliedump/1999/1105/sys/src/9/port/devroot.c
261,275d
218,225d
213,214d
175,197d
149,152d
128,134d
24,25c
static int	nroot = 0;
.
18,21c
Dirtab rootdir[Nfiles];
.
10d
## diffname port/devroot.c 1999/1230
## diff -e /n/emeliedump/1999/1105/sys/src/9/port/devroot.c /n/emeliedump/1999/1230/sys/src/9/port/devroot.c
172c
rootwrite(Chan *c, void*, long, vlong)
.
152d
## diffname port/devroot.c 2000/0221
## diff -e /n/emeliedump/1999/1230/sys/src/9/port/devroot.c /n/emeliedump/2000/0221/sys/src/9/port/devroot.c
88d
## diffname port/devroot.c 2000/0223
## diff -e /n/emeliedump/2000/0221/sys/src/9/port/devroot.c /n/emeliedump/2000/0223/sys/src/9/port/devroot.c
85a
	addrootdir("proc");
.
83d
## diffname port/devroot.c 2000/0615
## diff -e /n/emeliedump/2000/0223/sys/src/9/port/devroot.c /n/emeliedump/2000/0615/sys/src/9/port/devroot.c
201c
	devcreate,
.
179,189d
## diffname port/devroot.c 2001/0503
## diff -e /n/emeliedump/2000/0615/sys/src/9/port/devroot.c /n/emeliedump/2001/0503/sys/src/9/port/devroot.c
133,136d
131c
rootclose(Chan*)
.
## diffname port/devroot.c 2001/0527
## diff -e /n/emeliedump/2001/0503/sys/src/9/port/devroot.c /n/emeliedump/2001/0527/sys/src/9/port/devroot.c
182d
168c
	switch((ulong)c->qid.path){
.
149c
	t = c->qid.path;
.
135,140d
119c
	switch((ulong)c->qid.path) {
.
113c
	return devstat(c, dp, n, rootdir, nroot, devgen);
.
110,111c
static int
rootstat(Chan *c, uchar *dp, int n)
.
101,107c
	return devwalk(c,  nc, name, nname, rootdir, nroot, devgen);
.
98,99c
static Walkqid*
rootwalk(Chan *c, Chan *nc, char **name, int nname)
.
82a
	addrootdir("fd");
.
74c
	addroot(name, nil, 0, DMDIR|0555);
.
54,55c
	if(perm & DMDIR)
		d->qid.type |= QTDIR;
.
52a
	d->qid.type = 0;
	d->qid.vers = 0;
.
22,37d
20c
static int	nroot = 1;
.
17c
Dirtab rootdir[Nfiles] = {
	".",	{Qdir, 0, QTDIR},	0,		DMDIR|0555,
};
.
## diffname port/devroot.c 2001/0819
## diff -e /n/emeliedump/2001/0527/sys/src/9/port/devroot.c /n/emeliedump/2001/0819/sys/src/9/port/devroot.c
71a
	addrootdir("mnt");
.
## diffname port/devroot.c 2002/0109
## diff -e /n/emeliedump/2001/0819/sys/src/9/port/devroot.c /n/emeliedump/2002/0109/sys/src/9/port/devroot.c
158a
	devshutdown,
.
## diffname port/devroot.c 2002/1130
## diff -e /n/emeliedump/2002/0109/sys/src/9/port/devroot.c /n/emeliedump/2002/1130/sys/src/9/port/devroot.c
172a

.
146,149c
	error(Egreg);
.
144c
rootwrite(Chan*, void*, long, vlong)
.
133,134c
	if(t<Qboot)
		l = &rootlist;
	else{
		t -= Qboot;
		l = &bootlist;
	}

	d = &l->dir[t-1];
	data = l->data[t-1];
.
130c
	case Qboot:
		return devdirread(c, buf, n, nil, 0, rootgen);
.
123a
	Dirlist *l;
.
103,108c
	return devopen(c, omode, nil, 0, devgen);
.
97c
	return devstat(c, dp, n, nil, 0, rootgen);
.
91c
	return devwalk(c,  nc, name, nname, nil, 0, rootgen);
.
87a
static int
rootgen(Chan *c, char *name, Dirtab*, int, int s, Dir *dp)
{
	int t;
	Dirtab *d;
	Dirlist *l;

	switch((int)c->qid.path){
	case Qdir:
		return devgen(c, name, rootlist.dir, rootlist.ndir, s, dp);
	case Qboot:
		if(s == DEVDOTDOT){
			devdir(c, (Qid){Qdir, 0, QTDIR}, "#/", 0, eve, 0555, dp);
			return 1;
		}
		return devgen(c, name, bootlist.dir, bootlist.ndir, s, dp);
	default:
		if((int)c->qid.path < Qboot){
			t = c->qid.path-1;
			l = &rootlist;
		}else{
			t = c->qid.path - Qboot - 1;
			l = &bootlist;
		}
		if(t >= l->ndir)
			return -1;
		if(s != 0)
			return -1;
		d = &l->dir[t];
		devdir(c, d->qid, d->name, d->length, eve, d->perm, dp);
		return 1;
	}
	return -1;
}

.
78,79d
62c
	addlist(&rootlist, name, nil, 0, DMDIR|0555);
.
57c
 *  add a root directory
.
53c
	addlist(&bootlist, name, contents, len, 0555);
.
51c
addbootfile(char *name, uchar *contents, ulong len)
.
44d
41c
	d->qid.path = ++l->ndir + l->base;
.
34,35c
	l->data[l->ndir] = contents;
	d = &l->dir[l->ndir];
.
32c
	if(l->ndir >= l->mdir)
.
28c
addlist(Dirlist *l, char *name, uchar *contents, ulong len, int perm)
.
25c
 *  add a file to the list
.
21,22c
static Dirtab bootdir[Nbootfiles] = {
	"boot",	{Qboot, 0, QTDIR},	0,		DMDIR|0555,
};
static uchar *bootdata[Nbootfiles];
static Dirlist bootlist =
{
	Qboot,
	bootdir,
	bootdata,
	1,
	Nbootfiles
};
.
19a
static uchar *rootdata[Nrootfiles];
static Dirlist rootlist = 
{
	0,
	rootdir,
	rootdata,
	2,
	Nrootfiles
};
.
17,18c
static Dirtab rootdir[Nrootfiles] = {
	"#/",		{Qdir, 0, QTDIR},	0,		DMDIR|0555,
	"boot",	{Qboot, 0, QTDIR},	0,		DMDIR|0555,
.
14,15c
typedef struct Dirlist Dirlist;
struct Dirlist
{
	uint base;
	Dirtab *dir;
	uchar **data;
	int ndir;
	int mdir;
};
.
11c
	Nrootfiles = 32,
	Nbootfiles = 16,
.
8,9c
enum
{
	Qdir = 0,
	Qboot = 0x1000,
.
## diffname port/devroot.c 2003/0112
## diff -e /n/emeliedump/2002/1130/sys/src/9/port/devroot.c /n/emeliedump/2003/0112/sys/src/9/port/devroot.c
14c
	Nbootfiles = 32,
.
## diffname port/devroot.c 2003/0303
## diff -e /n/emeliedump/2003/0112/sys/src/9/port/devroot.c /n/emeliedump/2003/0303/sys/src/9/port/devroot.c
199,200c
	t--;
	if(t >= l->ndir)
		error(Egreg);

	d = &l->dir[t];
	data = l->data[t];
.
141,142d
131a
		if(s != 0)
			return -1;
.
123a
		if(s == DEVDOTDOT){
			devdir(c, (Qid){Qdir, 0, QTDIR}, "#/", 0, eve, 0555, dp);
			return 1;
		}
.
## diffname port/devroot.c 2003/0329
## diff -e /n/emeliedump/2003/0303/sys/src/9/port/devroot.c /n/emeliedump/2003/0329/sys/src/9/port/devroot.c
146a
if(t < 0){
print("rootgen %llud %d %d\n", c->qid.path, s, t);
panic("whoops");
}
.
135a
		if(s == DEVDOTDOT){
			if((int)c->qid.path < Qboot)
				devdir(c, (Qid){Qdir, 0, QTDIR}, "#/", 0, eve, 0555, dp);
			else
				devdir(c, (Qid){Qboot, 0, QTDIR}, "#/", 0, eve, 0555, dp);
			return 1;
		}
.
## diffname port/devroot.c 2003/0405
## diff -e /n/emeliedump/2003/0329/sys/src/9/port/devroot.c /n/emeliedump/2003/0405/sys/src/9/port/devroot.c
223a
#ifdef asdf
print("[%d] kaddr %.8ulx base %.8ulx offset %ld (%.8ulx), n %d %.8ulx %.8ulx %.8ulx\n", 
		t, buf, data, offset, offset, n,
		((ulong*)(data+offset))[0],
		((ulong*)(data+offset))[1],
		((ulong*)(data+offset))[2]);
#endif asdf
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

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