2 #include "../port/lib.h"
6 #include "../port/error.h"
17 typedef struct Dirlist Dirlist;
27 static Dirtab rootdir[Nrootfiles] = {
28 "#/", {Qdir, 0, QTDIR}, 0, DMDIR|0555,
29 "boot", {Qboot, 0, QTDIR}, 0, DMDIR|0555,
31 static uchar *rootdata[Nrootfiles];
32 static Dirlist rootlist =
41 static Dirtab bootdir[Nbootfiles] = {
42 "boot", {Qboot, 0, QTDIR}, 0, DMDIR|0555,
44 static uchar *bootdata[Nbootfiles];
45 static Dirlist bootlist =
55 * add a file to the list
58 addlist(Dirlist *l, char *name, uchar *contents, ulong len, int perm)
62 if(l->ndir >= l->mdir)
63 panic("too many root files");
64 l->data[l->ndir] = contents;
66 strcpy(d->name, name);
71 d->qid.path = ++l->ndir + l->base;
80 addbootfile(char *name, uchar *contents, ulong len)
82 addlist(&bootlist, name, contents, len, 0555);
86 * add a root directory
89 addrootdir(char *name)
91 addlist(&rootlist, name, nil, 0, DMDIR|0555);
103 addrootdir("net.alt");
110 rootattach(char *spec)
112 return devattach('/', spec);
116 rootgen(Chan *c, char *name, Dirtab*, int, int s, Dir *dp)
122 switch((int)c->qid.path){
125 devdir(c, (Qid){Qdir, 0, QTDIR}, "#/", 0, eve, 0555, dp);
128 return devgen(c, name, rootlist.dir, rootlist.ndir, s, dp);
131 devdir(c, (Qid){Qdir, 0, QTDIR}, "#/", 0, eve, 0555, dp);
134 return devgen(c, name, bootlist.dir, bootlist.ndir, s, dp);
137 if((int)c->qid.path < Qboot)
138 devdir(c, (Qid){Qdir, 0, QTDIR}, "#/", 0, eve, 0555, dp);
140 devdir(c, (Qid){Qboot, 0, QTDIR}, "#/", 0, eve, 0555, dp);
145 if((int)c->qid.path < Qboot){
149 t = c->qid.path - Qboot - 1;
155 print("rootgen %llud %d %d\n", c->qid.path, s, t);
159 devdir(c, d->qid, d->name, d->length, eve, d->perm, dp);
165 rootwalk(Chan *c, Chan *nc, char **name, int nname)
167 return devwalk(c, nc, name, nname, nil, 0, rootgen);
171 rootstat(Chan *c, uchar *dp, int n)
173 return devstat(c, dp, n, nil, 0, rootgen);
177 rootopen(Chan *c, int omode)
179 return devopen(c, omode, nil, 0, devgen);
183 * sysremove() knows this is a nop
191 rootread(Chan *c, void *buf, long n, vlong off)
203 return devdirread(c, buf, n, nil, 0, rootgen);
219 if(offset >= d->length)
221 if(offset+n > d->length)
222 n = d->length - offset;
224 print("[%d] kaddr %.8ulx base %.8ulx offset %ld (%.8ulx), n %d %.8ulx %.8ulx %.8ulx\n",
225 t, buf, data, offset, offset, n,
226 ((ulong*)(data+offset))[0],
227 ((ulong*)(data+offset))[1],
228 ((ulong*)(data+offset))[2]);
230 memmove(buf, data+offset, n);
235 rootwrite(Chan*, void*, long, vlong)