source: mainline/uspace/srv/vfs/vfs_ipc.c@ 6ff23ff

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6ff23ff was 7c3fb9b, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix block comment formatting (ccheck).

  • Property mode set to 100644
File size: 9.9 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
[b14d9f9]29#include <vfs/vfs.h>
[0d35511]30#include "vfs.h"
31
32#include <errno.h>
33#include <stdlib.h>
34#include <str.h>
35#include <vfs/canonify.h>
36
[77f0a1d]37static void vfs_in_clone(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]38{
39 int oldfd = IPC_GET_ARG1(*request);
[fcab7ef]40 int newfd = IPC_GET_ARG2(*request);
41 bool desc = IPC_GET_ARG3(*request);
[a35b458]42
[f77c1c9]43 int outfd = -1;
[b7fd2a0]44 errno_t rc = vfs_op_clone(oldfd, newfd, desc, &outfd);
[77f0a1d]45 async_answer_1(req_handle, rc, outfd);
[0d35511]46}
47
[77f0a1d]48static void vfs_in_fsprobe(cap_call_handle_t req_handle, ipc_call_t *request)
[d2c8533]49{
50 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request);
51 char *fs_name = NULL;
[a46e56b]52 cap_call_handle_t chandle;
[d2c8533]53 vfs_fs_probe_info_t info;
54 size_t len;
[b7fd2a0]55 errno_t rc;
[a35b458]56
[d2c8533]57 /*
[1b20da0]58 * Now we expect the client to send us data with the name of the file
[d2c8533]59 * system.
60 */
61 rc = async_data_write_accept((void **) &fs_name, true, 0,
62 FS_NAME_MAXLEN, 0, NULL);
63 if (rc != EOK) {
[77f0a1d]64 async_answer_0(req_handle, rc);
[d2c8533]65 return;
66 }
[a35b458]67
[d2c8533]68 rc = vfs_op_fsprobe(fs_name, service_id, &info);
[77f0a1d]69 async_answer_0(req_handle, rc);
[d2c8533]70 if (rc != EOK)
71 goto out;
[a35b458]72
[d2c8533]73 /* Now we should get a read request */
[a46e56b]74 if (!async_data_read_receive(&chandle, &len))
[d2c8533]75 goto out;
76
77 if (len > sizeof(info))
78 len = sizeof(info);
[a46e56b]79 (void) async_data_read_finalize(chandle, &info, len);
[d2c8533]80
81out:
82 free(fs_name);
83}
84
[77f0a1d]85static void vfs_in_fstypes(cap_call_handle_t req_handle, ipc_call_t *request)
[b14d9f9]86{
[a46e56b]87 cap_call_handle_t chandle;
[b14d9f9]88 size_t len;
89 vfs_fstypes_t fstypes;
[b7fd2a0]90 errno_t rc;
[b14d9f9]91
92 rc = vfs_get_fstypes(&fstypes);
93 if (rc != EOK) {
[77f0a1d]94 async_answer_0(req_handle, ENOMEM);
[b14d9f9]95 return;
96 }
97
98 /* Send size of the data */
[77f0a1d]99 async_answer_1(req_handle, EOK, fstypes.size);
[b14d9f9]100
101 /* Now we should get a read request */
[a46e56b]102 if (!async_data_read_receive(&chandle, &len))
[b14d9f9]103 goto out;
104
105 if (len > fstypes.size)
106 len = fstypes.size;
[a46e56b]107 (void) async_data_read_finalize(chandle, fstypes.buf, len);
[b14d9f9]108
109out:
110 vfs_fstypes_free(&fstypes);
111}
112
[77f0a1d]113static void vfs_in_mount(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]114{
115 int mpfd = IPC_GET_ARG1(*request);
[a35b458]116
[0d35511]117 /*
118 * We expect the library to do the device-name to device-handle
119 * translation for us, thus the device handle will arrive as ARG1
120 * in the request.
121 */
122 service_id_t service_id = (service_id_t) IPC_GET_ARG2(*request);
[a35b458]123
[0d35511]124 unsigned int flags = (unsigned int) IPC_GET_ARG3(*request);
125 unsigned int instance = IPC_GET_ARG4(*request);
[a35b458]126
[0d35511]127 char *opts = NULL;
128 char *fs_name = NULL;
[a35b458]129
[0d35511]130 /* Now we expect to receive the mount options. */
[b7fd2a0]131 errno_t rc = async_data_write_accept((void **) &opts, true, 0,
[0d35511]132 MAX_MNTOPTS_LEN, 0, NULL);
133 if (rc != EOK) {
[77f0a1d]134 async_answer_0(req_handle, rc);
[0d35511]135 return;
136 }
[a35b458]137
[7c3fb9b]138 /*
139 * Now we expect the client to send us data with the name of the file
[0d35511]140 * system.
141 */
142 rc = async_data_write_accept((void **) &fs_name, true, 0,
143 FS_NAME_MAXLEN, 0, NULL);
144 if (rc != EOK) {
145 free(opts);
[77f0a1d]146 async_answer_0(req_handle, rc);
[0d35511]147 return;
148 }
[a35b458]149
[0d35511]150 int outfd = 0;
151 rc = vfs_op_mount(mpfd, service_id, flags, instance, opts, fs_name,
[1433ecda]152 &outfd);
[77f0a1d]153 async_answer_1(req_handle, rc, outfd);
[a35b458]154
[0d35511]155 free(opts);
156 free(fs_name);
157}
158
[77f0a1d]159static void vfs_in_open(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]160{
161 int fd = IPC_GET_ARG1(*request);
[b19e892]162 int mode = IPC_GET_ARG2(*request);
[0d35511]163
[b7fd2a0]164 errno_t rc = vfs_op_open(fd, mode);
[77f0a1d]165 async_answer_0(req_handle, rc);
[0d35511]166}
167
[77f0a1d]168static void vfs_in_put(cap_call_handle_t req_handle, ipc_call_t *request)
[9c4cf0d]169{
170 int fd = IPC_GET_ARG1(*request);
[b7fd2a0]171 errno_t rc = vfs_op_put(fd);
[77f0a1d]172 async_answer_0(req_handle, rc);
[9c4cf0d]173}
174
[77f0a1d]175static void vfs_in_read(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]176{
177 int fd = IPC_GET_ARG1(*request);
[58898d1d]178 aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request),
179 IPC_GET_ARG3(*request));
[0d35511]180
181 size_t bytes = 0;
[b7fd2a0]182 errno_t rc = vfs_op_read(fd, pos, &bytes);
[77f0a1d]183 async_answer_1(req_handle, rc, bytes);
[0d35511]184}
185
[77f0a1d]186static void vfs_in_rename(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]187{
188 /* The common base directory. */
189 int basefd;
190 char *old = NULL;
191 char *new = NULL;
[b7fd2a0]192 errno_t rc;
[a35b458]193
[0d35511]194 basefd = IPC_GET_ARG1(*request);
[a35b458]195
[0d35511]196 /* Retrieve the old path. */
197 rc = async_data_write_accept((void **) &old, true, 0, 0, 0, NULL);
[ebf1011]198 if (rc != EOK)
[0d35511]199 goto out;
[a35b458]200
[0d35511]201 /* Retrieve the new path. */
202 rc = async_data_write_accept((void **) &new, true, 0, 0, 0, NULL);
[ebf1011]203 if (rc != EOK)
[0d35511]204 goto out;
[a35b458]205
[0d35511]206 size_t olen;
207 size_t nlen;
208 char *oldc = canonify(old, &olen);
209 char *newc = canonify(new, &nlen);
[a35b458]210
[0d35511]211 if ((!oldc) || (!newc)) {
212 rc = EINVAL;
213 goto out;
214 }
[a35b458]215
[0d35511]216 assert(oldc[olen] == '\0');
217 assert(newc[nlen] == '\0');
[a35b458]218
[0d35511]219 rc = vfs_op_rename(basefd, oldc, newc);
220
221out:
[77f0a1d]222 async_answer_0(req_handle, rc);
[0d35511]223
[ebf1011]224 if (old)
[0d35511]225 free(old);
[ebf1011]226 if (new)
[0d35511]227 free(new);
228}
229
[77f0a1d]230static void vfs_in_resize(cap_call_handle_t req_handle, ipc_call_t *request)
[67e881c]231{
232 int fd = IPC_GET_ARG1(*request);
233 int64_t size = MERGE_LOUP32(IPC_GET_ARG2(*request), IPC_GET_ARG3(*request));
[b7fd2a0]234 errno_t rc = vfs_op_resize(fd, size);
[77f0a1d]235 async_answer_0(req_handle, rc);
[67e881c]236}
237
[77f0a1d]238static void vfs_in_stat(cap_call_handle_t req_handle, ipc_call_t *request)
[fe91f66]239{
240 int fd = IPC_GET_ARG1(*request);
[b7fd2a0]241 errno_t rc = vfs_op_stat(fd);
[77f0a1d]242 async_answer_0(req_handle, rc);
[fe91f66]243}
244
[77f0a1d]245static void vfs_in_statfs(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]246{
247 int fd = (int) IPC_GET_ARG1(*request);
[a35b458]248
[b7fd2a0]249 errno_t rc = vfs_op_statfs(fd);
[77f0a1d]250 async_answer_0(req_handle, rc);
[0d35511]251}
252
[77f0a1d]253static void vfs_in_sync(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]254{
255 int fd = IPC_GET_ARG1(*request);
[b7fd2a0]256 errno_t rc = vfs_op_sync(fd);
[77f0a1d]257 async_answer_0(req_handle, rc);
[0d35511]258}
259
[77f0a1d]260static void vfs_in_unlink(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]261{
262 int parentfd = IPC_GET_ARG1(*request);
263 int expectfd = IPC_GET_ARG2(*request);
[a35b458]264
[0d35511]265 char *path;
[b7fd2a0]266 errno_t rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
[ebf1011]267 if (rc == EOK)
[79ea5af]268 rc = vfs_op_unlink(parentfd, expectfd, path);
[a35b458]269
[77f0a1d]270 async_answer_0(req_handle, rc);
[0d35511]271}
272
[77f0a1d]273static void vfs_in_unmount(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]274{
275 int mpfd = IPC_GET_ARG1(*request);
[b7fd2a0]276 errno_t rc = vfs_op_unmount(mpfd);
[77f0a1d]277 async_answer_0(req_handle, rc);
[0d35511]278}
279
[77f0a1d]280static void vfs_in_wait_handle(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]281{
282 bool high_fd = IPC_GET_ARG1(*request);
[6ad454f]283 int fd = -1;
[b7fd2a0]284 errno_t rc = vfs_op_wait_handle(high_fd, &fd);
[77f0a1d]285 async_answer_1(req_handle, rc, fd);
[0d35511]286}
287
[77f0a1d]288static void vfs_in_walk(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]289{
290 /*
291 * Parent is our relative root for file lookup.
292 * For defined flags, see <ipc/vfs.h>.
293 */
294 int parentfd = IPC_GET_ARG1(*request);
295 int flags = IPC_GET_ARG2(*request);
[a35b458]296
[0d35511]297 int fd = 0;
298 char *path;
[b7fd2a0]299 errno_t rc = async_data_write_accept((void **)&path, true, 0, 0, 0, NULL);
[0d35511]300 if (rc == EOK) {
301 rc = vfs_op_walk(parentfd, flags, path, &fd);
302 free(path);
303 }
[77f0a1d]304 async_answer_1(req_handle, rc, fd);
[0d35511]305}
306
[77f0a1d]307static void vfs_in_write(cap_call_handle_t req_handle, ipc_call_t *request)
[0d35511]308{
309 int fd = IPC_GET_ARG1(*request);
[58898d1d]310 aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request),
311 IPC_GET_ARG3(*request));
[0d35511]312
313 size_t bytes = 0;
[b7fd2a0]314 errno_t rc = vfs_op_write(fd, pos, &bytes);
[77f0a1d]315 async_answer_1(req_handle, rc, bytes);
[0d35511]316}
317
[a46e56b]318void vfs_connection(cap_call_handle_t icall_handle, ipc_call_t *icall, void *arg)
[0d35511]319{
320 bool cont = true;
[a35b458]321
[0d35511]322 /*
323 * The connection was opened via the IPC_CONNECT_ME_TO call.
324 * This call needs to be answered.
325 */
[a46e56b]326 async_answer_0(icall_handle, EOK);
[a35b458]327
[0d35511]328 while (cont) {
329 ipc_call_t call;
[a46e56b]330 cap_call_handle_t chandle = async_get_call(&call);
[a35b458]331
[0d35511]332 if (!IPC_GET_IMETHOD(call))
333 break;
[a35b458]334
[0d35511]335 switch (IPC_GET_IMETHOD(call)) {
336 case VFS_IN_CLONE:
[a46e56b]337 vfs_in_clone(chandle, &call);
[0d35511]338 break;
[d2c8533]339 case VFS_IN_FSPROBE:
[a46e56b]340 vfs_in_fsprobe(chandle, &call);
[d2c8533]341 break;
[b14d9f9]342 case VFS_IN_FSTYPES:
[a46e56b]343 vfs_in_fstypes(chandle, &call);
[b14d9f9]344 break;
[0d35511]345 case VFS_IN_MOUNT:
[a46e56b]346 vfs_in_mount(chandle, &call);
[0d35511]347 break;
[fe91f66]348 case VFS_IN_OPEN:
[a46e56b]349 vfs_in_open(chandle, &call);
[0d35511]350 break;
[9c4cf0d]351 case VFS_IN_PUT:
[a46e56b]352 vfs_in_put(chandle, &call);
[9c4cf0d]353 break;
[0d35511]354 case VFS_IN_READ:
[a46e56b]355 vfs_in_read(chandle, &call);
[0d35511]356 break;
357 case VFS_IN_REGISTER:
[a46e56b]358 vfs_register(chandle, &call);
[0d35511]359 cont = false;
360 break;
361 case VFS_IN_RENAME:
[a46e56b]362 vfs_in_rename(chandle, &call);
[0d35511]363 break;
[67e881c]364 case VFS_IN_RESIZE:
[a46e56b]365 vfs_in_resize(chandle, &call);
[67e881c]366 break;
[fe91f66]367 case VFS_IN_STAT:
[a46e56b]368 vfs_in_stat(chandle, &call);
[fe91f66]369 break;
[0d35511]370 case VFS_IN_STATFS:
[a46e56b]371 vfs_in_statfs(chandle, &call);
[0d35511]372 break;
373 case VFS_IN_SYNC:
[a46e56b]374 vfs_in_sync(chandle, &call);
[0d35511]375 break;
[fe91f66]376 case VFS_IN_UNLINK:
[a46e56b]377 vfs_in_unlink(chandle, &call);
[0d35511]378 break;
379 case VFS_IN_UNMOUNT:
[a46e56b]380 vfs_in_unmount(chandle, &call);
[0d35511]381 break;
382 case VFS_IN_WAIT_HANDLE:
[a46e56b]383 vfs_in_wait_handle(chandle, &call);
[0d35511]384 break;
385 case VFS_IN_WALK:
[a46e56b]386 vfs_in_walk(chandle, &call);
[0d35511]387 break;
388 case VFS_IN_WRITE:
[a46e56b]389 vfs_in_write(chandle, &call);
[0d35511]390 break;
391 default:
[a46e56b]392 async_answer_0(chandle, ENOTSUP);
[0d35511]393 break;
394 }
395 }
[a35b458]396
[0d35511]397 /*
398 * Open files for this client will be cleaned up when its last
399 * connection fibril terminates.
400 */
401}
Note: See TracBrowser for help on using the repository browser.