| plan 9 kernel history: overview | file list | diff list |
2003/0112/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 | ||
| 2002/1130 | enum { Qdir = 0, Qboot = 0x1000, | |
| 1999/0316 | ||
| 2002/1130 | Nrootfiles = 32, | |
| 2003/0112 | Nbootfiles = 32, | |
| 1990/0227 | }; | |
| 2002/1130 | typedef struct Dirlist Dirlist; struct Dirlist { uint base; Dirtab *dir; uchar **data; int ndir; int mdir; }; | |
| 1991/0214 | ||
| 2002/1130 | static Dirtab rootdir[Nrootfiles] = { "#/", {Qdir, 0, QTDIR}, 0, DMDIR|0555, "boot", {Qboot, 0, QTDIR}, 0, DMDIR|0555, | |
| 2001/0527 | }; | |
| 2002/1130 | static uchar *rootdata[Nrootfiles]; static Dirlist rootlist = { 0, rootdir, rootdata, 2, Nrootfiles }; | |
| 1990/0227 | ||
| 2002/1130 | static Dirtab bootdir[Nbootfiles] = { "boot", {Qboot, 0, QTDIR}, 0, DMDIR|0555, }; static uchar *bootdata[Nbootfiles]; static Dirlist bootlist = { Qboot, bootdir, bootdata, 1, Nbootfiles }; | |
| 1993/0724 | /* | |
| 2002/1130 | * add a file to the list | |
| 1993/0724 | */ | |
| 1999/0731 | static void | |
| 2002/1130 | addlist(Dirlist *l, char *name, uchar *contents, ulong len, int perm) | |
| 1991/0615 | { | |
| 1993/0724 | Dirtab *d; | |
| 1992/0711 | ||
| 2002/1130 | if(l->ndir >= l->mdir) | |
| 1993/0724 | panic("too many root files"); | |
| 2002/1130 | l->data[l->ndir] = contents; d = &l->dir[l->ndir]; | |
| 1993/0724 | strcpy(d->name, name); d->length = len; | |
| 1999/0731 | d->perm = perm; | |
| 2001/0527 | d->qid.type = 0; d->qid.vers = 0; | |
| 2002/1130 | d->qid.path = ++l->ndir + l->base; | |
| 2001/0527 | if(perm & DMDIR) d->qid.type |= QTDIR; | |
| 1991/0615 | } | |
| 1999/0729 | /* * add a root file */ | |
| 1999/0731 | void | |
| 2002/1130 | addbootfile(char *name, uchar *contents, ulong len) | |
| 1999/0731 | { | |
| 2002/1130 | addlist(&bootlist, name, contents, len, 0555); | |
| 1999/0731 | } /* | |
| 2002/1130 | * add a root directory | |
| 1999/0731 | */ | |
| 1997/0327 | static void | |
| 1999/0729 | addrootdir(char *name) { | |
| 2002/1130 | addlist(&rootlist, name, nil, 0, DMDIR|0555); | |
| 1999/0729 | } static void | |
| 1990/0227 | rootreset(void) { | |
| 1999/0731 | addrootdir("bin"); addrootdir("dev"); addrootdir("env"); | |
| 2001/0527 | addrootdir("fd"); | |
| 2001/0819 | addrootdir("mnt"); | |
| 1999/0731 | addrootdir("net"); addrootdir("net.alt"); | |
| 2000/0223 | addrootdir("proc"); | |
| 1999/0731 | addrootdir("root"); addrootdir("srv"); | |
| 1990/0227 | } | |
| 1997/0327 | static Chan* | |
| 1990/0227 | rootattach(char *spec) { return devattach('/', spec); } | |
| 2002/1130 | static int rootgen(Chan *c, char *name, Dirtab*, int, int s, Dir *dp) { int t; Dirtab *d; Dirlist *l; switch((int)c->qid.path){ case Qdir: return devgen(c, name, rootlist.dir, rootlist.ndir, s, dp); case Qboot: if(s == DEVDOTDOT){ devdir(c, (Qid){Qdir, 0, QTDIR}, "#/", 0, eve, 0555, dp); return 1; } return devgen(c, name, bootlist.dir, bootlist.ndir, s, dp); default: if((int)c->qid.path < Qboot){ t = c->qid.path-1; l = &rootlist; }else{ t = c->qid.path - Qboot - 1; l = &bootlist; } if(t >= l->ndir) return -1; if(s != 0) return -1; d = &l->dir[t]; devdir(c, d->qid, d->name, d->length, eve, d->perm, dp); return 1; } return -1; } | |
| 2001/0527 | static Walkqid* rootwalk(Chan *c, Chan *nc, char **name, int nname) | |
| 1990/0227 | { | |
| 2002/1130 | return devwalk(c, nc, name, nname, nil, 0, rootgen); | |
| 1990/0227 | } | |
| 2001/0527 | static int rootstat(Chan *c, uchar *dp, int n) | |
| 1990/0227 | { | |
| 2002/1130 | return devstat(c, dp, n, nil, 0, rootgen); | |
| 1990/0227 | } | |
| 1997/0327 | static Chan* | |
| 1990/0227 | rootopen(Chan *c, int omode) { | |
| 2002/1130 | return devopen(c, omode, nil, 0, devgen); | |
| 1990/0227 | } /* * sysremove() knows this is a nop */ | |
| 1998/0512 | static void | |
| 2001/0503 | rootclose(Chan*) | |
| 1990/0227 | { } | |
| 1998/0512 | static long | |
| 1998/0319 | rootread(Chan *c, void *buf, long n, vlong off) | |
| 1990/0227 | { | |
| 1993/0724 | ulong t; Dirtab *d; | |
| 2002/1130 | Dirlist *l; | |
| 1993/0724 | uchar *data; | |
| 1998/0319 | ulong offset = off; | |
| 1990/0227 | ||
| 2001/0527 | t = c->qid.path; | |
| 1993/0724 | switch(t){ | |
| 1990/0227 | case Qdir: | |
| 2002/1130 | case Qboot: return devdirread(c, buf, n, nil, 0, rootgen); | |
| 1993/0724 | } | |
| 1993/0501 | ||
| 2002/1130 | if(t<Qboot) l = &rootlist; else{ t -= Qboot; l = &bootlist; } d = &l->dir[t-1]; data = l->data[t-1]; | |
| 1993/0724 | 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 | |
| 2002/1130 | rootwrite(Chan*, void*, long, vlong) | |
| 1990/0227 | { | |
| 2002/1130 | error(Egreg); | |
| 1993/0501 | return 0; | |
| 1995/0108 | } | |
| 1997/0327 | Dev rootdevtab = { | |
| 1997/0408 | '/', "root", | |
| 1997/0327 | rootreset, devinit, | |
| 2002/0109 | devshutdown, | |
| 1997/0327 | rootattach, rootwalk, rootstat, rootopen, | |
| 2000/0615 | devcreate, | |
| 1997/0327 | rootclose, rootread, devbread, rootwrite, devbwrite, devremove, devwstat, }; | |
| 2002/1130 | ||