source: mainline/uspace/lib/fs/libfs.c@ 44c6091f

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

Put the libfs node upon its failure to link.

  • Property mode set to 100644
File size: 16.0 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);
[b946bf83]393 else
394 (void) ops->node_put(fn);
[ffa2c8ef]395 async_answer_0(rid, rc);
[2c448fb]396 } else {
[ed903174]397 aoff64_t size = ops->size_get(fn);
[ffa2c8ef]398 async_answer_5(rid, fs_handle,
[991f645]399 devmap_handle,
[b6035ba]400 ops->index_get(fn),
[ed903174]401 LOWER32(size),
402 UPPER32(size),
[b6035ba]403 ops->lnkcnt_get(fn));
[0daba212]404 (void) ops->node_put(fn);
[2c448fb]405 }
[1313ee9]406 } else
[ffa2c8ef]407 async_answer_0(rid, ENOSPC);
[1313ee9]408
[06901c6b]409 goto out;
[1313ee9]410 }
411
[ffa2c8ef]412 async_answer_0(rid, ENOENT);
[06901c6b]413 goto out;
[2c448fb]414 }
[1313ee9]415
[0daba212]416 if (par) {
417 rc = ops->node_put(par);
418 on_error(rc, goto out_with_answer);
419 }
[1313ee9]420
421 /* Descend one level */
[7b6d98b]422 par = cur;
[2c448fb]423 cur = tmp;
[06901c6b]424 tmp = NULL;
[2c448fb]425 }
[1313ee9]426
427 /* Handle miss: excessive components */
[0daba212]428 if (next <= last) {
429 bool has_children;
430 rc = ops->has_children(&has_children, cur);
431 on_error(rc, goto out_with_answer);
[1313ee9]432
[0daba212]433 if (has_children)
434 goto skip_miss;
[1313ee9]435
[a8e9ab8d]436 if (lflag & (L_CREATE | L_LINK)) {
[2c448fb]437 if (!ops->is_directory(cur)) {
[ffa2c8ef]438 async_answer_0(rid, ENOTDIR);
[06901c6b]439 goto out;
[2c448fb]440 }
[1313ee9]441
442 /* Collect next component */
[c9f6e49f]443 len = 0;
[2c448fb]444 while (next <= last) {
445 if (ops->plb_get_char(next) == '/') {
[1313ee9]446 /* More than one component */
[ffa2c8ef]447 async_answer_0(rid, ENOENT);
[06901c6b]448 goto out;
[2c448fb]449 }
[1313ee9]450
[2c448fb]451 if (len + 1 == NAME_MAX) {
[1313ee9]452 /* Component length overflow */
[ffa2c8ef]453 async_answer_0(rid, ENAMETOOLONG);
[06901c6b]454 goto out;
[2c448fb]455 }
[1313ee9]456
[2c448fb]457 component[len++] = ops->plb_get_char(next);
[1313ee9]458 /* Process next character */
459 next++;
[2c448fb]460 }
[1313ee9]461
[2c448fb]462 assert(len);
463 component[len] = '\0';
[1313ee9]464
[b6035ba]465 fs_node_t *fn;
[a8e9ab8d]466 if (lflag & L_CREATE)
[991f645]467 rc = ops->create(&fn, devmap_handle, lflag);
[a8e9ab8d]468 else
[991f645]469 rc = ops->node_get(&fn, devmap_handle, index);
[0daba212]470 on_error(rc, goto out_with_answer);
[1313ee9]471
[b6035ba]472 if (fn) {
473 rc = ops->link(cur, fn, component);
[0013b9ce]474 if (rc != EOK) {
[a8e9ab8d]475 if (lflag & L_CREATE)
[0daba212]476 (void) ops->destroy(fn);
[b946bf83]477 else
478 (void) ops->node_put(fn);
[ffa2c8ef]479 async_answer_0(rid, rc);
[2c448fb]480 } else {
[ed903174]481 aoff64_t size = ops->size_get(fn);
[ffa2c8ef]482 async_answer_5(rid, fs_handle,
[991f645]483 devmap_handle,
[b6035ba]484 ops->index_get(fn),
[ed903174]485 LOWER32(size),
486 UPPER32(size),
[b6035ba]487 ops->lnkcnt_get(fn));
[0daba212]488 (void) ops->node_put(fn);
[2c448fb]489 }
[1313ee9]490 } else
[ffa2c8ef]491 async_answer_0(rid, ENOSPC);
[1313ee9]492
[06901c6b]493 goto out;
[2c448fb]494 }
[1313ee9]495
[ffa2c8ef]496 async_answer_0(rid, ENOENT);
[06901c6b]497 goto out;
[2c448fb]498 }
[1313ee9]499
[0daba212]500skip_miss:
[1313ee9]501
502 /* Handle hit */
[a8e9ab8d]503 if (lflag & L_UNLINK) {
[1313ee9]504 unsigned int old_lnkcnt = ops->lnkcnt_get(cur);
[0daba212]505 rc = ops->unlink(par, cur, component);
[ed903174]506
507 if (rc == EOK) {
508 aoff64_t size = ops->size_get(cur);
[ffa2c8ef]509 async_answer_5(rid, fs_handle, devmap_handle,
[ed903174]510 ops->index_get(cur), LOWER32(size), UPPER32(size),
511 old_lnkcnt);
512 } else
[ffa2c8ef]513 async_answer_0(rid, rc);
[ed903174]514
[06901c6b]515 goto out;
[2c448fb]516 }
[1313ee9]517
[a8e9ab8d]518 if (((lflag & (L_CREATE | L_EXCLUSIVE)) == (L_CREATE | L_EXCLUSIVE)) ||
519 (lflag & L_LINK)) {
[ffa2c8ef]520 async_answer_0(rid, EEXIST);
[06901c6b]521 goto out;
[2c448fb]522 }
[1313ee9]523
[2c448fb]524 if ((lflag & L_FILE) && (ops->is_directory(cur))) {
[ffa2c8ef]525 async_answer_0(rid, EISDIR);
[06901c6b]526 goto out;
[2c448fb]527 }
[1313ee9]528
[2c448fb]529 if ((lflag & L_DIRECTORY) && (ops->is_file(cur))) {
[ffa2c8ef]530 async_answer_0(rid, ENOTDIR);
[06901c6b]531 goto out;
[2c448fb]532 }
[f7376cbf]533
534 if ((lflag & L_ROOT) && par) {
[ffa2c8ef]535 async_answer_0(rid, EINVAL);
[f7376cbf]536 goto out;
537 }
[1313ee9]538
[0daba212]539out_with_answer:
[1313ee9]540
[0daba212]541 if (rc == EOK) {
[1313ee9]542 if (lflag & L_OPEN)
543 rc = ops->node_open(cur);
544
[ed903174]545 if (rc == EOK) {
546 aoff64_t size = ops->size_get(cur);
[ffa2c8ef]547 async_answer_5(rid, fs_handle, devmap_handle,
[ed903174]548 ops->index_get(cur), LOWER32(size), UPPER32(size),
549 ops->lnkcnt_get(cur));
550 } else
[ffa2c8ef]551 async_answer_0(rid, rc);
[ed903174]552
[1313ee9]553 } else
[ffa2c8ef]554 async_answer_0(rid, rc);
[1313ee9]555
[06901c6b]556out:
[1313ee9]557
[06901c6b]558 if (par)
[0daba212]559 (void) ops->node_put(par);
[1313ee9]560
[06901c6b]561 if (cur)
[0daba212]562 (void) ops->node_put(cur);
[1313ee9]563
[06901c6b]564 if (tmp)
[0daba212]565 (void) ops->node_put(tmp);
[2c448fb]566}
567
[75160a6]568void libfs_stat(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
569 ipc_call_t *request)
570{
[991f645]571 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
[75160a6]572 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
[1313ee9]573
[0daba212]574 fs_node_t *fn;
[991f645]575 int rc = ops->node_get(&fn, devmap_handle, index);
[0daba212]576 on_error(rc, answer_and_return(rid, rc));
[1313ee9]577
[75160a6]578 ipc_callid_t callid;
579 size_t size;
[1313ee9]580 if ((!async_data_read_receive(&callid, &size)) ||
581 (size != sizeof(struct stat))) {
582 ops->node_put(fn);
[ffa2c8ef]583 async_answer_0(callid, EINVAL);
584 async_answer_0(rid, EINVAL);
[75160a6]585 return;
586 }
[1313ee9]587
[0143f72]588 struct stat stat;
589 memset(&stat, 0, sizeof(struct stat));
[75160a6]590
[0143f72]591 stat.fs_handle = fs_handle;
[991f645]592 stat.devmap_handle = devmap_handle;
[0143f72]593 stat.index = index;
[1313ee9]594 stat.lnkcnt = ops->lnkcnt_get(fn);
[0143f72]595 stat.is_file = ops->is_file(fn);
[1313ee9]596 stat.is_directory = ops->is_directory(fn);
[0143f72]597 stat.size = ops->size_get(fn);
[1313ee9]598 stat.device = ops->device_get(fn);
599
600 ops->node_put(fn);
601
[0da4e41]602 async_data_read_finalize(callid, &stat, sizeof(struct stat));
[ffa2c8ef]603 async_answer_0(rid, EOK);
[75160a6]604}
605
[595edf5]606/** Open VFS triplet.
607 *
[1313ee9]608 * @param ops libfs operations structure with function pointers to
609 * file system implementation
610 * @param rid Request ID of the VFS_OUT_OPEN_NODE request.
611 * @param request VFS_OUT_OPEN_NODE request data itself.
[595edf5]612 *
613 */
614void libfs_open_node(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
615 ipc_call_t *request)
616{
[991f645]617 devmap_handle_t devmap_handle = IPC_GET_ARG1(*request);
[595edf5]618 fs_index_t index = IPC_GET_ARG2(*request);
619
[ed903174]620 fs_node_t *fn;
[991f645]621 int rc = ops->node_get(&fn, devmap_handle, index);
[0daba212]622 on_error(rc, answer_and_return(rid, rc));
[595edf5]623
[0daba212]624 if (fn == NULL) {
[ffa2c8ef]625 async_answer_0(rid, ENOENT);
[595edf5]626 return;
627 }
628
[1313ee9]629 rc = ops->node_open(fn);
[ed903174]630 aoff64_t size = ops->size_get(fn);
[ffa2c8ef]631 async_answer_4(rid, rc, LOWER32(size), UPPER32(size), ops->lnkcnt_get(fn),
[2e983c7]632 (ops->is_file(fn) ? L_FILE : 0) | (ops->is_directory(fn) ? L_DIRECTORY : 0));
[595edf5]633
[0daba212]634 (void) ops->node_put(fn);
[595edf5]635}
636
[74303b6]637/** @}
638 */
Note: See TracBrowser for help on using the repository browser.