source: mainline/uspace/lib/fs/libfs.c@ e24e7b1

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

do not intermix low-level IPC methods with async framework methods

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