11 extern Channel *hc[2];
13 static File *devcons, *devconsctl;
15 static Channel *readreq;
16 static Channel *flushreq;
28 { flushreq, &fr, CHANRCV },
29 { readreq, &r, r == nil ? CHANRCV : CHANNOP },
30 { hc[0], &s, s == nil ? CHANRCV : CHANNOP },
31 { nil, nil, s == nil || r == nil ? CHANEND : CHANNOBLK },
35 respond(r, "interrupted");
40 if(s == nil || r == nil)
45 while(r->ifcall.count > r->ofcall.count){
48 r->ofcall.data[r->ofcall.count++] = *p++;
51 if((p = s = nbrecvp(hc[0])) == nil)
63 if(r->fid->file == devcons){
67 respond(r, "not implemented");
70 typedef struct Partutf Partutf;
78 cvtc2r(char *b, int n, Partutf *u)
84 rp = rb = emalloc9p(sizeof(Rune)*(n+2));
86 while(u->n > 0 && cp < ep){
88 if(fullrune(u->s, u->n)){
97 while(cp < ep && fullrune(cp, ep - cp)){
98 cp += chartorune(rp, cp);
104 memmove(u->s, cp, n);
120 if(r->fid->file == devcons){
124 if((u = r->fid->aux) == nil)
125 u = r->fid->aux = emalloc9p(sizeof(*u));
126 if((rp = cvtc2r((char*)r->ifcall.data, r->ifcall.count, u)) != nil)
129 r->ofcall.count = r->ifcall.count;
133 if(r->fid->file == devconsctl){
134 char *s = r->ifcall.data;
135 int n = r->ifcall.count;
137 if(n >= 5 && strncmp(s, "rawon", 5) == 0)
139 else if(n >= 6 && strncmp(s, "rawoff", 6) == 0)
141 else if(n >= 6 && strncmp(s, "holdon", 6) == 0)
143 else if(n >= 7 && strncmp(s, "holdoff", 7) == 0)
145 else if(n >= 7 && strncmp(s, "winchon", 7) == 0)
147 else if(n >= 8 && strncmp(s, "winchoff", 8) == 0)
150 r->ofcall.count = r->ifcall.count;
155 respond(r, "not implemented");
167 if(f->file == devconsctl && f->omode >= 0){
181 flushreq = chancreate(sizeof(Req*), 4);
182 readreq = chancreate(sizeof(Req*), 4);
183 proccreate(fsreader, nil, 16*1024);
196 .destroyfid=fsdestroyfid,
204 fs.tree = alloctree("vt", "vt", DMDIR|0555, nil);
205 devcons = createfile(fs.tree->root, "cons", "vt", 0666, nil);
207 sysfatal("creating /dev/cons: %r");
208 devconsctl = createfile(fs.tree->root, "consctl", "vt", 0666, nil);
209 if(devconsctl == nil)
210 sysfatal("creating /dev/consctl: %r");
211 threadpostmountsrv(&fs, nil, "/dev", MBEFORE);