xref: /minix3/minix/servers/devman/main.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc #define _SYSTEM		1	/* tell headers that this is the kernel */
2*433d6423SLionel Sambuc 
3*433d6423SLionel Sambuc #include <minix/config.h>
4*433d6423SLionel Sambuc #include <errno.h>
5*433d6423SLionel Sambuc #include <unistd.h>
6*433d6423SLionel Sambuc #include <stdlib.h>
7*433d6423SLionel Sambuc #include <stdio.h>
8*433d6423SLionel Sambuc #include <string.h>
9*433d6423SLionel Sambuc #include <lib.h>
10*433d6423SLionel Sambuc #include <minix/timers.h>
11*433d6423SLionel Sambuc 
12*433d6423SLionel Sambuc #include <minix/callnr.h>
13*433d6423SLionel Sambuc #include <minix/type.h>
14*433d6423SLionel Sambuc #include <minix/const.h>
15*433d6423SLionel Sambuc #include <minix/com.h>
16*433d6423SLionel Sambuc #include <minix/syslib.h>
17*433d6423SLionel Sambuc #include <minix/sysutil.h>
18*433d6423SLionel Sambuc #include <minix/vfsif.h>
19*433d6423SLionel Sambuc #include <minix/endpoint.h>
20*433d6423SLionel Sambuc #include <minix/sysinfo.h>
21*433d6423SLionel Sambuc #include <minix/u64.h>
22*433d6423SLionel Sambuc #include <minix/sysinfo.h>
23*433d6423SLionel Sambuc #include <minix/type.h>
24*433d6423SLionel Sambuc #include <minix/ipc.h>
25*433d6423SLionel Sambuc 
26*433d6423SLionel Sambuc #include <sys/time.h>
27*433d6423SLionel Sambuc #include <sys/times.h>
28*433d6423SLionel Sambuc #include <sys/types.h>
29*433d6423SLionel Sambuc #include <sys/stat.h>
30*433d6423SLionel Sambuc 
31*433d6423SLionel Sambuc 
32*433d6423SLionel Sambuc #include <minix/vtreefs.h>
33*433d6423SLionel Sambuc #include "devman.h"
34*433d6423SLionel Sambuc #include "proto.h"
35*433d6423SLionel Sambuc 
36*433d6423SLionel Sambuc static void init_hook(void) {
37*433d6423SLionel Sambuc 	static int first = 1;
38*433d6423SLionel Sambuc 
39*433d6423SLionel Sambuc 	if (first) {
40*433d6423SLionel Sambuc 		devman_init_devices();
41*433d6423SLionel Sambuc 		first = 0;
42*433d6423SLionel Sambuc 	}
43*433d6423SLionel Sambuc }
44*433d6423SLionel Sambuc 
45*433d6423SLionel Sambuc 
46*433d6423SLionel Sambuc static int message_hook (message *m)
47*433d6423SLionel Sambuc {
48*433d6423SLionel Sambuc 	switch (m->m_type) {
49*433d6423SLionel Sambuc 		case DEVMAN_ADD_DEV:
50*433d6423SLionel Sambuc 			return do_add_device(m);
51*433d6423SLionel Sambuc 		case DEVMAN_DEL_DEV:
52*433d6423SLionel Sambuc 			return do_del_device(m);
53*433d6423SLionel Sambuc 		case DEVMAN_BIND:
54*433d6423SLionel Sambuc 			return do_bind_device(m);
55*433d6423SLionel Sambuc 		case DEVMAN_UNBIND:
56*433d6423SLionel Sambuc 			return do_unbind_device(m);
57*433d6423SLionel Sambuc 		default: return -1;
58*433d6423SLionel Sambuc 	}
59*433d6423SLionel Sambuc }
60*433d6423SLionel Sambuc 
61*433d6423SLionel Sambuc static int
62*433d6423SLionel Sambuc read_hook
63*433d6423SLionel Sambuc (struct inode *inode, off_t offset, char **ptr, size_t *len, cbdata_t cbdata)
64*433d6423SLionel Sambuc {
65*433d6423SLionel Sambuc 	struct devman_inode *d_inode = (struct devman_inode *) cbdata;
66*433d6423SLionel Sambuc 
67*433d6423SLionel Sambuc 	return d_inode->read_fn(ptr, len, offset, d_inode->data);
68*433d6423SLionel Sambuc }
69*433d6423SLionel Sambuc 
70*433d6423SLionel Sambuc 
71*433d6423SLionel Sambuc int main (int argc, char* argv[])
72*433d6423SLionel Sambuc {
73*433d6423SLionel Sambuc 
74*433d6423SLionel Sambuc 	struct fs_hooks hooks;
75*433d6423SLionel Sambuc 	struct inode_stat root_stat;
76*433d6423SLionel Sambuc 
77*433d6423SLionel Sambuc 	/* fill in the hooks */
78*433d6423SLionel Sambuc 	memset(&hooks, 0, sizeof(hooks));
79*433d6423SLionel Sambuc 	hooks.init_hook 	= init_hook;
80*433d6423SLionel Sambuc 	hooks.read_hook 	= read_hook; /* read will never be called */
81*433d6423SLionel Sambuc 	hooks.message_hook 	= message_hook;	/* handle the ds_update call */
82*433d6423SLionel Sambuc 
83*433d6423SLionel Sambuc 	root_stat.mode 	= S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH;
84*433d6423SLionel Sambuc 	root_stat.uid 	= 0;
85*433d6423SLionel Sambuc 	root_stat.gid 	= 0;
86*433d6423SLionel Sambuc 	root_stat.size 	= 0;
87*433d6423SLionel Sambuc 	root_stat.dev 	= NO_DEV;
88*433d6423SLionel Sambuc 
89*433d6423SLionel Sambuc 	/* limit the number of indexed entries */
90*433d6423SLionel Sambuc 	start_vtreefs(&hooks, 1024 , &root_stat, 0);
91*433d6423SLionel Sambuc 	return 0;
92*433d6423SLionel Sambuc }
93*433d6423SLionel Sambuc 
94