Changeset c47e1a8 in mainline for uspace/srv/fs/tmpfs/tmpfs_ops.c
- Timestamp:
- 2010-05-21T07:50:04Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d51ee2b
- Parents:
- cf8cc36 (diff), 15b592b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
rcf8cc36 rc47e1a8 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> 42 44 #include <async.h> 43 45 #include <errno.h> 44 46 #include <atomic.h> 45 47 #include <stdlib.h> 46 #include <str ing.h>48 #include <str.h> 47 49 #include <stdio.h> 48 50 #include <assert.h> … … 93 95 } 94 96 95 static size_t tmpfs_size_get(fs_node_t *fn)97 static aoff64_t tmpfs_size_get(fs_node_t *fn) 96 98 { 97 99 return TMPFS_NODE(fn)->size; … … 168 170 (nodep->index == key[NODES_KEY_INDEX])); 169 171 default: 170 abort(); 171 } 172 assert((keys == 1) || (keys == 2)); 173 } 174 175 return 0; 172 176 } 173 177 … … 439 443 { 440 444 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 441 442 /* Accept the mount options */ 445 fs_node_t *rootfn; 446 int rc; 447 448 /* Accept the mount options. */ 443 449 char *opts; 444 int rc = async_string_receive(&opts, 0, NULL); 445 450 rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); 446 451 if (rc != EOK) { 447 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); 460 free(opts); 461 ipc_answer_0(rid, EEXIST); 448 462 return; 449 463 } … … 456 470 } 457 471 458 fs_node_t *rootfn;459 472 rc = tmpfs_root_get(&rootfn, dev_handle); 460 473 assert(rc == EOK); … … 498 511 void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) 499 512 { 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 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 504 518 /* 505 519 * Lookup the respective TMPFS node. … … 517 531 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 518 532 nh_link); 519 533 520 534 /* 521 535 * Receive the read request. … … 524 538 size_t size; 525 539 if (!async_data_read_receive(&callid, &size)) { 526 ipc_answer_0(callid, EINVAL); 540 ipc_answer_0(callid, EINVAL); 527 541 ipc_answer_0(rid, EINVAL); 528 542 return; … … 531 545 size_t bytes; 532 546 if (nodep->type == TMPFS_FILE) { 533 bytes = m ax(0, min(nodep->size - pos, size));547 bytes = min(nodep->size - pos, size); 534 548 (void) async_data_read_finalize(callid, nodep->data + pos, 535 549 bytes); … … 537 551 tmpfs_dentry_t *dentryp; 538 552 link_t *lnk; 539 int i;553 aoff64_t i; 540 554 541 555 assert(nodep->type == TMPFS_DIRECTORY); … … 547 561 */ 548 562 for (i = 0, lnk = nodep->cs_head.next; 549 i < pos && lnk != &nodep->cs_head;563 (i < pos) && (lnk != &nodep->cs_head); 550 564 i++, lnk = lnk->next) 551 565 ; … … 572 586 void tmpfs_write(ipc_callid_t rid, ipc_call_t *request) 573 587 { 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 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 578 593 /* 579 594 * Lookup the respective TMPFS node. … … 636 651 void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request) 637 652 { 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] = index 664 }; 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 { 638 706 dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); 639 707 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 640 size_t size = (off_t)IPC_GET_ARG3(*request); 641 642 /* 643 * Lookup the respective TMPFS node. 644 */ 708 int rc; 709 645 710 link_t *hlp; 646 711 unsigned long key[] = { … … 655 720 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 656 721 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] = index692 };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);700 722 rc = tmpfs_destroy_node(FS_NODE(nodep)); 701 723 ipc_answer_0(rid, rc);
Note:
See TracChangeset
for help on using the changeset viewer.