Changeset e97b8c6 in mainline for uspace/srv/fs/exfat/exfat_ops.c
- Timestamp:
- 2011-08-10T18:08:40Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e090244c
- Parents:
- ccfbf71
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/exfat/exfat_ops.c
rccfbf71 re97b8c6 68 68 69 69 /** List of cached free FAT nodes. */ 70 static LIST_INITIALIZE(ffn_ head);70 static LIST_INITIALIZE(ffn_list); 71 71 72 72 /* … … 90 90 static aoff64_t exfat_size_get(fs_node_t *); 91 91 static unsigned exfat_lnkcnt_get(fs_node_t *); 92 static char exfat_plb_get_char(unsigned);93 92 static bool exfat_is_directory(fs_node_t *); 94 93 static bool exfat_is_file(fs_node_t *node); … … 124 123 static int exfat_node_fini_by_devmap_handle(devmap_handle_t devmap_handle) 125 124 { 126 link_t *lnk;127 125 exfat_node_t *nodep; 128 126 int rc; … … 136 134 restart: 137 135 fibril_mutex_lock(&ffn_mutex); 138 for (lnk = ffn_head.next; lnk != &ffn_head; lnk = lnk->next) {136 list_foreach(ffn_list, lnk) { 139 137 nodep = list_get_instance(lnk, exfat_node_t, ffn_link); 140 138 if (!fibril_mutex_trylock(&nodep->lock)) { … … 173 171 free(nodep); 174 172 175 /* Need to restart because we changed the ffn_ headlist. */173 /* Need to restart because we changed the ffn_list. */ 176 174 goto restart; 177 175 } … … 188 186 189 187 fibril_mutex_lock(&ffn_mutex); 190 if (!list_empty(&ffn_ head)) {188 if (!list_empty(&ffn_list)) { 191 189 /* Try to use a cached free node structure. */ 192 190 exfat_idx_t *idxp_tmp; 193 nodep = list_get_instance(ffn_head.next, exfat_node_t, ffn_link); 191 nodep = list_get_instance(list_first(&ffn_list), exfat_node_t, 192 ffn_link); 194 193 if (!fibril_mutex_trylock(&nodep->lock)) 195 194 goto skip_cache; … … 483 482 if (nodep->idx) { 484 483 fibril_mutex_lock(&ffn_mutex); 485 list_append(&nodep->ffn_link, &ffn_ head);484 list_append(&nodep->ffn_link, &ffn_list); 486 485 fibril_mutex_unlock(&ffn_mutex); 487 486 } else { … … 588 587 { 589 588 return EXFAT_NODE(fn)->lnkcnt; 590 }591 592 char exfat_plb_get_char(unsigned pos)593 {594 return exfat_reg.plb_ro[pos % PLB_SIZE];595 589 } 596 590 … … 626 620 .size_get = exfat_size_get, 627 621 .lnkcnt_get = exfat_lnkcnt_get, 628 .plb_get_char = exfat_plb_get_char,629 622 .is_directory = exfat_is_directory, 630 623 .is_file = exfat_is_file, … … 634 627 635 628 /* 636 * VFS operations.629 * VFS_OUT operations. 637 630 */ 638 631 … … 664 657 } 665 658 666 void exfat_mounted(ipc_callid_t rid, ipc_call_t *request) 667 { 668 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 659 static int 660 exfat_mounted(devmap_handle_t devmap_handle, const char *opts, fs_index_t *index, 661 aoff64_t *size, unsigned *linkcnt) 662 { 663 int rc; 669 664 exfat_node_t *rootp=NULL, *bitmapp=NULL, *uctablep=NULL; 670 665 enum cache_mode cmode; 671 666 exfat_bs_t *bs; 672 673 /* Accept the mount options */674 char *opts;675 int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);676 677 if (rc != EOK) {678 async_answer_0(rid, rc);679 return;680 }681 667 682 668 /* Check for option enabling write through. */ … … 686 672 cmode = CACHE_MODE_WB; 687 673 688 free(opts);689 690 674 /* initialize libblock */ 691 rc = block_init(devmap_handle, BS_SIZE); 692 if (rc != EOK) { 693 async_answer_0(rid, rc); 694 return; 695 } 675 rc = block_init(EXCHANGE_SERIALIZE, devmap_handle, BS_SIZE); 676 if (rc != EOK) 677 return rc; 696 678 697 679 /* prepare the boot block */ … … 699 681 if (rc != EOK) { 700 682 block_fini(devmap_handle); 701 async_answer_0(rid, rc); 702 return; 683 return rc; 703 684 } 704 685 … … 710 691 if (rc != EOK) { 711 692 block_fini(devmap_handle); 712 async_answer_0(rid, rc); 713 return; 693 return rc; 714 694 } 715 695 … … 719 699 (void) block_cache_fini(devmap_handle); 720 700 block_fini(devmap_handle); 721 async_answer_0(rid, rc); 722 return; 701 return rc; 723 702 } 724 703 … … 727 706 (void) block_cache_fini(devmap_handle); 728 707 block_fini(devmap_handle); 729 async_answer_0(rid, rc); 730 return; 708 return rc; 731 709 } 732 710 … … 738 716 block_fini(devmap_handle); 739 717 exfat_idx_fini_by_devmap_handle(devmap_handle); 740 async_answer_0(rid, ENOMEM); 741 return; 718 return ENOMEM; 742 719 } 743 720 assert(rootp->idx->index == EXFAT_ROOT_IDX); … … 756 733 block_fini(devmap_handle); 757 734 exfat_idx_fini_by_devmap_handle(devmap_handle); 758 async_answer_0(rid, ENOTSUP); 759 return; 735 return ENOTSUP; 760 736 } 761 737 rootp->size = BPS(bs) * SPC(bs) * clusters; … … 771 747 block_fini(devmap_handle); 772 748 exfat_idx_fini_by_devmap_handle(devmap_handle); 773 async_answer_0(rid, ENOTSUP); 774 return; 749 return ENOTSUP; 775 750 } 776 751 … … 782 757 block_fini(devmap_handle); 783 758 exfat_idx_fini_by_devmap_handle(devmap_handle); 784 async_answer_0(rid, ENOTSUP); 785 return; 759 return ENOTSUP; 786 760 } 787 761 … … 793 767 block_fini(devmap_handle); 794 768 exfat_idx_fini_by_devmap_handle(devmap_handle); 795 async_answer_0(rid, ENOMEM); 796 return; 769 return ENOMEM; 797 770 } 798 771 assert(bitmapp->idx->index == EXFAT_BITMAP_IDX); … … 815 788 block_fini(devmap_handle); 816 789 exfat_idx_fini_by_devmap_handle(devmap_handle); 817 async_answer_0(rid, ENOTSUP); 818 return; 790 return ENOTSUP; 819 791 } 820 792 … … 826 798 block_fini(devmap_handle); 827 799 exfat_idx_fini_by_devmap_handle(devmap_handle); 828 async_answer_0(rid, ENOTSUP); 829 return; 800 return ENOTSUP; 830 801 } 831 802 … … 838 809 block_fini(devmap_handle); 839 810 exfat_idx_fini_by_devmap_handle(devmap_handle); 840 async_answer_0(rid, ENOMEM); 841 return; 811 return ENOMEM; 842 812 } 843 813 assert(uctablep->idx->index == EXFAT_UCTABLE_IDX); … … 860 830 block_fini(devmap_handle); 861 831 exfat_idx_fini_by_devmap_handle(devmap_handle); 862 async_answer_0(rid, ENOMEM); 863 return; 832 return ENOMEM; 864 833 } 865 834 … … 867 836 printf("Root dir size: %lld\n", rootp->size); 868 837 869 async_answer_3(rid, EOK, rootp->idx->index, rootp->size, rootp->lnkcnt); 870 } 871 872 void exfat_mount(ipc_callid_t rid, ipc_call_t *request) 873 { 874 libfs_mount(&exfat_libfs_ops, exfat_reg.fs_handle, rid, request); 875 } 876 877 void exfat_unmounted(ipc_callid_t rid, ipc_call_t *request) 878 { 879 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 838 *index = rootp->idx->index; 839 *size = rootp->size; 840 *linkcnt = rootp->lnkcnt; 841 842 return EOK; 843 } 844 845 static int exfat_unmounted(devmap_handle_t devmap_handle) 846 { 880 847 fs_node_t *fn; 881 848 exfat_node_t *nodep; … … 883 850 884 851 rc = exfat_root_get(&fn, devmap_handle); 885 if (rc != EOK) { 886 async_answer_0(rid, rc); 887 return; 888 } 852 if (rc != EOK) 853 return rc; 889 854 nodep = EXFAT_NODE(fn); 890 855 … … 895 860 if (nodep->refcnt != 2) { 896 861 (void) exfat_node_put(fn); 897 async_answer_0(rid, EBUSY); 898 return; 862 return EBUSY; 899 863 } 900 864 … … 915 879 block_fini(devmap_handle); 916 880 917 async_answer_0(rid, EOK); 918 } 919 920 void exfat_unmount(ipc_callid_t rid, ipc_call_t *request) 921 { 922 libfs_unmount(&exfat_libfs_ops, rid, request); 881 return EOK; 923 882 } 924 883 … … 942 901 */ 943 902 944 void exfat_lookup(ipc_callid_t rid, ipc_call_t *request) 945 { 946 libfs_lookup(&exfat_libfs_ops, exfat_reg.fs_handle, rid, request); 947 } 948 949 void exfat_read(ipc_callid_t rid, ipc_call_t *request) 950 { 951 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 952 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 953 aoff64_t pos = 954 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 903 static int 904 exfat_read(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos, 905 size_t *rbytes) 906 { 955 907 fs_node_t *fn; 956 908 exfat_node_t *nodep; … … 961 913 962 914 rc = exfat_node_get(&fn, devmap_handle, index); 963 if (rc != EOK) { 964 async_answer_0(rid, rc); 965 return; 966 } 967 if (!fn) { 968 async_answer_0(rid, ENOENT); 969 return; 970 } 915 if (rc != EOK) 916 return rc; 917 if (!fn) 918 return ENOENT; 971 919 nodep = EXFAT_NODE(fn); 972 920 … … 976 924 exfat_node_put(fn); 977 925 async_answer_0(callid, EINVAL); 978 async_answer_0(rid, EINVAL); 979 return; 926 return EINVAL; 980 927 } 981 928 … … 1000 947 exfat_node_put(fn); 1001 948 async_answer_0(callid, rc); 1002 async_answer_0(rid, rc); 1003 return; 949 return rc; 1004 950 } 1005 951 (void) async_data_read_finalize(callid, … … 1008 954 if (rc != EOK) { 1009 955 exfat_node_put(fn); 1010 async_answer_0(rid, rc); 1011 return; 956 return rc; 1012 957 } 1013 958 } … … 1015 960 if (nodep->type != EXFAT_DIRECTORY) { 1016 961 async_answer_0(callid, ENOTSUP); 1017 async_answer_0(rid, ENOTSUP); 1018 return; 962 return ENOTSUP; 1019 963 } 1020 964 … … 1043 987 (void) exfat_node_put(fn); 1044 988 async_answer_0(callid, rc); 1045 async_answer_0(rid, rc); 1046 return; 989 return rc; 1047 990 1048 991 miss: … … 1052 995 rc = exfat_node_put(fn); 1053 996 async_answer_0(callid, rc != EOK ? rc : ENOENT); 1054 async_answer_1(rid, rc != EOK ? rc : ENOENT, 0);1055 return ;997 *rbytes = 0; 998 return rc != EOK ? rc : ENOENT; 1056 999 1057 1000 hit: … … 1065 1008 1066 1009 rc = exfat_node_put(fn); 1067 async_answer_1(rid, rc, (sysarg_t)bytes); 1068 } 1069 1070 void exfat_close(ipc_callid_t rid, ipc_call_t *request) 1071 { 1072 async_answer_0(rid, EOK); 1073 } 1074 1075 void exfat_open_node(ipc_callid_t rid, ipc_call_t *request) 1076 { 1077 libfs_open_node(&exfat_libfs_ops, exfat_reg.fs_handle, rid, request); 1078 } 1079 1080 void exfat_stat(ipc_callid_t rid, ipc_call_t *request) 1081 { 1082 libfs_stat(&exfat_libfs_ops, exfat_reg.fs_handle, rid, request); 1083 } 1084 1085 void exfat_sync(ipc_callid_t rid, ipc_call_t *request) 1086 { 1087 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1088 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1089 1010 *rbytes = bytes; 1011 return rc; 1012 } 1013 1014 static int exfat_close(devmap_handle_t devmap_handle, fs_index_t index) 1015 { 1016 return EOK; 1017 } 1018 1019 static int exfat_sync(devmap_handle_t devmap_handle, fs_index_t index) 1020 { 1090 1021 fs_node_t *fn; 1091 1022 int rc = exfat_node_get(&fn, devmap_handle, index); 1092 if (rc != EOK) { 1093 async_answer_0(rid, rc); 1094 return; 1095 } 1096 if (!fn) { 1097 async_answer_0(rid, ENOENT); 1098 return; 1099 } 1023 if (rc != EOK) 1024 return rc; 1025 if (!fn) 1026 return ENOENT; 1100 1027 1101 1028 exfat_node_t *nodep = EXFAT_NODE(fn); … … 1105 1032 1106 1033 exfat_node_put(fn); 1107 async_answer_0(rid, rc); 1108 } 1034 return rc; 1035 } 1036 1037 static int 1038 exfat_write(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos, 1039 size_t *wbytes, aoff64_t *nsize) 1040 { 1041 /* TODO */ 1042 return EOK; 1043 } 1044 1045 static int 1046 exfat_truncate(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t size) 1047 { 1048 /* TODO */ 1049 return EOK; 1050 } 1051 static int exfat_destroy(devmap_handle_t devmap_handle, fs_index_t index) 1052 { 1053 /* TODO */ 1054 return EOK; 1055 } 1056 1057 vfs_out_ops_t exfat_ops = { 1058 .mounted = exfat_mounted, 1059 .unmounted = exfat_unmounted, 1060 .read = exfat_read, 1061 .write = exfat_write, 1062 .truncate = exfat_truncate, 1063 .close = exfat_close, 1064 .destroy = exfat_destroy, 1065 .sync = exfat_sync, 1066 }; 1067 1109 1068 1110 1069 /**
Note:
See TracChangeset
for help on using the changeset viewer.