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 if(strlen(name) >= sizeof d->name)
67 panic("root file name too long: %s", name);
68 strcpy(d->name, name);
73 d->qid.path = ++l->ndir + l->base;
82 addbootfile(char *name, uchar *contents, ulong len)
84 addlist(&bootlist, name, contents, len, 0555);
88 * add a root directory
91 addrootdir(char *name)
93 addlist(&rootlist, name, nil, 0, DMDIR|0555);
105 addrootdir("net.alt");
113 rootattach(char *spec)
115 return devattach('/', spec);
119 rootgen(Chan *c, char *name, Dirtab*, int, int s, Dir *dp)
125 switch((int)c->qid.path){
128 devdir(c, (Qid){Qdir, 0, QTDIR}, "#/", 0, eve, 0555, dp);
131 return devgen(c, name, rootlist.dir, rootlist.ndir, s, dp);
134 devdir(c, (Qid){Qdir, 0, QTDIR}, "#/", 0, eve, 0555, dp);
137 return devgen(c, name, bootlist.dir, bootlist.ndir, s, dp);
140 if((int)c->qid.path < Qboot)
141 devdir(c, (Qid){Qdir, 0, QTDIR}, "#/", 0, eve, 0555, dp);
143 devdir(c, (Qid){Qboot, 0, QTDIR}, "#/", 0, eve, 0555, dp);
148 if((int)c->qid.path < Qboot){
152 t = c->qid.path - Qboot - 1;
158 print("rootgen %llud %d %d\n", c->qid.path, s, t);
162 devdir(c, d->qid, d->name, d->length, eve, d->perm, dp);
168 rootwalk(Chan *c, Chan *nc, char **name, int nname)
170 return devwalk(c, nc, name, nname, nil, 0, rootgen);
174 rootstat(Chan *c, uchar *dp, int n)
176 return devstat(c, dp, n, nil, 0, rootgen);
180 rootopen(Chan *c, int omode)
182 return devopen(c, omode, nil, 0, devgen);
186 * sysremove() knows this is a nop
194 rootread(Chan *c, void *buf, long n, vlong off)
206 return devdirread(c, buf, n, nil, 0, rootgen);
222 if(offset >= d->length)
224 if(offset+n > d->length)
225 n = d->length - offset;
227 print("[%d] kaddr %.8ulx base %.8ulx offset %ld (%.8ulx), n %d %.8ulx %.8ulx %.8ulx\n",
228 t, buf, data, offset, offset, n,
229 ((ulong*)(data+offset))[0],
230 ((ulong*)(data+offset))[1],
231 ((ulong*)(data+offset))[2]);
233 memmove(buf, data+offset, n);
238 rootwrite(Chan*, void*, long, vlong)