source: mainline/uspace/lib/libfs/libfs.c@ eda925a

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

improve naming conventions:
merge async_data_receive() and async_string_receive() into async_data_write_accept()
rename async_data_void() to async_data_write_void()
rename async_data_forward_fast() to async_data_write_forward_fast()
rename async_data_forward_n_m to async_data_write_forward_n_m

  • Property mode set to 100644
File size: 15.5 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"
39#include <errno.h>
40#include <async.h>
41#include <ipc/ipc.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 { \
59 ipc_answer_0((rid), (rc)); \
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 */
103 ipc_connect_to_me(vfs_phone, 0, 0, 0, &reg->vfs_phonehash);
[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 * Create a connection fibril to handle the callback connection.
131 */
132 async_new_connection(reg->vfs_phonehash, 0, NULL, conn);
133
134 /*
135 * Tell the async framework that other connections are to be handled by
136 * the same connection fibril as well.
137 */
138 async_set_client_connection(conn);
[1313ee9]139
[efd4a72]140 return IPC_GET_RETVAL(answer);
141}
[74303b6]142
[83937ccd]143void fs_node_initialize(fs_node_t *fn)
144{
145 memset(fn, 0, sizeof(fs_node_t));
146}
147
[16d17ca]148void libfs_mount(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
149 ipc_call_t *request)
[83937ccd]150{
[55982d6]151 dev_handle_t mp_dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
152 fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*request);
153 fs_handle_t mr_fs_handle = (fs_handle_t) IPC_GET_ARG3(*request);
154 dev_handle_t mr_dev_handle = (dev_handle_t) IPC_GET_ARG4(*request);
[83937ccd]155 int res;
156 ipcarg_t rc;
[1313ee9]157
[83937ccd]158 ipc_call_t call;
159 ipc_callid_t callid;
[1313ee9]160
161 /* Accept the phone */
[83937ccd]162 callid = async_get_call(&call);
[b4cbef1]163 int mountee_phone = (int) IPC_GET_ARG1(call);
[83937ccd]164 if ((IPC_GET_METHOD(call) != IPC_M_CONNECTION_CLONE) ||
[1313ee9]165 (mountee_phone < 0)) {
[83937ccd]166 ipc_answer_0(callid, EINVAL);
167 ipc_answer_0(rid, EINVAL);
168 return;
169 }
[1313ee9]170
171 /* Acknowledge the mountee_phone */
172 ipc_answer_0(callid, EOK);
[83937ccd]173
[0daba212]174 fs_node_t *fn;
175 res = ops->node_get(&fn, mp_dev_handle, mp_fs_index);
[1313ee9]176 if ((res != EOK) || (!fn)) {
[83937ccd]177 ipc_hangup(mountee_phone);
[eda925a]178 async_data_write_void(combine_rc(res, ENOENT));
[0daba212]179 ipc_answer_0(rid, combine_rc(res, ENOENT));
[83937ccd]180 return;
181 }
[1313ee9]182
[83937ccd]183 if (fn->mp_data.mp_active) {
184 ipc_hangup(mountee_phone);
[0daba212]185 (void) ops->node_put(fn);
[eda925a]186 async_data_write_void(EBUSY);
[83937ccd]187 ipc_answer_0(rid, EBUSY);
188 return;
189 }
[1313ee9]190
[83937ccd]191 rc = async_req_0_0(mountee_phone, IPC_M_CONNECT_ME);
[0daba212]192 if (rc != EOK) {
[83937ccd]193 ipc_hangup(mountee_phone);
[0daba212]194 (void) ops->node_put(fn);
[eda925a]195 async_data_write_void(rc);
[83937ccd]196 ipc_answer_0(rid, rc);
197 return;
198 }
199
200 ipc_call_t answer;
[eda925a]201 rc = async_data_write_forward_1_1(mountee_phone, VFS_OUT_MOUNTED,
202 mr_dev_handle, &answer);
[83937ccd]203
204 if (rc == EOK) {
205 fn->mp_data.mp_active = true;
206 fn->mp_data.fs_handle = mr_fs_handle;
207 fn->mp_data.dev_handle = mr_dev_handle;
208 fn->mp_data.phone = mountee_phone;
209 }
[1313ee9]210
[83937ccd]211 /*
212 * Do not release the FS node so that it stays in memory.
213 */
[0442c02]214 ipc_answer_3(rid, rc, IPC_GET_ARG1(answer), IPC_GET_ARG2(answer),
215 IPC_GET_ARG3(answer));
[83937ccd]216}
217
[3c11713]218void libfs_unmount(libfs_ops_t *ops, ipc_callid_t rid, ipc_call_t *request)
219{
[c888102]220 dev_handle_t mp_dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
221 fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*request);
222 fs_node_t *fn;
223 int res;
224
225 res = ops->node_get(&fn, mp_dev_handle, mp_fs_index);
226 if ((res != EOK) || (!fn)) {
227 ipc_answer_0(rid, combine_rc(res, ENOENT));
228 return;
229 }
230
231 /*
232 * We are clearly expecting to find the mount point active.
233 */
234 if (!fn->mp_data.mp_active) {
235 (void) ops->node_put(fn);
236 ipc_answer_0(rid, EINVAL);
237 return;
238 }
239
240 /*
241 * Tell the mounted file system to unmount.
242 */
243 res = async_req_1_0(fn->mp_data.phone, VFS_OUT_UNMOUNTED,
244 fn->mp_data.dev_handle);
245
246 /*
247 * If everything went well, perform the clean-up on our side.
248 */
249 if (res == EOK) {
250 ipc_hangup(fn->mp_data.phone);
251 fn->mp_data.mp_active = false;
252 fn->mp_data.fs_handle = 0;
253 fn->mp_data.dev_handle = 0;
254 fn->mp_data.phone = 0;
255 /* Drop the reference created in libfs_mount(). */
256 (void) ops->node_put(fn);
257 }
258
259 (void) ops->node_put(fn);
260 ipc_answer_0(rid, res);
[3c11713]261}
262
[1e50f81]263/** Lookup VFS triplet by name in the file system name space.
[9bb85f3]264 *
265 * The path passed in the PLB must be in the canonical file system path format
266 * as returned by the canonify() function.
[1e50f81]267 *
[595edf5]268 * @param ops libfs operations structure with function pointers to
269 * file system implementation
270 * @param fs_handle File system handle of the file system where to perform
271 * the lookup.
[4198f9c3]272 * @param rid Request ID of the VFS_OUT_LOOKUP request.
273 * @param request VFS_OUT_LOOKUP request data itself.
[595edf5]274 *
[1e50f81]275 */
[f2ec8c8]276void libfs_lookup(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
[2c448fb]277 ipc_call_t *request)
278{
[1313ee9]279 unsigned int first = IPC_GET_ARG1(*request);
280 unsigned int last = IPC_GET_ARG2(*request);
281 unsigned int next = first;
[f2ec8c8]282 dev_handle_t dev_handle = IPC_GET_ARG3(*request);
[2c448fb]283 int lflag = IPC_GET_ARG4(*request);
[1313ee9]284 fs_index_t index = IPC_GET_ARG5(*request);
[c9f6e49f]285 char component[NAME_MAX + 1];
286 int len;
[0daba212]287 int rc;
[1313ee9]288
[2c448fb]289 if (last < next)
290 last += PLB_SIZE;
[1313ee9]291
[b6035ba]292 fs_node_t *par = NULL;
[0daba212]293 fs_node_t *cur = NULL;
[b6035ba]294 fs_node_t *tmp = NULL;
[1313ee9]295
[0daba212]296 rc = ops->root_get(&cur, dev_handle);
297 on_error(rc, goto out_with_answer);
[1313ee9]298
[83937ccd]299 if (cur->mp_data.mp_active) {
[4198f9c3]300 ipc_forward_slow(rid, cur->mp_data.phone, VFS_OUT_LOOKUP,
[83937ccd]301 next, last, cur->mp_data.dev_handle, lflag, index,
302 IPC_FF_ROUTE_FROM_ME);
[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 */
[2c448fb]324 ipc_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
[4198f9c3]358 ipc_forward_slow(rid, tmp->mp_data.phone,
359 VFS_OUT_LOOKUP, next, last, tmp->mp_data.dev_handle,
360 lflag, index, IPC_FF_ROUTE_FROM_ME);
[0daba212]361 (void) ops->node_put(cur);
362 (void) ops->node_put(tmp);
[83937ccd]363 if (par)
[0daba212]364 (void) ops->node_put(par);
[83937ccd]365 return;
366 }
[1313ee9]367
368 /* Handle miss: match amongst siblings */
[2c448fb]369 if (!tmp) {
[a8e9ab8d]370 if (next <= last) {
[1313ee9]371 /* There are unprocessed components */
[a8e9ab8d]372 ipc_answer_0(rid, ENOENT);
[06901c6b]373 goto out;
[a8e9ab8d]374 }
[1313ee9]375
376 /* Miss in the last component */
377 if (lflag & (L_CREATE | L_LINK)) {
378 /* Request to create a new link */
[2c448fb]379 if (!ops->is_directory(cur)) {
380 ipc_answer_0(rid, ENOTDIR);
[06901c6b]381 goto out;
[a8e9ab8d]382 }
[1313ee9]383
[b6035ba]384 fs_node_t *fn;
[a8e9ab8d]385 if (lflag & L_CREATE)
[0daba212]386 rc = ops->create(&fn, dev_handle,
387 lflag);
[a8e9ab8d]388 else
[0daba212]389 rc = ops->node_get(&fn, dev_handle,
[34f62f8]390 index);
[0daba212]391 on_error(rc, goto out_with_answer);
[1313ee9]392
[b6035ba]393 if (fn) {
394 rc = ops->link(cur, fn, component);
[0013b9ce]395 if (rc != EOK) {
[0daba212]396 if (lflag & L_CREATE)
397 (void) ops->destroy(fn);
[0013b9ce]398 ipc_answer_0(rid, rc);
[2c448fb]399 } else {
400 ipc_answer_5(rid, EOK,
401 fs_handle, dev_handle,
[b6035ba]402 ops->index_get(fn),
403 ops->size_get(fn),
404 ops->lnkcnt_get(fn));
[0daba212]405 (void) ops->node_put(fn);
[2c448fb]406 }
[1313ee9]407 } else
[2c448fb]408 ipc_answer_0(rid, ENOSPC);
[1313ee9]409
[06901c6b]410 goto out;
[1313ee9]411 }
412
[2c448fb]413 ipc_answer_0(rid, ENOENT);
[06901c6b]414 goto out;
[2c448fb]415 }
[1313ee9]416
[0daba212]417 if (par) {
418 rc = ops->node_put(par);
419 on_error(rc, goto out_with_answer);
420 }
[1313ee9]421
422 /* Descend one level */
[7b6d98b]423 par = cur;
[2c448fb]424 cur = tmp;
[06901c6b]425 tmp = NULL;
[2c448fb]426 }
[1313ee9]427
428 /* Handle miss: excessive components */
[0daba212]429 if (next <= last) {
430 bool has_children;
431 rc = ops->has_children(&has_children, cur);
432 on_error(rc, goto out_with_answer);
[1313ee9]433
[0daba212]434 if (has_children)
435 goto skip_miss;
[1313ee9]436
[a8e9ab8d]437 if (lflag & (L_CREATE | L_LINK)) {
[2c448fb]438 if (!ops->is_directory(cur)) {
439 ipc_answer_0(rid, ENOTDIR);
[06901c6b]440 goto out;
[2c448fb]441 }
[1313ee9]442
443 /* Collect next component */
[c9f6e49f]444 len = 0;
[2c448fb]445 while (next <= last) {
446 if (ops->plb_get_char(next) == '/') {
[1313ee9]447 /* More than one component */
[2c448fb]448 ipc_answer_0(rid, ENOENT);
[06901c6b]449 goto out;
[2c448fb]450 }
[1313ee9]451
[2c448fb]452 if (len + 1 == NAME_MAX) {
[1313ee9]453 /* Component length overflow */
[2c448fb]454 ipc_answer_0(rid, ENAMETOOLONG);
[06901c6b]455 goto out;
[2c448fb]456 }
[1313ee9]457
[2c448fb]458 component[len++] = ops->plb_get_char(next);
[1313ee9]459 /* Process next character */
460 next++;
[2c448fb]461 }
[1313ee9]462
[2c448fb]463 assert(len);
464 component[len] = '\0';
[1313ee9]465
[b6035ba]466 fs_node_t *fn;
[a8e9ab8d]467 if (lflag & L_CREATE)
[0daba212]468 rc = ops->create(&fn, dev_handle, lflag);
[a8e9ab8d]469 else
[0daba212]470 rc = ops->node_get(&fn, dev_handle, index);
471 on_error(rc, goto out_with_answer);
[1313ee9]472
[b6035ba]473 if (fn) {
474 rc = ops->link(cur, fn, component);
[0013b9ce]475 if (rc != EOK) {
[a8e9ab8d]476 if (lflag & L_CREATE)
[0daba212]477 (void) ops->destroy(fn);
[0013b9ce]478 ipc_answer_0(rid, rc);
[2c448fb]479 } else {
480 ipc_answer_5(rid, EOK,
481 fs_handle, dev_handle,
[b6035ba]482 ops->index_get(fn),
483 ops->size_get(fn),
484 ops->lnkcnt_get(fn));
[0daba212]485 (void) ops->node_put(fn);
[2c448fb]486 }
[1313ee9]487 } else
[2c448fb]488 ipc_answer_0(rid, ENOSPC);
[1313ee9]489
[06901c6b]490 goto out;
[2c448fb]491 }
[1313ee9]492
[2c448fb]493 ipc_answer_0(rid, ENOENT);
[06901c6b]494 goto out;
[2c448fb]495 }
[1313ee9]496
[0daba212]497skip_miss:
[1313ee9]498
499 /* Handle hit */
[a8e9ab8d]500 if (lflag & L_UNLINK) {
[1313ee9]501 unsigned int old_lnkcnt = ops->lnkcnt_get(cur);
[0daba212]502 rc = ops->unlink(par, cur, component);
[1313ee9]503 ipc_answer_5(rid, (ipcarg_t) rc, fs_handle, dev_handle,
[2c448fb]504 ops->index_get(cur), ops->size_get(cur), old_lnkcnt);
[06901c6b]505 goto out;
[2c448fb]506 }
[1313ee9]507
[a8e9ab8d]508 if (((lflag & (L_CREATE | L_EXCLUSIVE)) == (L_CREATE | L_EXCLUSIVE)) ||
509 (lflag & L_LINK)) {
[2c448fb]510 ipc_answer_0(rid, EEXIST);
[06901c6b]511 goto out;
[2c448fb]512 }
[1313ee9]513
[2c448fb]514 if ((lflag & L_FILE) && (ops->is_directory(cur))) {
515 ipc_answer_0(rid, EISDIR);
[06901c6b]516 goto out;
[2c448fb]517 }
[1313ee9]518
[2c448fb]519 if ((lflag & L_DIRECTORY) && (ops->is_file(cur))) {
520 ipc_answer_0(rid, ENOTDIR);
[06901c6b]521 goto out;
[2c448fb]522 }
[f7376cbf]523
524 if ((lflag & L_ROOT) && par) {
525 ipc_answer_0(rid, EINVAL);
526 goto out;
527 }
[1313ee9]528
[0daba212]529out_with_answer:
[1313ee9]530
[0daba212]531 if (rc == EOK) {
[1313ee9]532 if (lflag & L_OPEN)
533 rc = ops->node_open(cur);
534
535 ipc_answer_5(rid, rc, fs_handle, dev_handle,
[0daba212]536 ops->index_get(cur), ops->size_get(cur),
537 ops->lnkcnt_get(cur));
[1313ee9]538 } else
[0daba212]539 ipc_answer_0(rid, rc);
[1313ee9]540
[06901c6b]541out:
[1313ee9]542
[06901c6b]543 if (par)
[0daba212]544 (void) ops->node_put(par);
[1313ee9]545
[06901c6b]546 if (cur)
[0daba212]547 (void) ops->node_put(cur);
[1313ee9]548
[06901c6b]549 if (tmp)
[0daba212]550 (void) ops->node_put(tmp);
[2c448fb]551}
552
[75160a6]553void libfs_stat(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
554 ipc_call_t *request)
555{
556 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
557 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
[1313ee9]558
[0daba212]559 fs_node_t *fn;
[1313ee9]560 int rc = ops->node_get(&fn, dev_handle, index);
[0daba212]561 on_error(rc, answer_and_return(rid, rc));
[1313ee9]562
[75160a6]563 ipc_callid_t callid;
564 size_t size;
[1313ee9]565 if ((!async_data_read_receive(&callid, &size)) ||
566 (size != sizeof(struct stat))) {
567 ops->node_put(fn);
[75160a6]568 ipc_answer_0(callid, EINVAL);
569 ipc_answer_0(rid, EINVAL);
570 return;
571 }
[1313ee9]572
[0143f72]573 struct stat stat;
574 memset(&stat, 0, sizeof(struct stat));
[75160a6]575
[0143f72]576 stat.fs_handle = fs_handle;
577 stat.dev_handle = dev_handle;
578 stat.index = index;
[1313ee9]579 stat.lnkcnt = ops->lnkcnt_get(fn);
[0143f72]580 stat.is_file = ops->is_file(fn);
[1313ee9]581 stat.is_directory = ops->is_directory(fn);
[0143f72]582 stat.size = ops->size_get(fn);
[1313ee9]583 stat.device = ops->device_get(fn);
584
585 ops->node_put(fn);
586
[0da4e41]587 async_data_read_finalize(callid, &stat, sizeof(struct stat));
[75160a6]588 ipc_answer_0(rid, EOK);
589}
590
[595edf5]591/** Open VFS triplet.
592 *
[1313ee9]593 * @param ops libfs operations structure with function pointers to
594 * file system implementation
595 * @param rid Request ID of the VFS_OUT_OPEN_NODE request.
596 * @param request VFS_OUT_OPEN_NODE request data itself.
[595edf5]597 *
598 */
599void libfs_open_node(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
600 ipc_call_t *request)
601{
602 dev_handle_t dev_handle = IPC_GET_ARG1(*request);
603 fs_index_t index = IPC_GET_ARG2(*request);
[0daba212]604 fs_node_t *fn;
605 int rc;
[595edf5]606
[0daba212]607 rc = ops->node_get(&fn, dev_handle, index);
608 on_error(rc, answer_and_return(rid, rc));
[595edf5]609
[0daba212]610 if (fn == NULL) {
[595edf5]611 ipc_answer_0(rid, ENOENT);
612 return;
613 }
614
[1313ee9]615 rc = ops->node_open(fn);
616 ipc_answer_3(rid, rc, ops->size_get(fn), ops->lnkcnt_get(fn),
[2e983c7]617 (ops->is_file(fn) ? L_FILE : 0) | (ops->is_directory(fn) ? L_DIRECTORY : 0));
[595edf5]618
[0daba212]619 (void) ops->node_put(fn);
[595edf5]620}
621
[74303b6]622/** @}
623 */
Note: See TracBrowser for help on using the repository browser.