summaryrefslogtreecommitdiff
path: root/minix/servers/devman/main.c
blob: 74a427cf53abd1f3fd311d68a12d50b37479f1e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#define _SYSTEM		1	/* tell headers that this is the kernel */

#include <minix/config.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <lib.h>
#include <minix/timers.h>

#include <minix/callnr.h>
#include <minix/type.h>
#include <minix/const.h>
#include <minix/com.h>
#include <minix/syslib.h>
#include <minix/sysutil.h>
#include <minix/vfsif.h>
#include <minix/endpoint.h>
#include <minix/sysinfo.h>
#include <minix/u64.h>
#include <minix/sysinfo.h>
#include <minix/type.h>
#include <minix/ipc.h>

#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
#include <sys/stat.h>


#include <minix/vtreefs.h>
#include "devman.h"
#include "proto.h"

static void init_hook(void) {
	static int first = 1;
	
	if (first) {
		devman_init_devices();
		first = 0;
	}
}


static void message_hook(message *m, int __unused ipc_status)
{
	switch (m->m_type) {
		case DEVMAN_ADD_DEV:
			do_add_device(m);
		case DEVMAN_DEL_DEV:
			do_del_device(m);
		case DEVMAN_BIND:
			do_bind_device(m);
		case DEVMAN_UNBIND:
			do_unbind_device(m);
	}
}

static ssize_t
read_hook
(struct inode *inode, char *ptr, size_t len, off_t offset, cbdata_t cbdata)
{
	struct devman_inode *d_inode = (struct devman_inode *) cbdata;

	return d_inode->read_fn(ptr, len, offset, d_inode->data);
}


int main (int argc, char* argv[])
{

	static struct fs_hooks hooks;
	static struct inode_stat root_stat;

	/* fill in the hooks */
	memset(&hooks, 0, sizeof(hooks));
	hooks.init_hook 	= init_hook;
	hooks.read_hook 	= read_hook;
	hooks.message_hook 	= message_hook;	/* handle the ds_update call */

	root_stat.mode 	= S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH;
	root_stat.uid 	= 0;
	root_stat.gid 	= 0;
	root_stat.size 	= 0;
	root_stat.dev 	= NO_DEV;

	/* run VTreeFS */
	run_vtreefs(&hooks, 1024, 0, &root_stat, 0, BUF_SIZE);

	return 0;
}