Changeset 58b833c in mainline
- Timestamp:
- 2010-10-23T13:43:51Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1b11576d, c6c389ed
- Parents:
- 667eac4
- Location:
- uspace/srv/devman
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r667eac4 r58b833c 47 47 } 48 48 49 static int 50 devman_devices_compare(unsigned long key[], hash_count_t keys,link_t *item)49 static int devman_devices_compare(unsigned long key[], hash_count_t keys, 50 link_t *item) 51 51 { 52 52 node_t *dev = hash_table_get_instance(item, node_t, devman_link); … … 54 54 } 55 55 56 static int 57 devmap_devices_compare(unsigned long key[], hash_count_t keys,link_t *item)56 static int devmap_devices_compare(unsigned long key[], hash_count_t keys, 57 link_t *item) 58 58 { 59 59 node_t *dev = hash_table_get_instance(item, node_t, devmap_link); … … 79 79 /** Allocate and initialize a new driver structure. 80 80 * 81 * @return 81 * @return Driver structure. 82 82 */ 83 83 driver_t *create_driver(void) 84 { 84 { 85 85 driver_t *res = malloc(sizeof(driver_t)); 86 86 if (res != NULL) … … 91 91 /** Add a driver to the list of drivers. 92 92 * 93 * @param drivers_list the list of drivers.94 * @param drv the driver'sstructure.93 * @param drivers_list List of drivers. 94 * @param drv Driver structure. 95 95 */ 96 96 void add_driver(driver_list_t *drivers_list, driver_t *drv) … … 99 99 list_prepend(&drv->drivers, &drivers_list->drivers); 100 100 fibril_mutex_unlock(&drivers_list->drivers_mutex); 101 101 102 102 printf(NAME": the '%s' driver was added to the list of available " 103 103 "drivers.\n", drv->name); … … 218 218 "'%s'.\n", conf_path); 219 219 goto cleanup; 220 } 221 222 if ( 0 >= read(fd, buf, len)) {220 } 221 222 if (read(fd, buf, len) <= 0) { 223 223 printf(NAME ": unable to read file '%s'.\n", conf_path); 224 224 goto cleanup; … … 231 231 free(buf); 232 232 233 if (opened)233 if (opened) 234 234 close(fd); 235 235 … … 270 270 /* Read the list of match ids from the driver's configuration file. */ 271 271 match_path = get_abs_path(base_path, name, MATCH_EXT); 272 if ( NULL == match_path)272 if (match_path == NULL) 273 273 goto cleanup; 274 274 … … 279 279 name_size = str_size(name) + 1; 280 280 drv->name = malloc(name_size); 281 if ( !drv->name)281 if (drv->name == NULL) 282 282 goto cleanup; 283 283 str_cpy(drv->name, name_size, name); … … 285 285 /* Initialize path with driver's binary. */ 286 286 drv->binary_path = get_abs_path(base_path, name, ""); 287 if ( NULL == drv->binary_path)287 if (drv->binary_path == NULL) 288 288 goto cleanup; 289 289 290 290 /* Check whether the driver's binary exists. */ 291 291 struct stat s; 292 if (stat(drv->binary_path, &s) == ENOENT) { 292 if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */ 293 293 printf(NAME ": driver not found at path %s.", drv->binary_path); 294 294 goto cleanup; … … 344 344 /** Create root device node in the device tree. 345 345 * 346 * @param tree 347 * @return 346 * @param tree The device tree. 347 * @return True on success, false otherwise. 348 348 */ 349 349 bool create_root_node(dev_tree_t *tree) 350 350 { 351 node_t *node; 352 351 353 printf(NAME ": create_root_node\n"); 352 node_t *node = create_dev_node(); 353 if (node) { 354 355 node = create_dev_node(); 356 if (node != NULL) { 354 357 insert_dev_node(tree, node, clone_string(""), NULL); 355 358 match_id_t *id = create_match_id(); … … 359 362 tree->root_node = node; 360 363 } 364 361 365 return node != NULL; 362 366 } … … 391 395 best_score = score; 392 396 best_drv = drv; 393 } 397 } 394 398 link = link->next; 395 399 } … … 436 440 437 441 int err; 438 if ( !task_spawn(drv->binary_path, argv, &err)) {442 if (task_spawn(drv->binary_path, argv, &err) == 0) { 439 443 printf(NAME ": error spawning %s, errno = %d\n", 440 444 drv->name, err); … … 456 460 { 457 461 driver_t *res = NULL; 462 driver_t *drv = NULL; 463 link_t *link; 458 464 459 465 fibril_mutex_lock(&drv_list->drivers_mutex); 460 466 461 driver_t *drv = NULL; 462 link_t *link = drv_list->drivers.next; 463 while (link != &drv_list->drivers) { 467 link = drv_list->drivers.next; 468 while (link != &drv_list->drivers) { 464 469 drv = list_get_instance(link, driver_t, drivers); 465 if ( 0 == str_cmp(drv->name, drv_name)) {470 if (str_cmp(drv->name, drv_name) == 0) { 466 471 res = drv; 467 472 break; 468 } 473 } 474 469 475 link = link->next; 470 } 476 } 471 477 472 478 fibril_mutex_unlock(&drv_list->drivers_mutex); … … 483 489 { 484 490 fibril_mutex_lock(&driver->driver_mutex); 485 assert( DRIVER_STARTING == driver->state);491 assert(driver->state == DRIVER_STARTING); 486 492 driver->phone = phone; 487 493 fibril_mutex_unlock(&driver->driver_mutex); … … 496 502 static void pass_devices_to_driver(driver_t *driver, dev_tree_t *tree) 497 503 { 498 printf(NAME ": pass_devices_to_driver\n");499 504 node_t *dev; 500 505 link_t *link; 501 502 int phone = ipc_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 503 504 if (0 < phone) { 506 int phone; 507 508 printf(NAME ": pass_devices_to_driver\n"); 509 510 phone = ipc_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 511 if (phone > 0) { 505 512 506 513 link = driver->devices.next; … … 549 556 550 557 asprintf(&devmap_name, "%s", node->pathname); 551 if ( NULL == devmap_name)558 if (devmap_name == NULL) 552 559 return; 553 560 … … 556 563 asprintf(&devmap_pathname, "%s/%s", DEVMAP_DEVICE_NAMESPACE, 557 564 devmap_name); 558 if ( NULL == devmap_pathname) {565 if (devmap_pathname == NULL) { 559 566 free(devmap_name); 560 567 return; … … 623 630 */ 624 631 driver_t *drv = find_best_match_driver(drivers_list, node); 625 if ( NULL == drv) {632 if (drv == NULL) { 626 633 printf(NAME ": no driver found for device '%s'.\n", 627 634 node->pathname); … … 632 639 attach_driver(node, drv); 633 640 634 if ( DRIVER_NOT_STARTED == drv->state) {641 if (drv->state == DRIVER_NOT_STARTED) { 635 642 /* Start the driver. */ 636 643 start_driver(drv); 637 644 } 638 645 639 if ( DRIVER_RUNNING == drv->state) {646 if (drv->state == DRIVER_RUNNING) { 640 647 /* Notify the driver about the new device. */ 641 648 int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0); … … 687 694 static bool set_dev_path(node_t *node, node_t *parent) 688 695 { 689 assert( NULL != node->name);696 assert(node->name != NULL); 690 697 691 698 size_t pathsize = (str_size(node->name) + 1); 692 if ( NULL != parent)699 if (parent != NULL) 693 700 pathsize += str_size(parent->pathname) + 1; 694 701 695 702 node->pathname = (char *) malloc(pathsize); 696 if ( NULL == node->pathname) {703 if (node->pathname == NULL) { 697 704 printf(NAME ": failed to allocate device path.\n"); 698 705 return false; 699 706 } 700 707 701 if ( NULL != parent) {708 if (parent != NULL) { 702 709 str_cpy(node->pathname, pathsize, parent->pathname); 703 710 str_append(node->pathname, pathsize, "/"); … … 719 726 * @param dev_name The name of the newly added device. 720 727 * @param parent The parent device node. 728 * 721 729 * @return True on success, false otherwise (insufficient resources 722 730 * etc.). 723 731 */ 724 bool 725 insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, node_t *parent) 726 { 727 assert(NULL != node && NULL != tree && NULL != dev_name); 732 bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, 733 node_t *parent) 734 { 735 assert(node != NULL); 736 assert(tree != NULL); 737 assert(dev_name != NULL); 728 738 729 739 node->name = dev_name; … … 740 750 /* Add the node to the list of its parent's children. */ 741 751 node->parent = parent; 742 if ( NULL != parent)752 if (parent != NULL) 743 753 list_append(&node->sibling, &parent->children); 744 754 … … 764 774 char *rel_path = path; 765 775 char *next_path_elem = NULL; 766 bool cont = '/' == rel_path[0];767 768 while (cont && NULL != dev) {776 bool cont = (rel_path[0] == '/'); 777 778 while (cont && dev != NULL) { 769 779 next_path_elem = get_path_elem_end(rel_path + 1); 770 if ( '/' == next_path_elem[0]) {780 if (next_path_elem[0] == '/') { 771 781 cont = true; 772 782 next_path_elem[0] = 0; … … 807 817 dev = list_get_instance(link, node_t, sibling); 808 818 809 if ( 0 == str_cmp(name, dev->name))819 if (str_cmp(name, dev->name) == 0) 810 820 return dev; 811 821 … … 829 839 const char *base_name; 830 840 831 if ( NULL != base_dev_name)841 if (base_dev_name != NULL) 832 842 base_name = base_dev_name; 833 843 else … … 853 863 * with the class. 854 864 */ 855 dev_class_info_t * 856 add_device_to_class(node_t *dev, dev_class_t *cl,const char *base_dev_name)865 dev_class_info_t *add_device_to_class(node_t *dev, dev_class_t *cl, 866 const char *base_dev_name) 857 867 { 858 868 dev_class_info_t *info = create_dev_class_info(); 859 869 860 if ( NULL != info) {870 if (info != NULL) { 861 871 info->dev_class = cl; 862 872 info->dev = dev; … … 883 893 fibril_rwlock_write_lock(&class_list->rwlock); 884 894 cl = find_dev_class_no_lock(class_list, class_name); 885 if ( NULL == cl) {895 if (cl == NULL) { 886 896 cl = create_dev_class(); 887 if ( NULL != cl) {897 if (cl != NULL) { 888 898 cl->name = class_name; 889 899 cl->base_dev_name = ""; … … 891 901 } 892 902 } 903 893 904 fibril_rwlock_write_unlock(&class_list->rwlock); 894 905 return cl; 895 906 } 896 907 897 dev_class_t * 898 find_dev_class_no_lock(class_list_t *class_list,const char *class_name)908 dev_class_t *find_dev_class_no_lock(class_list_t *class_list, 909 const char *class_name) 899 910 { 900 911 dev_class_t *cl; … … 903 914 while (link != &class_list->classes) { 904 915 cl = list_get_instance(link, dev_class_t, link); 905 if ( 0 == str_cmp(cl->name, class_name))916 if (str_cmp(cl->name, class_name) == 0) 906 917 return cl; 907 918 } … … 929 940 fibril_rwlock_read_lock(&tree->rwlock); 930 941 link = hash_table_find(&tree->devmap_devices, &key); 931 if ( NULL != link)942 if (link != NULL) 932 943 dev = hash_table_get_instance(link, node_t, devmap_link); 933 944 fibril_rwlock_read_unlock(&tree->rwlock); … … 936 947 } 937 948 938 node_t * 939 find_devmap_class_device(class_list_t *classes,dev_handle_t devmap_handle)949 node_t *find_devmap_class_device(class_list_t *classes, 950 dev_handle_t devmap_handle) 940 951 { 941 952 node_t *dev = NULL; … … 946 957 fibril_rwlock_read_lock(&classes->rwlock); 947 958 link = hash_table_find(&classes->devmap_devices, &key); 948 if ( NULL != link) {959 if (link != NULL) { 949 960 cli = hash_table_get_instance(link, dev_class_info_t, 950 961 devmap_link); -
uspace/srv/devman/devman.h
r667eac4 r58b833c 222 222 } dev_class_t; 223 223 224 /** Provides n-to-m mapping between device nodes and classes - each device may 224 /** 225 * Provides n-to-m mapping between device nodes and classes - each device may 225 226 * be register to the arbitrary number of classes and each class may contain 226 227 * the arbitrary number of devices. … … 290 291 static inline void init_driver_list(driver_list_t *drv_list) 291 292 { 292 assert( NULL != drv_list);293 assert(drv_list != NULL); 293 294 294 295 list_initialize(&drv_list->drivers); … … 348 349 static inline void delete_driver(driver_t *drv) 349 350 { 350 assert( NULL != drv);351 assert(drv != NULL); 351 352 352 353 clean_driver(drv); … … 382 383 { 383 384 assert(list_empty(&node->children)); 384 assert( NULL == node->parent);385 assert( NULL == node->drv);385 assert(node->parent == NULL); 386 assert(node->drv == NULL); 386 387 387 388 clean_match_ids(&node->match_ids); … … 399 400 * @return The device node. 400 401 */ 401 static inline node_t * 402 find_dev_node_no_lock(dev_tree_t *tree,device_handle_t handle)402 static inline node_t *find_dev_node_no_lock(dev_tree_t *tree, 403 device_handle_t handle) 403 404 { 404 405 unsigned long key = handle; … … 413 414 * @return The device node. 414 415 */ 415 static inline node_t * 416 find_dev_node(dev_tree_t *tree, device_handle_t handle) 416 static inline node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle) 417 417 { 418 418 node_t *node = NULL; … … 440 440 /** Create device class. 441 441 * 442 * @return 442 * @return Device class. 443 443 */ 444 444 static inline dev_class_t *create_dev_class(void) … … 447 447 448 448 cl = (dev_class_t *) malloc(sizeof(dev_class_t)); 449 if ( NULL != cl) {449 if (cl != NULL) { 450 450 memset(cl, 0, sizeof(dev_class_t)); 451 451 list_initialize(&cl->devices); … … 465 465 466 466 info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t)); 467 if ( NULL != info)467 if (info != NULL) 468 468 memset(info, 0, sizeof(dev_class_info_t)); 469 469 … … 491 491 extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *); 492 492 493 static inline void 494 add_dev_class_no_lock(class_list_t *class_list,dev_class_t *cl)493 static inline void add_dev_class_no_lock(class_list_t *class_list, 494 dev_class_t *cl) 495 495 { 496 496 list_append(&cl->link, &class_list->classes); … … 503 503 extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t); 504 504 505 static inline void 506 class_add_devmap_device(class_list_t *class_list,dev_class_info_t *cli)505 static inline void class_add_devmap_device(class_list_t *class_list, 506 dev_class_info_t *cli) 507 507 { 508 508 unsigned long key = (unsigned long) cli->devmap_handle;
Note:
See TracChangeset
for help on using the changeset viewer.