~kris/9p

9hist

ref: b91c47e11c5ffe7dca63ce430006682072a6e095 9hist/gnot/devroot.c -rw-r--r-- 1.8 KiB
b91c47e1 — David du Colombier Plan 9 from Bell Labs 1990-07-31 36 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#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]);
}