Changes in uspace/lib/fs/libfs.c [b33870b:9934f7d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/fs/libfs.c
rb33870b r9934f7d 45 45 #include <mem.h> 46 46 #include <sys/stat.h> 47 #include <stdlib.h>48 47 49 48 #define on_error(rc, action) \ … … 62 61 } while (0) 63 62 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 {79 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);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;93 rc = vfs_out_ops->mounted(service_id, opts, &index, &size, &lnkcnt);94 95 if (rc == EOK)96 async_answer_4(rid, EOK, index, LOWER32(size), UPPER32(size),97 lnkcnt);98 else99 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 {111 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);112 int rc;113 114 rc = vfs_out_ops->unmounted(service_id);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 {132 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);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 139 rc = vfs_out_ops->read(service_id, index, pos, &rbytes);140 141 if (rc == EOK)142 async_answer_1(rid, EOK, rbytes);143 else144 async_answer_0(rid, rc);145 }146 147 static void vfs_out_write(ipc_callid_t rid, ipc_call_t *req)148 {149 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);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 157 rc = vfs_out_ops->write(service_id, index, pos, &wbytes, &nsize);158 159 if (rc == EOK)160 async_answer_3(rid, EOK, wbytes, LOWER32(nsize), UPPER32(nsize));161 else162 async_answer_0(rid, rc);163 }164 165 static void vfs_out_truncate(ipc_callid_t rid, ipc_call_t *req)166 {167 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);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 173 rc = vfs_out_ops->truncate(service_id, index, size);174 175 async_answer_0(rid, rc);176 }177 178 static void vfs_out_close(ipc_callid_t rid, ipc_call_t *req)179 {180 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);181 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req);182 int rc;183 184 rc = vfs_out_ops->close(service_id, index);185 186 async_answer_0(rid, rc);187 }188 189 static void vfs_out_destroy(ipc_callid_t rid, ipc_call_t *req)190 {191 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);192 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req);193 int rc;194 195 rc = vfs_out_ops->destroy(service_id, index);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 {212 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);213 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req);214 int rc;215 216 rc = vfs_out_ops->sync(service_id, index);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 by226 * IPC_M_CONNECT_ME_TO calls as opposed to callback connections227 * 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 286 63 /** Register file system server. 287 64 * … … 291 68 * 292 69 * @param sess Session for communication with VFS. 70 * @param reg File system registration structure. It will be 71 * initialized by this function. 293 72 * @param info VFS info structure supplied by the file system 294 73 * implementation. 295 * @param vops Address of the vfs_out_ops_t structure.296 * @param lops Address of the libfs_ops_t structure.74 * @param conn Connection fibril for handling all calls originating in 75 * VFS. 297 76 * 298 77 * @return EOK on success or a non-zero error code on errror. 299 78 * 300 79 */ 301 int fs_register(async_sess_t *sess, vfs_info_t *info, vfs_out_ops_t *vops,302 libfs_ops_t *lops)80 int fs_register(async_sess_t *sess, fs_reg_t *reg, vfs_info_t *info, 81 async_client_conn_t conn) 303 82 { 304 83 /* … … 325 104 326 105 /* 327 * Set VFS_OUT and libfs operations.328 */329 vfs_out_ops = vops;330 libfs_ops = lops;331 332 /*333 106 * Ask VFS for callback connection. 334 107 */ 335 async_connect_to_me(exch, 0, 0, 0, vfs_connection, NULL);108 async_connect_to_me(exch, 0, 0, 0, conn, NULL); 336 109 337 110 /* 338 111 * Allocate piece of address space for PLB. 339 112 */ 340 reg .plb_ro = as_get_mappable_page(PLB_SIZE);341 if (!reg .plb_ro) {113 reg->plb_ro = as_get_mappable_page(PLB_SIZE); 114 if (!reg->plb_ro) { 342 115 async_exchange_end(exch); 343 116 async_wait_for(req, NULL); … … 348 121 * Request sharing the Path Lookup Buffer with VFS. 349 122 */ 350 rc = async_share_in_start_0_0(exch, reg .plb_ro, PLB_SIZE);123 rc = async_share_in_start_0_0(exch, reg->plb_ro, PLB_SIZE); 351 124 352 125 async_exchange_end(exch); … … 361 134 */ 362 135 async_wait_for(req, NULL); 363 reg .fs_handle = (int) IPC_GET_ARG1(answer);136 reg->fs_handle = (int) IPC_GET_ARG1(answer); 364 137 365 138 /* … … 367 140 * the same connection fibril as well. 368 141 */ 369 async_set_client_connection( vfs_connection);142 async_set_client_connection(conn); 370 143 371 144 return IPC_GET_RETVAL(answer); … … 378 151 379 152 void libfs_mount(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid, 380 ipc_call_t *req )153 ipc_call_t *request) 381 154 { 382 service_id_t mp_service_id = (service_id_t) IPC_GET_ARG1(*req);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 );385 service_id_t mr_service_id = (service_id_t) IPC_GET_ARG4(*req);155 devmap_handle_t mp_devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 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); 158 devmap_handle_t mr_devmap_handle = (devmap_handle_t) IPC_GET_ARG4(*request); 386 159 387 160 async_sess_t *mountee_sess = async_clone_receive(EXCHANGE_PARALLEL); … … 392 165 393 166 fs_node_t *fn; 394 int res = ops->node_get(&fn, mp_ service_id, mp_fs_index);167 int res = ops->node_get(&fn, mp_devmap_handle, mp_fs_index); 395 168 if ((res != EOK) || (!fn)) { 396 169 async_hangup(mountee_sess); … … 422 195 ipc_call_t answer; 423 196 int rc = async_data_write_forward_1_1(exch, VFS_OUT_MOUNTED, 424 mr_ service_id, &answer);197 mr_devmap_handle, &answer); 425 198 async_exchange_end(exch); 426 199 … … 428 201 fn->mp_data.mp_active = true; 429 202 fn->mp_data.fs_handle = mr_fs_handle; 430 fn->mp_data. service_id = mr_service_id;203 fn->mp_data.devmap_handle = mr_devmap_handle; 431 204 fn->mp_data.sess = mountee_sess; 432 205 } … … 435 208 * Do not release the FS node so that it stays in memory. 436 209 */ 437 async_answer_ 4(rid, rc, IPC_GET_ARG1(answer), IPC_GET_ARG2(answer),438 IPC_GET_ARG3(answer) , IPC_GET_ARG4(answer));210 async_answer_3(rid, rc, IPC_GET_ARG1(answer), IPC_GET_ARG2(answer), 211 IPC_GET_ARG3(answer)); 439 212 } 440 213 441 void libfs_unmount(libfs_ops_t *ops, ipc_callid_t rid, ipc_call_t *req )214 void libfs_unmount(libfs_ops_t *ops, ipc_callid_t rid, ipc_call_t *request) 442 215 { 443 service_id_t mp_service_id = (service_id_t) IPC_GET_ARG1(*req);444 fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*req );216 devmap_handle_t mp_devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 217 fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*request); 445 218 fs_node_t *fn; 446 219 int res; 447 220 448 res = ops->node_get(&fn, mp_ service_id, mp_fs_index);221 res = ops->node_get(&fn, mp_devmap_handle, mp_fs_index); 449 222 if ((res != EOK) || (!fn)) { 450 223 async_answer_0(rid, combine_rc(res, ENOENT)); … … 465 238 */ 466 239 async_exch_t *exch = async_exchange_begin(fn->mp_data.sess); 467 res = async_req_1_0(exch, VFS_OUT_UNMOUNTED, fn->mp_data. service_id);240 res = async_req_1_0(exch, VFS_OUT_UNMOUNTED, fn->mp_data.devmap_handle); 468 241 async_exchange_end(exch); 469 242 … … 475 248 fn->mp_data.mp_active = false; 476 249 fn->mp_data.fs_handle = 0; 477 fn->mp_data. service_id= 0;250 fn->mp_data.devmap_handle = 0; 478 251 fn->mp_data.sess = NULL; 479 252 … … 484 257 (void) ops->node_put(fn); 485 258 async_answer_0(rid, res); 486 }487 488 static char plb_get_char(unsigned pos)489 {490 return reg.plb_ro[pos % PLB_SIZE];491 259 } 492 260 … … 505 273 */ 506 274 void libfs_lookup(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid, 507 ipc_call_t *req )275 ipc_call_t *request) 508 276 { 509 unsigned int first = IPC_GET_ARG1(*req );510 unsigned int last = IPC_GET_ARG2(*req );277 unsigned int first = IPC_GET_ARG1(*request); 278 unsigned int last = IPC_GET_ARG2(*request); 511 279 unsigned int next = first; 512 service_id_t service_id = IPC_GET_ARG3(*req);513 int lflag = IPC_GET_ARG4(*req );514 fs_index_t index = IPC_GET_ARG5(*req );280 devmap_handle_t devmap_handle = IPC_GET_ARG3(*request); 281 int lflag = IPC_GET_ARG4(*request); 282 fs_index_t index = IPC_GET_ARG5(*request); 515 283 char component[NAME_MAX + 1]; 516 284 int len; … … 524 292 fs_node_t *tmp = NULL; 525 293 526 rc = ops->root_get(&cur, service_id);294 rc = ops->root_get(&cur, devmap_handle); 527 295 on_error(rc, goto out_with_answer); 528 296 … … 530 298 async_exch_t *exch = async_exchange_begin(cur->mp_data.sess); 531 299 async_forward_slow(rid, exch, VFS_OUT_LOOKUP, next, last, 532 cur->mp_data.service_id, lflag, index, 533 IPC_FF_ROUTE_FROM_ME); 300 cur->mp_data.devmap_handle, lflag, index, IPC_FF_ROUTE_FROM_ME); 534 301 async_exchange_end(exch); 535 302 … … 539 306 540 307 /* Eat slash */ 541 if ( plb_get_char(next) == '/')308 if (ops->plb_get_char(next) == '/') 542 309 next++; 543 310 … … 552 319 /* Collect the component */ 553 320 len = 0; 554 while ((next <= last) && ( plb_get_char(next) != '/')) {321 while ((next <= last) && (ops->plb_get_char(next) != '/')) { 555 322 if (len + 1 == NAME_MAX) { 556 323 /* Component length overflow */ … … 558 325 goto out; 559 326 } 560 component[len++] = plb_get_char(next);327 component[len++] = ops->plb_get_char(next); 561 328 /* Process next character */ 562 329 next++; … … 590 357 591 358 async_exch_t *exch = async_exchange_begin(tmp->mp_data.sess); 592 async_forward_slow(rid, exch, VFS_OUT_LOOKUP, next, 593 last, tmp->mp_data.service_id, lflag, index,359 async_forward_slow(rid, exch, VFS_OUT_LOOKUP, next, last, 360 tmp->mp_data.devmap_handle, lflag, index, 594 361 IPC_FF_ROUTE_FROM_ME); 595 362 async_exchange_end(exch); … … 620 387 fs_node_t *fn; 621 388 if (lflag & L_CREATE) 622 rc = ops->create(&fn, service_id,389 rc = ops->create(&fn, devmap_handle, 623 390 lflag); 624 391 else 625 rc = ops->node_get(&fn, service_id,392 rc = ops->node_get(&fn, devmap_handle, 626 393 index); 627 394 on_error(rc, goto out_with_answer); … … 638 405 aoff64_t size = ops->size_get(fn); 639 406 async_answer_5(rid, fs_handle, 640 service_id,407 devmap_handle, 641 408 ops->index_get(fn), 642 409 LOWER32(size), … … 684 451 len = 0; 685 452 while (next <= last) { 686 if ( plb_get_char(next) == '/') {453 if (ops->plb_get_char(next) == '/') { 687 454 /* More than one component */ 688 455 async_answer_0(rid, ENOENT); … … 696 463 } 697 464 698 component[len++] = plb_get_char(next);465 component[len++] = ops->plb_get_char(next); 699 466 /* Process next character */ 700 467 next++; … … 706 473 fs_node_t *fn; 707 474 if (lflag & L_CREATE) 708 rc = ops->create(&fn, service_id, lflag);475 rc = ops->create(&fn, devmap_handle, lflag); 709 476 else 710 rc = ops->node_get(&fn, service_id, index);477 rc = ops->node_get(&fn, devmap_handle, index); 711 478 on_error(rc, goto out_with_answer); 712 479 … … 722 489 aoff64_t size = ops->size_get(fn); 723 490 async_answer_5(rid, fs_handle, 724 service_id,491 devmap_handle, 725 492 ops->index_get(fn), 726 493 LOWER32(size), … … 748 515 if (rc == EOK) { 749 516 aoff64_t size = ops->size_get(cur); 750 async_answer_5(rid, fs_handle, service_id,517 async_answer_5(rid, fs_handle, devmap_handle, 751 518 ops->index_get(cur), LOWER32(size), UPPER32(size), 752 519 old_lnkcnt); … … 786 553 if (rc == EOK) { 787 554 aoff64_t size = ops->size_get(cur); 788 async_answer_5(rid, fs_handle, service_id,555 async_answer_5(rid, fs_handle, devmap_handle, 789 556 ops->index_get(cur), LOWER32(size), UPPER32(size), 790 557 ops->lnkcnt_get(cur)); … … 810 577 ipc_call_t *request) 811 578 { 812 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request);579 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 813 580 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 814 581 815 582 fs_node_t *fn; 816 int rc = ops->node_get(&fn, service_id, index);583 int rc = ops->node_get(&fn, devmap_handle, index); 817 584 on_error(rc, answer_and_return(rid, rc)); 818 585 … … 831 598 832 599 stat.fs_handle = fs_handle; 833 stat. service_id = service_id;600 stat.devmap_handle = devmap_handle; 834 601 stat.index = index; 835 602 stat.lnkcnt = ops->lnkcnt_get(fn); … … 837 604 stat.is_directory = ops->is_directory(fn); 838 605 stat.size = ops->size_get(fn); 839 stat. service = ops->service_get(fn);606 stat.device = ops->device_get(fn); 840 607 841 608 ops->node_put(fn); … … 856 623 ipc_call_t *request) 857 624 { 858 service_id_t service_id= IPC_GET_ARG1(*request);625 devmap_handle_t devmap_handle = IPC_GET_ARG1(*request); 859 626 fs_index_t index = IPC_GET_ARG2(*request); 860 627 861 628 fs_node_t *fn; 862 int rc = ops->node_get(&fn, service_id, index);629 int rc = ops->node_get(&fn, devmap_handle, index); 863 630 on_error(rc, answer_and_return(rid, rc)); 864 631 … … 870 637 rc = ops->node_open(fn); 871 638 aoff64_t size = ops->size_get(fn); 872 async_answer_4(rid, rc, LOWER32(size), UPPER32(size), 873 ops->lnkcnt_get(fn), 639 async_answer_4(rid, rc, LOWER32(size), UPPER32(size), ops->lnkcnt_get(fn), 874 640 (ops->is_file(fn) ? L_FILE : 0) | (ops->is_directory(fn) ? L_DIRECTORY : 0)); 875 641
Note:
See TracChangeset
for help on using the changeset viewer.