source: mainline/uspace/srv/vfs/vfs_ipc.c@ 3648e184

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

Streamline vfs_op_fstat()

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