Changes in uspace/srv/fs/tmpfs/tmpfs_ops.c [b33870b:b72efe8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
rb33870b rb72efe8 69 69 /* Forward declarations of static functions. */ 70 70 static int tmpfs_match(fs_node_t **, fs_node_t *, const char *); 71 static int tmpfs_node_get(fs_node_t **, service_id_t, fs_index_t);71 static int tmpfs_node_get(fs_node_t **, devmap_handle_t, fs_index_t); 72 72 static int tmpfs_node_open(fs_node_t *); 73 73 static int tmpfs_node_put(fs_node_t *); 74 static int tmpfs_create_node(fs_node_t **, service_id_t, int);74 static int tmpfs_create_node(fs_node_t **, devmap_handle_t, int); 75 75 static int tmpfs_destroy_node(fs_node_t *); 76 76 static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *); … … 78 78 79 79 /* Implementation of helper functions. */ 80 static int tmpfs_root_get(fs_node_t **rfn, service_id_t service_id)81 { 82 return tmpfs_node_get(rfn, service_id, TMPFS_SOME_ROOT);80 static int tmpfs_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle) 81 { 82 return tmpfs_node_get(rfn, devmap_handle, TMPFS_SOME_ROOT); 83 83 } 84 84 … … 104 104 } 105 105 106 static char tmpfs_plb_get_char(unsigned pos) 107 { 108 return tmpfs_reg.plb_ro[pos % PLB_SIZE]; 109 } 110 106 111 static bool tmpfs_is_directory(fs_node_t *fn) 107 112 { … … 114 119 } 115 120 116 static service_id_t tmpfs_service_get(fs_node_t *fn)121 static devmap_handle_t tmpfs_device_get(fs_node_t *fn) 117 122 { 118 123 return 0; … … 134 139 .size_get = tmpfs_size_get, 135 140 .lnkcnt_get = tmpfs_lnkcnt_get, 141 .plb_get_char = tmpfs_plb_get_char, 136 142 .is_directory = tmpfs_is_directory, 137 143 .is_file = tmpfs_is_file, 138 . service_get = tmpfs_service_get144 .device_get = tmpfs_device_get 139 145 }; 140 146 … … 158 164 switch (keys) { 159 165 case 1: 160 return (nodep-> service_id== key[NODES_KEY_DEV]);166 return (nodep->devmap_handle == key[NODES_KEY_DEV]); 161 167 case 2: 162 return ((nodep-> service_id== key[NODES_KEY_DEV]) &&168 return ((nodep->devmap_handle == key[NODES_KEY_DEV]) && 163 169 (nodep->index == key[NODES_KEY_INDEX])); 164 170 default: … … 202 208 nodep->bp = NULL; 203 209 nodep->index = 0; 204 nodep-> service_id= 0;210 nodep->devmap_handle = 0; 205 211 nodep->type = TMPFS_NONE; 206 212 nodep->lnkcnt = 0; … … 226 232 } 227 233 228 static bool tmpfs_instance_init( service_id_t service_id)234 static bool tmpfs_instance_init(devmap_handle_t devmap_handle) 229 235 { 230 236 fs_node_t *rfn; 231 237 int rc; 232 238 233 rc = tmpfs_create_node(&rfn, service_id, L_DIRECTORY);239 rc = tmpfs_create_node(&rfn, devmap_handle, L_DIRECTORY); 234 240 if (rc != EOK || !rfn) 235 241 return false; … … 238 244 } 239 245 240 static void tmpfs_instance_done( service_id_t service_id)246 static void tmpfs_instance_done(devmap_handle_t devmap_handle) 241 247 { 242 248 unsigned long key[] = { 243 [NODES_KEY_DEV] = service_id249 [NODES_KEY_DEV] = devmap_handle 244 250 }; 245 251 /* … … 270 276 } 271 277 272 int tmpfs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index)278 int tmpfs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index) 273 279 { 274 280 unsigned long key[] = { 275 [NODES_KEY_DEV] = service_id,281 [NODES_KEY_DEV] = devmap_handle, 276 282 [NODES_KEY_INDEX] = index 277 283 }; … … 299 305 } 300 306 301 int tmpfs_create_node(fs_node_t **rfn, service_id_t service_id, int lflag)307 int tmpfs_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int lflag) 302 308 { 303 309 fs_node_t *rootfn; … … 318 324 nodep->bp->data = nodep; /* link the FS and TMPFS nodes */ 319 325 320 rc = tmpfs_root_get(&rootfn, service_id);326 rc = tmpfs_root_get(&rootfn, devmap_handle); 321 327 assert(rc == EOK); 322 328 if (!rootfn) … … 324 330 else 325 331 nodep->index = tmpfs_next_index++; 326 nodep-> service_id = service_id;332 nodep->devmap_handle = devmap_handle; 327 333 if (lflag & L_DIRECTORY) 328 334 nodep->type = TMPFS_DIRECTORY; … … 332 338 /* Insert the new node into the nodes hash table. */ 333 339 unsigned long key[] = { 334 [NODES_KEY_DEV] = nodep-> service_id,340 [NODES_KEY_DEV] = nodep->devmap_handle, 335 341 [NODES_KEY_INDEX] = nodep->index 336 342 }; … … 348 354 349 355 unsigned long key[] = { 350 [NODES_KEY_DEV] = nodep-> service_id,356 [NODES_KEY_DEV] = nodep->devmap_handle, 351 357 [NODES_KEY_INDEX] = nodep->index 352 358 }; … … 427 433 } 428 434 429 /* 430 * Implementation of the VFS_OUT interface. 431 */ 432 433 static int 434 tmpfs_mounted(service_id_t service_id, const char *opts, 435 fs_index_t *index, aoff64_t *size, unsigned *lnkcnt) 436 { 435 void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request) 436 { 437 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 437 438 fs_node_t *rootfn; 438 439 int rc; 439 440 441 /* Accept the mount options. */ 442 char *opts; 443 rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); 444 if (rc != EOK) { 445 async_answer_0(rid, rc); 446 return; 447 } 448 440 449 /* Check if this device is not already mounted. */ 441 rc = tmpfs_root_get(&rootfn, service_id);450 rc = tmpfs_root_get(&rootfn, devmap_handle); 442 451 if ((rc == EOK) && (rootfn)) { 443 452 (void) tmpfs_node_put(rootfn); 444 return EEXIST; 453 free(opts); 454 async_answer_0(rid, EEXIST); 455 return; 445 456 } 446 457 447 458 /* Initialize TMPFS instance. */ 448 if (!tmpfs_instance_init(service_id)) 449 return ENOMEM; 450 451 rc = tmpfs_root_get(&rootfn, service_id); 459 if (!tmpfs_instance_init(devmap_handle)) { 460 free(opts); 461 async_answer_0(rid, ENOMEM); 462 return; 463 } 464 465 rc = tmpfs_root_get(&rootfn, devmap_handle); 452 466 assert(rc == EOK); 453 467 tmpfs_node_t *rootp = TMPFS_NODE(rootfn); 454 468 if (str_cmp(opts, "restore") == 0) { 455 if (!tmpfs_restore(service_id)) 456 return ELIMIT; 457 } 458 459 *index = rootp->index; 460 *size = rootp->size; 461 *lnkcnt = rootp->lnkcnt; 462 463 return EOK; 464 } 465 466 static int tmpfs_unmounted(service_id_t service_id) 467 { 468 tmpfs_instance_done(service_id); 469 return EOK; 470 } 471 472 static int tmpfs_read(service_id_t service_id, fs_index_t index, aoff64_t pos, 473 size_t *rbytes) 474 { 469 if (tmpfs_restore(devmap_handle)) 470 async_answer_3(rid, EOK, rootp->index, rootp->size, 471 rootp->lnkcnt); 472 else 473 async_answer_0(rid, ELIMIT); 474 } else { 475 async_answer_3(rid, EOK, rootp->index, rootp->size, 476 rootp->lnkcnt); 477 } 478 free(opts); 479 } 480 481 void tmpfs_mount(ipc_callid_t rid, ipc_call_t *request) 482 { 483 libfs_mount(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request); 484 } 485 486 void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 487 { 488 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 489 490 tmpfs_instance_done(devmap_handle); 491 async_answer_0(rid, EOK); 492 } 493 494 void tmpfs_unmount(ipc_callid_t rid, ipc_call_t *request) 495 { 496 libfs_unmount(&tmpfs_libfs_ops, rid, request); 497 } 498 499 void tmpfs_lookup(ipc_callid_t rid, ipc_call_t *request) 500 { 501 libfs_lookup(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request); 502 } 503 504 void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) 505 { 506 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 507 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 508 aoff64_t pos = 509 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 510 475 511 /* 476 512 * Lookup the respective TMPFS node. … … 478 514 link_t *hlp; 479 515 unsigned long key[] = { 480 [NODES_KEY_DEV] = service_id,516 [NODES_KEY_DEV] = devmap_handle, 481 517 [NODES_KEY_INDEX] = index 482 518 }; 483 519 hlp = hash_table_find(&nodes, key); 484 if (!hlp) 485 return ENOENT; 520 if (!hlp) { 521 async_answer_0(rid, ENOENT); 522 return; 523 } 486 524 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 487 525 nh_link); … … 494 532 if (!async_data_read_receive(&callid, &size)) { 495 533 async_answer_0(callid, EINVAL); 496 return EINVAL; 534 async_answer_0(rid, EINVAL); 535 return; 497 536 } 498 537 … … 517 556 if (lnk == NULL) { 518 557 async_answer_0(callid, ENOENT); 519 return ENOENT; 558 async_answer_1(rid, ENOENT, 0); 559 return; 520 560 } 521 561 … … 527 567 } 528 568 529 *rbytes = bytes; 530 return EOK; 531 } 532 533 static int 534 tmpfs_write(service_id_t service_id, fs_index_t index, aoff64_t pos, 535 size_t *wbytes, aoff64_t *nsize) 536 { 569 /* 570 * Answer the VFS_READ call. 571 */ 572 async_answer_1(rid, EOK, bytes); 573 } 574 575 void tmpfs_write(ipc_callid_t rid, ipc_call_t *request) 576 { 577 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 578 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 579 aoff64_t pos = 580 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 581 537 582 /* 538 583 * Lookup the respective TMPFS node. … … 540 585 link_t *hlp; 541 586 unsigned long key[] = { 542 [NODES_KEY_DEV] = service_id,587 [NODES_KEY_DEV] = devmap_handle, 543 588 [NODES_KEY_INDEX] = index 544 589 }; 545 590 hlp = hash_table_find(&nodes, key); 546 if (!hlp) 547 return ENOENT; 591 if (!hlp) { 592 async_answer_0(rid, ENOENT); 593 return; 594 } 548 595 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 549 596 nh_link); … … 556 603 if (!async_data_write_receive(&callid, &size)) { 557 604 async_answer_0(callid, EINVAL); 558 return EINVAL; 605 async_answer_0(rid, EINVAL); 606 return; 559 607 } 560 608 … … 564 612 if (pos + size <= nodep->size) { 565 613 /* The file size is not changing. */ 566 (void) async_data_write_finalize(callid, nodep->data + pos, 567 568 goto out;614 (void) async_data_write_finalize(callid, nodep->data + pos, size); 615 async_answer_2(rid, EOK, size, nodep->size); 616 return; 569 617 } 570 618 size_t delta = (pos + size) - nodep->size; … … 579 627 if (!newdata) { 580 628 async_answer_0(callid, ENOMEM); 581 size = 0;582 goto out;629 async_answer_2(rid, EOK, 0, nodep->size); 630 return; 583 631 } 584 632 /* Clear any newly allocated memory in order to emulate gaps. */ … … 587 635 nodep->data = newdata; 588 636 (void) async_data_write_finalize(callid, nodep->data + pos, size); 589 590 out: 591 *wbytes = size; 592 *nsize = nodep->size; 593 return EOK; 594 } 595 596 static int tmpfs_truncate(service_id_t service_id, fs_index_t index, 597 aoff64_t size) 598 { 637 async_answer_2(rid, EOK, size, nodep->size); 638 } 639 640 void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request) 641 { 642 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 643 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 644 aoff64_t size = 645 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 646 599 647 /* 600 648 * Lookup the respective TMPFS node. 601 649 */ 602 650 unsigned long key[] = { 603 [NODES_KEY_DEV] = service_id,651 [NODES_KEY_DEV] = devmap_handle, 604 652 [NODES_KEY_INDEX] = index 605 653 }; 606 654 link_t *hlp = hash_table_find(&nodes, key); 607 if (!hlp) 608 return ENOENT; 609 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, nh_link); 610 611 if (size == nodep->size) 612 return EOK; 613 614 if (size > SIZE_MAX) 615 return ENOMEM; 655 if (!hlp) { 656 async_answer_0(rid, ENOENT); 657 return; 658 } 659 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 660 nh_link); 661 662 if (size == nodep->size) { 663 async_answer_0(rid, EOK); 664 return; 665 } 666 667 if (size > SIZE_MAX) { 668 async_answer_0(rid, ENOMEM); 669 return; 670 } 616 671 617 672 void *newdata = realloc(nodep->data, size); 618 if (!newdata) 619 return ENOMEM; 673 if (!newdata) { 674 async_answer_0(rid, ENOMEM); 675 return; 676 } 620 677 621 678 if (size > nodep->size) { … … 626 683 nodep->size = size; 627 684 nodep->data = newdata; 628 return EOK; 629 } 630 631 static int tmpfs_close(service_id_t service_id, fs_index_t index) 632 { 633 return EOK; 634 } 635 636 static int tmpfs_destroy(service_id_t service_id, fs_index_t index) 637 { 685 async_answer_0(rid, EOK); 686 } 687 688 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request) 689 { 690 async_answer_0(rid, EOK); 691 } 692 693 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request) 694 { 695 devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request); 696 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 697 int rc; 698 638 699 link_t *hlp; 639 700 unsigned long key[] = { 640 [NODES_KEY_DEV] = service_id,701 [NODES_KEY_DEV] = devmap_handle, 641 702 [NODES_KEY_INDEX] = index 642 703 }; 643 704 hlp = hash_table_find(&nodes, key); 644 if (!hlp) 645 return ENOENT; 705 if (!hlp) { 706 async_answer_0(rid, ENOENT); 707 return; 708 } 646 709 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 647 710 nh_link); 648 return tmpfs_destroy_node(FS_NODE(nodep)); 649 } 650 651 static int tmpfs_sync(service_id_t service_id, fs_index_t index) 711 rc = tmpfs_destroy_node(FS_NODE(nodep)); 712 async_answer_0(rid, rc); 713 } 714 715 void tmpfs_open_node(ipc_callid_t rid, ipc_call_t *request) 716 { 717 libfs_open_node(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request); 718 } 719 720 void tmpfs_stat(ipc_callid_t rid, ipc_call_t *request) 721 { 722 libfs_stat(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request); 723 } 724 725 void tmpfs_sync(ipc_callid_t rid, ipc_call_t *request) 652 726 { 653 727 /* … … 655 729 * thus the sync operation is a no-op. 656 730 */ 657 return EOK; 658 } 659 660 vfs_out_ops_t tmpfs_ops = { 661 .mounted = tmpfs_mounted, 662 .unmounted = tmpfs_unmounted, 663 .read = tmpfs_read, 664 .write = tmpfs_write, 665 .truncate = tmpfs_truncate, 666 .close = tmpfs_close, 667 .destroy = tmpfs_destroy, 668 .sync = tmpfs_sync, 669 }; 731 async_answer_0(rid, EOK); 732 } 670 733 671 734 /** 672 735 * @} 673 736 */ 674
Note:
See TracChangeset
for help on using the changeset viewer.