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

1992/0111/port/devroot.c (diff list | history)

port/devroot.c on 1990/0227
1990/0227    
#include	"u.h" 
#include	"lib.h" 
#include	"mem.h" 
#include	"dat.h" 
#include	"fns.h" 
1992/0111    
#include	"../port/error.h" 
1990/0227    
#include	"devtab.h" 
 
enum{ 
	Qdir, 
	Qbin, 
	Qdev, 
	Qenv, 
	Qproc, 
1991/1206    
 
	Qboot, 
	Qcfs, 
	Qkfs, 
1990/0227    
}; 
 
1991/0214    
extern long	cfslen; 
1991/0216    
extern ulong	cfscode[]; 
1991/0910    
extern long	kfslen; 
extern ulong	kfscode[]; 
1991/1206    
extern ulong	bootlen; 
extern ulong	bootcode[]; 
1991/0214    
 
1990/0227    
Dirtab rootdir[]={ 
1991/1112    
	"bin",		{Qbin|CHDIR},	0,			0777, 
	"boot",		{Qboot},	0,			0777, 
	"dev",		{Qdev|CHDIR},	0,			0777, 
	"env",		{Qenv|CHDIR},	0,			0777, 
	"proc",		{Qproc|CHDIR},	0,			0777, 
1990/0227    
}; 
#define	NROOT	(sizeof rootdir/sizeof(Dirtab)) 
1991/0615    
Dirtab rootpdir[]={ 
1991/1112    
	"cfs",		{Qcfs},		0,			0777, 
	"kfs",		{Qkfs},		0,			0777, 
1991/0615    
}; 
Dirtab *rootmap[sizeof rootpdir/sizeof(Dirtab)]; 
1991/0214    
int	nroot; 
1990/0227    
 
1991/0615    
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]; 
1991/1109    
	devdir(c, tab->qid, tab->name, tab->length, eve, tab->perm, dp); 
1991/0615    
	return 1; 
} 
 
1990/0227    
void 
rootreset(void) 
{ 
1991/0615    
	int i; 
 
	i = 0; 
	if(cfslen) 
		rootmap[i++] = &rootpdir[0]; 
1991/0910    
	if(kfslen) 
1991/0913    
		rootmap[i++] = &rootpdir[1]; 
1991/0615    
	nroot = NROOT + i; 
1990/0227    
} 
 
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) 
{ 
1991/1206    
	if(strcmp(name, "..") == 0) { 
		c->qid.path = Qdir|CHDIR; 
		return 1; 
	} 
1991/0615    
	return devwalk(c, name, rootdir, nroot, rootgen); 
1990/0227    
} 
 
void	  
rootstat(Chan *c, char *dp) 
{ 
1991/0615    
	devstat(c, dp, rootdir, nroot, rootgen); 
1990/0227    
} 
 
Chan* 
rootopen(Chan *c, int omode) 
{ 
1991/0615    
	return devopen(c, omode, rootdir, nroot, rootgen); 
1990/0227    
} 
 
void	  
rootcreate(Chan *c, char *name, int omode, ulong perm) 
{ 
1991/1115    
	USED(c, name, omode, perm); 
1990/11211    
	error(Eperm); 
1990/0227    
} 
 
/* 
 * sysremove() knows this is a nop 
 */ 
void	  
rootclose(Chan *c) 
{ 
1991/1115    
	USED(c); 
1990/0227    
} 
 
long	  
1991/0411    
rootread(Chan *c, void *buf, long n, ulong offset) 
1990/0227    
{ 
 
1990/11211    
	switch(c->qid.path & ~CHDIR){ 
1990/0227    
	case Qdir: 
1991/0615    
		return devdirread(c, buf, n, rootdir, nroot, rootgen); 
1990/0227    
 
	case Qboot:		/* boot */ 
1991/1206    
		if(offset >= bootlen) 
1990/0227    
			return 0; 
1991/1206    
		if(offset+n > bootlen) 
			n = bootlen - offset; 
1991/0411    
		memmove(buf, ((char*)bootcode)+offset, n); 
1991/0214    
		return n; 
 
1991/0312    
	case Qcfs:		/* cfs */ 
1991/0411    
		if(offset >= cfslen) 
1991/0214    
			return 0; 
1991/0411    
		if(offset+n > cfslen) 
			n = cfslen - offset; 
		memmove(buf, ((char*)cfscode)+offset, n); 
1991/0910    
		return n; 
 
	case Qkfs:		/* kfs */ 
		if(offset >= kfslen) 
			return 0; 
		if(offset+n > kfslen) 
			n = kfslen - offset; 
		memmove(buf, ((char*)kfscode)+offset, n); 
1990/0227    
		return n; 
 
	case Qdev: 
		return 0; 
	} 
1990/11211    
	error(Egreg); 
1990/0227    
	return 0; 
} 
 
long	  
1991/0411    
rootwrite(Chan *c, void *buf, long n, ulong offset) 
1990/0227    
{ 
1991/1115    
	USED(c, buf, n, offset); 
1990/11211    
	error(Egreg); 
1990/0227    
} 
 
void	  
rootremove(Chan *c) 
{ 
1991/1115    
	USED(c); 
1990/11211    
	error(Eperm); 
1990/0227    
} 
 
void	  
rootwstat(Chan *c, char *dp) 
{ 
1991/1115    
	USED(c, dp); 
1990/11211    
	error(Eperm); 
1990/0227    
} 


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