[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>
|
---|
[efcebe1] | 47 | #include <stdlib.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 { \
|
---|
[ffa2c8ef] | 60 | async_answer_0((rid), (rc)); \
|
---|
[0daba212] | 61 | return; \
|
---|
| 62 | } while (0)
|
---|
| 63 |
|
---|
[efcebe1] | 64 | static fs_reg_t reg;
|
---|
| 65 |
|
---|
| 66 | static vfs_out_ops_t *vfs_out_ops = NULL;
|
---|
| 67 | static libfs_ops_t *libfs_ops = NULL;
|
---|
| 68 |
|
---|
| 69 | static void libfs_mount(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *);
|
---|
| 70 | static void libfs_unmount(libfs_ops_t *, ipc_callid_t, ipc_call_t *);
|
---|
| 71 | static void libfs_lookup(libfs_ops_t *, fs_handle_t, ipc_callid_t,
|
---|
| 72 | ipc_call_t *);
|
---|
| 73 | static void libfs_stat(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *);
|
---|
| 74 | static void libfs_open_node(libfs_ops_t *, fs_handle_t, ipc_callid_t,
|
---|
| 75 | ipc_call_t *);
|
---|
| 76 |
|
---|
| 77 | static void vfs_out_mounted(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 78 | {
|
---|
[86ffa27f] | 79 | service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);
|
---|
[efcebe1] | 80 | char *opts;
|
---|
| 81 | int rc;
|
---|
| 82 |
|
---|
| 83 | /* Accept the mount options. */
|
---|
| 84 | rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
|
---|
| 85 | if (rc != EOK) {
|
---|
| 86 | async_answer_0(rid, rc);
|
---|
| 87 | return;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | fs_index_t index;
|
---|
| 91 | aoff64_t size;
|
---|
| 92 | unsigned lnkcnt;
|
---|
[86ffa27f] | 93 | rc = vfs_out_ops->mounted(service_id, opts, &index, &size, &lnkcnt);
|
---|
[efcebe1] | 94 |
|
---|
[7eb0fed8] | 95 | if (rc == EOK)
|
---|
| 96 | async_answer_4(rid, EOK, index, LOWER32(size), UPPER32(size),
|
---|
| 97 | lnkcnt);
|
---|
[efcebe1] | 98 | else
|
---|
| 99 | async_answer_0(rid, rc);
|
---|
| 100 |
|
---|
| 101 | free(opts);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | static void vfs_out_mount(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 105 | {
|
---|
| 106 | libfs_mount(libfs_ops, reg.fs_handle, rid, req);
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | static void vfs_out_unmounted(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 110 | {
|
---|
[86ffa27f] | 111 | service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);
|
---|
[efcebe1] | 112 | int rc;
|
---|
| 113 |
|
---|
[86ffa27f] | 114 | rc = vfs_out_ops->unmounted(service_id);
|
---|
[efcebe1] | 115 |
|
---|
| 116 | async_answer_0(rid, rc);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | static void vfs_out_unmount(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 120 | {
|
---|
| 121 |
|
---|
| 122 | libfs_unmount(libfs_ops, rid, req);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | static void vfs_out_lookup(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 126 | {
|
---|
| 127 | libfs_lookup(libfs_ops, reg.fs_handle, rid, req);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | static void vfs_out_read(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 131 | {
|
---|
[86ffa27f] | 132 | service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);
|
---|
[efcebe1] | 133 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req);
|
---|
| 134 | aoff64_t pos = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*req),
|
---|
| 135 | IPC_GET_ARG4(*req));
|
---|
| 136 | size_t rbytes;
|
---|
| 137 | int rc;
|
---|
| 138 |
|
---|
[86ffa27f] | 139 | rc = vfs_out_ops->read(service_id, index, pos, &rbytes);
|
---|
[efcebe1] | 140 |
|
---|
| 141 | if (rc == EOK)
|
---|
| 142 | async_answer_1(rid, EOK, rbytes);
|
---|
| 143 | else
|
---|
| 144 | async_answer_0(rid, rc);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | static void vfs_out_write(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 148 | {
|
---|
[86ffa27f] | 149 | service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);
|
---|
[efcebe1] | 150 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req);
|
---|
| 151 | aoff64_t pos = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*req),
|
---|
| 152 | IPC_GET_ARG4(*req));
|
---|
| 153 | size_t wbytes;
|
---|
| 154 | aoff64_t nsize;
|
---|
| 155 | int rc;
|
---|
| 156 |
|
---|
[86ffa27f] | 157 | rc = vfs_out_ops->write(service_id, index, pos, &wbytes, &nsize);
|
---|
[efcebe1] | 158 |
|
---|
[5bb9907] | 159 | if (rc == EOK)
|
---|
| 160 | async_answer_3(rid, EOK, wbytes, LOWER32(nsize), UPPER32(nsize));
|
---|
[efcebe1] | 161 | else
|
---|
| 162 | async_answer_0(rid, rc);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | static void vfs_out_truncate(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 166 | {
|
---|
[86ffa27f] | 167 | service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);
|
---|
[efcebe1] | 168 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req);
|
---|
| 169 | aoff64_t size = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*req),
|
---|
| 170 | IPC_GET_ARG4(*req));
|
---|
| 171 | int rc;
|
---|
| 172 |
|
---|
[86ffa27f] | 173 | rc = vfs_out_ops->truncate(service_id, index, size);
|
---|
[efcebe1] | 174 |
|
---|
| 175 | async_answer_0(rid, rc);
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | static void vfs_out_close(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 179 | {
|
---|
[86ffa27f] | 180 | service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);
|
---|
[efcebe1] | 181 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req);
|
---|
| 182 | int rc;
|
---|
| 183 |
|
---|
[86ffa27f] | 184 | rc = vfs_out_ops->close(service_id, index);
|
---|
[efcebe1] | 185 |
|
---|
| 186 | async_answer_0(rid, rc);
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | static void vfs_out_destroy(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 190 | {
|
---|
[86ffa27f] | 191 | service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);
|
---|
[efcebe1] | 192 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req);
|
---|
| 193 | int rc;
|
---|
| 194 |
|
---|
[86ffa27f] | 195 | rc = vfs_out_ops->destroy(service_id, index);
|
---|
[efcebe1] | 196 |
|
---|
| 197 | async_answer_0(rid, rc);
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | static void vfs_out_open_node(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 201 | {
|
---|
| 202 | libfs_open_node(libfs_ops, reg.fs_handle, rid, req);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | static void vfs_out_stat(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 206 | {
|
---|
| 207 | libfs_stat(libfs_ops, reg.fs_handle, rid, req);
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | static void vfs_out_sync(ipc_callid_t rid, ipc_call_t *req)
|
---|
| 211 | {
|
---|
[86ffa27f] | 212 | service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);
|
---|
[efcebe1] | 213 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req);
|
---|
| 214 | int rc;
|
---|
| 215 |
|
---|
[86ffa27f] | 216 | rc = vfs_out_ops->sync(service_id, index);
|
---|
[efcebe1] | 217 |
|
---|
| 218 | async_answer_0(rid, rc);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
| 222 | {
|
---|
| 223 | if (iid) {
|
---|
| 224 | /*
|
---|
| 225 | * This only happens for connections opened by
|
---|
| 226 | * IPC_M_CONNECT_ME_TO calls as opposed to callback connections
|
---|
| 227 | * created by IPC_M_CONNECT_TO_ME.
|
---|
| 228 | */
|
---|
| 229 | async_answer_0(iid, EOK);
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | while (true) {
|
---|
| 233 | ipc_call_t call;
|
---|
| 234 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 235 |
|
---|
| 236 | if (!IPC_GET_IMETHOD(call))
|
---|
| 237 | return;
|
---|
| 238 |
|
---|
| 239 | switch (IPC_GET_IMETHOD(call)) {
|
---|
| 240 | case VFS_OUT_MOUNTED:
|
---|
| 241 | vfs_out_mounted(callid, &call);
|
---|
| 242 | break;
|
---|
| 243 | case VFS_OUT_MOUNT:
|
---|
| 244 | vfs_out_mount(callid, &call);
|
---|
| 245 | break;
|
---|
| 246 | case VFS_OUT_UNMOUNTED:
|
---|
| 247 | vfs_out_unmounted(callid, &call);
|
---|
| 248 | break;
|
---|
| 249 | case VFS_OUT_UNMOUNT:
|
---|
| 250 | vfs_out_unmount(callid, &call);
|
---|
| 251 | break;
|
---|
| 252 | case VFS_OUT_LOOKUP:
|
---|
| 253 | vfs_out_lookup(callid, &call);
|
---|
| 254 | break;
|
---|
| 255 | case VFS_OUT_READ:
|
---|
| 256 | vfs_out_read(callid, &call);
|
---|
| 257 | break;
|
---|
| 258 | case VFS_OUT_WRITE:
|
---|
| 259 | vfs_out_write(callid, &call);
|
---|
| 260 | break;
|
---|
| 261 | case VFS_OUT_TRUNCATE:
|
---|
| 262 | vfs_out_truncate(callid, &call);
|
---|
| 263 | break;
|
---|
| 264 | case VFS_OUT_CLOSE:
|
---|
| 265 | vfs_out_close(callid, &call);
|
---|
| 266 | break;
|
---|
| 267 | case VFS_OUT_DESTROY:
|
---|
| 268 | vfs_out_destroy(callid, &call);
|
---|
| 269 | break;
|
---|
| 270 | case VFS_OUT_OPEN_NODE:
|
---|
| 271 | vfs_out_open_node(callid, &call);
|
---|
| 272 | break;
|
---|
| 273 | case VFS_OUT_STAT:
|
---|
| 274 | vfs_out_stat(callid, &call);
|
---|
| 275 | break;
|
---|
| 276 | case VFS_OUT_SYNC:
|
---|
| 277 | vfs_out_sync(callid, &call);
|
---|
| 278 | break;
|
---|
| 279 | default:
|
---|
| 280 | async_answer_0(callid, ENOTSUP);
|
---|
| 281 | break;
|
---|
| 282 | }
|
---|
| 283 | }
|
---|
| 284 | }
|
---|
| 285 |
|
---|
[efd4a72] | 286 | /** Register file system server.
|
---|
| 287 | *
|
---|
| 288 | * This function abstracts away the tedious registration protocol from
|
---|
| 289 | * file system implementations and lets them to reuse this registration glue
|
---|
| 290 | * code.
|
---|
| 291 | *
|
---|
[79ae36dd] | 292 | * @param sess Session for communication with VFS.
|
---|
| 293 | * @param info VFS info structure supplied by the file system
|
---|
| 294 | * implementation.
|
---|
[efcebe1] | 295 | * @param vops Address of the vfs_out_ops_t structure.
|
---|
| 296 | * @param lops Address of the libfs_ops_t structure.
|
---|
[1313ee9] | 297 | *
|
---|
| 298 | * @return EOK on success or a non-zero error code on errror.
|
---|
[efd4a72] | 299 | *
|
---|
| 300 | */
|
---|
[efcebe1] | 301 | int fs_register(async_sess_t *sess, vfs_info_t *info, vfs_out_ops_t *vops,
|
---|
| 302 | libfs_ops_t *lops)
|
---|
[efd4a72] | 303 | {
|
---|
| 304 | /*
|
---|
| 305 | * Tell VFS that we are here and want to get registered.
|
---|
| 306 | * We use the async framework because VFS will answer the request
|
---|
| 307 | * out-of-order, when it knows that the operation succeeded or failed.
|
---|
| 308 | */
|
---|
[79ae36dd] | 309 |
|
---|
| 310 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 311 |
|
---|
[efd4a72] | 312 | ipc_call_t answer;
|
---|
[79ae36dd] | 313 | aid_t req = async_send_0(exch, VFS_IN_REGISTER, &answer);
|
---|
[1313ee9] | 314 |
|
---|
[efd4a72] | 315 | /*
|
---|
| 316 | * Send our VFS info structure to VFS.
|
---|
| 317 | */
|
---|
[79ae36dd] | 318 | int rc = async_data_write_start(exch, info, sizeof(*info));
|
---|
| 319 |
|
---|
[efd4a72] | 320 | if (rc != EOK) {
|
---|
[79ae36dd] | 321 | async_exchange_end(exch);
|
---|
[efd4a72] | 322 | async_wait_for(req, NULL);
|
---|
| 323 | return rc;
|
---|
| 324 | }
|
---|
[1313ee9] | 325 |
|
---|
[efcebe1] | 326 | /*
|
---|
| 327 | * Set VFS_OUT and libfs operations.
|
---|
| 328 | */
|
---|
| 329 | vfs_out_ops = vops;
|
---|
| 330 | libfs_ops = lops;
|
---|
| 331 |
|
---|
[efd4a72] | 332 | /*
|
---|
| 333 | * Ask VFS for callback connection.
|
---|
| 334 | */
|
---|
[efcebe1] | 335 | async_connect_to_me(exch, 0, 0, 0, vfs_connection, NULL);
|
---|
[1313ee9] | 336 |
|
---|
[efd4a72] | 337 | /*
|
---|
| 338 | * Allocate piece of address space for PLB.
|
---|
| 339 | */
|
---|
[efcebe1] | 340 | reg.plb_ro = as_get_mappable_page(PLB_SIZE);
|
---|
| 341 | if (!reg.plb_ro) {
|
---|
[79ae36dd] | 342 | async_exchange_end(exch);
|
---|
[efd4a72] | 343 | async_wait_for(req, NULL);
|
---|
| 344 | return ENOMEM;
|
---|
| 345 | }
|
---|
[1313ee9] | 346 |
|
---|
[efd4a72] | 347 | /*
|
---|
| 348 | * Request sharing the Path Lookup Buffer with VFS.
|
---|
| 349 | */
|
---|
[efcebe1] | 350 | rc = async_share_in_start_0_0(exch, reg.plb_ro, PLB_SIZE);
|
---|
[79ae36dd] | 351 |
|
---|
| 352 | async_exchange_end(exch);
|
---|
| 353 |
|
---|
[efd4a72] | 354 | if (rc) {
|
---|
| 355 | async_wait_for(req, NULL);
|
---|
| 356 | return rc;
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | /*
|
---|
[4198f9c3] | 360 | * Pick up the answer for the request to the VFS_IN_REQUEST call.
|
---|
[efd4a72] | 361 | */
|
---|
| 362 | async_wait_for(req, NULL);
|
---|
[efcebe1] | 363 | reg.fs_handle = (int) IPC_GET_ARG1(answer);
|
---|
[efd4a72] | 364 |
|
---|
| 365 | /*
|
---|
| 366 | * Tell the async framework that other connections are to be handled by
|
---|
| 367 | * the same connection fibril as well.
|
---|
| 368 | */
|
---|
[efcebe1] | 369 | async_set_client_connection(vfs_connection);
|
---|
[1313ee9] | 370 |
|
---|
[efd4a72] | 371 | return IPC_GET_RETVAL(answer);
|
---|
| 372 | }
|
---|
[74303b6] | 373 |
|
---|
[83937ccd] | 374 | void fs_node_initialize(fs_node_t *fn)
|
---|
| 375 | {
|
---|
| 376 | memset(fn, 0, sizeof(fs_node_t));
|
---|
| 377 | }
|
---|
| 378 |
|
---|
[16d17ca] | 379 | void libfs_mount(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
|
---|
[efcebe1] | 380 | ipc_call_t *req)
|
---|
[83937ccd] | 381 | {
|
---|
[86ffa27f] | 382 | service_id_t mp_service_id = (service_id_t) IPC_GET_ARG1(*req);
|
---|
[efcebe1] | 383 | fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*req);
|
---|
| 384 | fs_handle_t mr_fs_handle = (fs_handle_t) IPC_GET_ARG3(*req);
|
---|
[86ffa27f] | 385 | service_id_t mr_service_id = (service_id_t) IPC_GET_ARG4(*req);
|
---|
[1313ee9] | 386 |
|
---|
[79ae36dd] | 387 | async_sess_t *mountee_sess = async_clone_receive(EXCHANGE_PARALLEL);
|
---|
| 388 | if (mountee_sess == NULL) {
|
---|
[ffa2c8ef] | 389 | async_answer_0(rid, EINVAL);
|
---|
[83937ccd] | 390 | return;
|
---|
| 391 | }
|
---|
[1313ee9] | 392 |
|
---|
[0daba212] | 393 | fs_node_t *fn;
|
---|
[15f3c3f] | 394 | int res = ops->node_get(&fn, mp_service_id, mp_fs_index);
|
---|
[1313ee9] | 395 | if ((res != EOK) || (!fn)) {
|
---|
[79ae36dd] | 396 | async_hangup(mountee_sess);
|
---|
[eda925a] | 397 | async_data_write_void(combine_rc(res, ENOENT));
|
---|
[ffa2c8ef] | 398 | async_answer_0(rid, combine_rc(res, ENOENT));
|
---|
[83937ccd] | 399 | return;
|
---|
| 400 | }
|
---|
[1313ee9] | 401 |
|
---|
[83937ccd] | 402 | if (fn->mp_data.mp_active) {
|
---|
[79ae36dd] | 403 | async_hangup(mountee_sess);
|
---|
[0daba212] | 404 | (void) ops->node_put(fn);
|
---|
[eda925a] | 405 | async_data_write_void(EBUSY);
|
---|
[ffa2c8ef] | 406 | async_answer_0(rid, EBUSY);
|
---|
[83937ccd] | 407 | return;
|
---|
| 408 | }
|
---|
[1313ee9] | 409 |
|
---|
[79ae36dd] | 410 | async_exch_t *exch = async_exchange_begin(mountee_sess);
|
---|
| 411 | async_sess_t *sess = async_connect_me(EXCHANGE_PARALLEL, exch);
|
---|
| 412 |
|
---|
| 413 | if (!sess) {
|
---|
| 414 | async_exchange_end(exch);
|
---|
| 415 | async_hangup(mountee_sess);
|
---|
[0daba212] | 416 | (void) ops->node_put(fn);
|
---|
[79ae36dd] | 417 | async_data_write_void(errno);
|
---|
| 418 | async_answer_0(rid, errno);
|
---|
[83937ccd] | 419 | return;
|
---|
| 420 | }
|
---|
| 421 |
|
---|
| 422 | ipc_call_t answer;
|
---|
[79ae36dd] | 423 | int rc = async_data_write_forward_1_1(exch, VFS_OUT_MOUNTED,
|
---|
[15f3c3f] | 424 | mr_service_id, &answer);
|
---|
[79ae36dd] | 425 | async_exchange_end(exch);
|
---|
[83937ccd] | 426 |
|
---|
| 427 | if (rc == EOK) {
|
---|
| 428 | fn->mp_data.mp_active = true;
|
---|
| 429 | fn->mp_data.fs_handle = mr_fs_handle;
|
---|
[15f3c3f] | 430 | fn->mp_data.service_id = mr_service_id;
|
---|
[79ae36dd] | 431 | fn->mp_data.sess = mountee_sess;
|
---|
[83937ccd] | 432 | }
|
---|
[1313ee9] | 433 |
|
---|
[83937ccd] | 434 | /*
|
---|
| 435 | * Do not release the FS node so that it stays in memory.
|
---|
| 436 | */
|
---|
[7eb0fed8] | 437 | async_answer_4(rid, rc, IPC_GET_ARG1(answer), IPC_GET_ARG2(answer),
|
---|
| 438 | IPC_GET_ARG3(answer), IPC_GET_ARG4(answer));
|
---|
[83937ccd] | 439 | }
|
---|
| 440 |
|
---|
[efcebe1] | 441 | void libfs_unmount(libfs_ops_t *ops, ipc_callid_t rid, ipc_call_t *req)
|
---|
[3c11713] | 442 | {
|
---|
[86ffa27f] | 443 | service_id_t mp_service_id = (service_id_t) IPC_GET_ARG1(*req);
|
---|
[efcebe1] | 444 | fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*req);
|
---|
[c888102] | 445 | fs_node_t *fn;
|
---|
| 446 | int res;
|
---|
| 447 |
|
---|
[15f3c3f] | 448 | res = ops->node_get(&fn, mp_service_id, mp_fs_index);
|
---|
[c888102] | 449 | if ((res != EOK) || (!fn)) {
|
---|
[ffa2c8ef] | 450 | async_answer_0(rid, combine_rc(res, ENOENT));
|
---|
[c888102] | 451 | return;
|
---|
| 452 | }
|
---|
| 453 |
|
---|
| 454 | /*
|
---|
| 455 | * We are clearly expecting to find the mount point active.
|
---|
| 456 | */
|
---|
| 457 | if (!fn->mp_data.mp_active) {
|
---|
| 458 | (void) ops->node_put(fn);
|
---|
[ffa2c8ef] | 459 | async_answer_0(rid, EINVAL);
|
---|
[c888102] | 460 | return;
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 | /*
|
---|
| 464 | * Tell the mounted file system to unmount.
|
---|
| 465 | */
|
---|
[79ae36dd] | 466 | async_exch_t *exch = async_exchange_begin(fn->mp_data.sess);
|
---|
[15f3c3f] | 467 | res = async_req_1_0(exch, VFS_OUT_UNMOUNTED, fn->mp_data.service_id);
|
---|
[79ae36dd] | 468 | async_exchange_end(exch);
|
---|
[c888102] | 469 |
|
---|
| 470 | /*
|
---|
| 471 | * If everything went well, perform the clean-up on our side.
|
---|
| 472 | */
|
---|
| 473 | if (res == EOK) {
|
---|
[79ae36dd] | 474 | async_hangup(fn->mp_data.sess);
|
---|
[c888102] | 475 | fn->mp_data.mp_active = false;
|
---|
| 476 | fn->mp_data.fs_handle = 0;
|
---|
[15f3c3f] | 477 | fn->mp_data.service_id = 0;
|
---|
[79ae36dd] | 478 | fn->mp_data.sess = NULL;
|
---|
| 479 |
|
---|
[c888102] | 480 | /* Drop the reference created in libfs_mount(). */
|
---|
| 481 | (void) ops->node_put(fn);
|
---|
| 482 | }
|
---|
| 483 |
|
---|
| 484 | (void) ops->node_put(fn);
|
---|
[ffa2c8ef] | 485 | async_answer_0(rid, res);
|
---|
[3c11713] | 486 | }
|
---|
| 487 |
|
---|
[efcebe1] | 488 | static char plb_get_char(unsigned pos)
|
---|
| 489 | {
|
---|
| 490 | return reg.plb_ro[pos % PLB_SIZE];
|
---|
| 491 | }
|
---|
| 492 |
|
---|
[1e50f81] | 493 | /** Lookup VFS triplet by name in the file system name space.
|
---|
[9bb85f3] | 494 | *
|
---|
| 495 | * The path passed in the PLB must be in the canonical file system path format
|
---|
| 496 | * as returned by the canonify() function.
|
---|
[1e50f81] | 497 | *
|
---|
[595edf5] | 498 | * @param ops libfs operations structure with function pointers to
|
---|
| 499 | * file system implementation
|
---|
| 500 | * @param fs_handle File system handle of the file system where to perform
|
---|
| 501 | * the lookup.
|
---|
[4198f9c3] | 502 | * @param rid Request ID of the VFS_OUT_LOOKUP request.
|
---|
| 503 | * @param request VFS_OUT_LOOKUP request data itself.
|
---|
[595edf5] | 504 | *
|
---|
[1e50f81] | 505 | */
|
---|
[f2ec8c8] | 506 | void libfs_lookup(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
|
---|
[efcebe1] | 507 | ipc_call_t *req)
|
---|
[2c448fb] | 508 | {
|
---|
[efcebe1] | 509 | unsigned int first = IPC_GET_ARG1(*req);
|
---|
| 510 | unsigned int last = IPC_GET_ARG2(*req);
|
---|
[1313ee9] | 511 | unsigned int next = first;
|
---|
[86ffa27f] | 512 | service_id_t service_id = IPC_GET_ARG3(*req);
|
---|
[efcebe1] | 513 | int lflag = IPC_GET_ARG4(*req);
|
---|
| 514 | fs_index_t index = IPC_GET_ARG5(*req);
|
---|
[c9f6e49f] | 515 | char component[NAME_MAX + 1];
|
---|
| 516 | int len;
|
---|
[0daba212] | 517 | int rc;
|
---|
[1313ee9] | 518 |
|
---|
[2c448fb] | 519 | if (last < next)
|
---|
| 520 | last += PLB_SIZE;
|
---|
[1313ee9] | 521 |
|
---|
[b6035ba] | 522 | fs_node_t *par = NULL;
|
---|
[0daba212] | 523 | fs_node_t *cur = NULL;
|
---|
[b6035ba] | 524 | fs_node_t *tmp = NULL;
|
---|
[1313ee9] | 525 |
|
---|
[15f3c3f] | 526 | rc = ops->root_get(&cur, service_id);
|
---|
[0daba212] | 527 | on_error(rc, goto out_with_answer);
|
---|
[1313ee9] | 528 |
|
---|
[83937ccd] | 529 | if (cur->mp_data.mp_active) {
|
---|
[79ae36dd] | 530 | async_exch_t *exch = async_exchange_begin(cur->mp_data.sess);
|
---|
| 531 | async_forward_slow(rid, exch, VFS_OUT_LOOKUP, next, last,
|
---|
[86ffa27f] | 532 | cur->mp_data.service_id, lflag, index,
|
---|
[efcebe1] | 533 | IPC_FF_ROUTE_FROM_ME);
|
---|
[79ae36dd] | 534 | async_exchange_end(exch);
|
---|
| 535 |
|
---|
[0daba212] | 536 | (void) ops->node_put(cur);
|
---|
[83937ccd] | 537 | return;
|
---|
| 538 | }
|
---|
[1313ee9] | 539 |
|
---|
| 540 | /* Eat slash */
|
---|
[efcebe1] | 541 | if (plb_get_char(next) == '/')
|
---|
[1313ee9] | 542 | next++;
|
---|
[2c448fb] | 543 |
|
---|
[0daba212] | 544 | while (next <= last) {
|
---|
| 545 | bool has_children;
|
---|
[1313ee9] | 546 |
|
---|
[0daba212] | 547 | rc = ops->has_children(&has_children, cur);
|
---|
| 548 | on_error(rc, goto out_with_answer);
|
---|
| 549 | if (!has_children)
|
---|
| 550 | break;
|
---|
[1313ee9] | 551 |
|
---|
| 552 | /* Collect the component */
|
---|
[c9f6e49f] | 553 | len = 0;
|
---|
[efcebe1] | 554 | while ((next <= last) && (plb_get_char(next) != '/')) {
|
---|
[2c448fb] | 555 | if (len + 1 == NAME_MAX) {
|
---|
[1313ee9] | 556 | /* Component length overflow */
|
---|
[ffa2c8ef] | 557 | async_answer_0(rid, ENAMETOOLONG);
|
---|
[06901c6b] | 558 | goto out;
|
---|
[2c448fb] | 559 | }
|
---|
[efcebe1] | 560 | component[len++] = plb_get_char(next);
|
---|
[1313ee9] | 561 | /* Process next character */
|
---|
| 562 | next++;
|
---|
[2c448fb] | 563 | }
|
---|
[1313ee9] | 564 |
|
---|
[2c448fb] | 565 | assert(len);
|
---|
| 566 | component[len] = '\0';
|
---|
[1313ee9] | 567 | /* Eat slash */
|
---|
| 568 | next++;
|
---|
| 569 |
|
---|
| 570 | /* Match the component */
|
---|
[0daba212] | 571 | rc = ops->match(&tmp, cur, component);
|
---|
| 572 | on_error(rc, goto out_with_answer);
|
---|
[1313ee9] | 573 |
|
---|
[4b995b92] | 574 | /*
|
---|
| 575 | * If the matching component is a mount point, there are two
|
---|
| 576 | * legitimate semantics of the lookup operation. The first is
|
---|
| 577 | * the commonly used one in which the lookup crosses each mount
|
---|
| 578 | * point into the mounted file system. The second semantics is
|
---|
| 579 | * used mostly during unmount() and differs from the first one
|
---|
| 580 | * only in that the last mount point in the looked up path,
|
---|
| 581 | * which is also its last component, is not crossed.
|
---|
| 582 | */
|
---|
| 583 |
|
---|
| 584 | if ((tmp) && (tmp->mp_data.mp_active) &&
|
---|
[f7376cbf] | 585 | (!(lflag & L_MP) || (next <= last))) {
|
---|
[83937ccd] | 586 | if (next > last)
|
---|
| 587 | next = last = first;
|
---|
| 588 | else
|
---|
| 589 | next--;
|
---|
[1313ee9] | 590 |
|
---|
[79ae36dd] | 591 | async_exch_t *exch = async_exchange_begin(tmp->mp_data.sess);
|
---|
[efcebe1] | 592 | async_forward_slow(rid, exch, VFS_OUT_LOOKUP, next,
|
---|
[86ffa27f] | 593 | last, tmp->mp_data.service_id, lflag, index,
|
---|
[79ae36dd] | 594 | IPC_FF_ROUTE_FROM_ME);
|
---|
| 595 | async_exchange_end(exch);
|
---|
| 596 |
|
---|
[0daba212] | 597 | (void) ops->node_put(cur);
|
---|
| 598 | (void) ops->node_put(tmp);
|
---|
[83937ccd] | 599 | if (par)
|
---|
[0daba212] | 600 | (void) ops->node_put(par);
|
---|
[83937ccd] | 601 | return;
|
---|
| 602 | }
|
---|
[1313ee9] | 603 |
|
---|
| 604 | /* Handle miss: match amongst siblings */
|
---|
[2c448fb] | 605 | if (!tmp) {
|
---|
[a8e9ab8d] | 606 | if (next <= last) {
|
---|
[1313ee9] | 607 | /* There are unprocessed components */
|
---|
[ffa2c8ef] | 608 | async_answer_0(rid, ENOENT);
|
---|
[06901c6b] | 609 | goto out;
|
---|
[a8e9ab8d] | 610 | }
|
---|
[1313ee9] | 611 |
|
---|
| 612 | /* Miss in the last component */
|
---|
| 613 | if (lflag & (L_CREATE | L_LINK)) {
|
---|
| 614 | /* Request to create a new link */
|
---|
[2c448fb] | 615 | if (!ops->is_directory(cur)) {
|
---|
[ffa2c8ef] | 616 | async_answer_0(rid, ENOTDIR);
|
---|
[06901c6b] | 617 | goto out;
|
---|
[a8e9ab8d] | 618 | }
|
---|
[1313ee9] | 619 |
|
---|
[b6035ba] | 620 | fs_node_t *fn;
|
---|
[a8e9ab8d] | 621 | if (lflag & L_CREATE)
|
---|
[15f3c3f] | 622 | rc = ops->create(&fn, service_id,
|
---|
[0daba212] | 623 | lflag);
|
---|
[a8e9ab8d] | 624 | else
|
---|
[15f3c3f] | 625 | rc = ops->node_get(&fn, service_id,
|
---|
[34f62f8] | 626 | index);
|
---|
[0daba212] | 627 | on_error(rc, goto out_with_answer);
|
---|
[1313ee9] | 628 |
|
---|
[b6035ba] | 629 | if (fn) {
|
---|
| 630 | rc = ops->link(cur, fn, component);
|
---|
[0013b9ce] | 631 | if (rc != EOK) {
|
---|
[0daba212] | 632 | if (lflag & L_CREATE)
|
---|
| 633 | (void) ops->destroy(fn);
|
---|
[b946bf83] | 634 | else
|
---|
| 635 | (void) ops->node_put(fn);
|
---|
[ffa2c8ef] | 636 | async_answer_0(rid, rc);
|
---|
[2c448fb] | 637 | } else {
|
---|
[ed903174] | 638 | aoff64_t size = ops->size_get(fn);
|
---|
[ffa2c8ef] | 639 | async_answer_5(rid, fs_handle,
|
---|
[15f3c3f] | 640 | service_id,
|
---|
[b6035ba] | 641 | ops->index_get(fn),
|
---|
[ed903174] | 642 | LOWER32(size),
|
---|
| 643 | UPPER32(size),
|
---|
[b6035ba] | 644 | ops->lnkcnt_get(fn));
|
---|
[0daba212] | 645 | (void) ops->node_put(fn);
|
---|
[2c448fb] | 646 | }
|
---|
[1313ee9] | 647 | } else
|
---|
[ffa2c8ef] | 648 | async_answer_0(rid, ENOSPC);
|
---|
[1313ee9] | 649 |
|
---|
[06901c6b] | 650 | goto out;
|
---|
[1313ee9] | 651 | }
|
---|
| 652 |
|
---|
[ffa2c8ef] | 653 | async_answer_0(rid, ENOENT);
|
---|
[06901c6b] | 654 | goto out;
|
---|
[2c448fb] | 655 | }
|
---|
[1313ee9] | 656 |
|
---|
[0daba212] | 657 | if (par) {
|
---|
| 658 | rc = ops->node_put(par);
|
---|
| 659 | on_error(rc, goto out_with_answer);
|
---|
| 660 | }
|
---|
[1313ee9] | 661 |
|
---|
| 662 | /* Descend one level */
|
---|
[7b6d98b] | 663 | par = cur;
|
---|
[2c448fb] | 664 | cur = tmp;
|
---|
[06901c6b] | 665 | tmp = NULL;
|
---|
[2c448fb] | 666 | }
|
---|
[1313ee9] | 667 |
|
---|
| 668 | /* Handle miss: excessive components */
|
---|
[0daba212] | 669 | if (next <= last) {
|
---|
| 670 | bool has_children;
|
---|
| 671 | rc = ops->has_children(&has_children, cur);
|
---|
| 672 | on_error(rc, goto out_with_answer);
|
---|
[1313ee9] | 673 |
|
---|
[0daba212] | 674 | if (has_children)
|
---|
| 675 | goto skip_miss;
|
---|
[1313ee9] | 676 |
|
---|
[a8e9ab8d] | 677 | if (lflag & (L_CREATE | L_LINK)) {
|
---|
[2c448fb] | 678 | if (!ops->is_directory(cur)) {
|
---|
[ffa2c8ef] | 679 | async_answer_0(rid, ENOTDIR);
|
---|
[06901c6b] | 680 | goto out;
|
---|
[2c448fb] | 681 | }
|
---|
[1313ee9] | 682 |
|
---|
| 683 | /* Collect next component */
|
---|
[c9f6e49f] | 684 | len = 0;
|
---|
[2c448fb] | 685 | while (next <= last) {
|
---|
[efcebe1] | 686 | if (plb_get_char(next) == '/') {
|
---|
[1313ee9] | 687 | /* More than one component */
|
---|
[ffa2c8ef] | 688 | async_answer_0(rid, ENOENT);
|
---|
[06901c6b] | 689 | goto out;
|
---|
[2c448fb] | 690 | }
|
---|
[1313ee9] | 691 |
|
---|
[2c448fb] | 692 | if (len + 1 == NAME_MAX) {
|
---|
[1313ee9] | 693 | /* Component length overflow */
|
---|
[ffa2c8ef] | 694 | async_answer_0(rid, ENAMETOOLONG);
|
---|
[06901c6b] | 695 | goto out;
|
---|
[2c448fb] | 696 | }
|
---|
[1313ee9] | 697 |
|
---|
[efcebe1] | 698 | component[len++] = plb_get_char(next);
|
---|
[1313ee9] | 699 | /* Process next character */
|
---|
| 700 | next++;
|
---|
[2c448fb] | 701 | }
|
---|
[1313ee9] | 702 |
|
---|
[2c448fb] | 703 | assert(len);
|
---|
| 704 | component[len] = '\0';
|
---|
[1313ee9] | 705 |
|
---|
[b6035ba] | 706 | fs_node_t *fn;
|
---|
[a8e9ab8d] | 707 | if (lflag & L_CREATE)
|
---|
[15f3c3f] | 708 | rc = ops->create(&fn, service_id, lflag);
|
---|
[a8e9ab8d] | 709 | else
|
---|
[15f3c3f] | 710 | rc = ops->node_get(&fn, service_id, index);
|
---|
[0daba212] | 711 | on_error(rc, goto out_with_answer);
|
---|
[1313ee9] | 712 |
|
---|
[b6035ba] | 713 | if (fn) {
|
---|
| 714 | rc = ops->link(cur, fn, component);
|
---|
[0013b9ce] | 715 | if (rc != EOK) {
|
---|
[a8e9ab8d] | 716 | if (lflag & L_CREATE)
|
---|
[0daba212] | 717 | (void) ops->destroy(fn);
|
---|
[b946bf83] | 718 | else
|
---|
| 719 | (void) ops->node_put(fn);
|
---|
[ffa2c8ef] | 720 | async_answer_0(rid, rc);
|
---|
[2c448fb] | 721 | } else {
|
---|
[ed903174] | 722 | aoff64_t size = ops->size_get(fn);
|
---|
[ffa2c8ef] | 723 | async_answer_5(rid, fs_handle,
|
---|
[15f3c3f] | 724 | service_id,
|
---|
[b6035ba] | 725 | ops->index_get(fn),
|
---|
[ed903174] | 726 | LOWER32(size),
|
---|
| 727 | UPPER32(size),
|
---|
[b6035ba] | 728 | ops->lnkcnt_get(fn));
|
---|
[0daba212] | 729 | (void) ops->node_put(fn);
|
---|
[2c448fb] | 730 | }
|
---|
[1313ee9] | 731 | } else
|
---|
[ffa2c8ef] | 732 | async_answer_0(rid, ENOSPC);
|
---|
[1313ee9] | 733 |
|
---|
[06901c6b] | 734 | goto out;
|
---|
[2c448fb] | 735 | }
|
---|
[1313ee9] | 736 |
|
---|
[ffa2c8ef] | 737 | async_answer_0(rid, ENOENT);
|
---|
[06901c6b] | 738 | goto out;
|
---|
[2c448fb] | 739 | }
|
---|
[1313ee9] | 740 |
|
---|
[0daba212] | 741 | skip_miss:
|
---|
[1313ee9] | 742 |
|
---|
| 743 | /* Handle hit */
|
---|
[a8e9ab8d] | 744 | if (lflag & L_UNLINK) {
|
---|
[1313ee9] | 745 | unsigned int old_lnkcnt = ops->lnkcnt_get(cur);
|
---|
[0daba212] | 746 | rc = ops->unlink(par, cur, component);
|
---|
[ed903174] | 747 |
|
---|
| 748 | if (rc == EOK) {
|
---|
| 749 | aoff64_t size = ops->size_get(cur);
|
---|
[15f3c3f] | 750 | async_answer_5(rid, fs_handle, service_id,
|
---|
[ed903174] | 751 | ops->index_get(cur), LOWER32(size), UPPER32(size),
|
---|
| 752 | old_lnkcnt);
|
---|
| 753 | } else
|
---|
[ffa2c8ef] | 754 | async_answer_0(rid, rc);
|
---|
[ed903174] | 755 |
|
---|
[06901c6b] | 756 | goto out;
|
---|
[2c448fb] | 757 | }
|
---|
[1313ee9] | 758 |
|
---|
[a8e9ab8d] | 759 | if (((lflag & (L_CREATE | L_EXCLUSIVE)) == (L_CREATE | L_EXCLUSIVE)) ||
|
---|
| 760 | (lflag & L_LINK)) {
|
---|
[ffa2c8ef] | 761 | async_answer_0(rid, EEXIST);
|
---|
[06901c6b] | 762 | goto out;
|
---|
[2c448fb] | 763 | }
|
---|
[1313ee9] | 764 |
|
---|
[2c448fb] | 765 | if ((lflag & L_FILE) && (ops->is_directory(cur))) {
|
---|
[ffa2c8ef] | 766 | async_answer_0(rid, EISDIR);
|
---|
[06901c6b] | 767 | goto out;
|
---|
[2c448fb] | 768 | }
|
---|
[1313ee9] | 769 |
|
---|
[2c448fb] | 770 | if ((lflag & L_DIRECTORY) && (ops->is_file(cur))) {
|
---|
[ffa2c8ef] | 771 | async_answer_0(rid, ENOTDIR);
|
---|
[06901c6b] | 772 | goto out;
|
---|
[2c448fb] | 773 | }
|
---|
[f7376cbf] | 774 |
|
---|
| 775 | if ((lflag & L_ROOT) && par) {
|
---|
[ffa2c8ef] | 776 | async_answer_0(rid, EINVAL);
|
---|
[f7376cbf] | 777 | goto out;
|
---|
| 778 | }
|
---|
[1313ee9] | 779 |
|
---|
[0daba212] | 780 | out_with_answer:
|
---|
[1313ee9] | 781 |
|
---|
[0daba212] | 782 | if (rc == EOK) {
|
---|
[1313ee9] | 783 | if (lflag & L_OPEN)
|
---|
| 784 | rc = ops->node_open(cur);
|
---|
| 785 |
|
---|
[ed903174] | 786 | if (rc == EOK) {
|
---|
| 787 | aoff64_t size = ops->size_get(cur);
|
---|
[15f3c3f] | 788 | async_answer_5(rid, fs_handle, service_id,
|
---|
[ed903174] | 789 | ops->index_get(cur), LOWER32(size), UPPER32(size),
|
---|
| 790 | ops->lnkcnt_get(cur));
|
---|
| 791 | } else
|
---|
[ffa2c8ef] | 792 | async_answer_0(rid, rc);
|
---|
[ed903174] | 793 |
|
---|
[1313ee9] | 794 | } else
|
---|
[ffa2c8ef] | 795 | async_answer_0(rid, rc);
|
---|
[1313ee9] | 796 |
|
---|
[06901c6b] | 797 | out:
|
---|
[1313ee9] | 798 |
|
---|
[06901c6b] | 799 | if (par)
|
---|
[0daba212] | 800 | (void) ops->node_put(par);
|
---|
[1313ee9] | 801 |
|
---|
[06901c6b] | 802 | if (cur)
|
---|
[0daba212] | 803 | (void) ops->node_put(cur);
|
---|
[1313ee9] | 804 |
|
---|
[06901c6b] | 805 | if (tmp)
|
---|
[0daba212] | 806 | (void) ops->node_put(tmp);
|
---|
[2c448fb] | 807 | }
|
---|
| 808 |
|
---|
[75160a6] | 809 | void libfs_stat(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
|
---|
| 810 | ipc_call_t *request)
|
---|
| 811 | {
|
---|
[15f3c3f] | 812 | service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request);
|
---|
[75160a6] | 813 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
|
---|
[1313ee9] | 814 |
|
---|
[0daba212] | 815 | fs_node_t *fn;
|
---|
[15f3c3f] | 816 | int rc = ops->node_get(&fn, service_id, index);
|
---|
[0daba212] | 817 | on_error(rc, answer_and_return(rid, rc));
|
---|
[1313ee9] | 818 |
|
---|
[75160a6] | 819 | ipc_callid_t callid;
|
---|
| 820 | size_t size;
|
---|
[1313ee9] | 821 | if ((!async_data_read_receive(&callid, &size)) ||
|
---|
| 822 | (size != sizeof(struct stat))) {
|
---|
| 823 | ops->node_put(fn);
|
---|
[ffa2c8ef] | 824 | async_answer_0(callid, EINVAL);
|
---|
| 825 | async_answer_0(rid, EINVAL);
|
---|
[75160a6] | 826 | return;
|
---|
| 827 | }
|
---|
[1313ee9] | 828 |
|
---|
[0143f72] | 829 | struct stat stat;
|
---|
| 830 | memset(&stat, 0, sizeof(struct stat));
|
---|
[75160a6] | 831 |
|
---|
[0143f72] | 832 | stat.fs_handle = fs_handle;
|
---|
[15f3c3f] | 833 | stat.service_id = service_id;
|
---|
[0143f72] | 834 | stat.index = index;
|
---|
[1313ee9] | 835 | stat.lnkcnt = ops->lnkcnt_get(fn);
|
---|
[0143f72] | 836 | stat.is_file = ops->is_file(fn);
|
---|
[1313ee9] | 837 | stat.is_directory = ops->is_directory(fn);
|
---|
[0143f72] | 838 | stat.size = ops->size_get(fn);
|
---|
[b33870b] | 839 | stat.service = ops->service_get(fn);
|
---|
[1313ee9] | 840 |
|
---|
| 841 | ops->node_put(fn);
|
---|
| 842 |
|
---|
[0da4e41] | 843 | async_data_read_finalize(callid, &stat, sizeof(struct stat));
|
---|
[ffa2c8ef] | 844 | async_answer_0(rid, EOK);
|
---|
[75160a6] | 845 | }
|
---|
| 846 |
|
---|
[595edf5] | 847 | /** Open VFS triplet.
|
---|
| 848 | *
|
---|
[1313ee9] | 849 | * @param ops libfs operations structure with function pointers to
|
---|
| 850 | * file system implementation
|
---|
| 851 | * @param rid Request ID of the VFS_OUT_OPEN_NODE request.
|
---|
| 852 | * @param request VFS_OUT_OPEN_NODE request data itself.
|
---|
[595edf5] | 853 | *
|
---|
| 854 | */
|
---|
| 855 | void libfs_open_node(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid,
|
---|
| 856 | ipc_call_t *request)
|
---|
| 857 | {
|
---|
[15f3c3f] | 858 | service_id_t service_id = IPC_GET_ARG1(*request);
|
---|
[595edf5] | 859 | fs_index_t index = IPC_GET_ARG2(*request);
|
---|
| 860 |
|
---|
[ed903174] | 861 | fs_node_t *fn;
|
---|
[15f3c3f] | 862 | int rc = ops->node_get(&fn, service_id, index);
|
---|
[0daba212] | 863 | on_error(rc, answer_and_return(rid, rc));
|
---|
[595edf5] | 864 |
|
---|
[0daba212] | 865 | if (fn == NULL) {
|
---|
[ffa2c8ef] | 866 | async_answer_0(rid, ENOENT);
|
---|
[595edf5] | 867 | return;
|
---|
| 868 | }
|
---|
| 869 |
|
---|
[1313ee9] | 870 | rc = ops->node_open(fn);
|
---|
[ed903174] | 871 | aoff64_t size = ops->size_get(fn);
|
---|
[efcebe1] | 872 | async_answer_4(rid, rc, LOWER32(size), UPPER32(size),
|
---|
| 873 | ops->lnkcnt_get(fn),
|
---|
[2e983c7] | 874 | (ops->is_file(fn) ? L_FILE : 0) | (ops->is_directory(fn) ? L_DIRECTORY : 0));
|
---|
[595edf5] | 875 |
|
---|
[0daba212] | 876 | (void) ops->node_put(fn);
|
---|
[595edf5] | 877 | }
|
---|
| 878 |
|
---|
[74303b6] | 879 | /** @}
|
---|
| 880 | */
|
---|