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