Changeset 5bf76c1 in mainline
- Timestamp:
- 2011-09-24T16:15:41Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 32f623d9
- Parents:
- 925a21e
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/fs/libfs.c
r925a21e r5bf76c1 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
r925a21e r5bf76c1 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/mfs/mfs.h
r925a21e r5bf76c1 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
r925a21e r5bf76c1 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.