source: mainline/uspace/lib/fs/libfs.c@ 96b02eb9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 96b02eb9 was 96b02eb9, checked in by Martin Decky <martin@…>, 15 years ago

more unification of basic types

  • use sysarg_t and native_t (unsigned and signed variant) in both kernel and uspace
  • remove ipcarg_t in favour of sysarg_t

(no change in functionality)

  • Property mode set to 100644
File size: 15.9 KB
RevLine 
[74303b6]1/*
[1313ee9]2 * Copyright (c) 2009 Jakub Jermar
[74303b6]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
[1313ee9]29/** @addtogroup libfs
[74303b6]30 * @{
[1313ee9]31 */
[74303b6]32/**
33 * @file
[1313ee9]34 * Glue code which is common to all FS implementations.
[74303b6]35 */
36
[1313ee9]37#include "libfs.h"
[efd4a72]38#include "../../srv/vfs/vfs.h"
[ed903174]39#include <macros.h>
[efd4a72]40#include <errno.h>
41#include <async.h>
42#include <ipc/ipc.h>
43#include <as.h>
[2c448fb]44#include <assert.h>
45#include <dirent.h>
[595edf5]46#include <mem.h>
[75160a6]47#include <sys/stat.h>
[efd4a72]48
[0daba212]49#define on_error(rc, action) \
50 do { \
51 if ((rc) != EOK) \
52 action; \
53 } while (0)
54
55#define combine_rc(rc1, rc2) \
56 ((rc1) == EOK ? (rc2) : (rc1))
57
58#define answer_and_return(rid, rc) \
59 do { \
60 ipc_answer_0((rid), (rc)); \
61 return; \
62 } while (0)
63
[efd4a72]64/** Register file system server.
65 *
66 * This function abstracts away the tedious registration protocol from
67 * file system implementations and lets them to reuse this registration glue
68 * code.
69 *
[1313ee9]70 * @param vfs_phone Open phone for communication with VFS.
71 * @param reg File system registration structure. It will be
72 * initialized by this function.
73 * @param info VFS info structure supplied by the file system
74 * implementation.
75 * @param conn Connection fibril for handling all calls originating in
76 * VFS.
77 *
78 * @return EOK on success or a non-zero error code on errror.
[efd4a72]79 *
80 */
81int fs_register(int vfs_phone, fs_reg_t *reg, vfs_info_t *info,
82 async_client_conn_t conn)
83{
84 /*
85 * Tell VFS that we are here and want to get registered.
86 * We use the async framework because VFS will answer the request
87 * out-of-order, when it knows that the operation succeeded or failed.
88 */
89 ipc_call_t answer;
[4198f9c3]90 aid_t req = async_send_0(vfs_phone, VFS_IN_REGISTER, &answer);
[1313ee9]91
[efd4a72]92 /*
93 * Send our VFS info structure to VFS.
94 */
[0da4e41]95 int rc = async_data_write_start(vfs_phone, info, sizeof(*info));
[efd4a72]96 if (rc != EOK) {
97 async_wait_for(req, NULL);
98 return rc;
99 }
[1313ee9]100
[efd4a72]101 /*
102 * Ask VFS for callback connection.
103 */
104 ipc_connect_to_me(vfs_phone, 0, 0, 0, &reg->vfs_phonehash);
[1313ee9]105
[efd4a72]106 /*
107 * Allocate piece of address space for PLB.
108 */
109 reg->plb_ro = as_get_mappable_page(PLB_SIZE);
110 if (!reg->plb_ro) {
111 async_wait_for(req, NULL);
112 return ENOMEM;
113 }
[1313ee9]114
[efd4a72]115 /*
116 * Request sharing the Path Lookup Buffer with VFS.
117 */
[0da4e41]118 rc = async_share_in_start_0_0(vfs_phone, reg->plb_ro, PLB_SIZE);
[efd4a72]119 if (rc) {
120 async_wait_for(req, NULL);
121 return rc;
122 }
123
124 /*
[4198f9c3]125 * Pick up the answer for the request to the VFS_IN_REQUEST call.
[efd4a72]126 */
127 async_wait_for(req, NULL);
128 reg->fs_handle = (int) IPC_GET_ARG1(answer);
129
130 /*
131 * Create a connection fibril to handle the callback connection.
132 */
133 async_new_connection(reg->vfs_phonehash, 0, NULL, conn);
134
135 /*
136 * Tell the async framework that other connections are to be handled by
137 * the same connection fibril as well.
138 */
139 async_set_client_connection(conn);
[1313ee9]140
[efd4a72]141 return IPC_GET_RETVAL(answer);
142}
[74303b6]143
[83937ccd]144void fs_node_initialize(fs_node_t *fn)
145{
146 memset(fn, 0, sizeof(fs_node_t));
147}
148
[16d17ca]149void libfs_mount(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
150 ipc_call_t *request)
[83937ccd]151{
[991f645]152 devmap_handle_t mp_devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
[55982d6]153 fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*request);
154 fs_handle_t mr_fs_handle = (fs_handle_t) IPC_GET_ARG3(*request);
[991f645]155 devmap_handle_t mr_devmap_handle = (devmap_handle_t) IPC_GET_ARG4(*request);
[83937ccd]156 int res;
[96b02eb9]157 sysarg_t rc;
[1313ee9]158
[83937ccd]159 ipc_call_t call;
160 ipc_callid_t callid;
[1313ee9]161
162 /* Accept the phone */
[83937ccd]163 callid = async_get_call(&call);
[b4cbef1]164 int mountee_phone = (int) IPC_GET_ARG1(call);
[83937ccd]165 if ((IPC_GET_METHOD(call) != IPC_M_CONNECTION_CLONE) ||
[1313ee9]166 (mountee_phone < 0)) {
[83937ccd]167 ipc_answer_0(callid, EINVAL);
168 ipc_answer_0(rid, EINVAL);
169 return;
170 }
[1313ee9]171
172 /* Acknowledge the mountee_phone */
173 ipc_answer_0(callid, EOK);
[83937ccd]174
[0daba212]175 fs_node_t *fn;
[991f645]176 res = ops->node_get(&fn, mp_devmap_handle, mp_fs_index);
[1313ee9]177 if ((res != EOK) || (!fn)) {
[83937ccd]178 ipc_hangup(mountee_phone);
[eda925a]179 async_data_write_void(combine_rc(res, ENOENT));
[0daba212]180 ipc_answer_0(rid, combine_rc(res, ENOENT));
[83937ccd]181 return;
182 }
[1313ee9]183
[83937ccd]184 if (fn->mp_data.mp_active) {
185 ipc_hangup(mountee_phone);
[0daba212]186 (void) ops->node_put(fn);
[eda925a]187 async_data_write_void(EBUSY);
[83937ccd]188 ipc_answer_0(rid, EBUSY);
189 return;
190 }
[1313ee9]191
[83937ccd]192 rc = async_req_0_0(mountee_phone, IPC_M_CONNECT_ME);
[0daba212]193 if (rc != EOK) {
[83937ccd]194 ipc_hangup(mountee_phone);
[0daba212]195 (void) ops->node_put(fn);
[eda925a]196 async_data_write_void(rc);
[83937ccd]197 ipc_answer_0(rid, rc);
198 return;
199 }
200
201 ipc_call_t answer;
[eda925a]202 rc = async_data_write_forward_1_1(mountee_phone, VFS_OUT_MOUNTED,
[991f645]203 mr_devmap_handle, &answer);
[83937ccd]204
205 if (rc == EOK) {
206 fn->mp_data.mp_active = true;
207 fn->mp_data.fs_handle = mr_fs_handle;
[991f645]208 fn->mp_data.devmap_handle = mr_devmap_handle;
[83937ccd]209 fn->mp_data.phone = mountee_phone;
210 }
[1313ee9]211
[83937ccd]212 /*
213 * Do not release the FS node so that it stays in memory.
214 */
[0442c02]215 ipc_answer_3(rid, rc, IPC_GET_ARG1(answer), IPC_GET_ARG2(answer),
216 IPC_GET_ARG3(answer));
[83937ccd]217}
218
[3c11713]219void libfs_unmount(libfs_ops_t *ops, ipc_callid_t rid, ipc_call_t *request)
220{
[991f645]221 devmap_handle_t mp_devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
[c888102]222 fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*request);
223 fs_node_t *fn;
224 int res;
225
[991f645]226 res = ops->node_get(&fn, mp_devmap_handle, mp_fs_index);
[c888102]227 if ((res != EOK) || (!fn)) {
228 ipc_answer_0(rid, combine_rc(res, ENOENT));
229 return;
230 }
231
232 /*
233 * We are clearly expecting to find the mount point active.
234 */
235 if (!fn->mp_data.mp_active) {
236 (void) ops->node_put(fn);
237 ipc_answer_0(rid, EINVAL);
238 return;
239 }
240
241 /*
242 * Tell the mounted file system to unmount.
243 */
244 res = async_req_1_0(fn->mp_data.phone, VFS_OUT_UNMOUNTED,
[991f645]245 fn->mp_data.devmap_handle);
[c888102]246
247 /*
248 * If everything went well, perform the clean-up on our side.
249 */
250 if (res == EOK) {
251 ipc_hangup(fn->mp_data.phone);
252 fn->mp_data.mp_active = false;
253 fn->mp_data.fs_handle = 0;
[991f645]254 fn->mp_data.devmap_handle = 0;
[c888102]255 fn->mp_data.phone = 0;
256 /* Drop the reference created in libfs_mount(). */
257 (void) ops->node_put(fn);
258 }
259
260 (void) ops->node_put(fn);
261 ipc_answer_0(rid, res);
[3c11713]262}
263
[1e50f81]264/** Lookup VFS triplet by name in the file system name space.
[9bb85f3]265 *
266 * The path passed in the PLB must be in the canonical file system path format
267 * as returned by the canonify() function.
[1e50f81]268 *
[595edf5]269 * @param ops libfs operations structure with function pointers to
270 * file system implementation
271 * @param fs_handle File system handle of the file system where to perform
272 * the lookup.
[4198f9c3]273 * @param rid Request ID of the VFS_OUT_LOOKUP request.
274 * @param request VFS_OUT_LOOKUP request data itself.
[595edf5]275 *
[1e50f81]276 */
[f2ec8c8]277void libfs_lookup(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
[2c448fb]278 ipc_call_t *request)
279{
[1313ee9]280 unsigned int first = IPC_GET_ARG1(*request);
281 unsigned int last = IPC_GET_ARG2(*request);
282 unsigned int next = first;
[991f645]283 devmap_handle_t devmap_handle = IPC_GET_ARG3(*request);
[2c448fb]284 int lflag = IPC_GET_ARG4(*request);
[1313ee9]285 fs_index_t index = IPC_GET_ARG5(*request);
[c9f6e49f]286 char component[NAME_MAX + 1];
287 int len;
[0daba212]288 int rc;
[1313ee9]289
[2c448fb]290 if (last < next)
291 last += PLB_SIZE;
[1313ee9]292
[b6035ba]293 fs_node_t *par = NULL;
[0daba212]294 fs_node_t *cur = NULL;
[b6035ba]295 fs_node_t *tmp = NULL;
[1313ee9]296
[991f645]297 rc = ops->root_get(&cur, devmap_handle);
[0daba212]298 on_error(rc, goto out_with_answer);
[1313ee9]299
[83937ccd]300 if (cur->mp_data.mp_active) {
[4198f9c3]301 ipc_forward_slow(rid, cur->mp_data.phone, VFS_OUT_LOOKUP,
[991f645]302 next, last, cur->mp_data.devmap_handle, lflag, index,
[83937ccd]303 IPC_FF_ROUTE_FROM_ME);
[0daba212]304 (void) ops->node_put(cur);
[83937ccd]305 return;
306 }
[1313ee9]307
308 /* Eat slash */
[2c448fb]309 if (ops->plb_get_char(next) == '/')
[1313ee9]310 next++;
[2c448fb]311
[0daba212]312 while (next <= last) {
313 bool has_children;
[1313ee9]314
[0daba212]315 rc = ops->has_children(&has_children, cur);
316 on_error(rc, goto out_with_answer);
317 if (!has_children)
318 break;
[1313ee9]319
320 /* Collect the component */
[c9f6e49f]321 len = 0;
[1313ee9]322 while ((next <= last) && (ops->plb_get_char(next) != '/')) {
[2c448fb]323 if (len + 1 == NAME_MAX) {
[1313ee9]324 /* Component length overflow */
[2c448fb]325 ipc_answer_0(rid, ENAMETOOLONG);
[06901c6b]326 goto out;
[2c448fb]327 }
328 component[len++] = ops->plb_get_char(next);
[1313ee9]329 /* Process next character */
330 next++;
[2c448fb]331 }
[1313ee9]332
[2c448fb]333 assert(len);
334 component[len] = '\0';
[1313ee9]335 /* Eat slash */
336 next++;
337
338 /* Match the component */
[0daba212]339 rc = ops->match(&tmp, cur, component);
340 on_error(rc, goto out_with_answer);
[1313ee9]341
[4b995b92]342 /*
343 * If the matching component is a mount point, there are two
344 * legitimate semantics of the lookup operation. The first is
345 * the commonly used one in which the lookup crosses each mount
346 * point into the mounted file system. The second semantics is
347 * used mostly during unmount() and differs from the first one
348 * only in that the last mount point in the looked up path,
349 * which is also its last component, is not crossed.
350 */
351
352 if ((tmp) && (tmp->mp_data.mp_active) &&
[f7376cbf]353 (!(lflag & L_MP) || (next <= last))) {
[83937ccd]354 if (next > last)
355 next = last = first;
356 else
357 next--;
[1313ee9]358
[4198f9c3]359 ipc_forward_slow(rid, tmp->mp_data.phone,
[991f645]360 VFS_OUT_LOOKUP, next, last, tmp->mp_data.devmap_handle,
[4198f9c3]361 lflag, index, IPC_FF_ROUTE_FROM_ME);
[0daba212]362 (void) ops->node_put(cur);
363 (void) ops->node_put(tmp);
[83937ccd]364 if (par)
[0daba212]365 (void) ops->node_put(par);
[83937ccd]366 return;
367 }
[1313ee9]368
369 /* Handle miss: match amongst siblings */
[2c448fb]370 if (!tmp) {
[a8e9ab8d]371 if (next <= last) {
[1313ee9]372 /* There are unprocessed components */
[a8e9ab8d]373 ipc_answer_0(rid, ENOENT);
[06901c6b]374 goto out;
[a8e9ab8d]375 }
[1313ee9]376
377 /* Miss in the last component */
378 if (lflag & (L_CREATE | L_LINK)) {
379 /* Request to create a new link */
[2c448fb]380 if (!ops->is_directory(cur)) {
381 ipc_answer_0(rid, ENOTDIR);
[06901c6b]382 goto out;
[a8e9ab8d]383 }
[1313ee9]384
[b6035ba]385 fs_node_t *fn;
[a8e9ab8d]386 if (lflag & L_CREATE)
[991f645]387 rc = ops->create(&fn, devmap_handle,
[0daba212]388 lflag);
[a8e9ab8d]389 else
[991f645]390 rc = ops->node_get(&fn, devmap_handle,
[34f62f8]391 index);
[0daba212]392 on_error(rc, goto out_with_answer);
[1313ee9]393
[b6035ba]394 if (fn) {
395 rc = ops->link(cur, fn, component);
[0013b9ce]396 if (rc != EOK) {
[0daba212]397 if (lflag & L_CREATE)
398 (void) ops->destroy(fn);
[0013b9ce]399 ipc_answer_0(rid, rc);
[2c448fb]400 } else {
[ed903174]401 aoff64_t size = ops->size_get(fn);
402 ipc_answer_5(rid, fs_handle,
[991f645]403 devmap_handle,
[b6035ba]404 ops->index_get(fn),
[ed903174]405 LOWER32(size),
406 UPPER32(size),
[b6035ba]407 ops->lnkcnt_get(fn));
[0daba212]408 (void) ops->node_put(fn);
[2c448fb]409 }
[1313ee9]410 } else
[2c448fb]411 ipc_answer_0(rid, ENOSPC);
[1313ee9]412
[06901c6b]413 goto out;
[1313ee9]414 }
415
[2c448fb]416 ipc_answer_0(rid, ENOENT);
[06901c6b]417 goto out;
[2c448fb]418 }
[1313ee9]419
[0daba212]420 if (par) {
421 rc = ops->node_put(par);
422 on_error(rc, goto out_with_answer);
423 }
[1313ee9]424
425 /* Descend one level */
[7b6d98b]426 par = cur;
[2c448fb]427 cur = tmp;
[06901c6b]428 tmp = NULL;
[2c448fb]429 }
[1313ee9]430
431 /* Handle miss: excessive components */
[0daba212]432 if (next <= last) {
433 bool has_children;
434 rc = ops->has_children(&has_children, cur);
435 on_error(rc, goto out_with_answer);
[1313ee9]436
[0daba212]437 if (has_children)
438 goto skip_miss;
[1313ee9]439
[a8e9ab8d]440 if (lflag & (L_CREATE | L_LINK)) {
[2c448fb]441 if (!ops->is_directory(cur)) {
442 ipc_answer_0(rid, ENOTDIR);
[06901c6b]443 goto out;
[2c448fb]444 }
[1313ee9]445
446 /* Collect next component */
[c9f6e49f]447 len = 0;
[2c448fb]448 while (next <= last) {
449 if (ops->plb_get_char(next) == '/') {
[1313ee9]450 /* More than one component */
[2c448fb]451 ipc_answer_0(rid, ENOENT);
[06901c6b]452 goto out;
[2c448fb]453 }
[1313ee9]454
[2c448fb]455 if (len + 1 == NAME_MAX) {
[1313ee9]456 /* Component length overflow */
[2c448fb]457 ipc_answer_0(rid, ENAMETOOLONG);
[06901c6b]458 goto out;
[2c448fb]459 }
[1313ee9]460
[2c448fb]461 component[len++] = ops->plb_get_char(next);
[1313ee9]462 /* Process next character */
463 next++;
[2c448fb]464 }
[1313ee9]465
[2c448fb]466 assert(len);
467 component[len] = '\0';
[1313ee9]468
[b6035ba]469 fs_node_t *fn;
[a8e9ab8d]470 if (lflag & L_CREATE)
[991f645]471 rc = ops->create(&fn, devmap_handle, lflag);
[a8e9ab8d]472 else
[991f645]473 rc = ops->node_get(&fn, devmap_handle, index);
[0daba212]474 on_error(rc, goto out_with_answer);
[1313ee9]475
[b6035ba]476 if (fn) {
477 rc = ops->link(cur, fn, component);
[0013b9ce]478 if (rc != EOK) {
[a8e9ab8d]479 if (lflag & L_CREATE)
[0daba212]480 (void) ops->destroy(fn);
[0013b9ce]481 ipc_answer_0(rid, rc);
[2c448fb]482 } else {
[ed903174]483 aoff64_t size = ops->size_get(fn);
484 ipc_answer_5(rid, fs_handle,
[991f645]485 devmap_handle,
[b6035ba]486 ops->index_get(fn),
[ed903174]487 LOWER32(size),
488 UPPER32(size),
[b6035ba]489 ops->lnkcnt_get(fn));
[0daba212]490 (void) ops->node_put(fn);
[2c448fb]491 }
[1313ee9]492 } else
[2c448fb]493 ipc_answer_0(rid, ENOSPC);
[1313ee9]494
[06901c6b]495 goto out;
[2c448fb]496 }
[1313ee9]497
[2c448fb]498 ipc_answer_0(rid, ENOENT);
[06901c6b]499 goto out;
[2c448fb]500 }
[1313ee9]501
[0daba212]502skip_miss:
[1313ee9]503
504 /* Handle hit */
[a8e9ab8d]505 if (lflag & L_UNLINK) {
[1313ee9]506 unsigned int old_lnkcnt = ops->lnkcnt_get(cur);
[0daba212]507 rc = ops->unlink(par, cur, component);
[ed903174]508
509 if (rc == EOK) {
510 aoff64_t size = ops->size_get(cur);
[991f645]511 ipc_answer_5(rid, fs_handle, devmap_handle,
[ed903174]512 ops->index_get(cur), LOWER32(size), UPPER32(size),
513 old_lnkcnt);
514 } else
515 ipc_answer_0(rid, rc);
516
[06901c6b]517 goto out;
[2c448fb]518 }
[1313ee9]519
[a8e9ab8d]520 if (((lflag & (L_CREATE | L_EXCLUSIVE)) == (L_CREATE | L_EXCLUSIVE)) ||
521 (lflag & L_LINK)) {
[2c448fb]522 ipc_answer_0(rid, EEXIST);
[06901c6b]523 goto out;
[2c448fb]524 }
[1313ee9]525
[2c448fb]526 if ((lflag & L_FILE) && (ops->is_directory(cur))) {
527 ipc_answer_0(rid, EISDIR);
[06901c6b]528 goto out;
[2c448fb]529 }
[1313ee9]530
[2c448fb]531 if ((lflag & L_DIRECTORY) && (ops->is_file(cur))) {
532 ipc_answer_0(rid, ENOTDIR);
[06901c6b]533 goto out;
[2c448fb]534 }
[f7376cbf]535
536 if ((lflag & L_ROOT) && par) {
537 ipc_answer_0(rid, EINVAL);
538 goto out;
539 }
[1313ee9]540
[0daba212]541out_with_answer:
[1313ee9]542
[0daba212]543 if (rc == EOK) {
[1313ee9]544 if (lflag & L_OPEN)
545 rc = ops->node_open(cur);
546
[ed903174]547 if (rc == EOK) {
548 aoff64_t size = ops->size_get(cur);
[991f645]549 ipc_answer_5(rid, fs_handle, devmap_handle,
[ed903174]550 ops->index_get(cur), LOWER32(size), UPPER32(size),
551 ops->lnkcnt_get(cur));
552 } else
553 ipc_answer_0(rid, rc);
554
[1313ee9]555 } else
[0daba212]556 ipc_answer_0(rid, rc);
[1313ee9]557
[06901c6b]558out:
[1313ee9]559
[06901c6b]560 if (par)
[0daba212]561 (void) ops->node_put(par);
[1313ee9]562
[06901c6b]563 if (cur)
[0daba212]564 (void) ops->node_put(cur);
[1313ee9]565
[06901c6b]566 if (tmp)
[0daba212]567 (void) ops->node_put(tmp);
[2c448fb]568}
569
[75160a6]570void libfs_stat(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
571 ipc_call_t *request)
572{
[991f645]573 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
[75160a6]574 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
[1313ee9]575
[0daba212]576 fs_node_t *fn;
[991f645]577 int rc = ops->node_get(&fn, devmap_handle, index);
[0daba212]578 on_error(rc, answer_and_return(rid, rc));
[1313ee9]579
[75160a6]580 ipc_callid_t callid;
581 size_t size;
[1313ee9]582 if ((!async_data_read_receive(&callid, &size)) ||
583 (size != sizeof(struct stat))) {
584 ops->node_put(fn);
[75160a6]585 ipc_answer_0(callid, EINVAL);
586 ipc_answer_0(rid, EINVAL);
587 return;
588 }
[1313ee9]589
[0143f72]590 struct stat stat;
591 memset(&stat, 0, sizeof(struct stat));
[75160a6]592
[0143f72]593 stat.fs_handle = fs_handle;
[991f645]594 stat.devmap_handle = devmap_handle;
[0143f72]595 stat.index = index;
[1313ee9]596 stat.lnkcnt = ops->lnkcnt_get(fn);
[0143f72]597 stat.is_file = ops->is_file(fn);
[1313ee9]598 stat.is_directory = ops->is_directory(fn);
[0143f72]599 stat.size = ops->size_get(fn);
[1313ee9]600 stat.device = ops->device_get(fn);
601
602 ops->node_put(fn);
603
[0da4e41]604 async_data_read_finalize(callid, &stat, sizeof(struct stat));
[75160a6]605 ipc_answer_0(rid, EOK);
606}
607
[595edf5]608/** Open VFS triplet.
609 *
[1313ee9]610 * @param ops libfs operations structure with function pointers to
611 * file system implementation
612 * @param rid Request ID of the VFS_OUT_OPEN_NODE request.
613 * @param request VFS_OUT_OPEN_NODE request data itself.
[595edf5]614 *
615 */
616void libfs_open_node(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
617 ipc_call_t *request)
618{
[991f645]619 devmap_handle_t devmap_handle = IPC_GET_ARG1(*request);
[595edf5]620 fs_index_t index = IPC_GET_ARG2(*request);
621
[ed903174]622 fs_node_t *fn;
[991f645]623 int rc = ops->node_get(&fn, devmap_handle, index);
[0daba212]624 on_error(rc, answer_and_return(rid, rc));
[595edf5]625
[0daba212]626 if (fn == NULL) {
[595edf5]627 ipc_answer_0(rid, ENOENT);
628 return;
629 }
630
[1313ee9]631 rc = ops->node_open(fn);
[ed903174]632 aoff64_t size = ops->size_get(fn);
633 ipc_answer_4(rid, rc, LOWER32(size), UPPER32(size), ops->lnkcnt_get(fn),
[2e983c7]634 (ops->is_file(fn) ? L_FILE : 0) | (ops->is_directory(fn) ? L_DIRECTORY : 0));
[595edf5]635
[0daba212]636 (void) ops->node_put(fn);
[595edf5]637}
638
[74303b6]639/** @}
640 */
Note: See TracBrowser for help on using the repository browser.