| plan 9 kernel history: overview | file list | diff list |
2000/0223/port/devroot.c (diff list | history)
| port/devroot.c on 1990/0227 | ||
| 1990/0227 | #include "u.h" | |
| 1992/0321 | #include "../port/lib.h" | |
| 1990/0227 | #include "mem.h" #include "dat.h" #include "fns.h" | |
| 1992/0111 | #include "../port/error.h" | |
| 1990/0227 | ||
| 1993/0724 | enum{ Qdir= 0, | |
| 1999/0316 | ||
| 1999/0731 | Nfiles=32, /* max root files */ | |
| 1990/0227 | }; | |
| 1991/1206 | extern ulong bootlen; | |
| 1992/0902 | extern uchar bootcode[]; | |
| 1991/0214 | ||
| 1999/1105 | Dirtab rootdir[Nfiles]; | |
| 1990/0227 | ||
| 1993/0724 | static uchar *rootdata[Nfiles]; | |
| 1999/1105 | static int nroot = 0; | |
| 1993/0724 | ||
| 1993/0501 | typedef struct Recover Recover; struct Recover { int len; char *req; Recover *next; }; | |
| 1998/0512 | struct | |
| 1993/0501 | { Lock; QLock; Rendez; Recover *q; }reclist; | |
| 1993/0724 | /* * add a root file */ | |
| 1999/0731 | static void addroot(char *name, uchar *contents, ulong len, int perm) | |
| 1991/0615 | { | |
| 1993/0724 | Dirtab *d; | |
| 1992/0711 | ||
| 1993/0724 | if(nroot >= Nfiles) panic("too many root files"); rootdata[nroot] = contents; d = &rootdir[nroot]; strcpy(d->name, name); d->length = len; | |
| 1999/0731 | d->perm = perm; | |
| 1993/0724 | d->qid.path = nroot+1; | |
| 1999/0731 | if(perm & CHDIR) d->qid.path |= CHDIR; | |
| 1993/0724 | nroot++; | |
| 1991/0615 | } | |
| 1999/0729 | /* * add a root file */ | |
| 1999/0731 | void addrootfile(char *name, uchar *contents, ulong len) { addroot(name, contents, len, 0555); } /* * add a root file */ | |
| 1997/0327 | static void | |
| 1999/0729 | addrootdir(char *name) { | |
| 1999/0803 | addroot(name, nil, 0, CHDIR|0555); | |
| 1999/0729 | } static void | |
| 1990/0227 | rootreset(void) { | |
| 1999/0731 | addrootdir("bin"); addrootdir("dev"); addrootdir("env"); addrootdir("net"); addrootdir("net.alt"); | |
| 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* | |
| 1990/0227 | rootattach(char *spec) { return devattach('/', spec); } | |
| 1998/0512 | static int | |
| 1990/0227 | rootwalk(Chan *c, char *name) { | |
| 1991/1206 | if(strcmp(name, "..") == 0) { c->qid.path = Qdir|CHDIR; return 1; } | |
| 1992/0225 | if((c->qid.path & ~CHDIR) != Qdir) | |
| 1992/0226 | return 0; | |
| 1993/0724 | return devwalk(c, name, rootdir, nroot, devgen); | |
| 1990/0227 | } | |
| 1998/0512 | static void | |
| 1990/0227 | rootstat(Chan *c, char *dp) { | |
| 1993/0724 | devstat(c, dp, rootdir, nroot, devgen); | |
| 1990/0227 | } | |
| 1997/0327 | static Chan* | |
| 1990/0227 | rootopen(Chan *c, int omode) { | |
| 1993/0501 | switch(c->qid.path & ~CHDIR) { default: break; } | |
| 1993/0724 | return devopen(c, omode, rootdir, nroot, devgen); | |
| 1990/0227 | } /* * sysremove() knows this is a nop */ | |
| 1998/0512 | static void | |
| 1990/0227 | rootclose(Chan *c) { | |
| 1993/1031 | switch(c->qid.path) { default: break; } | |
| 1990/0227 | } | |
| 1997/0327 | static int | |
| 1995/0804 | rdrdy(void*) | |
| 1993/0501 | { return reclist.q != 0; } | |
| 1998/0512 | static long | |
| 1998/0319 | rootread(Chan *c, void *buf, long n, vlong off) | |
| 1990/0227 | { | |
| 1993/0724 | ulong t; Dirtab *d; uchar *data; | |
| 1998/0319 | ulong offset = off; | |
| 1990/0227 | ||
| 1993/0724 | t = c->qid.path & ~CHDIR; switch(t){ | |
| 1990/0227 | case Qdir: | |
| 1993/0724 | return devdirread(c, buf, n, rootdir, nroot, devgen); } | |
| 1993/0501 | ||
| 1993/0724 | d = &rootdir[t-1]; data = rootdata[t-1]; if(offset >= d->length) return 0; if(offset+n > d->length) n = d->length - offset; memmove(buf, data+offset, n); return n; | |
| 1990/0227 | } | |
| 1998/0512 | static long | |
| 1999/1230 | rootwrite(Chan *c, void*, long, vlong) | |
| 1990/0227 | { | |
| 1993/0501 | switch(c->qid.path & ~CHDIR){ default: error(Egreg); } return 0; | |
| 1995/0108 | } | |
| 1999/0729 | static void rootcreate(Chan *c, char *name, int mode, ulong perm) { | |
| 1999/0731 | if(!iseve() || c->qid.path != (CHDIR|Qdir) || (perm & CHDIR) == 0 || mode != OREAD) | |
| 1999/0729 | error(Eperm); | |
| 1999/0730 | addrootdir(name); | |
| 1999/0729 | c->flag |= COPEN; | |
| 1999/0731 | c->mode = OREAD; | |
| 1999/0729 | } | |
| 1997/0327 | Dev rootdevtab = { | |
| 1997/0408 | '/', "root", | |
| 1997/0327 | rootreset, devinit, rootattach, devclone, rootwalk, rootstat, rootopen, | |
| 1999/0729 | rootcreate, | |
| 1997/0327 | rootclose, rootread, devbread, rootwrite, devbwrite, devremove, devwstat, }; | |