Changes in / [024fcc5:113093a] in mainline
- Location:
- uspace
- Files:
-
- 5 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/fs/libfs.c
r024fcc5 r113093a 877 877 } 878 878 879 static FIBRIL_MUTEX_INITIALIZE(instances_mutex); 880 static LIST_INITIALIZE(instances_list); 881 882 typedef struct { 883 service_id_t service_id; 884 link_t link; 885 void *data; 886 } fs_instance_t; 887 888 int fs_instance_create(service_id_t service_id, void *data) 889 { 890 fs_instance_t *inst = malloc(sizeof(fs_instance_t)); 891 if (!inst) 892 return ENOMEM; 893 894 link_initialize(&inst->link); 895 inst->service_id = service_id; 896 inst->data = data; 897 898 fibril_mutex_lock(&instances_mutex); 899 list_foreach(instances_list, link) { 900 fs_instance_t *cur = list_get_instance(link, fs_instance_t, 901 link); 902 903 if (cur->service_id == service_id) { 904 fibril_mutex_unlock(&instances_mutex); 905 free(inst); 906 return EEXIST; 907 } 908 909 /* keep the list sorted */ 910 if (cur->service_id < service_id) { 911 list_insert_before(&inst->link, &cur->link); 912 fibril_mutex_unlock(&instances_mutex); 913 return EOK; 914 } 915 } 916 list_append(&inst->link, &instances_list); 917 fibril_mutex_unlock(&instances_mutex); 918 919 return EOK; 920 } 921 922 int fs_instance_get(service_id_t service_id, void **idp) 923 { 924 fibril_mutex_lock(&instances_mutex); 925 list_foreach(instances_list, link) { 926 fs_instance_t *inst = list_get_instance(link, fs_instance_t, 927 link); 928 929 if (inst->service_id == service_id) { 930 *idp = inst->data; 931 fibril_mutex_unlock(&instances_mutex); 932 return EOK; 933 } 934 } 935 fibril_mutex_unlock(&instances_mutex); 936 return ENOENT; 937 } 938 939 int fs_instance_destroy(service_id_t service_id) 940 { 941 fibril_mutex_lock(&instances_mutex); 942 list_foreach(instances_list, link) { 943 fs_instance_t *inst = list_get_instance(link, fs_instance_t, 944 link); 945 946 if (inst->service_id == service_id) { 947 list_remove(&inst->link); 948 fibril_mutex_unlock(&instances_mutex); 949 free(inst); 950 return EOK; 951 } 952 } 953 fibril_mutex_unlock(&instances_mutex); 954 return ENOENT; 955 } 956 879 957 /** @} 880 958 */ -
uspace/lib/fs/libfs.h
r024fcc5 r113093a 105 105 extern void fs_node_initialize(fs_node_t *); 106 106 107 extern int fs_instance_create(service_id_t, void *); 108 extern int fs_instance_get(service_id_t, void **); 109 extern int fs_instance_destroy(service_id_t); 110 107 111 #endif 108 112 -
uspace/srv/fs/fat/fat.h
r024fcc5 r113093a 230 230 } fat_node_t; 231 231 232 typedef struct { 233 bool lfn_enabled; 234 } fat_instance_t; 235 232 236 extern vfs_out_ops_t fat_ops; 233 237 extern libfs_ops_t fat_libfs_ops; -
uspace/srv/fs/fat/fat_directory.c
r024fcc5 r113093a 262 262 { 263 263 int rc; 264 bool enable_lfn = true; /* TODO: make this a mount option */ 264 void *data; 265 fat_instance_t *instance; 266 267 rc = fs_instance_get(di->nodep->idx->service_id, &data); 268 assert(rc == EOK); 269 instance = (fat_instance_t *) data; 265 270 266 271 if (fat_valid_short_name(name)) { … … 277 282 rc = fat_directory_write_dentry(di, de); 278 283 return rc; 279 } else if ( enable_lfn&& fat_valid_name(name)) {284 } else if (instance->lfn_enabled && fat_valid_name(name)) { 280 285 /* We should create long entries to store name */ 281 286 int long_entry_count; … … 292 297 if (lfn_size % FAT_LFN_ENTRY_SIZE) 293 298 long_entry_count++; 294 rc = fat_directory_lookup_free(di, long_entry_count +1);299 rc = fat_directory_lookup_free(di, long_entry_count + 1); 295 300 if (rc != EOK) 296 301 return rc; … … 328 333 FAT_LFN_ORDER(d) |= FAT_LFN_LAST; 329 334 330 rc = fat_directory_seek(di, start_pos +long_entry_count);335 rc = fat_directory_seek(di, start_pos + long_entry_count); 331 336 return rc; 332 337 } -
uspace/srv/fs/fat/fat_ops.c
r024fcc5 r113093a 871 871 aoff64_t *size, unsigned *linkcnt) 872 872 { 873 enum cache_mode cmode ;873 enum cache_mode cmode = CACHE_MODE_WB; 874 874 fat_bs_t *bs; 875 int rc; 876 877 /* Check for option enabling write through. */ 878 if (str_cmp(opts, "wtcache") == 0) 879 cmode = CACHE_MODE_WT; 880 else 881 cmode = CACHE_MODE_WB; 875 fat_instance_t *instance; 876 int rc; 877 878 instance = malloc(sizeof(fat_instance_t)); 879 if (!instance) 880 return ENOMEM; 881 instance->lfn_enabled = true; 882 883 /* Parse mount options. */ 884 char *mntopts = (char *) opts; 885 char *saveptr; 886 char *opt; 887 while ((opt = strtok_r(mntopts, " ,", &saveptr)) != NULL) { 888 if (str_cmp(opt, "wtcache") == 0) 889 cmode = CACHE_MODE_WT; 890 else if (str_cmp(opt, "nolfn") == 0) 891 instance->lfn_enabled = false; 892 mntopts = NULL; 893 } 882 894 883 895 /* initialize libblock */ 884 896 rc = block_init(EXCHANGE_SERIALIZE, service_id, BS_SIZE); 885 if (rc != EOK) 886 return rc; 897 if (rc != EOK) { 898 free(instance); 899 return rc; 900 } 887 901 888 902 /* prepare the boot block */ 889 903 rc = block_bb_read(service_id, BS_BLOCK); 890 904 if (rc != EOK) { 905 free(instance); 891 906 block_fini(service_id); 892 907 return rc; … … 897 912 898 913 if (BPS(bs) != BS_SIZE) { 914 free(instance); 899 915 block_fini(service_id); 900 916 return ENOTSUP; … … 904 920 rc = block_cache_init(service_id, BPS(bs), 0 /* XXX */, cmode); 905 921 if (rc != EOK) { 922 free(instance); 906 923 block_fini(service_id); 907 924 return rc; … … 911 928 rc = fat_sanity_check(bs, service_id); 912 929 if (rc != EOK) { 930 free(instance); 913 931 (void) block_cache_fini(service_id); 914 932 block_fini(service_id); … … 918 936 rc = fat_idx_init_by_service_id(service_id); 919 937 if (rc != EOK) { 938 free(instance); 920 939 (void) block_cache_fini(service_id); 921 940 block_fini(service_id); … … 926 945 fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t)); 927 946 if (!rfn) { 947 free(instance); 928 948 (void) block_cache_fini(service_id); 929 949 block_fini(service_id); … … 935 955 fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t)); 936 956 if (!rootp) { 957 free(instance); 937 958 free(rfn); 938 959 (void) block_cache_fini(service_id); … … 945 966 fat_idx_t *ridxp = fat_idx_get_by_pos(service_id, FAT_CLST_ROOTPAR, 0); 946 967 if (!ridxp) { 968 free(instance); 947 969 free(rfn); 948 970 free(rootp); … … 964 986 rc = fat_clusters_get(&clusters, bs, service_id, rootp->firstc); 965 987 if (rc != EOK) { 988 fibril_mutex_unlock(&ridxp->lock); 989 free(instance); 966 990 free(rfn); 967 991 free(rootp); … … 974 998 } else 975 999 rootp->size = RDE(bs) * sizeof(fat_dentry_t); 1000 1001 rc = fs_instance_create(service_id, instance); 1002 if (rc != EOK) { 1003 fibril_mutex_unlock(&ridxp->lock); 1004 free(instance); 1005 free(rfn); 1006 free(rootp); 1007 (void) block_cache_fini(service_id); 1008 block_fini(service_id); 1009 fat_idx_fini_by_service_id(service_id); 1010 return rc; 1011 } 976 1012 977 1013 rootp->idx = ridxp; … … 1024 1060 (void) block_cache_fini(service_id); 1025 1061 block_fini(service_id); 1062 1063 void *data; 1064 if (fs_instance_get(service_id, &data) == EOK) { 1065 fs_instance_destroy(service_id); 1066 free(data); 1067 } 1026 1068 1027 1069 return EOK; -
uspace/srv/fs/mfs/mfs.h
r024fcc5 r113093a 131 131 132 132 struct mfs_instance { 133 link_t link;134 133 service_id_t service_id; 135 134 struct mfs_sb_info *sbi; -
uspace/srv/fs/mfs/mfs_ops.c
r024fcc5 r113093a 73 73 74 74 75 static LIST_INITIALIZE(inst_list);76 static FIBRIL_MUTEX_INITIALIZE(inst_list_mutex);77 75 static hash_table_t open_nodes; 78 76 static FIBRIL_MUTEX_INITIALIZE(open_nodes_lock); … … 179 177 return ENOMEM; 180 178 } 181 182 instance->open_nodes_cnt = 0;183 179 184 180 sb = malloc(MFS_SUPERBLOCK_SIZE); … … 268 264 free(instance); 269 265 free(sbi); 270 free(sb);271 266 block_cache_fini(service_id); 272 267 block_fini(service_id); … … 275 270 } 276 271 277 /*Initialize the instance structure and add it to the list*/ 278 link_initialize(&instance->link); 272 /*Initialize the instance structure and remember it*/ 279 273 instance->service_id = service_id; 280 274 instance->sbi = sbi; 281 282 fibril_mutex_lock(&inst_list_mutex); 283 list_append(&instance->link, &inst_list); 284 fibril_mutex_unlock(&inst_list_mutex); 275 instance->open_nodes_cnt = 0; 276 rc = fs_instance_create(service_id, instance); 277 if (rc != EOK) { 278 free(instance); 279 free(sbi); 280 block_cache_fini(service_id); 281 block_fini(service_id); 282 mfsdebug("fs instance creation failed\n"); 283 return rc; 284 } 285 285 286 286 mfsdebug("mount successful\n"); … … 315 315 block_fini(service_id); 316 316 317 /* Remove the instance from the list */ 318 fibril_mutex_lock(&inst_list_mutex); 319 list_remove(&inst->link); 320 fibril_mutex_unlock(&inst_list_mutex); 321 317 /* Remove and destroy the instance */ 318 (void) fs_instance_destroy(service_id); 322 319 free(inst->sbi); 323 320 free(inst); … … 1012 1009 mfs_instance_get(service_id_t service_id, struct mfs_instance **instance) 1013 1010 { 1014 struct mfs_instance *instance_ptr; 1015 1016 fibril_mutex_lock(&inst_list_mutex); 1017 1018 if (list_empty(&inst_list)) { 1019 fibril_mutex_unlock(&inst_list_mutex); 1020 return EINVAL; 1021 } 1022 1023 list_foreach(inst_list, link) { 1024 instance_ptr = list_get_instance(link, struct mfs_instance, 1025 link); 1026 1027 if (instance_ptr->service_id == service_id) { 1028 *instance = instance_ptr; 1029 fibril_mutex_unlock(&inst_list_mutex); 1030 return EOK; 1031 } 1032 } 1033 1034 mfsdebug("Instance not found\n"); 1035 1036 fibril_mutex_unlock(&inst_list_mutex); 1037 return EINVAL; 1011 void *data; 1012 int rc; 1013 1014 rc = fs_instance_get(service_id, &data); 1015 if (rc == EOK) { 1016 *instance = (struct mfs_instance *) data; 1017 } else { 1018 mfsdebug("instance not found\n"); 1019 } 1020 1021 return rc; 1038 1022 } 1039 1023
Note:
See TracChangeset
for help on using the changeset viewer.