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