source: mainline/uspace/lib/fs/libfs.c@ 1d1bb0f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1d1bb0f was 9934f7d, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Add extra argument to async connection handlers that can be used for passing
information from async_connect_to_me() to the handler.

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