]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/port/led.c
devproc: return process id when reading /proc/n/ctl file
[plan9front.git] / sys / src / 9 / port / led.c
1 #include "u.h"
2 #include "../port/lib.h"
3 #include "mem.h"
4 #include "dat.h"
5 #include "../port/error.h"
6 #include "fns.h"
7 #include "led.h"
8
9 static char *ibpinames[Ibpilast] = {
10 [Ibpinone]      "none",
11 [Ibpinormal]    "normal",
12 [Ibpilocate]    "locate",
13 [Ibpifail]              "fail",
14 [Ibpirebuild]   "rebuild",
15 [Ibpipfa]               "pfa",
16 [Ibpispare]     "spare",
17 [Ibpicritarray] "critarray",
18 [Ibpifailarray] "failarray",
19 };
20
21 char*
22 ledname(int c)
23 {
24         if(c >= 0 && c < Ibpilast)
25                 return ibpinames[c];
26         return "bad index";
27 }
28
29  int
30 name2led(char *s)
31 {
32         int i;
33
34         for(i = 0; i < nelem(ibpinames); i++)
35                 if(strcmp(ibpinames[i], s) == 0)
36                         return i;
37         return -1;
38 }
39
40 long
41 ledr(Ledport *p, Chan*, void *a, long n, vlong off)
42 {
43         char buf[64];
44
45         snprint(buf, sizeof buf, "%s\n", ledname(p->led));
46         return readstr(off, a, n, buf);
47 }
48
49 long
50 ledw(Ledport *p, Chan*, void *a, long n, vlong)
51 {
52         int i;
53         Cmdbuf *cb;
54
55         cb = parsecmd(a, n);
56         i = cb->nf < 1 ? -1 : name2led(cb->f[0]);
57         free(cb);
58         if(i == -1)
59                 error(Ebadarg);
60         p->led = i;
61         return n;
62 }