Changeset b910455 in mainline for uspace/srv


Ignore:
Timestamp:
2011-04-07T09:46:11Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6639ae1
Parents:
f6bffee (diff), 8e80d3f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
uspace/srv
Files:
36 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/ata_bd/ata_bd.c

    rf6bffee rb910455  
    372372        uint16_t w;
    373373        uint8_t c;
     374        uint16_t bc;
    374375        size_t pos, len;
    375376        int rc;
     
    387388        } else if (rc == EIO) {
    388389                /*
    389                  * There is something, but not a register device.
    390                  * It could be a packet device.
     390                 * There is something, but not a register device. Check to see
     391                 * whether the IDENTIFY command left the packet signature in
     392                 * the registers in case this is a packet device.
     393                 *
     394                 * According to the ATA specification, the LBA low and
     395                 * interrupt reason registers should be set to 0x01. However,
     396                 * there are many devices that do not follow this and only set
     397                 * the byte count registers. So, only check these.
    391398                 */
    392                 rc = identify_pkt_dev(disk_id, &idata);
    393                 if (rc == EOK) {
    394                         /* We have a packet device. */
    395                         d->dev_type = ata_pkt_dev;
     399                bc = ((uint16_t)pio_read_8(&cmd->cylinder_high) << 8) |
     400                    pio_read_8(&cmd->cylinder_low);
     401
     402                if (bc == PDEV_SIGNATURE_BC) {
     403                        rc = identify_pkt_dev(disk_id, &idata);
     404                        if (rc == EOK) {
     405                                /* We have a packet device. */
     406                                d->dev_type = ata_pkt_dev;
     407                        } else {
     408                                return EIO;
     409                        }
    396410                } else {
    397411                        /* Nope. Something's there, but not recognized. */
     
    403417        }
    404418
    405         printf("device caps: 0x%04x\n", idata.caps);
    406419        if (d->dev_type == ata_pkt_dev) {
    407420                /* Packet device */
     
    566579
    567580        /*
    568          * This is where we would most likely expect a non-existing device to
    569          * show up by not setting SR_DRDY.
     581         * Do not wait for DRDY to be set in case this is a packet device.
     582         * We determine whether the device is present by waiting for DRQ to be
     583         * set after issuing the command.
    570584         */
    571         if (wait_status(SR_DRDY, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
     585        if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
    572586                return ETIMEOUT;
    573587
     
    577591                return ETIMEOUT;
    578592
     593        /*
     594         * If ERR is set, this may be a packet device, so return EIO to cause
     595         * the caller to check for one.
     596         */
     597        if ((status & SR_ERR) != 0) {
     598                return EIO;
     599        }
     600
     601        if (wait_status(SR_DRQ, ~SR_BSY, &status, TIMEOUT_PROBE) != EOK)
     602                return ETIMEOUT;
     603
    579604        /* Read data from the disk buffer. */
    580605
    581         if ((status & SR_DRQ) != 0) {
    582                 for (i = 0; i < identify_data_size / 2; i++) {
    583                         data = pio_read_16(&cmd->data_port);
    584                         ((uint16_t *) buf)[i] = data;
    585                 }
    586         }
    587 
    588         if ((status & SR_ERR) != 0) {
    589                 return EIO;
     606        for (i = 0; i < identify_data_size / 2; i++) {
     607                data = pio_read_16(&cmd->data_port);
     608                ((uint16_t *) buf)[i] = data;
    590609        }
    591610
  • uspace/srv/bd/ata_bd/ata_hw.h

    rf6bffee rb910455  
    293293};
    294294
     295enum ata_pdev_signature {
     296        /**
     297         * Signature put by a packet device in byte count register
     298         * in response to Identify command.
     299         */
     300        PDEV_SIGNATURE_BC       = 0xEB14
     301};
     302
    295303#endif
    296304
  • uspace/srv/devman/devman.c

    rf6bffee rb910455  
    3434#include <fcntl.h>
    3535#include <sys/stat.h>
     36#include <io/log.h>
    3637#include <ipc/driver.h>
    3738#include <ipc/devman.h>
     
    146147        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    147148
    148         printf(NAME": the '%s' driver was added to the list of available "
    149             "drivers.\n", drv->name);
     149        log_msg(LVL_NOTE, "Driver `%s' was added to the list of available "
     150            "drivers.", drv->name);
    150151}
    151152
     
    237238bool read_match_ids(const char *conf_path, match_id_list_t *ids)
    238239{
    239         printf(NAME ": read_match_ids conf_path = %s.\n", conf_path);
     240        log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
    240241       
    241242        bool suc = false;
     
    247248        fd = open(conf_path, O_RDONLY);
    248249        if (fd < 0) {
    249                 printf(NAME ": unable to open %s\n", conf_path);
     250                log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.",
     251                    conf_path, str_error(fd));
    250252                goto cleanup;
    251253        }
     
    255257        lseek(fd, 0, SEEK_SET);
    256258        if (len == 0) {
    257                 printf(NAME ": configuration file '%s' is empty.\n", conf_path);
     259                log_msg(LVL_ERROR, "Configuration file '%s' is empty.",
     260                    conf_path);
    258261                goto cleanup;
    259262        }
     
    261264        buf = malloc(len + 1);
    262265        if (buf == NULL) {
    263                 printf(NAME ": memory allocation failed when parsing file "
    264                     "'%s'.\n", conf_path);
     266                log_msg(LVL_ERROR, "Memory allocation failed when parsing file "
     267                    "'%s'.", conf_path);
    265268                goto cleanup;
    266269        }
    267270       
    268         if (read(fd, buf, len) <= 0) {
    269                 printf(NAME ": unable to read file '%s'.\n", conf_path);
     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);
    270274                goto cleanup;
    271275        }
    272         buf[len] = 0;
     276        buf[read_bytes] = 0;
    273277       
    274278        suc = parse_match_ids(buf, ids);
     
    305309bool get_driver_info(const char *base_path, const char *name, driver_t *drv)
    306310{
    307         printf(NAME ": get_driver_info base_path = %s, name = %s.\n",
     311        log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",
    308312            base_path, name);
    309313       
     
    337341        struct stat s;
    338342        if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */
    339                 printf(NAME ": driver not found at path %s.", drv->binary_path);
     343                log_msg(LVL_ERROR, "Driver not found at path `%s'.",
     344                    drv->binary_path);
    340345                goto cleanup;
    341346        }
     
    364369int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path)
    365370{
    366         printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path);
     371        log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);
    367372       
    368373        int drv_cnt = 0;
     
    398403        dev_node_t *dev;
    399404       
    400         printf(NAME ": create_root_nodes\n");
     405        log_msg(LVL_DEBUG, "create_root_nodes()");
    401406       
    402407        fibril_rwlock_write_lock(&tree->rwlock);
     
    483488void attach_driver(dev_node_t *dev, driver_t *drv)
    484489{
    485         printf(NAME ": attach_driver %s to device %s\n",
    486             drv->name, dev->pfun->pathname);
     490        log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",
     491            dev->pfun->pathname, drv->name);
    487492       
    488493        fibril_mutex_lock(&drv->driver_mutex);
     
    506511        assert(fibril_mutex_is_locked(&drv->driver_mutex));
    507512       
    508         printf(NAME ": start_driver '%s'\n", drv->name);
     513        log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
    509514       
    510515        rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL);
    511516        if (rc != EOK) {
    512                 printf(NAME ": error spawning %s (%s)\n",
    513                     drv->name, str_error(rc));
     517                log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
     518                    drv->name, drv->binary_path, str_error(rc));
    514519                return false;
    515520        }
     
    573578        int phone;
    574579
    575         printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name);
     580        log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
     581            driver->name);
    576582
    577583        fibril_mutex_lock(&driver->driver_mutex);
     
    640646         * immediately and possibly started here as well.
    641647         */
    642         printf(NAME ": driver %s goes into running state.\n", driver->name);
     648        log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name);
    643649        driver->state = DRIVER_RUNNING;
    644650
     
    657663void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
    658664{
    659         printf(NAME ": initialize_running_driver (`%s')\n", driver->name);
     665        log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",
     666            driver->name);
    660667       
    661668        /*
     
    747754         * access any structures that would affect driver_t.
    748755         */
    749         printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
    750             dev->pfun->name);
     756        log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",
     757            drv->name, dev->pfun->name);
    751758       
    752759        sysarg_t rc;
     
    809816        driver_t *drv = find_best_match_driver(drivers_list, dev);
    810817        if (drv == NULL) {
    811                 printf(NAME ": no driver found for device '%s'.\n",
     818                log_msg(LVL_ERROR, "No driver found for device `%s'.",
    812819                    dev->pfun->pathname);
    813820                return false;
     
    847854bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list)
    848855{
    849         printf(NAME ": init_device_tree.\n");
     856        log_msg(LVL_DEBUG, "init_device_tree()");
    850857       
    851858        tree->current_handle = 0;
     
    10261033        fun->pathname = (char *) malloc(pathsize);
    10271034        if (fun->pathname == NULL) {
    1028                 printf(NAME ": failed to allocate device path.\n");
     1035                log_msg(LVL_ERROR, "Failed to allocate device path.");
    10291036                return false;
    10301037        }
     
    10571064        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    10581065       
     1066        log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",
     1067            dev, pfun, pfun->pathname);
     1068
    10591069        /* Add the node to the handle-to-node map. */
    10601070        dev->handle = ++tree->current_handle;
     
    10631073
    10641074        /* Add the node to the list of its parent's children. */
    1065         printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);
    10661075        dev->pfun = pfun;
    10671076        pfun->child = dev;
     
    11231132fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path)
    11241133{
     1134        assert(path != NULL);
     1135
     1136        bool is_absolute = path[0] == '/';
     1137        if (!is_absolute) {
     1138                return NULL;
     1139        }
     1140
    11251141        fibril_rwlock_read_lock(&tree->rwlock);
    11261142       
     
    11321148        char *rel_path = path;
    11331149        char *next_path_elem = NULL;
    1134         bool cont = (rel_path[0] == '/');
     1150        bool cont = true;
    11351151       
    11361152        while (cont && fun != NULL) {
     
    11571173}
    11581174
     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 */
     1184fun_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. */
     1205fun_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
    11591234/** Find child function node with a specified name.
    11601235 *
     
    11671242fun_node_t *find_node_child(fun_node_t *pfun, const char *name)
    11681243{
    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;
     1244        return find_fun_node_in_device(pfun->child, name);
    11841245}
    11851246
     
    13431404}
    13441405
     1406dev_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
    13451426void init_class_list(class_list_t *class_list)
    13461427{
  • uspace/srv/devman/devman.h

    rf6bffee rb910455  
    338338extern fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle);
    339339extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *);
     340extern fun_node_t *find_fun_node_in_device(dev_node_t *, const char *);
     341extern fun_node_t *find_fun_node_by_class(class_list_t *, const char *, const char *);
    340342
    341343/* Device tree */
     
    359361extern dev_class_t *get_dev_class(class_list_t *, char *);
    360362extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
     363extern dev_class_info_t *find_dev_in_class(dev_class_t *, const char *);
    361364extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
    362365
  • uspace/srv/devman/main.c

    rf6bffee rb910455  
    4343#include <stdio.h>
    4444#include <errno.h>
     45#include <str_error.h>
    4546#include <bool.h>
    4647#include <fibril_synch.h>
     
    5152#include <sys/stat.h>
    5253#include <ctype.h>
     54#include <io/log.h>
    5355#include <ipc/devman.h>
    5456#include <ipc/driver.h>
     
    7173        driver_t *driver = NULL;
    7274
    73         printf(NAME ": devman_driver_register \n");
     75        log_msg(LVL_DEBUG, "devman_driver_register");
    7476       
    7577        iid = async_get_call(&icall);
     
    8890        }
    8991
    90         printf(NAME ": the %s driver is trying to register by the service.\n",
     92        log_msg(LVL_DEBUG, "The `%s' driver is trying to register.",
    9193            drv_name);
    9294       
     
    9597       
    9698        if (driver == NULL) {
    97                 printf(NAME ": no driver named %s was found.\n", drv_name);
     99                log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name);
    98100                free(drv_name);
    99101                drv_name = NULL;
     
    106108       
    107109        /* Create connection to the driver. */
    108         printf(NAME ":  creating connection to the %s driver.\n", driver->name);
     110        log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.",
     111            driver->name);
    109112        ipc_call_t call;
    110113        ipc_callid_t callid = async_get_call(&call);
     
    118121        set_driver_phone(driver, IPC_GET_ARG5(call));
    119122       
    120         printf(NAME ": the %s driver was successfully registered as running.\n",
     123        log_msg(LVL_NOTE,
     124            "The `%s' driver was successfully registered as running.",
    121125            driver->name);
    122126       
     
    142146        callid = async_get_call(&call);
    143147        if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
    144                 printf(NAME ": ERROR: devman_receive_match_id - invalid "
    145                     "protocol.\n");
     148                log_msg(LVL_ERROR,
     149                    "Invalid protocol when trying to receive match id.");
    146150                async_answer_0(callid, EINVAL);
    147151                delete_match_id(match_id);
     
    150154       
    151155        if (match_id == NULL) {
    152                 printf(NAME ": ERROR: devman_receive_match_id - failed to "
    153                     "allocate match id.\n");
     156                log_msg(LVL_ERROR, "Failed to allocate match id.");
    154157                async_answer_0(callid, ENOMEM);
    155158                return ENOMEM;
     
    165168        if (rc != EOK) {
    166169                delete_match_id(match_id);
    167                 printf(NAME ": devman_receive_match_id - failed to receive "
    168                     "match id string.\n");
     170                log_msg(LVL_ERROR, "Failed to receive match id string: %s.",
     171                    str_error(rc));
    169172                return rc;
    170173        }
     
    172175        list_append(&match_id->link, &match_ids->ids);
    173176       
    174         printf(NAME ": received match id '%s', score = %d \n",
     177        log_msg(LVL_DEBUG, "Received match id `%s', score %d.",
    175178            match_id->id, match_id->score);
    176179        return rc;
     
    228231        if (ftype != fun_inner && ftype != fun_exposed) {
    229232                /* Unknown function type */
    230                 printf(NAME ": Error, unknown function type provided by driver!\n");
     233                log_msg(LVL_ERROR,
     234                    "Unknown function type %d provided by driver.",
     235                    (int) ftype);
    231236
    232237                fibril_rwlock_write_unlock(&tree->rwlock);
     
    243248        }
    244249       
     250        /* Check that function with same name is not there already. */
     251        if (find_fun_node_in_device(pdev, fun_name) != NULL) {
     252                fibril_rwlock_write_unlock(&tree->rwlock);
     253                async_answer_0(callid, EEXISTS);
     254                printf(NAME ": Warning, driver tried to register `%s' twice.\n",
     255                    fun_name);
     256                free(fun_name);
     257                return;
     258        }
     259
    245260        fun_node_t *fun = create_fun_node();
    246261        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
     
    265280        fibril_rwlock_write_unlock(&tree->rwlock);
    266281       
    267         printf(NAME ": devman_add_function %s\n", fun->pathname);
     282        log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);
    268283       
    269284        devman_receive_match_ids(match_count, &fun->match_ids);
     
    347362        devmap_register_class_dev(class_info);
    348363       
    349         printf(NAME ": function'%s' added to class '%s', class name '%s' was "
    350             "asigned to it\n", fun->pathname, class_name, class_info->dev_name);
     364        log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",
     365            fun->pathname, class_name, class_info->dev_name);
    351366
    352367        async_answer_0(callid, EOK);
     
    363378       
    364379        initialize_running_driver(driver, &device_tree);
    365         printf(NAME ": the %s driver was successfully initialized. \n",
     380        log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.",
    366381            driver->name);
    367382        return 0;
     
    385400        fid_t fid = fibril_create(init_running_drv, driver);
    386401        if (fid == 0) {
    387                 printf(NAME ": Error creating fibril for the initialization of "
    388                     "the newly registered running driver.\n");
     402                log_msg(LVL_ERROR, "Failed to create initialization fibril " \
     403                    "for driver `%s'.", driver->name);
    389404                return;
    390405        }
     
    438453}
    439454
     455/** Find handle for the device instance identified by device class name. */
     456static void devman_function_get_handle_by_class(ipc_callid_t iid,
     457    ipc_call_t *icall)
     458{
     459        char *classname;
     460        char *devname;
     461
     462        int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0);
     463        if (rc != EOK) {
     464                async_answer_0(iid, rc);
     465                return;
     466        }
     467        rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0);
     468        if (rc != EOK) {
     469                free(classname);
     470                async_answer_0(iid, rc);
     471                return;
     472        }
     473
     474
     475        fun_node_t *fun = find_fun_node_by_class(&class_list,
     476            classname, devname);
     477
     478        free(classname);
     479        free(devname);
     480
     481        if (fun == NULL) {
     482                async_answer_0(iid, ENOENT);
     483                return;
     484        }
     485
     486        async_answer_1(iid, EOK, fun->handle);
     487}
     488
    440489
    441490/** Function for handling connections from a client to the device manager. */
     
    457506                        devman_function_get_handle(callid, &call);
    458507                        break;
     508                case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
     509                        devman_function_get_handle_by_class(callid, &call);
     510                        break;
    459511                default:
    460512                        async_answer_0(callid, ENOENT);
     
    477529                dev = fun->dev;
    478530
    479         if (fun == NULL && dev == NULL) {
    480                 printf(NAME ": devman_forward error - no device or function with "
    481                     "handle %" PRIun " was found.\n", handle);
     531        /*
     532         * For a valid function to connect to we need a device. The root
     533         * function, for example, has no device and cannot be connected to.
     534         * This means @c dev needs to be valid regardless whether we are
     535         * connecting to a device or to a function.
     536         */
     537        if (dev == NULL) {
     538                log_msg(LVL_ERROR, "IPC forwarding failed - no device or "
     539                    "function with handle %" PRIun " was found.", handle);
    482540                async_answer_0(iid, ENOENT);
    483541                return;
     
    485543
    486544        if (fun == NULL && !drv_to_parent) {
    487                 printf(NAME ": devman_forward error - cannot connect to "
    488                     "handle %" PRIun ", refers to a device.\n", handle);
     545                log_msg(LVL_ERROR, NAME ": devman_forward error - cannot "
     546                    "connect to handle %" PRIun ", refers to a device.",
     547                    handle);
    489548                async_answer_0(iid, ENOENT);
    490549                return;
     
    507566       
    508567        if (driver == NULL) {
    509                 printf(NAME ": devman_forward error - the device is not in %" PRIun
    510                     " usable state.\n", handle);
     568                log_msg(LVL_ERROR, "IPC forwarding refused - " \
     569                    "the device %" PRIun " is not in usable state.", handle);
    511570                async_answer_0(iid, ENOENT);
    512571                return;
     
    520579       
    521580        if (driver->phone <= 0) {
    522                 printf(NAME ": devman_forward: cound not forward to driver %s ",
    523                     driver->name);
    524                 printf("the driver's phone is %" PRIun ").\n", driver->phone);
     581                log_msg(LVL_ERROR,
     582                    "Could not forward to driver `%s' (phone is %d).",
     583                    driver->name, (int) driver->phone);
    525584                async_answer_0(iid, EINVAL);
    526585                return;
     
    528587
    529588        if (fun != NULL) {
    530                 printf(NAME ": devman_forward: forward connection to function %s to "
    531                     "driver %s.\n", fun->pathname, driver->name);
     589                log_msg(LVL_DEBUG,
     590                    "Forwarding request for `%s' function to driver `%s'.",
     591                    fun->pathname, driver->name);
    532592        } else {
    533                 printf(NAME ": devman_forward: forward connection to device %s to "
    534                     "driver %s.\n", dev->pfun->pathname, driver->name);
     593                log_msg(LVL_DEBUG,
     594                    "Forwarding request for `%s' device to driver `%s'.",
     595                    dev->pfun->pathname, driver->name);
    535596        }
    536597
     
    564625        async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0,
    565626            IPC_FF_NONE);
    566         printf(NAME ": devman_connection_devmapper: forwarded connection to "
    567             "device %s to driver %s.\n", fun->pathname, dev->drv->name);
     627        log_msg(LVL_DEBUG,
     628            "Forwarding devmapper request for `%s' function to driver `%s'.",
     629            fun->pathname, dev->drv->name);
    568630}
    569631
     
    600662static bool devman_init(void)
    601663{
    602         printf(NAME ": devman_init - looking for available drivers.\n");
     664        log_msg(LVL_DEBUG, "devman_init - looking for available drivers.");
    603665       
    604666        /* Initialize list of available drivers. */
     
    606668        if (lookup_available_drivers(&drivers_list,
    607669            DRIVER_DEFAULT_STORE) == 0) {
    608                 printf(NAME " no drivers found.");
     670                log_msg(LVL_FATAL, "No drivers found.");
    609671                return false;
    610672        }
    611673
    612         printf(NAME ": devman_init  - list of drivers has been initialized.\n");
     674        log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");
    613675
    614676        /* Create root device node. */
    615677        if (!init_device_tree(&device_tree, &drivers_list)) {
    616                 printf(NAME " failed to initialize device tree.");
     678                log_msg(LVL_FATAL, "Failed to initialize device tree.");
    617679                return false;
    618680        }
     
    635697        printf(NAME ": HelenOS Device Manager\n");
    636698
     699        if (log_init(NAME, LVL_ERROR) != EOK) {
     700                printf(NAME ": Error initializing logging subsystem.\n");
     701                return -1;
     702        }
     703
    637704        if (!devman_init()) {
    638                 printf(NAME ": Error while initializing service\n");
     705                log_msg(LVL_ERROR, "Error while initializing service.");
    639706                return -1;
    640707        }
     
    644711
    645712        /* Register device manager at naming service. */
    646         if (service_register(SERVICE_DEVMAN) != EOK)
     713        if (service_register(SERVICE_DEVMAN) != EOK) {
     714                log_msg(LVL_ERROR, "Failed registering as a service.");
    647715                return -1;
    648 
    649         printf(NAME ": Accepting connections\n");
     716        }
     717
     718        printf(NAME ": Accepting connections.\n");
    650719        async_manager();
    651720
  • uspace/srv/devman/util.c

    rf6bffee rb910455  
    111111}
    112112
     113ssize_t safe_read(int fd, void *buffer, size_t size)
     114{
     115        if (size == 0) {
     116                return 0;
     117        }
     118
     119        uint8_t *buf_ptr = (uint8_t *) buffer;
     120
     121        size_t total_read = 0;
     122        while (total_read < size) {
     123                ssize_t bytes_read = read(fd, buf_ptr, size - total_read);
     124                if (bytes_read < 0) {
     125                        /* Error. */
     126                        return bytes_read;
     127                } else if (bytes_read == 0) {
     128                        /* Possibly end of file. */
     129                        break;
     130                } else {
     131                        /* Read at least something. */
     132                        buf_ptr += bytes_read;
     133                        total_read += bytes_read;
     134                }
     135        }
     136
     137        return (ssize_t) total_read;
     138}
     139
    113140/** @}
    114141 */
  • uspace/srv/devman/util.h

    rf6bffee rb910455  
    4747extern void replace_char(char *, char, char);
    4848
     49extern ssize_t safe_read(int, void *, size_t);
     50
    4951#endif
    5052
  • uspace/srv/devmap/devmap.c

    rf6bffee rb910455  
    551551        if (devmap_device_find_name(namespace->name, device->name) != NULL) {
    552552                printf("%s: Device '%s/%s' already registered\n", NAME,
    553                     device->namespace->name, device->name);
     553                    namespace->name, device->name);
    554554                devmap_namespace_destroy(namespace);
    555555                fibril_mutex_unlock(&devices_list_mutex);
  • uspace/srv/hid/kbd/generic/kbd.c

    rf6bffee rb910455  
    6767static unsigned lock_keys;
    6868
    69 int cir_service = 0;
    70 int cir_phone = -1;
     69bool irc_service = false;
     70int irc_phone = -1;
    7171
    7272#define NUM_LAYOUTS 3
     
    216216        sysarg_t obio;
    217217       
    218         if ((sysinfo_get_value("kbd.cir.fhc", &fhc) == EOK) && (fhc))
    219                 cir_service = SERVICE_FHC;
    220         else if ((sysinfo_get_value("kbd.cir.obio", &obio) == EOK) && (obio))
    221                 cir_service = SERVICE_OBIO;
    222        
    223         if (cir_service) {
    224                 while (cir_phone < 0)
    225                         cir_phone = service_connect_blocking(cir_service, 0, 0);
     218        if (((sysinfo_get_value("kbd.cir.fhc", &fhc) == EOK) && (fhc))
     219            || ((sysinfo_get_value("kbd.cir.obio", &obio) == EOK) && (obio)))
     220                irc_service = true;
     221       
     222        if (irc_service) {
     223                while (irc_phone < 0)
     224                        irc_phone = service_connect_blocking(SERVICE_IRC, 0, 0);
    226225        }
    227226       
  • uspace/srv/hid/kbd/include/kbd.h

    rf6bffee rb910455  
    3838#define KBD_KBD_H_
    3939
    40 extern int cir_service;
    41 extern int cir_phone;
     40#include <bool.h>
     41
     42extern bool irc_service;
     43extern int irc_phone;
    4244
    4345extern void kbd_push_scancode(int);
  • uspace/srv/hid/kbd/port/ns16550.c

    rf6bffee rb910455  
    120120        kbd_push_scancode(scan_code);
    121121       
    122         if (cir_service)
    123                 async_msg_1(cir_phone, IRC_CLEAR_INTERRUPT,
     122        if (irc_service)
     123                async_msg_1(irc_phone, IRC_CLEAR_INTERRUPT,
    124124                    IPC_GET_IMETHOD(*call));
    125125}
  • uspace/srv/hid/kbd/port/z8530.c

    rf6bffee rb910455  
    108108        kbd_push_scancode(scan_code);
    109109       
    110         if (cir_service)
    111                 async_msg_1(cir_phone, IRC_CLEAR_INTERRUPT,
     110        if (irc_service)
     111                async_msg_1(irc_phone, IRC_CLEAR_INTERRUPT,
    112112                    IPC_GET_IMETHOD(*call));
    113113}
  • uspace/srv/hw/bus/cuda_adb/cuda_adb.c

    rf6bffee rb910455  
    367367static void cuda_irq_rcv_end(void *buf, size_t *len)
    368368{
    369         uint8_t data, b;
    370 
     369        uint8_t b;
     370       
    371371        b = pio_read_8(&dev->b);
    372         data = pio_read_8(&dev->sr);
    373 
     372        pio_read_8(&dev->sr);
     373       
    374374        if ((b & TREQ) == 0) {
    375375                instance->xstate = cx_receive;
     
    379379                cuda_send_start();
    380380        }
    381 
    382         memcpy(buf, instance->rcv_buf, instance->bidx);
    383         *len = instance->bidx;
     381       
     382        memcpy(buf, instance->rcv_buf, instance->bidx);
     383        *len = instance->bidx;
    384384        instance->bidx = 0;
    385385}
  • uspace/srv/hw/irc/apic/apic.c

    rf6bffee rb910455  
    5656static int apic_enable_irq(sysarg_t irq)
    5757{
    58         // FIXME: TODO
     58        /* FIXME: TODO */
    5959        return ENOTSUP;
    6060}
     
    107107       
    108108        async_set_client_connection(apic_connection);
    109         service_register(SERVICE_APIC);
     109        service_register(SERVICE_IRC);
    110110       
    111111        return true;
  • uspace/srv/hw/irc/fhc/fhc.c

    rf6bffee rb910455  
    136136       
    137137        async_set_client_connection(fhc_connection);
    138         service_register(SERVICE_FHC);
     138        service_register(SERVICE_IRC);
    139139       
    140140        return true;
  • uspace/srv/hw/irc/i8259/i8259.c

    rf6bffee rb910455  
    149149       
    150150        async_set_client_connection(i8259_connection);
    151         service_register(SERVICE_I8259);
     151        service_register(SERVICE_IRC);
    152152       
    153153        return true;
  • uspace/srv/hw/irc/obio/obio.c

    rf6bffee rb910455  
    137137       
    138138        async_set_client_connection(obio_connection);
    139         service_register(SERVICE_OBIO);
     139        service_register(SERVICE_IRC);
    140140       
    141141        return true;
  • uspace/srv/hw/netif/ne2000/dp8390.c

    rf6bffee rb910455  
    391391       
    392392        if ((size < ETH_MIN_PACK_SIZE) || (size > ETH_MAX_PACK_SIZE_TAGGED)) {
     393                fibril_mutex_unlock(&ne2k->sq_mutex);
    393394                fprintf(stderr, "%s: Frame dropped (invalid size %zu bytes)\n",
    394395                    NAME, size);
  • uspace/srv/hw/netif/ne2000/ne2000.c

    rf6bffee rb910455  
    7575#define IRQ_GET_TSR(call)  ((int) IPC_GET_ARG3(call))
    7676
    77 static int irc_service = 0;
     77static bool irc_service = false;
    7878static int irc_phone = -1;
    7979
     
    383383        sysarg_t i8259;
    384384       
    385         if ((sysinfo_get_value("apic", &apic) == EOK) && (apic))
    386                 irc_service = SERVICE_APIC;
    387         else if ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))
    388                 irc_service = SERVICE_I8259;
     385        if (((sysinfo_get_value("apic", &apic) == EOK) && (apic))
     386            || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259)))
     387                irc_service = true;
    389388       
    390389        if (irc_service) {
    391390                while (irc_phone < 0)
    392                         irc_phone = service_connect_blocking(irc_service, 0, 0);
     391                        irc_phone = service_connect_blocking(SERVICE_IRC, 0, 0);
    393392        }
    394393       
  • uspace/srv/loader/arch/abs32le/_link.ld.in

    rf6bffee rb910455  
    2121       
    2222        .text : {
    23                 *(.text);
    24                 *(.rodata*);
     23                *(.text .text.*);
     24                *(.rodata .rodata.*);
    2525        } :text
    2626       
  • uspace/srv/loader/arch/amd64/_link.ld.in

    rf6bffee rb910455  
    2727       
    2828        .text : {
    29                 *(.text);
    30                 *(.rodata*);
     29                *(.text .text.*);
     30                *(.rodata .rodata.*);
    3131        } :text
    3232       
  • uspace/srv/loader/arch/arm32/_link.ld.in

    rf6bffee rb910455  
    2525       
    2626        .text : {
    27                 *(.text);
    28                 *(.rodata*);
     27                *(.text .text.*);
     28                *(.rodata .rodata.*);
    2929        } :text
    3030       
  • uspace/srv/loader/arch/ia32/_link.ld.in

    rf6bffee rb910455  
    2626       
    2727        .text : {
    28                 *(.text);
    29                 *(.rodata*);
     28                *(.text .text.*);
     29                *(.rodata .rodata.*);
    3030        } :text
    3131       
  • uspace/srv/loader/arch/ia64/_link.ld.in

    rf6bffee rb910455  
    2121       
    2222        .text : {
    23                 *(.text);
    24                 *(.rodata*);
     23                *(.text .text.*);
     24                *(.rodata .rodata.*);
    2525        } :text
    2626       
     
    2929        .got : {
    3030                _gp = .;
    31                 *(.got*);
     31                *(.got .got.*);
    3232        } :data
    3333       
  • uspace/srv/loader/arch/mips32/_link.ld.in

    rf6bffee rb910455  
    2525       
    2626        .text : {
    27                 *(.text);
    28                 *(.rodata*);
     27                *(.text .text.*);
     28                *(.rodata .rodata.*);
    2929        } :text
    3030       
  • uspace/srv/loader/arch/ppc32/_link.ld.in

    rf6bffee rb910455  
    2525       
    2626        .text : {
    27                 *(.text);
    28                 *(.rodata*);
     27                *(.text .text.*);
     28                *(.rodata .rodata.*);
    2929        } :text
    3030       
  • uspace/srv/loader/arch/sparc64/_link.ld.in

    rf6bffee rb910455  
    2020       
    2121        .text : {
    22                 *(.text);
    23                 *(.rodata*);
     22                *(.text .text.*);
     23                *(.rodata .rodata.*);
    2424        } :text
    2525       
  • uspace/srv/loader/main.c

    rf6bffee rb910455  
    407407                        /* Not reached */
    408408                default:
    409                         retval = ENOENT;
     409                        retval = EINVAL;
    410410                        break;
    411411                }
    412                 if (IPC_GET_IMETHOD(call) != IPC_M_PHONE_HUNGUP) {
    413                         DPRINTF("Responding EINVAL to method %d.\n",
    414                             IPC_GET_IMETHOD(call));
    415                         async_answer_0(callid, EINVAL);
    416                 }
     412               
     413                if (IPC_GET_IMETHOD(call) != IPC_M_PHONE_HUNGUP)
     414                        async_answer_0(callid, retval);
    417415        }
    418416}
  • uspace/srv/net/il/arp/arp.c

    rf6bffee rb910455  
    157157                       
    158158                        arp_clear_addr(&proto->addresses);
    159                         arp_addr_destroy(&proto->addresses);
    160                 }
    161         }
    162        
    163         arp_protos_clear(&device->protos);
     159                        arp_addr_destroy(&proto->addresses, free);
     160                }
     161        }
     162       
     163        arp_protos_clear(&device->protos, free);
    164164}
    165165
     
    184184        }
    185185       
    186         arp_cache_clear(&arp_globals.cache);
     186        arp_cache_clear(&arp_globals.cache, free);
    187187        fibril_mutex_unlock(&arp_globals.lock);
    188188       
     
    212212                arp_clear_trans(trans);
    213213       
    214         arp_addr_exclude(&proto->addresses, address->value, address->length);
     214        arp_addr_exclude(&proto->addresses, address->value, address->length, free);
    215215       
    216216        fibril_mutex_unlock(&arp_globals.lock);
     
    345345                            header->protocol_length, trans);
    346346                        if (rc != EOK) {
    347                                 /* The generic char map has already freed trans! */
     347                                free(trans);
    348348                                return rc;
    349349                        }
     
    556556                if (index < 0) {
    557557                        fibril_mutex_unlock(&arp_globals.lock);
    558                         arp_protos_destroy(&device->protos);
     558                        arp_protos_destroy(&device->protos, free);
    559559                        free(device);
    560560                        return index;
     
    569569                if (device->phone < 0) {
    570570                        fibril_mutex_unlock(&arp_globals.lock);
    571                         arp_protos_destroy(&device->protos);
     571                        arp_protos_destroy(&device->protos, free);
    572572                        free(device);
    573573                        return EREFUSED;
     
    579579                if (rc != EOK) {
    580580                        fibril_mutex_unlock(&arp_globals.lock);
    581                         arp_protos_destroy(&device->protos);
     581                        arp_protos_destroy(&device->protos, free);
    582582                        free(device);
    583583                        return rc;
     
    589589                if (rc != EOK) {
    590590                        fibril_mutex_unlock(&arp_globals.lock);
    591                         arp_protos_destroy(&device->protos);
     591                        arp_protos_destroy(&device->protos, free);
    592592                        free(device);
    593593                        return rc;
     
    601601                        free(device->addr);
    602602                        free(device->addr_data);
    603                         arp_protos_destroy(&device->protos);
     603                        arp_protos_destroy(&device->protos, free);
    604604                        free(device);
    605605                        return rc;
     
    614614                        free(device->broadcast_addr);
    615615                        free(device->broadcast_data);
    616                         arp_protos_destroy(&device->protos);
     616                        arp_protos_destroy(&device->protos, free);
    617617                        free(device);
    618618                        return rc;
     
    746746                        arp_clear_trans(trans);
    747747                        arp_addr_exclude(&proto->addresses, target->value,
    748                             target->length);
     748                            target->length, free);
    749749                        return EAGAIN;
    750750                }
     
    794794            trans);
    795795        if (rc != EOK) {
    796                 /* The generic char map has already freed trans! */
     796                free(trans);
    797797                return rc;
    798798        }
     
    807807                arp_clear_trans(trans);
    808808                arp_addr_exclude(&proto->addresses, target->value,
    809                     target->length);
     809                    target->length, free);
    810810                return ENOENT;
    811811        }
  • uspace/srv/net/il/ip/ip.c

    rf6bffee rb910455  
    176176        socklen_t addrlen;
    177177
    178         // detach the first packet and release the others
     178        /* Detach the first packet and release the others */
    179179        next = pq_detach(packet);
    180180        if (next)
     
    185185                        return ENOMEM;
    186186
    187                 // get header
     187                /* Get header */
    188188                header = (ip_header_t *) packet_get_data(packet);
    189189                if (!header)
     
    192192        }
    193193
    194         // only for the first fragment
     194        /* Only for the first fragment */
    195195        if (IP_FRAGMENT_OFFSET(header))
    196196                return EINVAL;
    197197
    198         // not for the ICMP protocol
     198        /* Not for the ICMP protocol */
    199199        if (header->protocol == IPPROTO_ICMP)
    200200                return EPERM;
    201201
    202         // set the destination address
     202        /* Set the destination address */
    203203        switch (header->version) {
    204204        case IPVERSION:
     
    351351        configuration = &names[0];
    352352
    353         // get configuration
     353        /* Get configuration */
    354354        rc = net_get_device_conf_req(ip_globals.net_phone, ip_netif->device_id,
    355355            &configuration, count, &data);
     
    365365               
    366366                if (ip_netif->dhcp) {
    367                         // TODO dhcp
     367                        /* TODO dhcp */
    368368                        net_free_settings(configuration, data);
    369369                        return ENOTSUP;
     
    398398                        }
    399399                } else {
    400                         // TODO ipv6 in separate module
     400                        /* TODO ipv6 in separate module */
    401401                        net_free_settings(configuration, data);
    402402                        return ENOTSUP;
     
    419419        }
    420420
    421         // binds the netif service which also initializes the device
     421        /* Bind netif service which also initializes the device */
    422422        ip_netif->phone = nil_bind_service(ip_netif->service,
    423423            (sysarg_t) ip_netif->device_id, SERVICE_IP,
     
    429429        }
    430430
    431         // has to be after the device netif module initialization
     431        /* Has to be after the device netif module initialization */
    432432        if (ip_netif->arp) {
    433433                if (route) {
     
    445445        }
    446446
    447         // get packet dimensions
     447        /* Get packet dimensions */
    448448        rc = nil_packet_size_req(ip_netif->phone, ip_netif->device_id,
    449449            &ip_netif->packet_dimension);
     
    463463       
    464464        if (gateway.s_addr) {
    465                 // the default gateway
     465                /* The default gateway */
    466466                ip_globals.gateway.address.s_addr = 0;
    467467                ip_globals.gateway.netmask.s_addr = 0;
     
    505505        if (rc != EOK) {
    506506                fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
    507                 ip_routes_destroy(&ip_netif->routes);
     507                ip_routes_destroy(&ip_netif->routes, free);
    508508                free(ip_netif);
    509509                return rc;
     
    512512                ip_netif->arp->usage++;
    513513
    514         // print the settings
     514        /* Print the settings */
    515515        printf("%s: Device registered (id: %d, phone: %d, ipv: %d, conf: %s)\n",
    516516            NAME, ip_netif->device_id, ip_netif->phone, ip_netif->ipv,
    517517            ip_netif->dhcp ? "dhcp" : "static");
    518518       
    519         // TODO ipv6 addresses
     519        /* TODO ipv6 addresses */
    520520       
    521521        char address[INET_ADDRSTRLEN];
     
    587587        ip_netif_t *netif;
    588588
    589         // start with the last netif - the newest one
     589        /* Start with the last netif - the newest one */
    590590        index = ip_netifs_count(&ip_globals.netifs) - 1;
    591591        while (index >= 0) {
     
    629629        size_t length;
    630630
    631         // copy first itself
     631        /* Copy first itself */
    632632        memcpy(last, first, sizeof(ip_header_t));
    633633        length = sizeof(ip_header_t);
    634634        next = sizeof(ip_header_t);
    635635
    636         // process all ip options
     636        /* Process all IP options */
    637637        while (next < first->header_length) {
    638638                option = (ip_option_t *) (((uint8_t *) first) + next);
    639                 // skip end or noop
     639                /* Skip end or noop */
    640640                if ((option->type == IPOPT_END) ||
    641641                    (option->type == IPOPT_NOOP)) {
    642642                        next++;
    643643                } else {
    644                         // copy if told so or skip
     644                        /* Copy if told so or skip */
    645645                        if (IPOPT_COPIED(option->type)) {
    646646                                memcpy(((uint8_t *) last) + length,
     
    648648                                length += option->length;
    649649                        }
    650                         // next option
     650                        /* Next option */
    651651                        next += option->length;
    652652                }
    653653        }
    654654
    655         // align 4 byte boundary
     655        /* Align 4 byte boundary */
    656656        if (length % 4) {
    657657                bzero(((uint8_t *) last) + length, 4 - (length % 4));
     
    789789
    790790        header->total_length = htons(length);
    791         // unnecessary for all protocols
     791        /* Unnecessary for all protocols */
    792792        header->header_checksum = IP_HEADER_CHECKSUM(header);
    793793
     
    916916                return ENOMEM;
    917917
    918         // get header
     918        /* Get header */
    919919        header = (ip_header_t *) packet_get_data(packet);
    920920        if (!header)
    921921                return EINVAL;
    922922
    923         // fragmentation forbidden?
     923        /* Fragmentation forbidden? */
    924924        if(header->flags & IPFLAG_DONT_FRAGMENT)
    925925                return EPERM;
    926926
    927         // create the last fragment
     927        /* Create the last fragment */
    928928        new_packet = packet_get_4_remote(ip_globals.net_phone, prefix, length,
    929929            suffix, ((addrlen > addr_len) ? addrlen : addr_len));
     
    931931                return ENOMEM;
    932932
    933         // allocate as much as originally
     933        /* Allocate as much as originally */
    934934        last_header = (ip_header_t *) packet_suffix(new_packet,
    935935            IP_HEADER_LENGTH(header));
     
    939939        ip_create_last_header(last_header, header);
    940940
    941         // trim the unused space
     941        /* Trim the unused space */
    942942        rc = packet_trim(new_packet, 0,
    943943            IP_HEADER_LENGTH(header) - IP_HEADER_LENGTH(last_header));
     
    945945                return ip_release_and_return(packet, rc);
    946946
    947         // biggest multiple of 8 lower than content
    948         // TODO even fragmentation?
     947        /* Greatest multiple of 8 lower than content */
     948        /* TODO even fragmentation? */
    949949        length = length & ~0x7;
    950950       
     
    957957                return ip_release_and_return(packet, rc);
    958958
    959         // mark the first as fragmented
     959        /* Mark the first as fragmented */
    960960        header->flags |= IPFLAG_MORE_FRAGMENTS;
    961961
    962         // create middle framgents
     962        /* Create middle fragments */
    963963        while (IP_TOTAL_LENGTH(header) > length) {
    964964                new_packet = packet_get_4_remote(ip_globals.net_phone, prefix,
     
    981981        }
    982982
    983         // finish the first fragment
     983        /* Finish the first fragment */
    984984        header->header_checksum = IP_HEADER_CHECKSUM(header);
    985985
     
    10121012
    10131013        next = packet;
    1014         // check all packets
     1014        /* Check all packets */
    10151015        while (next) {
    10161016                length = packet_get_data_length(next);
     
    10211021                }
    10221022
    1023                 // too long
     1023                /* Too long */
    10241024                result = ip_fragment_packet(next, content, prefix,
    10251025                    suffix, addr_len);
     
    10271027                        new_packet = pq_detach(next);
    10281028                        if (next == packet) {
    1029                                 // the new first packet of the queue
     1029                                /* The new first packet of the queue */
    10301030                                packet = new_packet;
    10311031                        }
    1032                         // fragmentation needed?
     1032                        /* Fragmentation needed? */
    10331033                        if (result == EPERM) {
    10341034                                phone = ip_prepare_icmp_and_get_phone(
    10351035                                    error, next, NULL);
    10361036                                if (phone >= 0) {
    1037                                         // fragmentation necessary ICMP
     1037                                        /* Fragmentation necessary ICMP */
    10381038                                        icmp_destination_unreachable_msg(phone,
    10391039                                            ICMP_FRAG_NEEDED, content, next);
     
    10801080        int rc;
    10811081
    1082         // get destination hardware address
     1082        /* Get destination hardware address */
    10831083        if (netif->arp && (route->address.s_addr != dest.s_addr)) {
    10841084                destination.value = route->gateway.s_addr ?
     
    11021102                            NULL);
    11031103                        if (phone >= 0) {
    1104                                 // unreachable ICMP if no routing
     1104                                /* Unreachable ICMP if no routing */
    11051105                                icmp_destination_unreachable_msg(phone,
    11061106                                    ICMP_HOST_UNREACH, 0, packet);
     
    11481148        int rc;
    11491149
    1150         // addresses in the host byte order
    1151         // should be the next hop address or the target destination address
     1150        /*
     1151         * Addresses in the host byte order
     1152         * Should be the next hop address or the target destination address
     1153         */
    11521154        addrlen = packet_get_addr(packet, NULL, (uint8_t **) &addr);
    11531155        if (addrlen < 0)
     
    11741176        fibril_rwlock_read_lock(&ip_globals.netifs_lock);
    11751177
    1176         // device specified?
     1178        /* Device specified? */
    11771179        if (device_id > 0) {
    11781180                netif = ip_netifs_find(&ip_globals.netifs, device_id);
     
    11901192                phone = ip_prepare_icmp_and_get_phone(error, packet, NULL);
    11911193                if (phone >= 0) {
    1192                         // unreachable ICMP if no routing
     1194                        /* Unreachable ICMP if no routing */
    11931195                        icmp_destination_unreachable_msg(phone,
    11941196                            ICMP_NET_UNREACH, 0, packet);
     
    11981200
    11991201        if (error) {
    1200                 // do not send for broadcast, anycast packets or network
    1201                 // broadcast
     1202                /*
     1203                 * Do not send for broadcast, anycast packets or network
     1204                 * broadcast.
     1205                 */
    12021206                if (!dest->s_addr || !(~dest->s_addr) ||
    12031207                    !(~((dest->s_addr & ~route->netmask.s_addr) |
     
    12081212        }
    12091213       
    1210         // if the local host is the destination
     1214        /* Ff the local host is the destination */
    12111215        if ((route->address.s_addr == dest->s_addr) &&
    12121216            (dest->s_addr != IPV4_LOCALHOST_ADDRESS)) {
    1213                 // find the loopback device to deliver
     1217                /* Find the loopback device to deliver */
    12141218                dest->s_addr = IPV4_LOCALHOST_ADDRESS;
    12151219                route = ip_find_route(*dest);
     
    12201224                            NULL);
    12211225                        if (phone >= 0) {
    1222                                 // unreachable ICMP if no routing
     1226                                /* Unreachable ICMP if no routing */
    12231227                                icmp_destination_unreachable_msg(phone,
    12241228                                    ICMP_HOST_UNREACH, 0, packet);
     
    12521256
    12531257        fibril_rwlock_write_lock(&ip_globals.netifs_lock);
    1254         // find the device
     1258        /* Find the device */
    12551259        netif = ip_netifs_find(&ip_globals.netifs, device_id);
    12561260        if (!netif) {
     
    12751279        in_addr_t destination;
    12761280
    1277         // TODO search set ipopt route?
     1281        /* TODO search set ipopt route? */
    12781282        destination.s_addr = header->destination_address;
    12791283        return destination;
     
    13171321        if ((header->flags & IPFLAG_MORE_FRAGMENTS) ||
    13181322            IP_FRAGMENT_OFFSET(header)) {
    1319                 // TODO fragmented
     1323                /* TODO fragmented */
    13201324                return ENOTSUP;
    13211325        }
     
    13441348                return ip_release_and_return(packet, rc);
    13451349
    1346         // trim padding if present
     1350        /* Trim padding if present */
    13471351        if (!error &&
    13481352            (IP_TOTAL_LENGTH(header) < packet_get_data_length(packet))) {
     
    13601364                phone = ip_prepare_icmp_and_get_phone(error, packet, header);
    13611365                if (phone >= 0) {
    1362                         // unreachable ICMP
     1366                        /* Unreachable ICMP */
    13631367                        icmp_destination_unreachable_msg(phone,
    13641368                            ICMP_PROT_UNREACH, 0, packet);
     
    14171421                return ip_release_and_return(packet, ENOMEM);
    14181422
    1419         // checksum
     1423        /* Checksum */
    14201424        if ((header->header_checksum) &&
    14211425            (IP_HEADER_CHECKSUM(header) != IP_CHECKSUM_ZERO)) {
    14221426                phone = ip_prepare_icmp_and_get_phone(0, packet, header);
    14231427                if (phone >= 0) {
    1424                         // checksum error ICMP
     1428                        /* Checksum error ICMP */
    14251429                        icmp_parameter_problem_msg(phone, ICMP_PARAM_POINTER,
    14261430                            ((size_t) ((void *) &header->header_checksum)) -
     
    14331437                phone = ip_prepare_icmp_and_get_phone(0, packet, header);
    14341438                if (phone >= 0) {
    1435                         // ttl exceeded ICMP
     1439                        /* ttl exceeded ICMP */
    14361440                        icmp_time_exceeded_msg(phone, ICMP_EXC_TTL, packet);
    14371441                }
     
    14391443        }
    14401444       
    1441         // process ipopt and get destination
     1445        /* Process ipopt and get destination */
    14421446        dest = ip_get_destination(header);
    14431447
    1444         // set the addrination address
     1448        /* Set the destination address */
    14451449        switch (header->version) {
    14461450        case IPVERSION:
     
    14641468                phone = ip_prepare_icmp_and_get_phone(0, packet, header);
    14651469                if (phone >= 0) {
    1466                         // unreachable ICMP
     1470                        /* Unreachable ICMP */
    14671471                        icmp_destination_unreachable_msg(phone,
    14681472                            ICMP_HOST_UNREACH, 0, packet);
     
    14721476
    14731477        if (route->address.s_addr == dest.s_addr) {
    1474                 // local delivery
     1478                /* Local delivery */
    14751479                return ip_deliver_local(device_id, packet, header, 0);
    14761480        }
     
    14841488        phone = ip_prepare_icmp_and_get_phone(0, packet, header);
    14851489        if (phone >= 0) {
    1486                 // unreachable ICMP if no routing
     1490                /* Unreachable ICMP if no routing */
    14871491                icmp_destination_unreachable_msg(phone, ICMP_HOST_UNREACH, 0,
    14881492                    packet);
     
    17701774                header = (ip_header_t *)(data + offset);
    17711775
    1772                 // destination host unreachable?
     1776                /* Destination host unreachable? */
    17731777                if ((type != ICMP_DEST_UNREACH) ||
    17741778                    (code != ICMP_HOST_UNREACH)) {
    1775                         // no, something else
     1779                        /* No, something else */
    17761780                        break;
    17771781                }
     
    17871791                route = ip_routes_get_index(&netif->routes, 0);
    17881792
    1789                 // from the same network?
     1793                /* From the same network? */
    17901794                if (route && ((route->address.s_addr & route->netmask.s_addr) ==
    17911795                    (header->destination_address & route->netmask.s_addr))) {
    1792                         // clear the ARP mapping if any
     1796                        /* Clear the ARP mapping if any */
    17931797                        address.value = (uint8_t *) &header->destination_address;
    17941798                        address.length = sizeof(header->destination_address);
     
    18441848        fibril_rwlock_read_lock(&ip_globals.lock);
    18451849        route = ip_find_route(*dest);
    1846         // if the local host is the destination
     1850        /* If the local host is the destination */
    18471851        if (route && (route->address.s_addr == dest->s_addr) &&
    18481852            (dest->s_addr != IPV4_LOCALHOST_ADDRESS)) {
    1849                 // find the loopback device to deliver
     1853                /* Find the loopback device to deliver */
    18501854                dest->s_addr = IPV4_LOCALHOST_ADDRESS;
    18511855                route = ip_find_route(*dest);
  • uspace/srv/net/net/net.c

    rf6bffee rb910455  
    289289        if (rc != EOK)
    290290                return rc;
     291       
    291292        rc = add_module(NULL, &net_globals.modules, (uint8_t *) NE2000_NAME,
    292293            (uint8_t *) NE2000_FILENAME, SERVICE_NE2000, 0, connect_to_service);
    293294        if (rc != EOK)
    294295                return rc;
     296       
    295297        rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME,
    296298            (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
    297299        if (rc != EOK)
    298300                return rc;
     301       
    299302        rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME,
    300303            (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
     
    552555                rc = read_netif_configuration(conf_files[i], netif);
    553556                if (rc != EOK) {
    554                         measured_strings_destroy(&netif->configuration);
     557                        measured_strings_destroy(&netif->configuration, free);
    555558                        free(netif);
    556559                        return rc;
     
    562565                if (!setting) {
    563566                        fprintf(stderr, "%s: Network interface name is missing\n", NAME);
    564                         measured_strings_destroy(&netif->configuration);
     567                        measured_strings_destroy(&netif->configuration, free);
    565568                        free(netif);
    566569                        return EINVAL;
     
    571574                int index = netifs_add(&net_globals.netifs, netif->id, netif);
    572575                if (index < 0) {
    573                         measured_strings_destroy(&netif->configuration);
     576                        measured_strings_destroy(&netif->configuration, free);
    574577                        free(netif);
    575578                        return index;
     
    583586                    index);
    584587                if (rc != EOK) {
    585                         measured_strings_destroy(&netif->configuration);
    586                         netifs_exclude_index(&net_globals.netifs, index);
     588                        measured_strings_destroy(&netif->configuration, free);
     589                        netifs_exclude_index(&net_globals.netifs, index, free);
    587590                        return rc;
    588591                }
     
    590593                rc = start_device(netif);
    591594                if (rc != EOK) {
    592                         printf("%s: Error starting interface %s (%s)\n", NAME,
     595                        printf("%s: Ignoring failed interface %s (%s)\n", NAME,
    593596                            netif->name, str_error(rc));
    594                         measured_strings_destroy(&netif->configuration);
    595                         netifs_exclude_index(&net_globals.netifs, index);
    596                        
    597                         return rc;
     597                        measured_strings_destroy(&netif->configuration, free);
     598                        netifs_exclude_index(&net_globals.netifs, index, free);
     599                        continue;
    598600                }
    599601               
  • uspace/srv/net/nil/eth/eth.c

    rf6bffee rb910455  
    214214        if (rc != EOK) {
    215215                free(eth_globals.broadcast_addr);
    216                 eth_devices_destroy(&eth_globals.devices);
     216                eth_devices_destroy(&eth_globals.devices, free);
    217217        }
    218218out:
     
    531531                            proto->service);
    532532                } else {
    533                         // drop invalid/unknown
     533                        /* Drop invalid/unknown */
    534534                        pq_release_remote(eth_globals.net_phone,
    535535                            packet_get_id(packet));
  • uspace/srv/net/tl/tcp/tcp.c

    rf6bffee rb910455  
    299299                return tcp_release_and_return(packet, NO_DATA);
    300300
    301 //      printf("header len %d, port %d \n", TCP_HEADER_LENGTH(header),
    302 //          ntohs(header->destination_port));
    303 
     301#if 0
     302        printf("header len %d, port %d \n", TCP_HEADER_LENGTH(header),
     303            ntohs(header->destination_port));
     304#endif
    304305        result = packet_get_addr(packet, (uint8_t **) &src, (uint8_t **) &dest);
    305306        if (result <= 0)
     
    10621063        tcp_process_acknowledgement(socket, socket_data, header);
    10631064
    1064         socket_data->next_incoming = ntohl(header->sequence_number);    // + 1;
     1065        socket_data->next_incoming = ntohl(header->sequence_number); /* + 1; */
    10651066        pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    10661067        socket_data->state = TCP_SOCKET_ESTABLISHED;
     
    17071708                if (socket->port > 0) {
    17081709                        socket_ports_exclude(&tcp_globals.sockets,
    1709                             socket->port);
     1710                            socket->port, free);
    17101711                        socket->port = 0;
    17111712                }
     
    24922493        rc = packet_dimensions_initialize(&tcp_globals.dimensions);
    24932494        if (rc != EOK) {
    2494                 socket_ports_destroy(&tcp_globals.sockets);
     2495                socket_ports_destroy(&tcp_globals.sockets, free);
    24952496                goto out;
    24962497        }
  • uspace/srv/net/tl/tcp/tcp.h

    rf6bffee rb910455  
    190190        int backlog;
    191191       
    192 //      /** Segment size. */
    193 //      size_t segment_size;
    194 
    195192        /**
    196193         * Parent listening socket identifier.
  • uspace/srv/net/tl/udp/udp.c

    rf6bffee rb910455  
    417417        rc = packet_dimensions_initialize(&udp_globals.dimensions);
    418418        if (rc != EOK) {
    419                 socket_ports_destroy(&udp_globals.sockets);
     419                socket_ports_destroy(&udp_globals.sockets, free);
    420420                fibril_rwlock_write_unlock(&udp_globals.lock);
    421421                return rc;
     
    434434            &data);
    435435        if (rc != EOK) {
    436                 socket_ports_destroy(&udp_globals.sockets);
     436                socket_ports_destroy(&udp_globals.sockets, free);
    437437                fibril_rwlock_write_unlock(&udp_globals.lock);
    438438                return rc;
     
    499499        device_id_t device_id;
    500500        packet_dimension_t *packet_dimension;
     501        size_t size;
    501502        int rc;
     503
     504        /* In case of error, do not update the data fragment size. */
     505        *data_fragment_size = 0;
    502506       
    503507        rc = tl_get_address_port(addr, addrlen, &dest_port);
     
    539543                packet_dimension = &udp_globals.packet_dimension;
    540544//      }
     545
     546        /*
     547         * Update the data fragment size based on what the lower layers can
     548         * handle without fragmentation, but not more than the maximum allowed
     549         * for UDP.
     550         */
     551        size = MAX_UDP_FRAGMENT_SIZE;
     552        if (packet_dimension->content < size)
     553            size = packet_dimension->content;
     554        *data_fragment_size = size;
    541555
    542556        /* Read the first packet fragment */
     
    740754        int socket_id;
    741755        size_t addrlen;
    742         size_t size = 0;
     756        size_t size;
    743757        ipc_call_t answer;
    744758        size_t answer_count;
     
    786800                                break;
    787801                       
     802                        size = MAX_UDP_FRAGMENT_SIZE;
    788803                        if (tl_get_ip_packet_dimension(udp_globals.ip_phone,
    789804                            &udp_globals.dimensions, DEVICE_INVALID_ID,
    790805                            &packet_dimension) == EOK) {
    791                                 SOCKET_SET_DATA_FRAGMENT_SIZE(answer,
    792                                     packet_dimension->content);
     806                                if (packet_dimension->content < size)
     807                                        size = packet_dimension->content;
    793808                        }
    794 
    795 //                      SOCKET_SET_DATA_FRAGMENT_SIZE(answer,
    796 //                          MAX_UDP_FRAGMENT_SIZE);
     809                        SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
    797810                        SOCKET_SET_HEADER_SIZE(answer, UDP_HEADER_SIZE);
    798811                        answer_count = 3;
  • uspace/srv/vfs/vfs_ops.c

    rf6bffee rb910455  
    611611void vfs_open_node(ipc_callid_t rid, ipc_call_t *request)
    612612{
    613         // FIXME: check for sanity of the supplied fs, dev and index
     613        /* FIXME: check for sanity of the supplied fs, dev and index */
    614614       
    615615        /*
Note: See TracChangeset for help on using the changeset viewer.