1 | /*
|
---|
2 | * Copyright (c) 2009 Martin Decky
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup fs
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * @file devfs.c
|
---|
35 | * @brief Devices file system.
|
---|
36 | *
|
---|
37 | * Every device registered to device mapper is represented as a file in this
|
---|
38 | * file system.
|
---|
39 | */
|
---|
40 |
|
---|
41 | #include <stdio.h>
|
---|
42 | #include <ipc/services.h>
|
---|
43 | #include <ns.h>
|
---|
44 | #include <async.h>
|
---|
45 | #include <errno.h>
|
---|
46 | #include <task.h>
|
---|
47 | #include <libfs.h>
|
---|
48 | #include "devfs.h"
|
---|
49 | #include "devfs_ops.h"
|
---|
50 |
|
---|
51 | #define NAME "devfs"
|
---|
52 |
|
---|
53 | static vfs_info_t devfs_vfs_info = {
|
---|
54 | .name = NAME,
|
---|
55 | .concurrent_read_write = false,
|
---|
56 | .write_retains_size = false,
|
---|
57 | };
|
---|
58 |
|
---|
59 | fs_reg_t devfs_reg;
|
---|
60 |
|
---|
61 | static void devfs_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
62 | {
|
---|
63 | if (iid)
|
---|
64 | async_answer_0(iid, EOK);
|
---|
65 |
|
---|
66 | while (true) {
|
---|
67 | ipc_call_t call;
|
---|
68 | ipc_callid_t callid = async_get_call(&call);
|
---|
69 |
|
---|
70 | if (!IPC_GET_IMETHOD(call))
|
---|
71 | return;
|
---|
72 |
|
---|
73 | switch (IPC_GET_IMETHOD(call)) {
|
---|
74 | case VFS_OUT_MOUNTED:
|
---|
75 | devfs_mounted(callid, &call);
|
---|
76 | break;
|
---|
77 | case VFS_OUT_MOUNT:
|
---|
78 | devfs_mount(callid, &call);
|
---|
79 | break;
|
---|
80 | case VFS_OUT_UNMOUNTED:
|
---|
81 | devfs_unmounted(callid, &call);
|
---|
82 | break;
|
---|
83 | case VFS_OUT_UNMOUNT:
|
---|
84 | devfs_unmount(callid, &call);
|
---|
85 | break;
|
---|
86 | case VFS_OUT_LOOKUP:
|
---|
87 | devfs_lookup(callid, &call);
|
---|
88 | break;
|
---|
89 | case VFS_OUT_OPEN_NODE:
|
---|
90 | devfs_open_node(callid, &call);
|
---|
91 | break;
|
---|
92 | case VFS_OUT_STAT:
|
---|
93 | devfs_stat(callid, &call);
|
---|
94 | break;
|
---|
95 | case VFS_OUT_READ:
|
---|
96 | devfs_read(callid, &call);
|
---|
97 | break;
|
---|
98 | case VFS_OUT_WRITE:
|
---|
99 | devfs_write(callid, &call);
|
---|
100 | break;
|
---|
101 | case VFS_OUT_TRUNCATE:
|
---|
102 | devfs_truncate(callid, &call);
|
---|
103 | break;
|
---|
104 | case VFS_OUT_CLOSE:
|
---|
105 | devfs_close(callid, &call);
|
---|
106 | break;
|
---|
107 | case VFS_OUT_SYNC:
|
---|
108 | devfs_sync(callid, &call);
|
---|
109 | break;
|
---|
110 | case VFS_OUT_DESTROY:
|
---|
111 | devfs_destroy(callid, &call);
|
---|
112 | break;
|
---|
113 | default:
|
---|
114 | async_answer_0(callid, ENOTSUP);
|
---|
115 | break;
|
---|
116 | }
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | int main(int argc, char *argv[])
|
---|
121 | {
|
---|
122 | printf("%s: HelenOS Device Filesystem\n", NAME);
|
---|
123 |
|
---|
124 | if (!devfs_init()) {
|
---|
125 | printf("%s: failed to initialize devfs\n", NAME);
|
---|
126 | return -1;
|
---|
127 | }
|
---|
128 |
|
---|
129 | async_sess_t *vfs_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
|
---|
130 | SERVICE_VFS, 0, 0);
|
---|
131 | if (!vfs_sess) {
|
---|
132 | printf("%s: Unable to connect to VFS\n", NAME);
|
---|
133 | return -1;
|
---|
134 | }
|
---|
135 |
|
---|
136 | int rc = fs_register(vfs_sess, &devfs_reg, &devfs_vfs_info,
|
---|
137 | devfs_connection);
|
---|
138 | if (rc != EOK) {
|
---|
139 | printf("%s: Failed to register file system (%d)\n", NAME, rc);
|
---|
140 | return rc;
|
---|
141 | }
|
---|
142 |
|
---|
143 | printf("%s: Accepting connections\n", NAME);
|
---|
144 | task_retval(0);
|
---|
145 | async_manager();
|
---|
146 |
|
---|
147 | /* Not reached */
|
---|
148 | return 0;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * @}
|
---|
153 | */
|
---|