Changes in uspace/srv/devman/devman.c [4022513:15f3c3f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r4022513 r15f3c3f 37 37 #include <ipc/driver.h> 38 38 #include <ipc/devman.h> 39 #include < devmap.h>39 #include <loc.h> 40 40 #include <str_error.h> 41 41 #include <stdio.h> … … 66 66 } 67 67 68 static int devmap_functions_compare(unsigned long key[], hash_count_t keys,68 static int loc_functions_compare(unsigned long key[], hash_count_t keys, 69 69 link_t *item) 70 70 { 71 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devmap_fun);72 return (fun-> devmap_handle == (devmap_handle_t) key[0]);73 } 74 75 static int devmap_devices_class_compare(unsigned long key[], hash_count_t keys,71 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, loc_fun); 72 return (fun->service_id == (service_id_t) key[0]); 73 } 74 75 static int loc_devices_class_compare(unsigned long key[], hash_count_t keys, 76 76 link_t *item) 77 77 { 78 78 dev_class_info_t *class_info 79 = hash_table_get_instance(item, dev_class_info_t, devmap_link);79 = hash_table_get_instance(item, dev_class_info_t, loc_link); 80 80 assert(class_info != NULL); 81 81 82 return (class_info-> devmap_handle == (devmap_handle_t) key[0]);82 return (class_info->service_id == (service_id_t) key[0]); 83 83 } 84 84 … … 99 99 }; 100 100 101 static hash_table_operations_t devmap_devices_ops = {101 static hash_table_operations_t loc_devices_ops = { 102 102 .hash = devices_hash, 103 .compare = devmap_functions_compare,103 .compare = loc_functions_compare, 104 104 .remove_callback = devices_remove_callback 105 105 }; 106 106 107 static hash_table_operations_t devmap_devices_class_ops = {107 static hash_table_operations_t loc_devices_class_ops = { 108 108 .hash = devices_hash, 109 .compare = devmap_devices_class_compare,109 .compare = loc_devices_class_compare, 110 110 .remove_callback = devices_remove_callback 111 111 }; … … 270 270 } 271 271 272 ssize_t read_bytes = read_all(fd, buf, len);272 ssize_t read_bytes = safe_read(fd, buf, len); 273 273 if (read_bytes <= 0) { 274 log_msg(LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path, 275 read_bytes); 274 log_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path); 276 275 goto cleanup; 277 276 } … … 422 421 } 423 422 424 insert_fun_node(tree, fun, str_dup(""), NULL);423 insert_fun_node(tree, fun, clone_string(""), NULL); 425 424 match_id_t *id = create_match_id(); 426 id->id = str_dup("root");425 id->id = clone_string("root"); 427 426 id->score = 100; 428 427 add_match_id(&fun->match_ids, id); … … 701 700 } 702 701 703 /** Create devmappath and name for the function. */704 void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)705 { 706 char * devmap_pathname = NULL;707 char * devmap_name = NULL;708 709 asprintf(& devmap_name, "%s", fun->pathname);710 if ( devmap_name == NULL)702 /** Create loc path and name for the function. */ 703 void loc_register_tree_function(fun_node_t *fun, dev_tree_t *tree) 704 { 705 char *loc_pathname = NULL; 706 char *loc_name = NULL; 707 708 asprintf(&loc_name, "%s", fun->pathname); 709 if (loc_name == NULL) 711 710 return; 712 711 713 replace_char( devmap_name, '/', DEVMAP_SEPARATOR);714 715 asprintf(& devmap_pathname, "%s/%s", DEVMAP_DEVICE_NAMESPACE,716 devmap_name);717 if ( devmap_pathname == NULL) {718 free( devmap_name);712 replace_char(loc_name, '/', LOC_SEPARATOR); 713 714 asprintf(&loc_pathname, "%s/%s", LOC_DEVICE_NAMESPACE, 715 loc_name); 716 if (loc_pathname == NULL) { 717 free(loc_name); 719 718 return; 720 719 } 721 720 722 devmap_device_register_with_iface(devmap_pathname,723 &fun-> devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);724 725 tree_add_ devmap_function(tree, fun);726 727 free( devmap_name);728 free( devmap_pathname);721 loc_service_register_with_iface(loc_pathname, 722 &fun->service_id, DEVMAN_CONNECT_FROM_LOC); 723 724 tree_add_loc_function(tree, fun); 725 726 free(loc_name); 727 free(loc_pathname); 729 728 } 730 729 … … 856 855 hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1, 857 856 &devman_functions_ops); 858 hash_table_create(&tree-> devmap_functions, DEVICE_BUCKETS, 1,859 & devmap_devices_ops);857 hash_table_create(&tree->loc_functions, DEVICE_BUCKETS, 1, 858 &loc_devices_ops); 860 859 861 860 fibril_rwlock_initialize(&tree->rwlock); … … 952 951 list_initialize(&res->classes); 953 952 link_initialize(&res->devman_fun); 954 link_initialize(&res-> devmap_fun);953 link_initialize(&res->loc_fun); 955 954 } 956 955 … … 1268 1267 memset(info, 0, sizeof(dev_class_info_t)); 1269 1268 link_initialize(&info->dev_classes); 1270 link_initialize(&info-> devmap_link);1269 link_initialize(&info->loc_link); 1271 1270 link_initialize(&info->link); 1272 1271 } … … 1414 1413 list_initialize(&class_list->classes); 1415 1414 fibril_rwlock_initialize(&class_list->rwlock); 1416 hash_table_create(&class_list-> devmap_functions, DEVICE_BUCKETS, 1,1417 & devmap_devices_class_ops);1418 } 1419 1420 1421 /* Devmapdevices */1422 1423 fun_node_t *find_ devmap_tree_function(dev_tree_t *tree, devmap_handle_t devmap_handle)1415 hash_table_create(&class_list->loc_functions, DEVICE_BUCKETS, 1, 1416 &loc_devices_class_ops); 1417 } 1418 1419 1420 /* loc devices */ 1421 1422 fun_node_t *find_loc_tree_function(dev_tree_t *tree, service_id_t service_id) 1424 1423 { 1425 1424 fun_node_t *fun = NULL; 1426 1425 link_t *link; 1427 unsigned long key = (unsigned long) devmap_handle;1426 unsigned long key = (unsigned long) service_id; 1428 1427 1429 1428 fibril_rwlock_read_lock(&tree->rwlock); 1430 link = hash_table_find(&tree-> devmap_functions, &key);1429 link = hash_table_find(&tree->loc_functions, &key); 1431 1430 if (link != NULL) 1432 fun = hash_table_get_instance(link, fun_node_t, devmap_fun);1431 fun = hash_table_get_instance(link, fun_node_t, loc_fun); 1433 1432 fibril_rwlock_read_unlock(&tree->rwlock); 1434 1433 … … 1436 1435 } 1437 1436 1438 fun_node_t *find_ devmap_class_function(class_list_t *classes,1439 devmap_handle_t devmap_handle)1437 fun_node_t *find_loc_class_function(class_list_t *classes, 1438 service_id_t service_id) 1440 1439 { 1441 1440 fun_node_t *fun = NULL; 1442 1441 dev_class_info_t *cli; 1443 1442 link_t *link; 1444 unsigned long key = (unsigned long) devmap_handle;1443 unsigned long key = (unsigned long)service_id; 1445 1444 1446 1445 fibril_rwlock_read_lock(&classes->rwlock); 1447 link = hash_table_find(&classes-> devmap_functions, &key);1446 link = hash_table_find(&classes->loc_functions, &key); 1448 1447 if (link != NULL) { 1449 1448 cli = hash_table_get_instance(link, dev_class_info_t, 1450 devmap_link);1449 loc_link); 1451 1450 fun = cli->fun; 1452 1451 } … … 1456 1455 } 1457 1456 1458 void class_add_ devmap_function(class_list_t *class_list, dev_class_info_t *cli)1459 { 1460 unsigned long key = (unsigned long) cli-> devmap_handle;1457 void class_add_loc_function(class_list_t *class_list, dev_class_info_t *cli) 1458 { 1459 unsigned long key = (unsigned long) cli->service_id; 1461 1460 1462 1461 fibril_rwlock_write_lock(&class_list->rwlock); 1463 hash_table_insert(&class_list-> devmap_functions, &key, &cli->devmap_link);1462 hash_table_insert(&class_list->loc_functions, &key, &cli->loc_link); 1464 1463 fibril_rwlock_write_unlock(&class_list->rwlock); 1465 1464 1466 assert(find_ devmap_class_function(class_list, cli->devmap_handle) != NULL);1467 } 1468 1469 void tree_add_ devmap_function(dev_tree_t *tree, fun_node_t *fun)1470 { 1471 unsigned long key = (unsigned long) fun-> devmap_handle;1465 assert(find_loc_class_function(class_list, cli->service_id) != NULL); 1466 } 1467 1468 void tree_add_loc_function(dev_tree_t *tree, fun_node_t *fun) 1469 { 1470 unsigned long key = (unsigned long) fun->service_id; 1472 1471 fibril_rwlock_write_lock(&tree->rwlock); 1473 hash_table_insert(&tree-> devmap_functions, &key, &fun->devmap_fun);1472 hash_table_insert(&tree->loc_functions, &key, &fun->loc_fun); 1474 1473 fibril_rwlock_write_unlock(&tree->rwlock); 1475 1474 }
Note:
See TracChangeset
for help on using the changeset viewer.