xref: /minix3/minix/servers/devman/main.c (revision 50b7f13f9fbd498540451ca8c6411c6a364ce95c)
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 
init_hook(void)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 
message_hook(message * m,int __unused ipc_status)46 static void message_hook(message *m, int __unused ipc_status)
47 {
48 	switch (m->m_type) {
49 		case DEVMAN_ADD_DEV:
50 			do_add_device(m);
51 		case DEVMAN_DEL_DEV:
52 			do_del_device(m);
53 		case DEVMAN_BIND:
54 			do_bind_device(m);
55 		case DEVMAN_UNBIND:
56 			do_unbind_device(m);
57 	}
58 }
59 
60 static ssize_t
read_hook(struct inode * inode,char * ptr,size_t len,off_t offset,cbdata_t cbdata)61 read_hook
62 (struct inode *inode, char *ptr, size_t len, off_t offset, cbdata_t cbdata)
63 {
64 	struct devman_inode *d_inode = (struct devman_inode *) cbdata;
65 
66 	return d_inode->read_fn(ptr, len, offset, d_inode->data);
67 }
68 
69 
main(int argc,char * argv[])70 int main (int argc, char* argv[])
71 {
72 
73 	static struct fs_hooks hooks;
74 	static struct inode_stat root_stat;
75 
76 	/* fill in the hooks */
77 	memset(&hooks, 0, sizeof(hooks));
78 	hooks.init_hook 	= init_hook;
79 	hooks.read_hook 	= read_hook;
80 	hooks.message_hook 	= message_hook;	/* handle the ds_update call */
81 
82 	root_stat.mode 	= S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH;
83 	root_stat.uid 	= 0;
84 	root_stat.gid 	= 0;
85 	root_stat.size 	= 0;
86 	root_stat.dev 	= NO_DEV;
87 
88 	/* run VTreeFS */
89 	run_vtreefs(&hooks, 1024, 0, &root_stat, 0, BUF_SIZE);
90 
91 	return 0;
92 }
93 
94