2 #include "../port/lib.h"
6 #include "../port/error.h"
18 typedef long Rdwrfn(Chan*, void*, long, vlong);
20 static Rdwrfn *readfn[Qmax];
21 static Rdwrfn *writefn[Qmax];
23 static Dirtab archdir[Qmax] = {
24 ".", { Qdir, 0, QTDIR }, 0, 0555,
27 Lock archwlock; /* the lock is only for changing archdir */
31 * Add a file to the #P listing. Once added, you can't delete it.
32 * You can't add a file with the same name as one already there,
33 * and you get a pointer to the Dirtab entry so you can do things
34 * like change the Qid version. Changing the Qid path is disallowed.
37 addarchfile(char *name, int perm, Rdwrfn *rdfn, Rdwrfn *wrfn)
43 memset(&d, 0, sizeof d);
53 for(i=0; i<narchdir; i++)
54 if(strcmp(archdir[i].name, name) == 0){
59 d.qid.path = narchdir;
60 archdir[narchdir] = d;
61 readfn[narchdir] = rdfn;
62 writefn[narchdir] = wrfn;
63 dp = &archdir[narchdir++];
70 archattach(char* spec)
72 return devattach('P', spec);
76 archwalk(Chan* c, Chan *nc, char** name, int nname)
78 return devwalk(c, nc, name, nname, archdir, narchdir, devgen);
82 archstat(Chan* c, uchar* dp, int n)
84 return devstat(c, dp, n, archdir, narchdir, devgen);
88 archopen(Chan* c, int omode)
90 return devopen(c, omode, archdir, narchdir, devgen);
99 archread(Chan *c, void *a, long n, vlong offset)
103 switch((ulong)c->qid.path){
105 return devdirread(c, a, n, archdir, narchdir, devgen);
108 if(c->qid.path < narchdir && (fn = readfn[c->qid.path]))
109 return fn(c, a, n, offset);
118 archwrite(Chan *c, void *a, long n, vlong offset)
122 if(c->qid.path < narchdir && (fn = writefn[c->qid.path]))
123 return fn(c, a, n, offset);
153 cputyperead(Chan*, void *a, long n, vlong offset)
155 char name[64], str[128];
157 cputype2name(name, sizeof name);
158 snprint(str, sizeof str, "ARM %s %llud\n", name, m->cpuhz / Mhz);
159 return readstr(offset, a, n, str);
163 tbread(Chan*, void *a, long n, vlong offset)
170 snprint(str, sizeof(str), "%16.16llux", tb);
171 return readstr(offset, a, n, str);
175 nsread(Chan*, void *a, long n, vlong offset)
182 snprint(str, sizeof(str), "%16.16llux", (tb/700)* 1000);
183 return readstr(offset, a, n, str);
189 addarchfile("cputype", 0444, cputyperead, nil);
190 addarchfile("timebase",0444, tbread, nil);
191 // addarchfile("nsec", 0444, nsread, nil);