1 | /*
|
---|
2 | * Copyright (c) 2008 Jakub Jermar
|
---|
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 vfs.c
|
---|
35 | * @brief VFS service for HelenOS.
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include <vfs/vfs.h>
|
---|
39 | #include <ipc/services.h>
|
---|
40 | #include <abi/ipc/event.h>
|
---|
41 | #include <event.h>
|
---|
42 | #include <ns.h>
|
---|
43 | #include <async.h>
|
---|
44 | #include <errno.h>
|
---|
45 | #include <stdio.h>
|
---|
46 | #include <stdbool.h>
|
---|
47 | #include <str.h>
|
---|
48 | #include <as.h>
|
---|
49 | #include <atomic.h>
|
---|
50 | #include <macros.h>
|
---|
51 | #include "vfs.h"
|
---|
52 |
|
---|
53 | #define NAME "vfs"
|
---|
54 |
|
---|
55 | enum {
|
---|
56 | VFS_TASK_STATE_CHANGE
|
---|
57 | };
|
---|
58 |
|
---|
59 | static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
60 | {
|
---|
61 | bool cont = true;
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * The connection was opened via the IPC_CONNECT_ME_TO call.
|
---|
65 | * This call needs to be answered.
|
---|
66 | */
|
---|
67 | async_answer_0(iid, EOK);
|
---|
68 |
|
---|
69 | while (cont) {
|
---|
70 | ipc_call_t call;
|
---|
71 | ipc_callid_t callid = async_get_call(&call);
|
---|
72 |
|
---|
73 | if (!IPC_GET_IMETHOD(call))
|
---|
74 | break;
|
---|
75 |
|
---|
76 | switch (IPC_GET_IMETHOD(call)) {
|
---|
77 | case VFS_IN_REGISTER:
|
---|
78 | vfs_register(callid, &call);
|
---|
79 | cont = false;
|
---|
80 | break;
|
---|
81 | case VFS_IN_MOUNT:
|
---|
82 | vfs_mount(callid, &call);
|
---|
83 | break;
|
---|
84 | case VFS_IN_UNMOUNT:
|
---|
85 | vfs_unmount(callid, &call);
|
---|
86 | break;
|
---|
87 | case VFS_IN_WALK:
|
---|
88 | vfs_walk(callid, &call);
|
---|
89 | break;
|
---|
90 | case VFS_IN_OPEN2:
|
---|
91 | vfs_open(callid, &call);
|
---|
92 | break;
|
---|
93 | case VFS_IN_OPEN:
|
---|
94 | vfs_open(callid, &call);
|
---|
95 | break;
|
---|
96 | case VFS_IN_CLOSE:
|
---|
97 | vfs_close(callid, &call);
|
---|
98 | break;
|
---|
99 | case VFS_IN_READ:
|
---|
100 | vfs_read(callid, &call);
|
---|
101 | break;
|
---|
102 | case VFS_IN_WRITE:
|
---|
103 | vfs_write(callid, &call);
|
---|
104 | break;
|
---|
105 | case VFS_IN_SEEK:
|
---|
106 | vfs_seek(callid, &call);
|
---|
107 | break;
|
---|
108 | case VFS_IN_TRUNCATE:
|
---|
109 | vfs_truncate(callid, &call);
|
---|
110 | break;
|
---|
111 | case VFS_IN_FSTAT:
|
---|
112 | vfs_fstat(callid, &call);
|
---|
113 | break;
|
---|
114 | case VFS_IN_STAT:
|
---|
115 | vfs_stat(callid, &call);
|
---|
116 | break;
|
---|
117 | case VFS_IN_MKDIR:
|
---|
118 | vfs_mkdir(callid, &call);
|
---|
119 | break;
|
---|
120 | case VFS_IN_UNLINK:
|
---|
121 | vfs_unlink(callid, &call);
|
---|
122 | break;
|
---|
123 | case VFS_IN_RENAME:
|
---|
124 | vfs_rename(callid, &call);
|
---|
125 | break;
|
---|
126 | case VFS_IN_SYNC:
|
---|
127 | vfs_sync(callid, &call);
|
---|
128 | break;
|
---|
129 | case VFS_IN_DUP:
|
---|
130 | vfs_dup(callid, &call);
|
---|
131 | break;
|
---|
132 | case VFS_IN_WAIT_HANDLE:
|
---|
133 | vfs_wait_handle(callid, &call);
|
---|
134 | break;
|
---|
135 | case VFS_IN_MTAB_GET:
|
---|
136 | vfs_get_mtab(callid, &call);
|
---|
137 | break;
|
---|
138 | default:
|
---|
139 | async_answer_0(callid, ENOTSUP);
|
---|
140 | break;
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | /*
|
---|
145 | * Open files for this client will be cleaned up when its last
|
---|
146 | * connection fibril terminates.
|
---|
147 | */
|
---|
148 | }
|
---|
149 |
|
---|
150 | static void notification_received(ipc_callid_t callid, ipc_call_t *call)
|
---|
151 | {
|
---|
152 | switch (IPC_GET_IMETHOD(*call)) {
|
---|
153 | case VFS_TASK_STATE_CHANGE:
|
---|
154 | if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE)
|
---|
155 | vfs_pass_handle(
|
---|
156 | (task_id_t) MERGE_LOUP32(IPC_GET_ARG4(*call),
|
---|
157 | IPC_GET_ARG5(*call)), call->in_task_id,
|
---|
158 | (int) IPC_GET_ARG2(*call));
|
---|
159 | break;
|
---|
160 | default:
|
---|
161 | break;
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 | int main(int argc, char **argv)
|
---|
166 | {
|
---|
167 | printf("%s: HelenOS VFS server\n", NAME);
|
---|
168 |
|
---|
169 | /*
|
---|
170 | * Initialize VFS node hash table.
|
---|
171 | */
|
---|
172 | if (!vfs_nodes_init()) {
|
---|
173 | printf("%s: Failed to initialize VFS node hash table\n",
|
---|
174 | NAME);
|
---|
175 | return ENOMEM;
|
---|
176 | }
|
---|
177 |
|
---|
178 | /*
|
---|
179 | * Allocate and initialize the Path Lookup Buffer.
|
---|
180 | */
|
---|
181 | plb = as_area_create(AS_AREA_ANY, PLB_SIZE,
|
---|
182 | AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
|
---|
183 | if (plb == AS_MAP_FAILED) {
|
---|
184 | printf("%s: Cannot create address space area\n", NAME);
|
---|
185 | return ENOMEM;
|
---|
186 | }
|
---|
187 | memset(plb, 0, PLB_SIZE);
|
---|
188 |
|
---|
189 | /*
|
---|
190 | * Set client data constructor and destructor.
|
---|
191 | */
|
---|
192 | async_set_client_data_constructor(vfs_client_data_create);
|
---|
193 | async_set_client_data_destructor(vfs_client_data_destroy);
|
---|
194 |
|
---|
195 | /*
|
---|
196 | * Set a connection handling function/fibril.
|
---|
197 | */
|
---|
198 | async_set_client_connection(vfs_connection);
|
---|
199 |
|
---|
200 | /*
|
---|
201 | * Set notification handler and subscribe to notifications.
|
---|
202 | */
|
---|
203 | async_set_interrupt_received(notification_received);
|
---|
204 | event_task_subscribe(EVENT_TASK_STATE_CHANGE, VFS_TASK_STATE_CHANGE);
|
---|
205 |
|
---|
206 | /*
|
---|
207 | * Register at the naming service.
|
---|
208 | */
|
---|
209 | int rc = service_register(SERVICE_VFS);
|
---|
210 | if (rc != EOK) {
|
---|
211 | printf("%s: Cannot register VFS service\n", NAME);
|
---|
212 | return rc;
|
---|
213 | }
|
---|
214 |
|
---|
215 | /*
|
---|
216 | * Start accepting connections.
|
---|
217 | */
|
---|
218 | printf("%s: Accepting connections\n", NAME);
|
---|
219 | async_manager();
|
---|
220 | return 0;
|
---|
221 | }
|
---|
222 |
|
---|
223 | /**
|
---|
224 | * @}
|
---|
225 | */
|
---|