Changeset 00c2de63 in mainline for uspace/srv/fs/ext2fs/ext2fs_ops.c
- Timestamp:
- 2011-07-29T14:50:22Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b6759f4
- Parents:
- 6c69d19 (diff), 7ae249d (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/ext2fs/ext2fs_ops.c
r6c69d19 r00c2de63 1 1 /* 2 * Copyright (c) 2008 Jakub Jermar3 2 * Copyright (c) 2011 Martin Sucha 4 3 * All rights reserved. … … 87 86 */ 88 87 static int ext2fs_instance_get(devmap_handle_t, ext2fs_instance_t **); 89 static void ext2fs_read_directory(ipc_callid_t, ipc_callid_t, aoff64_t,90 size_t, ext2fs_instance_t *, ext2_inode_ref_t *);91 static void ext2fs_read_file(ipc_callid_t, ipc_callid_t, aoff64_t,92 size_t, ext2fs_instance_t *, ext2_inode_ref_t *);88 static int ext2fs_read_directory(ipc_callid_t, aoff64_t, size_t, 89 ext2fs_instance_t *, ext2_inode_ref_t *, size_t *); 90 static int ext2fs_read_file(ipc_callid_t, aoff64_t, size_t, ext2fs_instance_t *, 91 ext2_inode_ref_t *, size_t *); 93 92 static bool ext2fs_is_dots(const uint8_t *, size_t); 94 93 static int ext2fs_node_get_core(fs_node_t **, ext2fs_instance_t *, fs_index_t); … … 111 110 static aoff64_t ext2fs_size_get(fs_node_t *); 112 111 static unsigned ext2fs_lnkcnt_get(fs_node_t *); 113 static char ext2fs_plb_get_char(unsigned);114 112 static bool ext2fs_is_directory(fs_node_t *); 115 113 static bool ext2fs_is_file(fs_node_t *node); … … 538 536 EXT2FS_DBG("%u", count); 539 537 return count; 540 }541 542 char ext2fs_plb_get_char(unsigned pos)543 {544 return ext2fs_reg.plb_ro[pos % PLB_SIZE];545 538 } 546 539 … … 586 579 .size_get = ext2fs_size_get, 587 580 .lnkcnt_get = ext2fs_lnkcnt_get, 588 .plb_get_char = ext2fs_plb_get_char,589 581 .is_directory = ext2fs_is_directory, 590 582 .is_file = ext2fs_is_file, … … 596 588 */ 597 589 598 void ext2fs_mounted(ipc_callid_t rid, ipc_call_t *request) 599 { 600 EXT2FS_DBG(""); 601 int rc;602 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);590 static int ext2fs_mounted(devmap_handle_t devmap_handle, const char *opts, 591 fs_index_t *index, aoff64_t *size, unsigned *lnkcnt) 592 { 593 EXT2FS_DBG(""); 594 int rc; 603 595 ext2_filesystem_t *fs; 604 596 ext2fs_instance_t *inst; 605 597 bool read_only; 606 598 607 /* Accept the mount options */608 char *opts;609 rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);610 611 if (rc != EOK) {612 async_answer_0(rid, rc);613 return;614 }615 616 free(opts);617 618 599 /* Allocate libext2 filesystem structure */ 619 600 fs = (ext2_filesystem_t *) malloc(sizeof(ext2_filesystem_t)); 620 if (fs == NULL) { 621 async_answer_0(rid, ENOMEM); 622 return; 623 } 601 if (fs == NULL) 602 return ENOMEM; 624 603 625 604 /* Allocate instance structure */ … … 627 606 if (inst == NULL) { 628 607 free(fs); 629 async_answer_0(rid, ENOMEM); 630 return; 608 return ENOMEM; 631 609 } 632 610 … … 636 614 free(fs); 637 615 free(inst); 638 async_answer_0(rid, rc); 639 return; 616 return rc; 640 617 } 641 618 … … 646 623 free(fs); 647 624 free(inst); 648 async_answer_0(rid, rc); 649 return; 625 return rc; 650 626 } 651 627 … … 656 632 free(fs); 657 633 free(inst); 658 async_answer_0(rid, rc); 659 return; 634 return rc; 660 635 } 661 636 … … 673 648 free(fs); 674 649 free(inst); 675 async_answer_0(rid, rc); 676 return; 650 return rc; 677 651 } 678 652 ext2fs_node_t *enode = EXT2FS_NODE(root_node); … … 683 657 fibril_mutex_unlock(&instance_list_mutex); 684 658 685 async_answer_3(rid, EOK, 686 EXT2_INODE_ROOT_INDEX, 687 0, 688 ext2_inode_get_usage_count(enode->inode_ref->inode)); 659 *index = EXT2_INODE_ROOT_INDEX; 660 *size = 0; 661 *lnkcnt = ext2_inode_get_usage_count(enode->inode_ref->inode); 689 662 690 663 ext2fs_node_put(root_node); 691 } 692 693 void ext2fs_mount(ipc_callid_t rid, ipc_call_t *request) 694 { 695 EXT2FS_DBG(""); 696 libfs_mount(&ext2fs_libfs_ops, ext2fs_reg.fs_handle, rid, request); 697 } 698 699 void ext2fs_unmounted(ipc_callid_t rid, ipc_call_t *request) 700 { 701 EXT2FS_DBG(""); 702 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 664 665 return EOK; 666 } 667 668 static int ext2fs_unmounted(devmap_handle_t devmap_handle) 669 { 670 EXT2FS_DBG(""); 703 671 ext2fs_instance_t *inst; 704 672 int rc; … … 706 674 rc = ext2fs_instance_get(devmap_handle, &inst); 707 675 708 if (rc != EOK) { 709 async_answer_0(rid, rc); 710 return; 711 } 676 if (rc != EOK) 677 return rc; 712 678 713 679 fibril_mutex_lock(&open_nodes_lock); … … 716 682 if (inst->open_nodes_count != 0) { 717 683 fibril_mutex_unlock(&open_nodes_lock); 718 async_answer_0(rid, EBUSY); 719 return; 684 return EBUSY; 720 685 } 721 686 … … 729 694 ext2_filesystem_fini(inst->filesystem); 730 695 731 async_answer_0(rid, EOK); 732 } 733 734 void ext2fs_unmount(ipc_callid_t rid, ipc_call_t *request) 735 { 736 EXT2FS_DBG(""); 737 libfs_unmount(&ext2fs_libfs_ops, rid, request); 738 } 739 740 void ext2fs_lookup(ipc_callid_t rid, ipc_call_t *request) 741 { 742 EXT2FS_DBG(""); 743 libfs_lookup(&ext2fs_libfs_ops, ext2fs_reg.fs_handle, rid, request); 744 } 745 746 void ext2fs_read(ipc_callid_t rid, ipc_call_t *request) 747 { 748 EXT2FS_DBG(""); 749 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 750 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 751 aoff64_t pos = 752 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 696 return EOK; 697 } 698 699 static int 700 ext2fs_read(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos, 701 size_t *rbytes) 702 { 703 EXT2FS_DBG(""); 753 704 754 705 ext2fs_instance_t *inst; … … 763 714 if (!async_data_read_receive(&callid, &size)) { 764 715 async_answer_0(callid, EINVAL); 765 async_answer_0(rid, EINVAL); 766 return; 716 return EINVAL; 767 717 } 768 718 … … 770 720 if (rc != EOK) { 771 721 async_answer_0(callid, rc); 772 async_answer_0(rid, rc); 773 return; 722 return rc; 774 723 } 775 724 … … 777 726 if (rc != EOK) { 778 727 async_answer_0(callid, rc); 779 async_answer_0(rid, rc); 780 return; 728 return rc; 781 729 } 782 730 783 731 if (ext2_inode_is_type(inst->filesystem->superblock, inode_ref->inode, 784 785 ext2fs_read_file(rid, callid, pos, size, inst, inode_ref);786 }787 else if (ext2_inode_is_type(inst->filesystem->superblock, inode_ref->inode,788 789 ext2fs_read_directory(rid, callid, pos, size, inst, inode_ref);790 }791 else {732 EXT2_INODE_MODE_FILE)) { 733 rc = ext2fs_read_file(callid, pos, size, inst, inode_ref, 734 rbytes); 735 } else if (ext2_inode_is_type(inst->filesystem->superblock, 736 inode_ref->inode, EXT2_INODE_MODE_DIRECTORY)) { 737 rc = ext2fs_read_directory(callid, pos, size, inst, inode_ref, 738 rbytes); 739 } else { 792 740 /* Other inode types not supported */ 793 741 async_answer_0(callid, ENOTSUP); 794 async_answer_0(rid, ENOTSUP);742 rc = ENOTSUP; 795 743 } 796 744 797 745 ext2_filesystem_put_inode_ref(inode_ref); 798 746 747 return rc; 799 748 } 800 749 … … 814 763 } 815 764 816 void ext2fs_read_directory(ipc_callid_t rid, ipc_callid_t callid, aoff64_t pos,817 size_t size, ext2fs_instance_t *inst, ext2_inode_ref_t *inode_ref)765 int ext2fs_read_directory(ipc_callid_t callid, aoff64_t pos, size_t size, 766 ext2fs_instance_t *inst, ext2_inode_ref_t *inode_ref, size_t *rbytes) 818 767 { 819 768 ext2_directory_iterator_t it; … … 827 776 if (rc != EOK) { 828 777 async_answer_0(callid, rc); 829 async_answer_0(rid, rc); 830 return; 778 return rc; 831 779 } 832 780 … … 841 789 842 790 name_size = ext2_directory_entry_ll_get_name_length( 843 791 inst->filesystem->superblock, it.current); 844 792 845 793 /* skip . and .. */ … … 849 797 850 798 /* The on-disk entry does not contain \0 at the end 851 852 853 799 * end of entry name, so we copy it to new buffer 800 * and add the \0 at the end 801 */ 854 802 buf = malloc(name_size+1); 855 803 if (buf == NULL) { 856 804 ext2_directory_iterator_fini(&it); 857 805 async_answer_0(callid, ENOMEM); 858 async_answer_0(rid, ENOMEM); 859 return; 806 return ENOMEM; 860 807 } 861 808 memcpy(buf, &it.current->name, name_size); 862 *(buf +name_size) = 0;809 *(buf + name_size) = 0; 863 810 found = true; 864 (void) async_data_read_finalize(callid, buf, name_size +1);811 (void) async_data_read_finalize(callid, buf, name_size + 1); 865 812 free(buf); 866 813 break; … … 871 818 ext2_directory_iterator_fini(&it); 872 819 async_answer_0(callid, rc); 873 async_answer_0(rid, rc); 874 return; 820 return rc; 875 821 } 876 822 } … … 878 824 if (found) { 879 825 rc = ext2_directory_iterator_next(&it); 880 if (rc != EOK) { 881 async_answer_0(rid, rc); 882 return; 883 } 826 if (rc != EOK) 827 return rc; 884 828 next = it.current_offset; 885 829 } 886 830 887 831 rc = ext2_directory_iterator_fini(&it); 888 if (rc != EOK) { 889 async_answer_0(rid, rc); 890 return; 891 } 832 if (rc != EOK) 833 return rc; 892 834 893 835 if (found) { 894 async_answer_1(rid, EOK, next-pos);895 }896 else {836 *rbytes = next - pos; 837 return EOK; 838 } else { 897 839 async_answer_0(callid, ENOENT); 898 async_answer_0(rid, ENOENT);899 } 900 } 901 902 void ext2fs_read_file(ipc_callid_t rid, ipc_callid_t callid, aoff64_t pos,903 size_t size, ext2fs_instance_t *inst, ext2_inode_ref_t *inode_ref)840 return ENOENT; 841 } 842 } 843 844 int ext2fs_read_file(ipc_callid_t callid, aoff64_t pos, size_t size, 845 ext2fs_instance_t *inst, ext2_inode_ref_t *inode_ref, size_t *rbytes) 904 846 { 905 847 int rc; … … 919 861 /* Read 0 bytes successfully */ 920 862 async_data_read_finalize(callid, NULL, 0); 921 async_answer_1(rid, EOK, 0);922 return ;863 *rbytes = 0; 864 return EOK; 923 865 } 924 866 … … 939 881 if (rc != EOK) { 940 882 async_answer_0(callid, rc); 941 async_answer_0(rid, rc); 942 return; 883 return rc; 943 884 } 944 885 … … 952 893 if (buffer == NULL) { 953 894 async_answer_0(callid, ENOMEM); 954 async_answer_0(rid, ENOMEM); 955 return; 895 return ENOMEM; 956 896 } 957 897 … … 959 899 960 900 async_data_read_finalize(callid, buffer, bytes); 961 async_answer_1(rid, EOK, bytes);901 *rbytes = bytes; 962 902 963 903 free(buffer); 964 904 965 return ;905 return EOK; 966 906 } 967 907 … … 970 910 if (rc != EOK) { 971 911 async_answer_0(callid, rc); 972 async_answer_0(rid, rc); 973 return; 912 return rc; 974 913 } 975 914 … … 978 917 979 918 rc = block_put(block); 980 if (rc != EOK) { 981 async_answer_0(rid, rc); 982 return; 983 } 984 985 async_answer_1(rid, EOK, bytes); 986 } 987 988 void ext2fs_write(ipc_callid_t rid, ipc_call_t *request) 989 { 990 EXT2FS_DBG(""); 991 // devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 992 // fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 993 // aoff64_t pos = 994 // (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 995 996 // TODO 997 async_answer_0(rid, ENOTSUP); 998 } 999 1000 void ext2fs_truncate(ipc_callid_t rid, ipc_call_t *request) 1001 { 1002 EXT2FS_DBG(""); 1003 // devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1004 // fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1005 // aoff64_t size = 1006 // (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 1007 1008 // TODO 1009 async_answer_0(rid, ENOTSUP); 1010 } 1011 1012 void ext2fs_close(ipc_callid_t rid, ipc_call_t *request) 1013 { 1014 EXT2FS_DBG(""); 1015 async_answer_0(rid, EOK); 1016 } 1017 1018 void ext2fs_destroy(ipc_callid_t rid, ipc_call_t *request) 1019 { 1020 EXT2FS_DBG(""); 1021 // devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request); 1022 // fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1023 1024 // TODO 1025 async_answer_0(rid, ENOTSUP); 1026 } 1027 1028 void ext2fs_open_node(ipc_callid_t rid, ipc_call_t *request) 1029 { 1030 EXT2FS_DBG(""); 1031 libfs_open_node(&ext2fs_libfs_ops, ext2fs_reg.fs_handle, rid, request); 1032 } 1033 1034 void ext2fs_stat(ipc_callid_t rid, ipc_call_t *request) 1035 { 1036 EXT2FS_DBG(""); 1037 libfs_stat(&ext2fs_libfs_ops, ext2fs_reg.fs_handle, rid, request); 1038 } 1039 1040 void ext2fs_sync(ipc_callid_t rid, ipc_call_t *request) 1041 { 1042 EXT2FS_DBG(""); 1043 // devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1044 // fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1045 1046 // TODO 1047 async_answer_0(rid, ENOTSUP); 1048 } 919 if (rc != EOK) 920 return rc; 921 922 *rbytes = bytes; 923 return EOK; 924 } 925 926 static int 927 ext2fs_write(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos, 928 size_t *wbytes, aoff64_t *nsize) 929 { 930 EXT2FS_DBG(""); 931 return ENOTSUP; 932 } 933 934 static int 935 ext2fs_truncate(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t size) 936 { 937 EXT2FS_DBG(""); 938 return ENOTSUP; 939 } 940 941 static int ext2fs_close(devmap_handle_t devmap_handle, fs_index_t index) 942 { 943 EXT2FS_DBG(""); 944 return EOK; 945 } 946 947 static int ext2fs_destroy(devmap_handle_t devmap_handle, fs_index_t index) 948 { 949 EXT2FS_DBG(""); 950 return ENOTSUP; 951 } 952 953 static int ext2fs_sync(devmap_handle_t devmap_handle, fs_index_t index) 954 { 955 EXT2FS_DBG(""); 956 return ENOTSUP; 957 } 958 959 vfs_out_ops_t ext2fs_ops = { 960 .mounted = ext2fs_mounted, 961 .unmounted = ext2fs_unmounted, 962 .read = ext2fs_read, 963 .write = ext2fs_write, 964 .truncate = ext2fs_truncate, 965 .close = ext2fs_close, 966 .destroy = ext2fs_destroy, 967 .sync = ext2fs_sync, 968 }; 1049 969 1050 970 /** 1051 971 * @} 1052 972 */ 973
Note:
See TracChangeset
for help on using the changeset viewer.