Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/devman.c

    rebcb05a r8b1e15ac  
    3434#include <fcntl.h>
    3535#include <sys/stat.h>
    36 #include <io/log.h>
    3736#include <ipc/driver.h>
    3837#include <ipc/devman.h>
     
    147146        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    148147
    149         log_msg(LVL_NOTE, "Driver `%s' was added to the list of available "
    150             "drivers.", drv->name);
     148        printf(NAME": the '%s' driver was added to the list of available "
     149            "drivers.\n", drv->name);
    151150}
    152151
     
    238237bool read_match_ids(const char *conf_path, match_id_list_t *ids)
    239238{
    240         log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
     239        printf(NAME ": read_match_ids conf_path = %s.\n", conf_path);
    241240       
    242241        bool suc = false;
     
    248247        fd = open(conf_path, O_RDONLY);
    249248        if (fd < 0) {
    250                 log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.",
    251                     conf_path, str_error(fd));
     249                printf(NAME ": unable to open %s\n", conf_path);
    252250                goto cleanup;
    253251        }
     
    257255        lseek(fd, 0, SEEK_SET);
    258256        if (len == 0) {
    259                 log_msg(LVL_ERROR, "Configuration file '%s' is empty.",
    260                     conf_path);
     257                printf(NAME ": configuration file '%s' is empty.\n", conf_path);
    261258                goto cleanup;
    262259        }
     
    264261        buf = malloc(len + 1);
    265262        if (buf == NULL) {
    266                 log_msg(LVL_ERROR, "Memory allocation failed when parsing file "
    267                     "'%s'.", conf_path);
     263                printf(NAME ": memory allocation failed when parsing file "
     264                    "'%s'.\n", conf_path);
    268265                goto cleanup;
    269266        }
    270267       
    271         ssize_t read_bytes = safe_read(fd, buf, len);
    272         if (read_bytes <= 0) {
    273                 log_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
     268        if (read(fd, buf, len) <= 0) {
     269                printf(NAME ": unable to read file '%s'.\n", conf_path);
    274270                goto cleanup;
    275271        }
    276         buf[read_bytes] = 0;
     272        buf[len] = 0;
    277273       
    278274        suc = parse_match_ids(buf, ids);
     
    309305bool get_driver_info(const char *base_path, const char *name, driver_t *drv)
    310306{
    311         log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",
     307        printf(NAME ": get_driver_info base_path = %s, name = %s.\n",
    312308            base_path, name);
    313309       
     
    341337        struct stat s;
    342338        if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */
    343                 log_msg(LVL_ERROR, "Driver not found at path `%s'.",
    344                     drv->binary_path);
     339                printf(NAME ": driver not found at path %s.", drv->binary_path);
    345340                goto cleanup;
    346341        }
     
    369364int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path)
    370365{
    371         log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);
     366        printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path);
    372367       
    373368        int drv_cnt = 0;
     
    403398        dev_node_t *dev;
    404399       
    405         log_msg(LVL_DEBUG, "create_root_nodes()");
     400        printf(NAME ": create_root_nodes\n");
    406401       
    407402        fibril_rwlock_write_lock(&tree->rwlock);
     
    488483void attach_driver(dev_node_t *dev, driver_t *drv)
    489484{
    490         log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",
    491             dev->pfun->pathname, drv->name);
     485        printf(NAME ": attach_driver %s to device %s\n",
     486            drv->name, dev->pfun->pathname);
    492487       
    493488        fibril_mutex_lock(&drv->driver_mutex);
     
    511506        assert(fibril_mutex_is_locked(&drv->driver_mutex));
    512507       
    513         log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
     508        printf(NAME ": start_driver '%s'\n", drv->name);
    514509       
    515510        rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL);
    516511        if (rc != EOK) {
    517                 log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
    518                     drv->name, drv->binary_path, str_error(rc));
     512                printf(NAME ": error spawning %s (%s)\n",
     513                    drv->name, str_error(rc));
    519514                return false;
    520515        }
     
    578573        int phone;
    579574
    580         log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
    581             driver->name);
     575        printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name);
    582576
    583577        fibril_mutex_lock(&driver->driver_mutex);
     
    646640         * immediately and possibly started here as well.
    647641         */
    648         log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name);
     642        printf(NAME ": driver %s goes into running state.\n", driver->name);
    649643        driver->state = DRIVER_RUNNING;
    650644
     
    663657void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
    664658{
    665         log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",
    666             driver->name);
     659        printf(NAME ": initialize_running_driver (`%s')\n", driver->name);
    667660       
    668661        /*
     
    754747         * access any structures that would affect driver_t.
    755748         */
    756         log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",
    757             drv->name, dev->pfun->name);
     749        printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
     750            dev->pfun->name);
    758751       
    759752        sysarg_t rc;
     
    816809        driver_t *drv = find_best_match_driver(drivers_list, dev);
    817810        if (drv == NULL) {
    818                 log_msg(LVL_ERROR, "No driver found for device `%s'.",
     811                printf(NAME ": no driver found for device '%s'.\n",
    819812                    dev->pfun->pathname);
    820813                return false;
     
    854847bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list)
    855848{
    856         log_msg(LVL_DEBUG, "init_device_tree()");
     849        printf(NAME ": init_device_tree.\n");
    857850       
    858851        tree->current_handle = 0;
     
    10331026        fun->pathname = (char *) malloc(pathsize);
    10341027        if (fun->pathname == NULL) {
    1035                 log_msg(LVL_ERROR, "Failed to allocate device path.");
     1028                printf(NAME ": failed to allocate device path.\n");
    10361029                return false;
    10371030        }
     
    10641057        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    10651058       
    1066         log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",
    1067             dev, pfun, pfun->pathname);
    1068 
    10691059        /* Add the node to the handle-to-node map. */
    10701060        dev->handle = ++tree->current_handle;
     
    10731063
    10741064        /* Add the node to the list of its parent's children. */
     1065        printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);
    10751066        dev->pfun = pfun;
    10761067        pfun->child = dev;
     
    11321123fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path)
    11331124{
    1134         assert(path != NULL);
    1135 
    1136         bool is_absolute = path[0] == '/';
    1137         if (!is_absolute) {
    1138                 return NULL;
    1139         }
    1140 
    11411125        fibril_rwlock_read_lock(&tree->rwlock);
    11421126       
     
    11481132        char *rel_path = path;
    11491133        char *next_path_elem = NULL;
    1150         bool cont = true;
     1134        bool cont = (rel_path[0] == '/');
    11511135       
    11521136        while (cont && fun != NULL) {
     
    11731157}
    11741158
    1175 /** Find function with a specified name belonging to given device.
    1176  *
    1177  * Device tree rwlock should be held at least for reading.
    1178  *
    1179  * @param dev Device the function belongs to.
    1180  * @param name Function name (not path).
    1181  * @return Function node.
    1182  * @retval NULL No function with given name.
    1183  */
    1184 fun_node_t *find_fun_node_in_device(dev_node_t *dev, const char *name)
    1185 {
    1186         assert(dev != NULL);
    1187         assert(name != NULL);
    1188 
    1189         fun_node_t *fun;
    1190         link_t *link;
    1191 
    1192         for (link = dev->functions.next;
    1193             link != &dev->functions;
    1194             link = link->next) {
    1195                 fun = list_get_instance(link, fun_node_t, dev_functions);
    1196 
    1197                 if (str_cmp(name, fun->name) == 0)
    1198                         return fun;
    1199         }
    1200 
    1201         return NULL;
    1202 }
    1203 
    1204 /** Find function node by its class name and index. */
    1205 fun_node_t *find_fun_node_by_class(class_list_t *class_list,
    1206     const char *class_name, const char *dev_name)
    1207 {
    1208         assert(class_list != NULL);
    1209         assert(class_name != NULL);
    1210         assert(dev_name != NULL);
    1211 
    1212         fibril_rwlock_read_lock(&class_list->rwlock);
    1213 
    1214         dev_class_t *cl = find_dev_class_no_lock(class_list, class_name);
    1215         if (cl == NULL) {
    1216                 fibril_rwlock_read_unlock(&class_list->rwlock);
    1217                 return NULL;
    1218         }
    1219 
    1220         dev_class_info_t *dev = find_dev_in_class(cl, dev_name);
    1221         if (dev == NULL) {
    1222                 fibril_rwlock_read_unlock(&class_list->rwlock);
    1223                 return NULL;
    1224         }
    1225 
    1226         fun_node_t *fun = dev->fun;
    1227 
    1228         fibril_rwlock_read_unlock(&class_list->rwlock);
    1229 
    1230         return fun;
    1231 }
    1232 
    1233 
    12341159/** Find child function node with a specified name.
    12351160 *
     
    12421167fun_node_t *find_node_child(fun_node_t *pfun, const char *name)
    12431168{
    1244         return find_fun_node_in_device(pfun->child, name);
     1169        fun_node_t *fun;
     1170        link_t *link;
     1171       
     1172        link = pfun->child->functions.next;
     1173       
     1174        while (link != &pfun->child->functions) {
     1175                fun = list_get_instance(link, fun_node_t, dev_functions);
     1176               
     1177                if (str_cmp(name, fun->name) == 0)
     1178                        return fun;
     1179               
     1180                link = link->next;
     1181        }
     1182       
     1183        return NULL;
    12451184}
    12461185
     
    12761215        if (info != NULL) {
    12771216                memset(info, 0, sizeof(dev_class_info_t));
    1278                 link_initialize(&info->dev_classes);
    1279                 link_initialize(&info->devmap_link);
    1280                 link_initialize(&info->link);
     1217                list_initialize(&info->dev_classes);
     1218                list_initialize(&info->devmap_link);
     1219                list_initialize(&info->link);
    12811220        }
    12821221       
     
    14041343}
    14051344
    1406 dev_class_info_t *find_dev_in_class(dev_class_t *dev_class, const char *dev_name)
    1407 {
    1408         assert(dev_class != NULL);
    1409         assert(dev_name != NULL);
    1410 
    1411         link_t *link;
    1412         for (link = dev_class->devices.next;
    1413             link != &dev_class->devices;
    1414             link = link->next) {
    1415                 dev_class_info_t *dev = list_get_instance(link,
    1416                     dev_class_info_t, link);
    1417 
    1418                 if (str_cmp(dev->dev_name, dev_name) == 0) {
    1419                         return dev;
    1420                 }
    1421         }
    1422 
    1423         return NULL;
    1424 }
    1425 
    14261345void init_class_list(class_list_t *class_list)
    14271346{
Note: See TracChangeset for help on using the changeset viewer.