plan 9 kernel history: overview | file list | diff list

2002/0109/port/devroot.c (diff list | history)

2002/0109/sys/src/9/port/devroot.c:5,472002/1130/sys/src/9/port/devroot.c:5,76 (short | long | prev | next)
1990/0227    
#include	"fns.h" 
1992/0111    
#include	"../port/error.h" 
1990/0227    
 
1993/0724    
enum{ 
	Qdir=	0, 
2002/1130    
enum 
{ 
	Qdir = 0, 
	Qboot = 0x1000, 
1999/0316    
 
1999/0731    
	Nfiles=32,	/* max root files */ 
2002/1130    
	Nrootfiles = 32, 
	Nbootfiles = 16, 
1990/0227    
}; 
 
1991/1206    
extern ulong	bootlen; 
1992/0902    
extern uchar	bootcode[]; 
2002/1130    
typedef struct Dirlist Dirlist; 
struct Dirlist 
{ 
	uint base; 
	Dirtab *dir; 
	uchar **data; 
	int ndir; 
	int mdir; 
}; 
1991/0214    
 
2001/0527    
Dirtab rootdir[Nfiles] = { 
	".",	{Qdir, 0, QTDIR},	0,		DMDIR|0555, 
2002/1130    
static Dirtab rootdir[Nrootfiles] = { 
	"#/",		{Qdir, 0, QTDIR},	0,		DMDIR|0555, 
	"boot",	{Qboot, 0, QTDIR},	0,		DMDIR|0555, 
2001/0527    
}; 
2002/1130    
static uchar *rootdata[Nrootfiles]; 
static Dirlist rootlist =  
{ 
	0, 
	rootdir, 
	rootdata, 
	2, 
	Nrootfiles 
}; 
1990/0227    
 
1993/0724    
static uchar	*rootdata[Nfiles]; 
2001/0527    
static int	nroot = 1; 
2002/1130    
static Dirtab bootdir[Nbootfiles] = { 
	"boot",	{Qboot, 0, QTDIR},	0,		DMDIR|0555, 
}; 
static uchar *bootdata[Nbootfiles]; 
static Dirlist bootlist = 
{ 
	Qboot, 
	bootdir, 
	bootdata, 
	1, 
	Nbootfiles 
}; 
1993/0724    
 
/* 
 *  add a root file 
2002/1130    
 *  add a file to the list 
1993/0724    
 */ 
1999/0731    
static void 
addroot(char *name, uchar *contents, ulong len, int perm) 
2002/1130    
addlist(Dirlist *l, char *name, uchar *contents, ulong len, int perm) 
1991/0615    
{ 
1993/0724    
	Dirtab *d; 
1992/0711    
 
1993/0724    
	if(nroot >= Nfiles) 
2002/1130    
	if(l->ndir >= l->mdir) 
1993/0724    
		panic("too many root files"); 
	rootdata[nroot] = contents; 
	d = &rootdir[nroot]; 
2002/1130    
	l->data[l->ndir] = contents; 
	d = &l->dir[l->ndir]; 
1993/0724    
	strcpy(d->name, name); 
	d->length = len; 
1999/0731    
	d->perm = perm; 
2001/0527    
	d->qid.type = 0; 
	d->qid.vers = 0; 
1993/0724    
	d->qid.path = nroot+1; 
2002/1130    
	d->qid.path = ++l->ndir + l->base; 
2001/0527    
	if(perm & DMDIR) 
		d->qid.type |= QTDIR; 
1993/0724    
	nroot++; 
1991/0615    
} 
 
1999/0729    
/* 
2002/0109/sys/src/9/port/devroot.c:48,652002/1130/sys/src/9/port/devroot.c:77,94
1999/0729    
 *  add a root file 
 */ 
1999/0731    
void 
addrootfile(char *name, uchar *contents, ulong len) 
2002/1130    
addbootfile(char *name, uchar *contents, ulong len) 
1999/0731    
{ 
	addroot(name, contents, len, 0555); 
2002/1130    
	addlist(&bootlist, name, contents, len, 0555); 
1999/0731    
} 
 
/* 
 *  add a root file 
2002/1130    
 *  add a root directory 
1999/0731    
 */ 
1997/0327    
static void 
1999/0729    
addrootdir(char *name) 
{ 
2001/0527    
	addroot(name, nil, 0, DMDIR|0555); 
2002/1130    
	addlist(&rootlist, name, nil, 0, DMDIR|0555); 
1999/0729    
} 
 
static void 
2002/0109/sys/src/9/port/devroot.c:75,822002/1130/sys/src/9/port/devroot.c:104,109
2000/0223    
	addrootdir("proc"); 
1999/0731    
	addrootdir("root"); 
	addrootdir("srv"); 
                 
1993/0724    
	addrootfile("boot", bootcode, bootlen);	/* always have a boot file */ 
1990/0227    
} 
 
1997/0327    
static Chan* 
2002/0109/sys/src/9/port/devroot.c:85,1112002/1130/sys/src/9/port/devroot.c:112,168
1990/0227    
	return devattach('/', spec); 
} 
 
