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