2 #include "../port/lib.h"
7 #include "../port/error.h"
19 typedef long Rdwrfn(Chan*, void*, long, vlong);
21 static Rdwrfn *readfn[Qmax];
22 static Rdwrfn *writefn[Qmax];
24 static Dirtab archdir[] = {
25 ".", { Qdir, 0, QTDIR }, 0, 0555,
26 "iob", { Qiob, 0 }, 0, 0660,
27 "iow", { Qiow, 0 }, 0, 0660,
28 "iol", { Qiol, 0 }, 0, 0660,
30 Lock archwlock; /* the lock is only for changing archdir */
32 int (*_pcmspecial)(char *, ISAConf *);
33 void (*_pcmspecialclose)(int);
36 * Add a file to the #P listing. Once added, you can't delete it.
37 * You can't add a file with the same name as one already there,
38 * and you get a pointer to the Dirtab entry so you can do things
39 * like change the Qid version. Changing the Qid path is disallowed.
42 addarchfile(char *name, int perm, Rdwrfn *rdfn, Rdwrfn *wrfn)
48 memset(&d, 0, sizeof d);
58 for(i=0; i<narchdir; i++)
59 if(strcmp(archdir[i].name, name) == 0){
64 d.qid.path = narchdir;
65 archdir[narchdir] = d;
66 readfn[narchdir] = rdfn;
67 writefn[narchdir] = wrfn;
68 dp = &archdir[narchdir++];
79 // a dummy entry at 2^17
80 ioalloc(0x20000, 1, 0, "dummy");
84 checkport(int start, int end)
86 /* standard vga regs are OK */
87 if(start >= 0x2b0 && end <= 0x2df+1)
89 if(start >= 0x3c0 && end <= 0x3da+1)
92 if(iounused(start, end))
98 archattach(char* spec)
100 return devattach('P', spec);
104 archwalk(Chan* c, Chan *nc, char** name, int nname)
106 return devwalk(c, nc, name, nname, archdir, narchdir, devgen);
110 archstat(Chan* c, uchar* dp, int n)
112 return devstat(c, dp, n, archdir, narchdir, devgen);
116 archopen(Chan* c, int omode)
118 return devopen(c, omode, archdir, nelem(archdir), devgen);
127 archread(Chan *c, void *a, long n, vlong offset)
136 switch((ulong)c->qid.path){
139 return devdirread(c, a, n, archdir, nelem(archdir), devgen);
143 checkport(offset, offset+n);
144 for(cp = a; port < offset+n; port++)
149 if((n & 0x01) || (offset & 0x01))
151 checkport(offset, offset+n+1);
154 for(port = offset; port < offset+n; port += 2)
159 if((n & 0x03) || (offset & 0x03))
161 checkport(offset, offset+n+3);
164 for(port = offset; port < offset+n; port += 4)
169 if(c->qid.path < narchdir && (fn = readfn[c->qid.path]))
170 return fn(c, a, n, offset);
178 archwrite(Chan *c, void *a, long n, vlong offset)
186 switch((ulong)c->qid.path){
190 checkport(offset, offset+n);
191 for(port = offset; port < offset+n; port++)
196 if((n & 01) || (offset & 01))
198 checkport(offset, offset+n+1);
201 for(port = offset; port < offset+n; port += 2)
206 if((n & 0x03) || (offset & 0x03))
208 checkport(offset, offset+n+3);
211 for(port = offset; port < offset+n; port += 4)
216 if(c->qid.path < narchdir && (fn = writefn[c->qid.path]))
217 return fn(c, a, n, offset);
246 pcmspecial(char *idstr, ISAConf *isa)
248 return (_pcmspecial != nil)? _pcmspecial(idstr, isa): -1;
252 pcmspecialclose(int a)
254 if (_pcmspecialclose != nil)