xref: /plan9-contrib/sys/src/9k/port/devtab.c (revision 9ef1f84b659abcb917c5c090acbce0772e494f21)
1 /*
2  * Stub.
3  */
4 #include "u.h"
5 #include "../port/lib.h"
6 #include "mem.h"
7 #include "dat.h"
8 #include "fns.h"
9 #include "../port/error.h"
10 
11 extern Dev* devtab[];
12 
13 void
devtabreset(void)14 devtabreset(void)
15 {
16 	int i;
17 
18 	for(i = 0; devtab[i] != nil; i++)
19 		devtab[i]->reset();
20 }
21 
22 void
devtabinit(void)23 devtabinit(void)
24 {
25 	int i;
26 
27 	for(i = 0; devtab[i] != nil; i++)
28 		devtab[i]->init();
29 }
30 
31 void
devtabshutdown(void)32 devtabshutdown(void)
33 {
34 	int i;
35 
36 	/*
37 	 * Shutdown in reverse order.
38 	 */
39 	for(i = 0; devtab[i] != nil; i++)
40 		;
41 	for(i--; i >= 0; i--)
42 		devtab[i]->shutdown();
43 }
44 
45 
46 Dev*
devtabget(int dc,int user)47 devtabget(int dc, int user)
48 {
49 	int i;
50 
51 	for(i = 0; devtab[i] != nil; i++){
52 		if(devtab[i]->dc == dc)
53 			return devtab[i];
54 	}
55 
56 	if(user == 0)
57 		panic("devtabget %C\n", dc);
58 
59 	return nil;
60 }
61 
62 long
devtabread(Chan *,void * buf,long n,vlong off)63 devtabread(Chan*, void* buf, long n, vlong off)
64 {
65 	int i;
66 	Dev *dev;
67 	char *alloc, *e, *p;
68 
69 	alloc = malloc(READSTR);
70 	if(alloc == nil)
71 		error(Enomem);
72 
73 	p = alloc;
74 	e = p + READSTR;
75 	for(i = 0; devtab[i] != nil; i++){
76 		dev = devtab[i];
77 		p = seprint(p, e, "#%C %s\n", dev->dc, dev->name);
78 	}
79 
80 	if(waserror()){
81 		free(alloc);
82 		nexterror();
83 	}
84 	n = readstr(off, buf, n, alloc);
85 	free(alloc);
86 	poperror();
87 
88 	return n;
89 }
90