Changes in uspace/srv/fs/tmpfs/tmpfs_ops.c [19f857a:472c09d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
r19f857a r472c09d 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> 46 44 #include <atomic.h> 47 45 #include <stdlib.h> 48 #include <str .h>46 #include <string.h> 49 47 #include <stdio.h> 50 48 #include <assert.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 int rc;447 441 448 /* Accept the mount options .*/442 /* Accept the mount options */ 449 443 char *opts; 450 rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); 444 int rc = async_string_receive(&opts, 0, NULL); 445 451 446 if (rc != EOK) { 452 447 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);460 free(opts);461 ipc_answer_0(rid, EEXIST);462 448 return; 463 449 } … … 470 456 } 471 457 458 fs_node_t *rootfn; 472 459 rc = tmpfs_root_get(&rootfn, dev_handle); 473 460 assert(rc == EOK); … … 511 498 void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) 512 499 { 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 500 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 501 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 502 off_t pos = (off_t)IPC_GET_ARG3(*request); 503 518 504 /* 519 505 * Lookup the respective TMPFS node. … … 531 517 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 532 518 nh_link); 533 519 534 520 /* 535 521 * Receive the read request. … … 538 524 size_t size; 539 525 if (!async_data_read_receive(&callid, &size)) { 540 ipc_answer_0(callid, EINVAL); 526 ipc_answer_0(callid, EINVAL); 541 527 ipc_answer_0(rid, EINVAL); 542 528 return; … … 545 531 size_t bytes; 546 532 if (nodep->type == TMPFS_FILE) { 547 bytes = m in(nodep->size - pos, size);533 bytes = max(0, min(nodep->size - pos, size)); 548 534 (void) async_data_read_finalize(callid, nodep->data + pos, 549 535 bytes); … … 551 537 tmpfs_dentry_t *dentryp; 552 538 link_t *lnk; 553 aoff64_t i;539 int i; 554 540 555 541 assert(nodep->type == TMPFS_DIRECTORY); … … 561 547 */ 562 548 for (i = 0, lnk = nodep->cs_head.next; 563 (i < pos) && (lnk != &nodep->cs_head);549 i < pos && lnk != &nodep->cs_head; 564 550 i++, lnk = lnk->next) 565 551 ; … … 586 572 void tmpfs_write(ipc_callid_t rid, ipc_call_t *request) 587 573 { 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 574 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 575 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 576 off_t pos = (off_t)IPC_GET_ARG3(*request); 577 593 578 /* 594 579 * Lookup the respective TMPFS node. … … 651 636 void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request) 652 637 { 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 638 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 707 639 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 708 int rc; 709 640 size_t size = (off_t)IPC_GET_ARG3(*request); 641 642 /* 643 * Lookup the respective TMPFS node. 644 */ 710 645 link_t *hlp; 711 646 unsigned long key[] = { … … 720 655 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 721 656 nh_link); 657 658 if (size == nodep->size) { 659 ipc_answer_0(rid, EOK); 660 return; 661 } 662 663 void *newdata = realloc(nodep->data, size); 664 if (!newdata) { 665 ipc_answer_0(rid, ENOMEM); 666 return; 667 } 668 if (size > nodep->size) { 669 size_t delta = size - nodep->size; 670 memset(newdata + nodep->size, 0, delta); 671 } 672 nodep->size = size; 673 nodep->data = newdata; 674 ipc_answer_0(rid, EOK); 675 } 676 677 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request) 678 { 679 ipc_answer_0(rid, EOK); 680 } 681 682 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request) 683 { 684 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 685 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 686 int rc; 687 688 link_t *hlp; 689 unsigned long key[] = { 690 [NODES_KEY_DEV] = dev_handle, 691 [NODES_KEY_INDEX] = index 692 }; 693 hlp = hash_table_find(&nodes, key); 694 if (!hlp) { 695 ipc_answer_0(rid, ENOENT); 696 return; 697 } 698 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 699 nh_link); 722 700 rc = tmpfs_destroy_node(FS_NODE(nodep)); 723 701 ipc_answer_0(rid, rc);
Note:
See TracChangeset
for help on using the changeset viewer.