Changes in uspace/srv/fs/tmpfs/tmpfs_ops.c [ffa2c8ef:69a60c4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
rffa2c8ef r69a60c4 39 39 #include "tmpfs.h" 40 40 #include "../../vfs/vfs.h" 41 #include <ipc/ipc.h> 41 42 #include <macros.h> 42 43 #include <stdint.h> … … 69 70 /* Forward declarations of static functions. */ 70 71 static int tmpfs_match(fs_node_t **, fs_node_t *, const char *); 71 static int tmpfs_node_get(fs_node_t **, dev map_handle_t, fs_index_t);72 static int tmpfs_node_get(fs_node_t **, dev_handle_t, fs_index_t); 72 73 static int tmpfs_node_open(fs_node_t *); 73 74 static int tmpfs_node_put(fs_node_t *); 74 static int tmpfs_create_node(fs_node_t **, dev map_handle_t, int);75 static int tmpfs_create_node(fs_node_t **, dev_handle_t, int); 75 76 static int tmpfs_destroy_node(fs_node_t *); 76 77 static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *); … … 78 79 79 80 /* Implementation of helper functions. */ 80 static int tmpfs_root_get(fs_node_t **rfn, dev map_handle_t devmap_handle)81 { 82 return tmpfs_node_get(rfn, dev map_handle, TMPFS_SOME_ROOT);81 static int tmpfs_root_get(fs_node_t **rfn, dev_handle_t dev_handle) 82 { 83 return tmpfs_node_get(rfn, dev_handle, TMPFS_SOME_ROOT); 83 84 } 84 85 … … 119 120 } 120 121 121 static dev map_handle_t tmpfs_device_get(fs_node_t *fn)122 static dev_handle_t tmpfs_device_get(fs_node_t *fn) 122 123 { 123 124 return 0; … … 164 165 switch (keys) { 165 166 case 1: 166 return (nodep->dev map_handle == key[NODES_KEY_DEV]);167 return (nodep->dev_handle == key[NODES_KEY_DEV]); 167 168 case 2: 168 return ((nodep->dev map_handle == key[NODES_KEY_DEV]) &&169 return ((nodep->dev_handle == key[NODES_KEY_DEV]) && 169 170 (nodep->index == key[NODES_KEY_INDEX])); 170 171 default: … … 208 209 nodep->bp = NULL; 209 210 nodep->index = 0; 210 nodep->dev map_handle = 0;211 nodep->dev_handle = 0; 211 212 nodep->type = TMPFS_NONE; 212 213 nodep->lnkcnt = 0; … … 232 233 } 233 234 234 static bool tmpfs_instance_init(dev map_handle_t devmap_handle)235 static bool tmpfs_instance_init(dev_handle_t dev_handle) 235 236 { 236 237 fs_node_t *rfn; 237 238 int rc; 238 239 239 rc = tmpfs_create_node(&rfn, dev map_handle, L_DIRECTORY);240 rc = tmpfs_create_node(&rfn, dev_handle, L_DIRECTORY); 240 241 if (rc != EOK || !rfn) 241 242 return false; … … 244 245 } 245 246 246 static void tmpfs_instance_done(dev map_handle_t devmap_handle)247 static void tmpfs_instance_done(dev_handle_t dev_handle) 247 248 { 248 249 unsigned long key[] = { 249 [NODES_KEY_DEV] = dev map_handle250 [NODES_KEY_DEV] = dev_handle 250 251 }; 251 252 /* … … 278 279 } 279 280 280 int tmpfs_node_get(fs_node_t **rfn, dev map_handle_t devmap_handle, fs_index_t index)281 int tmpfs_node_get(fs_node_t **rfn, dev_handle_t dev_handle, fs_index_t index) 281 282 { 282 283 unsigned long key[] = { 283 [NODES_KEY_DEV] = dev map_handle,284 [NODES_KEY_DEV] = dev_handle, 284 285 [NODES_KEY_INDEX] = index 285 286 }; … … 307 308 } 308 309 309 int tmpfs_create_node(fs_node_t **rfn, dev map_handle_t devmap_handle, int lflag)310 int tmpfs_create_node(fs_node_t **rfn, dev_handle_t dev_handle, int lflag) 310 311 { 311 312 fs_node_t *rootfn; … … 326 327 nodep->bp->data = nodep; /* link the FS and TMPFS nodes */ 327 328 328 rc = tmpfs_root_get(&rootfn, dev map_handle);329 rc = tmpfs_root_get(&rootfn, dev_handle); 329 330 assert(rc == EOK); 330 331 if (!rootfn) … … 332 333 else 333 334 nodep->index = tmpfs_next_index++; 334 nodep->dev map_handle = devmap_handle;335 nodep->dev_handle = dev_handle; 335 336 if (lflag & L_DIRECTORY) 336 337 nodep->type = TMPFS_DIRECTORY; … … 340 341 /* Insert the new node into the nodes hash table. */ 341 342 unsigned long key[] = { 342 [NODES_KEY_DEV] = nodep->dev map_handle,343 [NODES_KEY_DEV] = nodep->dev_handle, 343 344 [NODES_KEY_INDEX] = nodep->index 344 345 }; … … 356 357 357 358 unsigned long key[] = { 358 [NODES_KEY_DEV] = nodep->dev map_handle,359 [NODES_KEY_DEV] = nodep->dev_handle, 359 360 [NODES_KEY_INDEX] = nodep->index 360 361 }; … … 441 442 void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request) 442 443 { 443 dev map_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);444 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 444 445 fs_node_t *rootfn; 445 446 int rc; … … 449 450 rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); 450 451 if (rc != EOK) { 451 async_answer_0(rid, rc);452 ipc_answer_0(rid, rc); 452 453 return; 453 454 } 454 455 455 456 /* Check if this device is not already mounted. */ 456 rc = tmpfs_root_get(&rootfn, dev map_handle);457 rc = tmpfs_root_get(&rootfn, dev_handle); 457 458 if ((rc == EOK) && (rootfn)) { 458 459 (void) tmpfs_node_put(rootfn); 459 460 free(opts); 460 async_answer_0(rid, EEXIST);461 ipc_answer_0(rid, EEXIST); 461 462 return; 462 463 } 463 464 464 465 /* Initialize TMPFS instance. */ 465 if (!tmpfs_instance_init(dev map_handle)) {466 if (!tmpfs_instance_init(dev_handle)) { 466 467 free(opts); 467 async_answer_0(rid, ENOMEM);468 return; 469 } 470 471 rc = tmpfs_root_get(&rootfn, dev map_handle);468 ipc_answer_0(rid, ENOMEM); 469 return; 470 } 471 472 rc = tmpfs_root_get(&rootfn, dev_handle); 472 473 assert(rc == EOK); 473 474 tmpfs_node_t *rootp = TMPFS_NODE(rootfn); 474 475 if (str_cmp(opts, "restore") == 0) { 475 if (tmpfs_restore(dev map_handle))476 async_answer_3(rid, EOK, rootp->index, rootp->size,476 if (tmpfs_restore(dev_handle)) 477 ipc_answer_3(rid, EOK, rootp->index, rootp->size, 477 478 rootp->lnkcnt); 478 479 else 479 async_answer_0(rid, ELIMIT);480 ipc_answer_0(rid, ELIMIT); 480 481 } else { 481 async_answer_3(rid, EOK, rootp->index, rootp->size,482 ipc_answer_3(rid, EOK, rootp->index, rootp->size, 482 483 rootp->lnkcnt); 483 484 } … … 492 493 void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 493 494 { 494 dev map_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);495 496 tmpfs_instance_done(dev map_handle);497 async_answer_0(rid, EOK);495 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 496 497 tmpfs_instance_done(dev_handle); 498 ipc_answer_0(rid, EOK); 498 499 } 499 500 … … 510 511 void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) 511 512 { 512 dev map_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);513 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 513 514 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 514 515 aoff64_t pos = … … 520 521 link_t *hlp; 521 522 unsigned long key[] = { 522 [NODES_KEY_DEV] = dev map_handle,523 [NODES_KEY_DEV] = dev_handle, 523 524 [NODES_KEY_INDEX] = index 524 525 }; 525 526 hlp = hash_table_find(&nodes, key); 526 527 if (!hlp) { 527 async_answer_0(rid, ENOENT);528 ipc_answer_0(rid, ENOENT); 528 529 return; 529 530 } … … 537 538 size_t size; 538 539 if (!async_data_read_receive(&callid, &size)) { 539 async_answer_0(callid, EINVAL);540 async_answer_0(rid, EINVAL);540 ipc_answer_0(callid, EINVAL); 541 ipc_answer_0(rid, EINVAL); 541 542 return; 542 543 } … … 565 566 566 567 if (lnk == &nodep->cs_head) { 567 async_answer_0(callid, ENOENT);568 async_answer_1(rid, ENOENT, 0);568 ipc_answer_0(callid, ENOENT); 569 ipc_answer_1(rid, ENOENT, 0); 569 570 return; 570 571 } … … 580 581 * Answer the VFS_READ call. 581 582 */ 582 async_answer_1(rid, EOK, bytes);583 ipc_answer_1(rid, EOK, bytes); 583 584 } 584 585 585 586 void tmpfs_write(ipc_callid_t rid, ipc_call_t *request) 586 587 { 587 dev map_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);588 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 588 589 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 589 590 aoff64_t pos = … … 595 596 link_t *hlp; 596 597 unsigned long key[] = { 597 [NODES_KEY_DEV] = dev map_handle,598 [NODES_KEY_DEV] = dev_handle, 598 599 [NODES_KEY_INDEX] = index 599 600 }; 600 601 hlp = hash_table_find(&nodes, key); 601 602 if (!hlp) { 602 async_answer_0(rid, ENOENT);603 ipc_answer_0(rid, ENOENT); 603 604 return; 604 605 } … … 612 613 size_t size; 613 614 if (!async_data_write_receive(&callid, &size)) { 614 async_answer_0(callid, EINVAL);615 async_answer_0(rid, EINVAL);615 ipc_answer_0(callid, EINVAL); 616 ipc_answer_0(rid, EINVAL); 616 617 return; 617 618 } … … 623 624 /* The file size is not changing. */ 624 625 (void) async_data_write_finalize(callid, nodep->data + pos, size); 625 async_answer_2(rid, EOK, size, nodep->size);626 ipc_answer_2(rid, EOK, size, nodep->size); 626 627 return; 627 628 } … … 636 637 void *newdata = realloc(nodep->data, nodep->size + delta); 637 638 if (!newdata) { 638 async_answer_0(callid, ENOMEM);639 async_answer_2(rid, EOK, 0, nodep->size);639 ipc_answer_0(callid, ENOMEM); 640 ipc_answer_2(rid, EOK, 0, nodep->size); 640 641 return; 641 642 } … … 645 646 nodep->data = newdata; 646 647 (void) async_data_write_finalize(callid, nodep->data + pos, size); 647 async_answer_2(rid, EOK, size, nodep->size);648 ipc_answer_2(rid, EOK, size, nodep->size); 648 649 } 649 650 650 651 void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request) 651 652 { 652 dev map_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);653 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 653 654 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 654 655 aoff64_t size = … … 659 660 */ 660 661 unsigned long key[] = { 661 [NODES_KEY_DEV] = dev map_handle,662 [NODES_KEY_DEV] = dev_handle, 662 663 [NODES_KEY_INDEX] = index 663 664 }; 664 665 link_t *hlp = hash_table_find(&nodes, key); 665 666 if (!hlp) { 666 async_answer_0(rid, ENOENT);667 ipc_answer_0(rid, ENOENT); 667 668 return; 668 669 } … … 671 672 672 673 if (size == nodep->size) { 673 async_answer_0(rid, EOK);674 ipc_answer_0(rid, EOK); 674 675 return; 675 676 } 676 677 677 678 if (size > SIZE_MAX) { 678 async_answer_0(rid, ENOMEM);679 ipc_answer_0(rid, ENOMEM); 679 680 return; 680 681 } … … 682 683 void *newdata = realloc(nodep->data, size); 683 684 if (!newdata) { 684 async_answer_0(rid, ENOMEM);685 ipc_answer_0(rid, ENOMEM); 685 686 return; 686 687 } … … 693 694 nodep->size = size; 694 695 nodep->data = newdata; 695 async_answer_0(rid, EOK);696 ipc_answer_0(rid, EOK); 696 697 } 697 698 698 699 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request) 699 700 { 700 async_answer_0(rid, EOK);701 ipc_answer_0(rid, EOK); 701 702 } 702 703 703 704 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request) 704 705 { 705 dev map_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request);706 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 706 707 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 707 708 int rc; … … 709 710 link_t *hlp; 710 711 unsigned long key[] = { 711 [NODES_KEY_DEV] = dev map_handle,712 [NODES_KEY_DEV] = dev_handle, 712 713 [NODES_KEY_INDEX] = index 713 714 }; 714 715 hlp = hash_table_find(&nodes, key); 715 716 if (!hlp) { 716 async_answer_0(rid, ENOENT);717 ipc_answer_0(rid, ENOENT); 717 718 return; 718 719 } … … 720 721 nh_link); 721 722 rc = tmpfs_destroy_node(FS_NODE(nodep)); 722 async_answer_0(rid, rc);723 ipc_answer_0(rid, rc); 723 724 } 724 725 … … 739 740 * thus the sync operation is a no-op. 740 741 */ 741 async_answer_0(rid, EOK);742 ipc_answer_0(rid, EOK); 742 743 } 743 744
Note:
See TracChangeset
for help on using the changeset viewer.