Changes in uspace/srv/fs/ext2fs/ext2fs_ops.c [efcebe1:82a3b31f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/ext2fs/ext2fs_ops.c
refcebe1 r82a3b31f 1 1 /* 2 * Copyright (c) 2008 Jakub Jermar 2 3 * Copyright (c) 2011 Martin Sucha 3 4 * All rights reserved. … … 86 87 */ 87 88 static int ext2fs_instance_get(devmap_handle_t, ext2fs_instance_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 *);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 *); 92 93 static bool ext2fs_is_dots(const uint8_t *, size_t); 93 94 static int ext2fs_node_get_core(fs_node_t **, ext2fs_instance_t *, fs_index_t); … … 110 111 static aoff64_t ext2fs_size_get(fs_node_t *); 111 112 static unsigned ext2fs_lnkcnt_get(fs_node_t *); 113 static char ext2fs_plb_get_char(unsigned); 112 114 static bool ext2fs_is_directory(fs_node_t *); 113 115 static bool ext2fs_is_file(fs_node_t *node); … … 185 187 { 186 188 EXT2FS_DBG("(%" PRIun ", -)", devmap_handle); 189 link_t *link; 187 190 ext2fs_instance_t *tmp; 188 191 … … 195 198 } 196 199 197 list_foreach(instance_list, link) {200 for (link = instance_list.next; link != &instance_list; link = link->next) { 198 201 tmp = list_get_instance(link, ext2fs_instance_t, link); 199 202 … … 238 241 } 239 242 240 rc = ext2_directory_iterator_init(&it, fs, eparent->inode_ref , 0);243 rc = ext2_directory_iterator_init(&it, fs, eparent->inode_ref); 241 244 if (rc != EOK) { 242 245 return rc; … … 476 479 } 477 480 478 rc = ext2_directory_iterator_init(&it, fs, enode->inode_ref , 0);481 rc = ext2_directory_iterator_init(&it, fs, enode->inode_ref); 479 482 if (rc != EOK) { 480 483 EXT2FS_DBG("error %u", rc); … … 536 539 EXT2FS_DBG("%u", count); 537 540 return count; 541 } 542 543 char ext2fs_plb_get_char(unsigned pos) 544 { 545 return ext2fs_reg.plb_ro[pos % PLB_SIZE]; 538 546 } 539 547 … … 579 587 .size_get = ext2fs_size_get, 580 588 .lnkcnt_get = ext2fs_lnkcnt_get, 589 .plb_get_char = ext2fs_plb_get_char, 581 590 .is_directory = ext2fs_is_directory, 582 591 .is_file = ext2fs_is_file, … … 588 597 */ 589 598 590 static int ext2fs_mounted(devmap_handle_t devmap_handle, const char *opts, 591 fs_index_t *index, aoff64_t *size, unsigned *lnkcnt) 599 void ext2fs_mounted(ipc_callid_t rid, ipc_call_t *request) 592 600 { 593 601 EXT2FS_DBG(""); 594 602 int rc; 603 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 595 604 ext2_filesystem_t *fs; 596 605 ext2fs_instance_t *inst; 597 606 bool read_only; 598 607 608 /* Accept the mount options */ 609 char *opts; 610 rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); 611 612 if (rc != EOK) { 613 async_answer_0(rid, rc); 614 return; 615 } 616 617 free(opts); 618 599 619 /* Allocate libext2 filesystem structure */ 600 620 fs = (ext2_filesystem_t *) malloc(sizeof(ext2_filesystem_t)); 601 if (fs == NULL) 602 return ENOMEM; 621 if (fs == NULL) { 622 async_answer_0(rid, ENOMEM); 623 return; 624 } 603 625 604 626 /* Allocate instance structure */ … … 606 628 if (inst == NULL) { 607 629 free(fs); 608 return ENOMEM; 630 async_answer_0(rid, ENOMEM); 631 return; 609 632 } 610 633 … … 614 637 free(fs); 615 638 free(inst); 616 return rc; 639 async_answer_0(rid, rc); 640 return; 617 641 } 618 642 … … 623 647 free(fs); 624 648 free(inst); 625 return rc; 649 async_answer_0(rid, rc); 650 return; 626 651 } 627 652 … … 632 657 free(fs); 633 658 free(inst); 634 return rc; 659 async_answer_0(rid, rc); 660 return; 635 661 } 636 662 … … 648 674 free(fs); 649 675 free(inst); 650 return rc; 676 async_answer_0(rid, rc); 677 return; 651 678 } 652 679 ext2fs_node_t *enode = EXT2FS_NODE(root_node); … … 657 684 fibril_mutex_unlock(&instance_list_mutex); 658 685 659 *index = EXT2_INODE_ROOT_INDEX; 660 *size = 0; 661 *lnkcnt = ext2_inode_get_usage_count(enode->inode_ref->inode); 686 async_answer_3(rid, EOK, 687 EXT2_INODE_ROOT_INDEX, 688 0, 689 ext2_inode_get_usage_count(enode->inode_ref->inode)); 662 690 663 691 ext2fs_node_put(root_node); 664 665 return EOK; 666 } 667 668 static int ext2fs_unmounted(devmap_handle_t devmap_handle) 669 { 670 EXT2FS_DBG(""); 692 } 693 694 void ext2fs_mount(ipc_callid_t rid, ipc_call_t *request) 695 { 696 EXT2FS_DBG(""); 697 libfs_mount(&ext2fs_libfs_ops, ext2fs_reg.fs_handle, rid, request); 698 } 699 700 void ext2fs_unmounted(ipc_callid_t rid, ipc_call_t *request) 701 { 702 EXT2FS_DBG(""); 703 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 671 704 ext2fs_instance_t *inst; 672 705 int rc; … … 674 707 rc = ext2fs_instance_get(devmap_handle, &inst); 675 708 676 if (rc != EOK) 677 return rc; 709 if (rc != EOK) { 710 async_answer_0(rid, rc); 711 return; 712 } 678 713 679 714 fibril_mutex_lock(&open_nodes_lock); … … 682 717 if (inst->open_nodes_count != 0) { 683 718 fibril_mutex_unlock(&open_nodes_lock); 684 return EBUSY; 719 async_answer_0(rid, EBUSY); 720 return; 685 721 } 686 722 … … 694 730 ext2_filesystem_fini(inst->filesystem); 695 731 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(""); 732 async_answer_0(rid, EOK); 733 } 734 735 void ext2fs_unmount(ipc_callid_t rid, ipc_call_t *request) 736 { 737 EXT2FS_DBG(""); 738 libfs_unmount(&ext2fs_libfs_ops, rid, request); 739 } 740 741 void ext2fs_lookup(ipc_callid_t rid, ipc_call_t *request) 742 { 743 EXT2FS_DBG(""); 744 libfs_lookup(&ext2fs_libfs_ops, ext2fs_reg.fs_handle, rid, request); 745 } 746 747 void ext2fs_read(ipc_callid_t rid, ipc_call_t *request) 748 { 749 EXT2FS_DBG(""); 750 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 751 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 752 aoff64_t pos = 753 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 704 754 705 755 ext2fs_instance_t *inst; … … 714 764 if (!async_data_read_receive(&callid, &size)) { 715 765 async_answer_0(callid, EINVAL); 716 return EINVAL; 766 async_answer_0(rid, EINVAL); 767 return; 717 768 } 718 769 … … 720 771 if (rc != EOK) { 721 772 async_answer_0(callid, rc); 722 return rc; 773 async_answer_0(rid, rc); 774 return; 723 775 } 724 776 … … 726 778 if (rc != EOK) { 727 779 async_answer_0(callid, rc); 728 return rc; 780 async_answer_0(rid, rc); 781 return; 729 782 } 730 783 731 784 if (ext2_inode_is_type(inst->filesystem->superblock, inode_ref->inode, 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 {785 EXT2_INODE_MODE_FILE)) { 786 ext2fs_read_file(rid, callid, pos, size, inst, inode_ref); 787 } 788 else if (ext2_inode_is_type(inst->filesystem->superblock, inode_ref->inode, 789 EXT2_INODE_MODE_DIRECTORY)) { 790 ext2fs_read_directory(rid, callid, pos, size, inst, inode_ref); 791 } 792 else { 740 793 /* Other inode types not supported */ 741 794 async_answer_0(callid, ENOTSUP); 742 rc = ENOTSUP;795 async_answer_0(rid, ENOTSUP); 743 796 } 744 797 745 798 ext2_filesystem_put_inode_ref(inode_ref); 746 799 747 return rc;748 800 } 749 801 … … 763 815 } 764 816 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)817 void ext2fs_read_directory(ipc_callid_t rid, ipc_callid_t callid, aoff64_t pos, 818 size_t size, ext2fs_instance_t *inst, ext2_inode_ref_t *inode_ref) 767 819 { 768 820 ext2_directory_iterator_t it; 769 aoff64_t next;821 aoff64_t cur; 770 822 uint8_t *buf; 771 823 size_t name_size; … … 773 825 bool found = false; 774 826 775 rc = ext2_directory_iterator_init(&it, inst->filesystem, inode_ref , pos);827 rc = ext2_directory_iterator_init(&it, inst->filesystem, inode_ref); 776 828 if (rc != EOK) { 777 829 async_answer_0(callid, rc); 778 return rc; 779 } 780 781 /* Find next interesting directory entry. 782 * We want to skip . and .. entries 830 async_answer_0(rid, rc); 831 return; 832 } 833 834 /* Find the index we want to read 835 * Note that we need to iterate and count as 836 * the underlying structure is a linked list 837 * Moreover, we want to skip . and .. entries 783 838 * as these are not used in HelenOS 784 839 */ 840 cur = 0; 785 841 while (it.current != NULL) { 786 842 if (it.current->inode == 0) { … … 789 845 790 846 name_size = ext2_directory_entry_ll_get_name_length( 791 847 inst->filesystem->superblock, it.current); 792 848 793 849 /* skip . and .. */ … … 796 852 } 797 853 798 /* The on-disk entry does not contain \0 at the end 799 * end of entry name, so we copy it to new buffer 800 * and add the \0 at the end 801 */ 802 buf = malloc(name_size+1); 803 if (buf == NULL) { 804 ext2_directory_iterator_fini(&it); 805 async_answer_0(callid, ENOMEM); 806 return ENOMEM; 854 /* Is this the dir entry we want to read? */ 855 if (cur == pos) { 856 /* The on-disk entry does not contain \0 at the end 857 * end of entry name, so we copy it to new buffer 858 * and add the \0 at the end 859 */ 860 buf = malloc(name_size+1); 861 if (buf == NULL) { 862 ext2_directory_iterator_fini(&it); 863 async_answer_0(callid, ENOMEM); 864 async_answer_0(rid, ENOMEM); 865 return; 866 } 867 memcpy(buf, &it.current->name, name_size); 868 *(buf+name_size) = 0; 869 found = true; 870 (void) async_data_read_finalize(callid, buf, name_size+1); 871 free(buf); 872 break; 807 873 } 808 memcpy(buf, &it.current->name, name_size); 809 *(buf + name_size) = 0; 810 found = true; 811 (void) async_data_read_finalize(callid, buf, name_size + 1); 812 free(buf); 813 break; 874 cur++; 814 875 815 876 skip: … … 818 879 ext2_directory_iterator_fini(&it); 819 880 async_answer_0(callid, rc); 820 return rc; 881 async_answer_0(rid, rc); 882 return; 821 883 } 822 884 } 823 885 886 rc = ext2_directory_iterator_fini(&it); 887 if (rc != EOK) { 888 async_answer_0(rid, rc); 889 return; 890 } 891 824 892 if (found) { 825 rc = ext2_directory_iterator_next(&it); 826 if (rc != EOK) 827 return rc; 828 next = it.current_offset; 829 } 830 831 rc = ext2_directory_iterator_fini(&it); 832 if (rc != EOK) 833 return rc; 834 835 if (found) { 836 *rbytes = next - pos; 837 return EOK; 838 } else { 893 async_answer_1(rid, EOK, 1); 894 } 895 else { 839 896 async_answer_0(callid, ENOENT); 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)897 async_answer_0(rid, ENOENT); 898 } 899 } 900 901 void ext2fs_read_file(ipc_callid_t rid, ipc_callid_t callid, aoff64_t pos, 902 size_t size, ext2fs_instance_t *inst, ext2_inode_ref_t *inode_ref) 846 903 { 847 904 int rc; … … 861 918 /* Read 0 bytes successfully */ 862 919 async_data_read_finalize(callid, NULL, 0); 863 *rbytes = 0;864 return EOK;920 async_answer_1(rid, EOK, 0); 921 return; 865 922 } 866 923 … … 881 938 if (rc != EOK) { 882 939 async_answer_0(callid, rc); 883 return rc; 940 async_answer_0(rid, rc); 941 return; 884 942 } 885 943 … … 893 951 if (buffer == NULL) { 894 952 async_answer_0(callid, ENOMEM); 895 return ENOMEM; 953 async_answer_0(rid, ENOMEM); 954 return; 896 955 } 897 956 … … 899 958 900 959 async_data_read_finalize(callid, buffer, bytes); 901 *rbytes = bytes;960 async_answer_1(rid, EOK, bytes); 902 961 903 962 free(buffer); 904 963 905 return EOK;964 return; 906 965 } 907 966 … … 910 969 if (rc != EOK) { 911 970 async_answer_0(callid, rc); 912 return rc; 971 async_answer_0(rid, rc); 972 return; 913 973 } 914 974 … … 917 977 918 978 rc = block_put(block); 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 }; 979 if (rc != EOK) { 980 async_answer_0(rid, rc); 981 return; 982 } 983 984 async_answer_1(rid, EOK, bytes); 985 } 986 987 void ext2fs_write(ipc_callid_t rid, ipc_call_t *request) 988 { 989 EXT2FS_DBG(""); 990 // devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 991 // fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 992 // aoff64_t pos = 993 // (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 994 995 // TODO 996 async_answer_0(rid, ENOTSUP); 997 } 998 999 void ext2fs_truncate(ipc_callid_t rid, ipc_call_t *request) 1000 { 1001 EXT2FS_DBG(""); 1002 // devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1003 // fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1004 // aoff64_t size = 1005 // (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 1006 1007 // TODO 1008 async_answer_0(rid, ENOTSUP); 1009 } 1010 1011 void ext2fs_close(ipc_callid_t rid, ipc_call_t *request) 1012 { 1013 EXT2FS_DBG(""); 1014 async_answer_0(rid, EOK); 1015 } 1016 1017 void ext2fs_destroy(ipc_callid_t rid, ipc_call_t *request) 1018 { 1019 EXT2FS_DBG(""); 1020 // devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request); 1021 // fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1022 1023 // TODO 1024 async_answer_0(rid, ENOTSUP); 1025 } 1026 1027 void ext2fs_open_node(ipc_callid_t rid, ipc_call_t *request) 1028 { 1029 EXT2FS_DBG(""); 1030 libfs_open_node(&ext2fs_libfs_ops, ext2fs_reg.fs_handle, rid, request); 1031 } 1032 1033 void ext2fs_stat(ipc_callid_t rid, ipc_call_t *request) 1034 { 1035 EXT2FS_DBG(""); 1036 libfs_stat(&ext2fs_libfs_ops, ext2fs_reg.fs_handle, rid, request); 1037 } 1038 1039 void ext2fs_sync(ipc_callid_t rid, ipc_call_t *request) 1040 { 1041 EXT2FS_DBG(""); 1042 // devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1043 // fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1044 1045 // TODO 1046 async_answer_0(rid, ENOTSUP); 1047 } 969 1048 970 1049 /** 971 1050 * @} 972 1051 */ 973
Note:
See TracChangeset
for help on using the changeset viewer.