Changeset 5bf76c1 in mainline for uspace/lib/fs/libfs.c
- 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
- File:
-
- 1 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 */
Note:
See TracChangeset
for help on using the changeset viewer.