Changes in uspace/srv/fs/tmpfs/tmpfs_ops.c [ed903174:1715b6af] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
red903174 r1715b6af 29 29 /** @addtogroup fs 30 30 * @{ 31 */ 31 */ 32 32 33 33 /** … … 40 40 #include "../../vfs/vfs.h" 41 41 #include <ipc/ipc.h> 42 #include <macros.h>43 #include <limits.h>44 42 #include <async.h> 45 43 #include <errno.h> … … 95 93 } 96 94 97 static aoff64_t tmpfs_size_get(fs_node_t *fn)95 static size_t tmpfs_size_get(fs_node_t *fn) 98 96 { 99 97 return TMPFS_NODE(fn)->size; … … 170 168 (nodep->index == key[NODES_KEY_INDEX])); 171 169 default: 172 assert((keys == 1) || (keys == 2)); 173 } 174 175 return 0; 170 abort(); 171 } 176 172 } 177 173 … … 443 439 { 444 440 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 445 fs_node_t *rootfn;446 441 int rc; 447 448 /* Accept the mount options. */ 449 char *opts; 450 rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); 451 if (rc != EOK) { 452 ipc_answer_0(rid, rc); 453 return; 454 } 455 456 /* Check if this device is not already mounted. */ 457 rc = tmpfs_root_get(&rootfn, dev_handle); 458 if ((rc == EOK) && (rootfn)) { 459 (void) tmpfs_node_put(rootfn); 442 443 /* accept the mount options */ 444 ipc_callid_t callid; 445 size_t size; 446 if (!async_data_write_receive(&callid, &size)) { 447 ipc_answer_0(callid, EINVAL); 448 ipc_answer_0(rid, EINVAL); 449 return; 450 } 451 char *opts = malloc(size + 1); 452 if (!opts) { 453 ipc_answer_0(callid, ENOMEM); 454 ipc_answer_0(rid, ENOMEM); 455 return; 456 } 457 ipcarg_t retval = async_data_write_finalize(callid, opts, size); 458 if (retval != EOK) { 459 ipc_answer_0(rid, retval); 460 460 free(opts); 461 ipc_answer_0(rid, EEXIST);462 return;463 }461 return; 462 } 463 opts[size] = '\0'; 464 464 465 465 /* Initialize TMPFS instance. */ … … 470 470 } 471 471 472 fs_node_t *rootfn; 472 473 rc = tmpfs_root_get(&rootfn, dev_handle); 473 474 assert(rc == EOK); … … 511 512 void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) 512 513 { 513 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 514 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 515 aoff64_t pos = 516 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 517 514 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 515 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 516 off_t pos = (off_t)IPC_GET_ARG3(*request); 517 518 518 /* 519 519 * Lookup the respective TMPFS node. … … 531 531 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 532 532 nh_link); 533 533 534 534 /* 535 535 * Receive the read request. … … 538 538 size_t size; 539 539 if (!async_data_read_receive(&callid, &size)) { 540 ipc_answer_0(callid, EINVAL); 540 ipc_answer_0(callid, EINVAL); 541 541 ipc_answer_0(rid, EINVAL); 542 542 return; … … 545 545 size_t bytes; 546 546 if (nodep->type == TMPFS_FILE) { 547 bytes = m in(nodep->size - pos, size);547 bytes = max(0, min(nodep->size - pos, size)); 548 548 (void) async_data_read_finalize(callid, nodep->data + pos, 549 549 bytes); … … 551 551 tmpfs_dentry_t *dentryp; 552 552 link_t *lnk; 553 aoff64_t i;553 int i; 554 554 555 555 assert(nodep->type == TMPFS_DIRECTORY); … … 561 561 */ 562 562 for (i = 0, lnk = nodep->cs_head.next; 563 (i < pos) && (lnk != &nodep->cs_head);563 i < pos && lnk != &nodep->cs_head; 564 564 i++, lnk = lnk->next) 565 565 ; … … 586 586 void tmpfs_write(ipc_callid_t rid, ipc_call_t *request) 587 587 { 588 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 589 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 590 aoff64_t pos = 591 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 592 588 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 589 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 590 off_t pos = (off_t)IPC_GET_ARG3(*request); 591 593 592 /* 594 593 * Lookup the respective TMPFS node. … … 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);654 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);655 aoff64_t size =656 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));657 658 /*659 * Lookup the respective TMPFS node.660 */661 unsigned long key[] = {662 [NODES_KEY_DEV] = dev_handle,663 [NODES_KEY_INDEX] = index664 };665 link_t *hlp = hash_table_find(&nodes, key);666 if (!hlp) {667 ipc_answer_0(rid, ENOENT);668 return;669 }670 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,671 nh_link);672 673 if (size == nodep->size) {674 ipc_answer_0(rid, EOK);675 return;676 }677 678 if (size > SIZE_MAX) {679 ipc_answer_0(rid, ENOMEM);680 return;681 }682 683 void *newdata = realloc(nodep->data, size);684 if (!newdata) {685 ipc_answer_0(rid, ENOMEM);686 return;687 }688 689 if (size > nodep->size) {690 size_t delta = size - nodep->size;691 memset(newdata + nodep->size, 0, delta);692 }693 694 nodep->size = size;695 nodep->data = newdata;696 ipc_answer_0(rid, EOK);697 }698 699 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request)700 {701 ipc_answer_0(rid, EOK);702 }703 704 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)705 {706 652 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 707 653 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 708 int rc; 709 654 size_t size = (off_t)IPC_GET_ARG3(*request); 655 656 /* 657 * Lookup the respective TMPFS node. 658 */ 710 659 link_t *hlp; 711 660 unsigned long key[] = { … … 720 669 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 721 670 nh_link); 671 672 if (size == nodep->size) { 673 ipc_answer_0(rid, EOK); 674 return; 675 } 676 677 void *newdata = realloc(nodep->data, size); 678 if (!newdata) { 679 ipc_answer_0(rid, ENOMEM); 680 return; 681 } 682 if (size > nodep->size) { 683 size_t delta = size - nodep->size; 684 memset(newdata + nodep->size, 0, delta); 685 } 686 nodep->size = size; 687 nodep->data = newdata; 688 ipc_answer_0(rid, EOK); 689 } 690 691 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request) 692 { 693 ipc_answer_0(rid, EOK); 694 } 695 696 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request) 697 { 698 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 699 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 700 int rc; 701 702 link_t *hlp; 703 unsigned long key[] = { 704 [NODES_KEY_DEV] = dev_handle, 705 [NODES_KEY_INDEX] = index 706 }; 707 hlp = hash_table_find(&nodes, key); 708 if (!hlp) { 709 ipc_answer_0(rid, ENOENT); 710 return; 711 } 712 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 713 nh_link); 722 714 rc = tmpfs_destroy_node(FS_NODE(nodep)); 723 715 ipc_answer_0(rid, rc);
Note:
See TracChangeset
for help on using the changeset viewer.