2002/1130    
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; 
} 
 
2001/0527    
static Walkqid* 
rootwalk(Chan *c, Chan *nc, char **name, int nname) 
1990/0227    
{ 
2001/0527    
	return devwalk(c,  nc, name, nname, rootdir, nroot, devgen); 
2002/1130    
	return devwalk(c,  nc, name, nname, nil, 0, rootgen); 
1990/0227    
} 
 
2001/0527    
static int 
rootstat(Chan *c, uchar *dp, int n) 
1990/0227    
{ 
2001/0527    
	return devstat(c, dp, n, rootdir, nroot, devgen); 
2002/1130    
	return devstat(c, dp, n, nil, 0, rootgen); 
1990/0227    
} 
 
1997/0327    
static Chan* 
1990/0227    
rootopen(Chan *c, int omode) 
{ 
2001/0527    
	switch((ulong)c->qid.path) { 
1993/0501    
	default: 
		break; 
	} 
                 
1993/0724    
	return devopen(c, omode, rootdir, nroot, devgen); 
2002/1130    
	return devopen(c, omode, nil, 0, devgen); 
1990/0227    
} 
 
/* 
2002/0109/sys/src/9/port/devroot.c:121,1262002/1130/sys/src/9/port/devroot.c:178,184
1990/0227    
{ 
1993/0724    
	ulong t; 
	Dirtab *d; 
2002/1130    
	Dirlist *l; 
1993/0724    
	uchar *data; 
1998/0319    
	ulong offset = off; 
1990/0227    
 
2002/0109/sys/src/9/port/devroot.c:127,1372002/1130/sys/src/9/port/devroot.c:185,203
2001/0527    
	t = c->qid.path; 
1993/0724    
	switch(t){ 
1990/0227    
	case Qdir: 
1993/0724    
		return devdirread(c, buf, n, rootdir, nroot, devgen); 
2002/1130    
	case Qboot: 
		return devdirread(c, buf, n, nil, 0, rootgen); 
1993/0724    
	} 
1993/0501    
 
1993/0724    
	d = &rootdir[t-1]; 
	data = rootdata[t-1]; 
2002/1130    
	if(t<Qboot) 
		l = &rootlist; 
	else{ 
		t -= Qboot; 
		l = &bootlist; 
	} 
 
	d = &l->dir[t-1]; 
	data = l->data[t-1]; 
1993/0724    
	if(offset >= d->length) 
		return 0; 
	if(offset+n > d->length) 
2002/0109/sys/src/9/port/devroot.c:141,1522002/1130/sys/src/9/port/devroot.c:207,215
1990/0227    
} 
 
1998/0512    
static long 
1999/1230    
rootwrite(Chan *c, void*, long, vlong) 
2002/1130    
rootwrite(Chan*, void*, long, vlong) 
1990/0227    
{ 
2001/0527    
	switch((ulong)c->qid.path){ 
1993/0501    
	default: 
		error(Egreg); 
	} 
2002/1130    
	error(Egreg); 
1993/0501    
	return 0; 
1995/0108    
} 
 
2002/0109/sys/src/9/port/devroot.c:170,1722002/1130/sys/src/9/port/devroot.c:233,236
1997/0327    
	devremove, 
	devwstat, 
}; 
2002/1130    
 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)