source: mainline/uspace/srv/vfs/vfs_ipc.c@ fe91f66

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fe91f66 was fe91f66, checked in by Jakub Jermar <jakub@…>, 8 years ago

Omit unnecessary prefixes and suffixes from method and interface names

  • Property mode set to 100644
File size: 8.0 KB
RevLine 
[0d35511]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#include "vfs.h"
30
31#include <errno.h>
32#include <stdlib.h>
33#include <str.h>
34#include <vfs/canonify.h>
35
36static void vfs_in_clone(ipc_callid_t rid, ipc_call_t *request)
37{
38 int oldfd = IPC_GET_ARG1(*request);
[fcab7ef]39 int newfd = IPC_GET_ARG2(*request);
40 bool desc = IPC_GET_ARG3(*request);
[0d35511]41
[fcab7ef]42 int ret = vfs_op_clone(oldfd, newfd, desc);
[0d35511]43 async_answer_0(rid, ret);
44}
45
46static void vfs_in_close(ipc_callid_t rid, ipc_call_t *request)
47{
48 int fd = IPC_GET_ARG1(*request);
49 int rc = vfs_op_close(fd);
50 async_answer_0(rid, rc);
51}
52
53static void vfs_in_mount(ipc_callid_t rid, ipc_call_t *request)
54{
55 int mpfd = IPC_GET_ARG1(*request);
56
57 /*
58 * We expect the library to do the device-name to device-handle
59 * translation for us, thus the device handle will arrive as ARG1
60 * in the request.
61 */
62 service_id_t service_id = (service_id_t) IPC_GET_ARG2(*request);
63
64 unsigned int flags = (unsigned int) IPC_GET_ARG3(*request);
65 unsigned int instance = IPC_GET_ARG4(*request);
66
67 char *opts = NULL;
68 char *fs_name = NULL;
69
70 /* Now we expect to receive the mount options. */
71 int rc = async_data_write_accept((void **) &opts, true, 0,
72 MAX_MNTOPTS_LEN, 0, NULL);
73 if (rc != EOK) {
74 async_answer_0(rid, rc);
75 return;
76 }
77
78 /* Now, we expect the client to send us data with the name of the file
79 * system.
80 */
81 rc = async_data_write_accept((void **) &fs_name, true, 0,
82 FS_NAME_MAXLEN, 0, NULL);
83 if (rc != EOK) {
84 free(opts);
85 async_answer_0(rid, rc);
86 return;
87 }
88
89 int outfd = 0;
90 rc = vfs_op_mount(mpfd, service_id, flags, instance, opts, fs_name,
91 &outfd);
92 async_answer_1(rid, rc, outfd);
93
94 free(opts);
95 free(fs_name);
96}
97
[fe91f66]98static void vfs_in_open(ipc_callid_t rid, ipc_call_t *request)
[0d35511]99{
100 int fd = IPC_GET_ARG1(*request);
101 int flags = IPC_GET_ARG2(*request);
102
[fe91f66]103 int rc = vfs_op_open(fd, flags);
[0d35511]104 async_answer_0(rid, rc);
105}
106
107static void vfs_in_read(ipc_callid_t rid, ipc_call_t *request)
108{
109 int fd = IPC_GET_ARG1(*request);
[58898d1d]110 aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request),
111 IPC_GET_ARG3(*request));
[0d35511]112
113 size_t bytes = 0;
[58898d1d]114 int rc = vfs_op_read(fd, pos, &bytes);
[0d35511]115 async_answer_1(rid, rc, bytes);
116}
117
118static void vfs_in_rename(ipc_callid_t rid, ipc_call_t *request)
119{
120 /* The common base directory. */
121 int basefd;
122 char *old = NULL;
123 char *new = NULL;
124 int rc;
125
126 basefd = IPC_GET_ARG1(*request);
127
128 /* Retrieve the old path. */
129 rc = async_data_write_accept((void **) &old, true, 0, 0, 0, NULL);
[ebf1011]130 if (rc != EOK)
[0d35511]131 goto out;
132
133 /* Retrieve the new path. */
134 rc = async_data_write_accept((void **) &new, true, 0, 0, 0, NULL);
[ebf1011]135 if (rc != EOK)
[0d35511]136 goto out;
137
138 size_t olen;
139 size_t nlen;
140 char *oldc = canonify(old, &olen);
141 char *newc = canonify(new, &nlen);
142
143 if ((!oldc) || (!newc)) {
144 rc = EINVAL;
145 goto out;
146 }
147
148 assert(oldc[olen] == '\0');
149 assert(newc[nlen] == '\0');
150
151 rc = vfs_op_rename(basefd, oldc, newc);
152
153out:
154 async_answer_0(rid, rc);
155
[ebf1011]156 if (old)
[0d35511]157 free(old);
[ebf1011]158 if (new)
[0d35511]159 free(new);
160}
161
[fe91f66]162static void vfs_in_stat(ipc_callid_t rid, ipc_call_t *request)
163{
164 int fd = IPC_GET_ARG1(*request);
165 int rc = vfs_op_stat(fd);
166 async_answer_0(rid, rc);
167}
168
[0d35511]169static void vfs_in_statfs(ipc_callid_t rid, ipc_call_t *request)
170{
171 int fd = (int) IPC_GET_ARG1(*request);
172
173 int rc = vfs_op_statfs(fd);
174 async_answer_0(rid, rc);
175}
176
177static void vfs_in_sync(ipc_callid_t rid, ipc_call_t *request)
178{
179 int fd = IPC_GET_ARG1(*request);
180 int rc = vfs_op_sync(fd);
181 async_answer_0(rid, rc);
182}
183
184static void vfs_in_truncate(ipc_callid_t rid, ipc_call_t *request)
185{
186 int fd = IPC_GET_ARG1(*request);
187 int64_t size = MERGE_LOUP32(IPC_GET_ARG2(*request), IPC_GET_ARG3(*request));
188 int rc = vfs_op_truncate(fd, size);
189 async_answer_0(rid, rc);
190}
191
[fe91f66]192static void vfs_in_unlink(ipc_callid_t rid, ipc_call_t *request)
[0d35511]193{
194 int parentfd = IPC_GET_ARG1(*request);
195 int expectfd = IPC_GET_ARG2(*request);
196 int wflag = IPC_GET_ARG3(*request);
197
198 char *path;
199 int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
[ebf1011]200 if (rc == EOK)
[fe91f66]201 rc = vfs_op_unlink(parentfd, expectfd, wflag, path);
[0d35511]202
203 async_answer_0(rid, rc);
204}
205
206static void vfs_in_unmount(ipc_callid_t rid, ipc_call_t *request)
207{
208 int mpfd = IPC_GET_ARG1(*request);
209 int rc = vfs_op_unmount(mpfd);
210 async_answer_0(rid, rc);
211}
212
213static void vfs_in_wait_handle(ipc_callid_t rid, ipc_call_t *request)
214{
215 bool high_fd = IPC_GET_ARG1(*request);
216 int fd = vfs_op_wait_handle(high_fd);
217 async_answer_1(rid, EOK, fd);
218}
219
220static void vfs_in_walk(ipc_callid_t rid, ipc_call_t *request)
221{
222 /*
223 * Parent is our relative root for file lookup.
224 * For defined flags, see <ipc/vfs.h>.
225 */
226 int parentfd = IPC_GET_ARG1(*request);
227 int flags = IPC_GET_ARG2(*request);
228
229 int fd = 0;
230 char *path;
231 int rc = async_data_write_accept((void **)&path, true, 0, 0, 0, NULL);
232 if (rc == EOK) {
233 rc = vfs_op_walk(parentfd, flags, path, &fd);
234 free(path);
235 }
236 async_answer_1(rid, rc, fd);
237}
238
239static void vfs_in_write(ipc_callid_t rid, ipc_call_t *request)
240{
241 int fd = IPC_GET_ARG1(*request);
[58898d1d]242 aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request),
243 IPC_GET_ARG3(*request));
[0d35511]244
245 size_t bytes = 0;
[58898d1d]246 int rc = vfs_op_write(fd, pos, &bytes);
[0d35511]247 async_answer_1(rid, rc, bytes);
248}
249
250void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
251{
252 bool cont = true;
253
254 /*
255 * The connection was opened via the IPC_CONNECT_ME_TO call.
256 * This call needs to be answered.
257 */
258 async_answer_0(iid, EOK);
259
260 while (cont) {
261 ipc_call_t call;
262 ipc_callid_t callid = async_get_call(&call);
263
264 if (!IPC_GET_IMETHOD(call))
265 break;
266
267 switch (IPC_GET_IMETHOD(call)) {
268 case VFS_IN_CLONE:
269 vfs_in_clone(callid, &call);
270 break;
271 case VFS_IN_CLOSE:
272 vfs_in_close(callid, &call);
273 break;
274 case VFS_IN_MOUNT:
275 vfs_in_mount(callid, &call);
276 break;
[fe91f66]277 case VFS_IN_OPEN:
278 vfs_in_open(callid, &call);
[0d35511]279 break;
280 case VFS_IN_READ:
281 vfs_in_read(callid, &call);
282 break;
283 case VFS_IN_REGISTER:
284 vfs_register(callid, &call);
285 cont = false;
286 break;
287 case VFS_IN_RENAME:
288 vfs_in_rename(callid, &call);
289 break;
[fe91f66]290 case VFS_IN_STAT:
291 vfs_in_stat(callid, &call);
292 break;
[0d35511]293 case VFS_IN_STATFS:
294 vfs_in_statfs(callid, &call);
295 break;
296 case VFS_IN_SYNC:
297 vfs_in_sync(callid, &call);
298 break;
299 case VFS_IN_TRUNCATE:
300 vfs_in_truncate(callid, &call);
301 break;
[fe91f66]302 case VFS_IN_UNLINK:
303 vfs_in_unlink(callid, &call);
[0d35511]304 break;
305 case VFS_IN_UNMOUNT:
306 vfs_in_unmount(callid, &call);
307 break;
308 case VFS_IN_WAIT_HANDLE:
309 vfs_in_wait_handle(callid, &call);
310 break;
311 case VFS_IN_WALK:
312 vfs_in_walk(callid, &call);
313 break;
314 case VFS_IN_WRITE:
315 vfs_in_write(callid, &call);
316 break;
317 default:
318 async_answer_0(callid, ENOTSUP);
319 break;
320 }
321 }
322
323 /*
324 * Open files for this client will be cleaned up when its last
325 * connection fibril terminates.
326 */
327}
Note: See TracBrowser for help on using the repository browser.