Changeset 07b39338 in mainline for uspace/lib


Ignore:
Timestamp:
2011-08-20T18:21:49Z (14 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6ab014d
Parents:
0cf27ee (diff), f00af83 (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 libposix.

Location:
uspace/lib
Files:
59 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/arch/abs32le/include/types.h

    r0cf27ee r07b39338  
    5353typedef int32_t intptr_t;
    5454typedef uint32_t uintptr_t;
     55typedef int32_t intptr_t;
    5556typedef uint32_t atomic_count_t;
    5657typedef int32_t atomic_signed_t;
  • uspace/lib/c/arch/amd64/include/types.h

    r0cf27ee r07b39338  
    5353typedef int64_t intptr_t;
    5454typedef uint64_t uintptr_t;
     55typedef int64_t intptr_t;
    5556typedef uint64_t atomic_count_t;
    5657typedef int64_t atomic_signed_t;
  • uspace/lib/c/arch/arm32/include/types.h

    r0cf27ee r07b39338  
    5454typedef int32_t intptr_t;
    5555typedef uint32_t uintptr_t;
     56typedef int32_t intptr_t;
    5657typedef uint32_t atomic_count_t;
    5758typedef int32_t atomic_signed_t;
  • uspace/lib/c/arch/ia32/Makefile.common

    r0cf27ee r07b39338  
    2828
    2929CLANG_ARCH = i386
     30ifeq ($(PROCESSOR),i486)
     31GCC_CFLAGS += -march=i486 -fno-omit-frame-pointer
     32else
    3033GCC_CFLAGS += -march=pentium -fno-omit-frame-pointer
     34endif
    3135
    3236ENDIANESS = LE
  • uspace/lib/c/arch/ia32/Makefile.inc

    r0cf27ee r07b39338  
    2828
    2929ARCH_SOURCES = \
    30         arch/$(UARCH)/src/entry.s \
     30        arch/$(UARCH)/src/entry.S \
    3131        arch/$(UARCH)/src/entryjmp.s \
    3232        arch/$(UARCH)/src/thread_entry.s \
  • uspace/lib/c/arch/ia32/include/types.h

    r0cf27ee r07b39338  
    5353typedef int32_t intptr_t;
    5454typedef uint32_t uintptr_t;
     55typedef int32_t intptr_t;
    5556typedef uint32_t atomic_count_t;
    5657typedef int32_t atomic_signed_t;
  • uspace/lib/c/arch/ia32/src/entry.S

    r0cf27ee r07b39338  
    4646        mov %ax, %fs
    4747        # Do not set %gs, it contains descriptor that can see TLS
    48        
     48
     49#ifndef PROCESSOR_i486 
    4950        # Detect the mechanism used for making syscalls
    5051        movl $(INTEL_CPUID_STANDARD), %eax
     
    5556        movl $__syscall_fast, (%eax)
    56570:
     58#endif
    5759        #
    5860        # Create the first stack frame.
  • uspace/lib/c/arch/ia64/include/types.h

    r0cf27ee r07b39338  
    6363typedef int64_t intptr_t;
    6464typedef uint64_t uintptr_t;
     65typedef int64_t intptr_t;
    6566typedef uint64_t atomic_count_t;
    6667typedef int64_t atomic_signed_t;
  • uspace/lib/c/arch/mips32/include/types.h

    r0cf27ee r07b39338  
    5454typedef int32_t intptr_t;
    5555typedef uint32_t uintptr_t;
     56typedef int32_t intptr_t;
    5657typedef uint32_t atomic_count_t;
    5758typedef int32_t atomic_signed_t;
  • uspace/lib/c/arch/mips64/include/types.h

    r0cf27ee r07b39338  
    5353
    5454typedef uint64_t uintptr_t;
     55typedef int64_t intptr_t;
    5556typedef uint64_t atomic_count_t;
    5657typedef int64_t atomic_signed_t;
  • uspace/lib/c/arch/ppc32/include/types.h

    r0cf27ee r07b39338  
    5353typedef int32_t intptr_t;
    5454typedef uint32_t uintptr_t;
     55typedef int32_t intptr_t;
    5556typedef uint32_t atomic_count_t;
    5657typedef int32_t atomic_signed_t;
  • uspace/lib/c/arch/sparc64/include/types.h

    r0cf27ee r07b39338  
    5353typedef int64_t intptr_t;
    5454typedef uint64_t uintptr_t;
     55typedef int64_t intptr_t;
    5556typedef uint64_t atomic_count_t;
    5657typedef int64_t atomic_signed_t;
  • uspace/lib/c/generic/async.c

    r0cf27ee r07b39338  
    112112#include <mem.h>
    113113#include <stdlib.h>
     114#include <macros.h>
    114115#include "private/async.h"
    115116
     
    138139        link_t link;
    139140       
    140         sysarg_t in_task_hash;
     141        task_id_t in_task_id;
    141142        atomic_t refcnt;
    142143        void *data;
     
    150151        link_t link;
    151152       
    152         /** Incoming client task hash. */
    153         sysarg_t in_task_hash;
     153        /** Incoming client task ID. */
     154        task_id_t in_task_id;
    154155       
    155156        /** Incoming phone hash. */
     
    203204}
    204205
    205 void *async_get_client_data(void)
    206 {
    207         assert(fibril_connection);
    208         return fibril_connection->client->data;
    209 }
    210 
    211206/** Default fibril function that gets called to handle new connection.
    212207 *
     
    289284{
    290285        assert(key);
     286        assert(keys == 2);
    291287        assert(item);
    292288       
    293289        client_t *client = hash_table_get_instance(item, client_t, link);
    294         return (key[0] == client->in_task_hash);
     290        return (key[0] == LOWER32(client->in_task_id) &&
     291            (key[1] == UPPER32(client->in_task_id)));
    295292}
    296293
     
    580577}
    581578
     579static client_t *async_client_get(task_id_t client_id, bool create)
     580{
     581        unsigned long key[2] = {
     582                LOWER32(client_id),
     583                UPPER32(client_id),
     584        };
     585        client_t *client = NULL;
     586
     587        futex_down(&async_futex);
     588        link_t *lnk = hash_table_find(&client_hash_table, key);
     589        if (lnk) {
     590                client = hash_table_get_instance(lnk, client_t, link);
     591                atomic_inc(&client->refcnt);
     592        } else if (create) {
     593                client = malloc(sizeof(client_t));
     594                if (client) {
     595                        client->in_task_id = client_id;
     596                        client->data = async_client_data_create();
     597               
     598                        atomic_set(&client->refcnt, 1);
     599                        hash_table_insert(&client_hash_table, key, &client->link);
     600                }
     601        }
     602
     603        futex_up(&async_futex);
     604        return client;
     605}
     606
     607static void async_client_put(client_t *client)
     608{
     609        bool destroy;
     610        unsigned long key[2] = {
     611                LOWER32(client->in_task_id),
     612                UPPER32(client->in_task_id)
     613        };
     614       
     615        futex_down(&async_futex);
     616       
     617        if (atomic_predec(&client->refcnt) == 0) {
     618                hash_table_remove(&client_hash_table, key, 2);
     619                destroy = true;
     620        } else
     621                destroy = false;
     622       
     623        futex_up(&async_futex);
     624       
     625        if (destroy) {
     626                if (client->data)
     627                        async_client_data_destroy(client->data);
     628               
     629                free(client);
     630        }
     631}
     632
     633void *async_get_client_data(void)
     634{
     635        assert(fibril_connection);
     636        return fibril_connection->client->data;
     637}
     638
     639void *async_get_client_data_by_id(task_id_t client_id)
     640{
     641        client_t *client = async_client_get(client_id, false);
     642        if (!client)
     643                return NULL;
     644        if (!client->data) {
     645                async_client_put(client);
     646                return NULL;
     647        }
     648
     649        return client->data;
     650}
     651
     652void async_put_client_data_by_id(task_id_t client_id)
     653{
     654        client_t *client = async_client_get(client_id, false);
     655
     656        assert(client);
     657        assert(client->data);
     658
     659        /* Drop the reference we got in async_get_client_data_by_hash(). */
     660        async_client_put(client);
     661
     662        /* Drop our own reference we got at the beginning of this function. */
     663        async_client_put(client);
     664}
     665
    582666/** Wrapper for client connection fibril.
    583667 *
     
    598682         */
    599683        fibril_connection = (connection_t *) arg;
    600        
    601         futex_down(&async_futex);
    602684       
    603685        /*
     
    606688         * hash in a new tracking structure.
    607689         */
    608        
    609         unsigned long key = fibril_connection->in_task_hash;
    610         link_t *lnk = hash_table_find(&client_hash_table, &key);
    611        
    612         client_t *client;
    613        
    614         if (lnk) {
    615                 client = hash_table_get_instance(lnk, client_t, link);
    616                 atomic_inc(&client->refcnt);
    617         } else {
    618                 client = malloc(sizeof(client_t));
    619                 if (!client) {
    620                         ipc_answer_0(fibril_connection->callid, ENOMEM);
    621                         futex_up(&async_futex);
    622                         return 0;
    623                 }
    624                
    625                 client->in_task_hash = fibril_connection->in_task_hash;
    626                 client->data = async_client_data_create();
    627                
    628                 atomic_set(&client->refcnt, 1);
    629                 hash_table_insert(&client_hash_table, &key, &client->link);
    630         }
    631        
    632         futex_up(&async_futex);
    633        
     690
     691        client_t *client = async_client_get(fibril_connection->in_task_id, true);
     692        if (!client) {
     693                ipc_answer_0(fibril_connection->callid, ENOMEM);
     694                return 0;
     695        }
     696
    634697        fibril_connection->client = client;
    635698       
     
    643706         * Remove the reference for this client task connection.
    644707         */
    645         bool destroy;
    646        
    647         futex_down(&async_futex);
    648        
    649         if (atomic_predec(&client->refcnt) == 0) {
    650                 hash_table_remove(&client_hash_table, &key, 1);
    651                 destroy = true;
    652         } else
    653                 destroy = false;
    654        
    655         futex_up(&async_futex);
    656        
    657         if (destroy) {
    658                 if (client->data)
    659                         async_client_data_destroy(client->data);
    660                
    661                 free(client);
    662         }
     708        async_client_put(client);
    663709       
    664710        /*
     
    666712         */
    667713        futex_down(&async_futex);
    668         key = fibril_connection->in_phone_hash;
     714        unsigned long key = fibril_connection->in_phone_hash;
    669715        hash_table_remove(&conn_hash_table, &key, 1);
    670716        futex_up(&async_futex);
     
    700746 * particular fibrils.
    701747 *
    702  * @param in_task_hash  Identification of the incoming connection.
     748 * @param in_task_id    Identification of the incoming connection.
    703749 * @param in_phone_hash Identification of the incoming connection.
    704750 * @param callid        Hash of the opening IPC_M_CONNECT_ME_TO call.
     
    714760 *
    715761 */
    716 fid_t async_new_connection(sysarg_t in_task_hash, sysarg_t in_phone_hash,
     762fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash,
    717763    ipc_callid_t callid, ipc_call_t *call,
    718764    async_client_conn_t cfibril, void *carg)
     
    726772        }
    727773       
    728         conn->in_task_hash = in_task_hash;
     774        conn->in_task_id = in_task_id;
    729775        conn->in_phone_hash = in_phone_hash;
    730776        list_initialize(&conn->msg_queue);
     
    785831        case IPC_M_CONNECT_ME_TO:
    786832                /* Open new connection with fibril, etc. */
    787                 async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call),
     833                async_new_connection(call->in_task_id, IPC_GET_ARG5(*call),
    788834                    callid, call, client_connection, NULL);
    789835                return;
     
    933979{
    934980        if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS,
    935             1, &client_hash_table_ops))
     981            2, &client_hash_table_ops))
    936982                abort();
    937983       
     
    14261472                return ENOENT;
    14271473       
    1428         sysarg_t task_hash;
     1474        task_id_t task_id;
     1475        sysarg_t task_id_lo;
     1476        sysarg_t task_id_hi;
    14291477        sysarg_t phone_hash;
    14301478        int rc = async_req_3_5(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
    1431             NULL, NULL, NULL, &task_hash, &phone_hash);
     1479            NULL, NULL, &task_id_lo, &task_id_hi, &phone_hash);
    14321480        if (rc != EOK)
    14331481                return rc;
     1482
     1483        task_id = (task_id_t) MERGE_LOUP32(task_id_lo, task_id_hi);
    14341484       
    14351485        if (client_receiver != NULL)
    1436                 async_new_connection(task_hash, phone_hash, 0, NULL,
     1486                async_new_connection(task_id, phone_hash, 0, NULL,
    14371487                    client_receiver, carg);
    14381488       
     
    24292479}
    24302480
     2481int async_state_change_start(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2,
     2482    sysarg_t arg3, async_exch_t *other_exch)
     2483{
     2484        return async_req_5_0(exch, IPC_M_STATE_CHANGE_AUTHORIZE,
     2485            arg1, arg2, arg3, 0, other_exch->phone);
     2486}
     2487
     2488bool async_state_change_receive(ipc_callid_t *callid, sysarg_t *arg1,
     2489    sysarg_t *arg2, sysarg_t *arg3)
     2490{
     2491        assert(callid);
     2492
     2493        ipc_call_t call;
     2494        *callid = async_get_call(&call);
     2495
     2496        if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE)
     2497                return false;
     2498       
     2499        if (arg1)
     2500                *arg1 = IPC_GET_ARG1(call);
     2501        if (arg2)
     2502                *arg2 = IPC_GET_ARG2(call);
     2503        if (arg3)
     2504                *arg3 = IPC_GET_ARG3(call);
     2505
     2506        return true;
     2507}
     2508
     2509int async_state_change_finalize(ipc_callid_t callid, async_exch_t *other_exch)
     2510{
     2511        return ipc_answer_1(callid, EOK, other_exch->phone);
     2512}
     2513
    24312514/** @}
    24322515 */
  • uspace/lib/c/generic/devman.c

    r0cf27ee r07b39338  
    11/*
    22 * Copyright (c) 2007 Josef Cejka
    3  * Copyright (c) 2009 Jiri Svoboda
     3 * Copyright (c) 2011 Jiri Svoboda
    44 * Copyright (c) 2010 Lenka Trochtova
    55 * All rights reserved.
     
    195195       
    196196        exch = devman_exchange_begin(DEVMAN_DRIVER);
    197         async_connect_to_me(exch, 0, 0, 0, NULL, NULL);
     197        async_connect_to_me(exch, 0, 0, 0, conn, NULL);
    198198        devman_exchange_end(exch);
    199199       
     
    271271}
    272272
    273 int devman_add_device_to_class(devman_handle_t devman_handle,
    274     const char *class_name)
     273int devman_add_device_to_category(devman_handle_t devman_handle,
     274    const char *cat_name)
    275275{
    276276        async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
    277277       
    278278        ipc_call_t answer;
    279         aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_CLASS,
     279        aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_CATEGORY,
    280280            devman_handle, &answer);
    281         sysarg_t retval = async_data_write_start(exch, class_name,
    282             str_size(class_name));
     281        sysarg_t retval = async_data_write_start(exch, cat_name,
     282            str_size(cat_name));
    283283       
    284284        devman_exchange_end(exch);
     
    308308}
    309309
     310/** Remove function from device.
     311 *
     312 * Request devman to remove function owned by this driver task.
     313 * @param funh      Devman handle of the function
     314 *
     315 * @return EOK on success or negative error code.
     316 */
     317int devman_remove_function(devman_handle_t funh)
     318{
     319        async_exch_t *exch;
     320        sysarg_t retval;
     321       
     322        exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
     323        retval = async_req_1_0(exch, DEVMAN_REMOVE_FUNCTION, (sysarg_t) funh);
     324        devman_exchange_end(exch);
     325       
     326        return (int) retval;
     327}
     328
    310329async_sess_t *devman_parent_device_connect(exch_mgmt_t mgmt,
    311330    devman_handle_t handle, unsigned int flags)
     
    323342}
    324343
    325 int devman_device_get_handle(const char *pathname, devman_handle_t *handle,
     344int devman_fun_get_handle(const char *pathname, devman_handle_t *handle,
    326345    unsigned int flags)
    327346{
     
    333352                exch = devman_exchange_begin(DEVMAN_CLIENT);
    334353                if (exch == NULL)
    335                         return errno;
     354                        return ENOMEM;
    336355        }
    337356       
     
    364383}
    365384
    366 int devman_device_get_handle_by_class(const char *classname,
    367     const char *devname, devman_handle_t *handle, unsigned int flags)
     385static int devman_get_str_internal(sysarg_t method, sysarg_t arg1, char *buf,
     386    size_t buf_size)
    368387{
    369388        async_exch_t *exch;
    370        
    371         if (flags & IPC_FLAG_BLOCKING)
    372                 exch = devman_exchange_begin_blocking(DEVMAN_CLIENT);
    373         else {
    374                 exch = devman_exchange_begin(DEVMAN_CLIENT);
    375                 if (exch == NULL)
    376                         return errno;
    377         }
     389        ipc_call_t dreply;
     390        size_t act_size;
     391        sysarg_t dretval;
     392       
     393        exch = devman_exchange_begin_blocking(LOC_PORT_CONSUMER);
    378394       
    379395        ipc_call_t answer;
    380         aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
    381             flags, &answer);
    382         sysarg_t retval = async_data_write_start(exch, classname,
    383             str_size(classname));
     396        aid_t req = async_send_1(exch, method, arg1, &answer);
     397        aid_t dreq = async_data_read(exch, buf, buf_size - 1, &dreply);
     398        async_wait_for(dreq, &dretval);
     399       
     400        devman_exchange_end(exch);
     401       
     402        if (dretval != EOK) {
     403                async_wait_for(req, NULL);
     404                return dretval;
     405        }
     406       
     407        sysarg_t retval;
     408        async_wait_for(req, &retval);
     409       
     410        if (retval != EOK)
     411                return retval;
     412       
     413        act_size = IPC_GET_ARG2(dreply);
     414        assert(act_size <= buf_size - 1);
     415        buf[act_size] = '\0';
     416       
     417        return EOK;
     418}
     419
     420int devman_fun_get_path(devman_handle_t handle, char *buf, size_t buf_size)
     421{
     422        return devman_get_str_internal(DEVMAN_FUN_GET_PATH, handle, buf,
     423            buf_size);
     424}
     425
     426int devman_fun_get_name(devman_handle_t handle, char *buf, size_t buf_size)
     427{
     428        return devman_get_str_internal(DEVMAN_FUN_GET_NAME, handle, buf,
     429            buf_size);
     430}
     431
     432static int devman_get_handles_once(sysarg_t method, sysarg_t arg1,
     433    devman_handle_t *handle_buf, size_t buf_size, size_t *act_size)
     434{
     435        async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_CLIENT);
     436
     437        ipc_call_t answer;
     438        aid_t req = async_send_1(exch, method, arg1, &answer);
     439        int rc = async_data_read_start(exch, handle_buf, buf_size);
     440       
     441        devman_exchange_end(exch);
     442       
     443        if (rc != EOK) {
     444                async_wait_for(req, NULL);
     445                return rc;
     446        }
     447       
     448        sysarg_t retval;
     449        async_wait_for(req, &retval);
    384450       
    385451        if (retval != EOK) {
    386                 devman_exchange_end(exch);
    387                 async_wait_for(req, NULL);
    388                 return retval;
    389         }
    390        
    391         retval = async_data_write_start(exch, devname,
    392             str_size(devname));
    393        
    394         devman_exchange_end(exch);
    395        
    396         if (retval != EOK) {
    397                 async_wait_for(req, NULL);
    398                 return retval;
    399         }
    400        
    401         async_wait_for(req, &retval);
    402        
    403         if (retval != EOK) {
    404                 if (handle != NULL)
    405                         *handle = (devman_handle_t) -1;
    406                
    407                 return retval;
    408         }
    409        
    410         if (handle != NULL)
    411                 *handle = (devman_handle_t) IPC_GET_ARG1(answer);
    412        
    413         return retval;
    414 }
    415 
    416 int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size)
     452                return retval;
     453        }
     454       
     455        *act_size = IPC_GET_ARG1(answer);
     456        return EOK;
     457}
     458
     459/** Get list of handles.
     460 *
     461 * Returns an allocated array of handles.
     462 *
     463 * @param method        IPC method
     464 * @param arg1          IPC argument 1
     465 * @param data          Place to store pointer to array of handles
     466 * @param count         Place to store number of handles
     467 * @return              EOK on success or negative error code
     468 */
     469static int devman_get_handles_internal(sysarg_t method, sysarg_t arg1,
     470    devman_handle_t **data, size_t *count)
     471{
     472        devman_handle_t *handles;
     473        size_t act_size;
     474        size_t alloc_size;
     475        int rc;
     476
     477        *data = NULL;
     478        act_size = 0;   /* silence warning */
     479
     480        rc = devman_get_handles_once(method, arg1, NULL, 0,
     481            &act_size);
     482        if (rc != EOK)
     483                return rc;
     484
     485        alloc_size = act_size;
     486        handles = malloc(alloc_size);
     487        if (handles == NULL)
     488                return ENOMEM;
     489
     490        while (true) {
     491                rc = devman_get_handles_once(method, arg1, handles, alloc_size,
     492                    &act_size);
     493                if (rc != EOK)
     494                        return rc;
     495
     496                if (act_size <= alloc_size)
     497                        break;
     498
     499                alloc_size *= 2;
     500                free(handles);
     501
     502                handles = malloc(alloc_size);
     503                if (handles == NULL)
     504                        return ENOMEM;
     505        }
     506
     507        *count = act_size / sizeof(devman_handle_t);
     508        *data = handles;
     509        return EOK;
     510}
     511
     512int devman_fun_get_child(devman_handle_t funh, devman_handle_t *devh)
    417513{
    418514        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
    419515        if (exch == NULL)
    420                 return errno;
    421        
    422         ipc_call_t answer;
    423         aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_DEVICE_PATH,
    424             handle, &answer);
    425        
    426         ipc_call_t data_request_call;
    427         aid_t data_request = async_data_read(exch, path, path_size,
    428             &data_request_call);
    429        
    430         devman_exchange_end(exch);
    431        
    432         if (data_request == 0) {
    433                 async_wait_for(req, NULL);
    434516                return ENOMEM;
    435         }
    436        
    437         sysarg_t data_request_rc;
    438         async_wait_for(data_request, &data_request_rc);
    439        
    440         sysarg_t opening_request_rc;
    441         async_wait_for(req, &opening_request_rc);
    442        
    443         if (data_request_rc != EOK) {
    444                 /* Prefer the return code of the opening request. */
    445                 if (opening_request_rc != EOK)
    446                         return (int) opening_request_rc;
    447                 else
    448                         return (int) data_request_rc;
    449         }
    450        
    451         if (opening_request_rc != EOK)
    452                 return (int) opening_request_rc;
    453        
    454         /* To be on the safe-side. */
    455         path[path_size - 1] = 0;
    456         size_t transferred_size = IPC_GET_ARG2(data_request_call);
    457         if (transferred_size >= path_size)
    458                 return ELIMIT;
    459        
    460         /* Terminate the string (trailing 0 not send over IPC). */
    461         path[transferred_size] = 0;
    462         return EOK;
     517       
     518        sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_GET_CHILD,
     519            funh, devh);
     520       
     521        devman_exchange_end(exch);
     522        return (int) retval;
     523}
     524
     525int devman_dev_get_functions(devman_handle_t devh, devman_handle_t **funcs,
     526    size_t *count)
     527{
     528        return devman_get_handles_internal(DEVMAN_DEV_GET_FUNCTIONS,
     529            devh, funcs, count);
     530}
     531
     532int devman_fun_sid_to_handle(service_id_t sid, devman_handle_t *handle)
     533{
     534        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     535        if (exch == NULL)
     536                return ENOMEM;
     537       
     538        sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_SID_TO_HANDLE,
     539            sid, handle);
     540       
     541        devman_exchange_end(exch);
     542        return (int) retval;
    463543}
    464544
  • uspace/lib/c/generic/event.c

    r0cf27ee r07b39338  
    5454}
    5555
     56int event_task_subscribe(event_task_type_t evno, sysarg_t imethod)
     57{
     58        return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) evno,
     59            (sysarg_t) imethod);
     60}
     61
    5662/** Unmask event notifications.
    5763 *
     
    6672}
    6773
     74int event_task_unmask(event_task_type_t evno)
     75{
     76        return __SYSCALL1(SYS_EVENT_UNMASK, (sysarg_t) evno);
     77}
     78
    6879/** @}
    6980 */
  • uspace/lib/c/generic/io/io.c

    r0cf27ee r07b39338  
    101101static LIST_INITIALIZE(files);
    102102
    103 void __stdio_init(int filc, fdi_node_t *filv[])
     103void __stdio_init(int filc)
    104104{
    105105        if (filc > 0) {
    106                 stdin = fopen_node(filv[0], "r");
     106                stdin = fdopen(0, "r");
    107107        } else {
    108108                stdin = &stdin_null;
     
    111111       
    112112        if (filc > 1) {
    113                 stdout = fopen_node(filv[1], "w");
     113                stdout = fdopen(1, "w");
    114114        } else {
    115115                stdout = &stdout_klog;
     
    118118       
    119119        if (filc > 2) {
    120                 stderr = fopen_node(filv[2], "w");
     120                stderr = fdopen(2, "w");
    121121        } else {
    122122                stderr = &stderr_klog;
     
    285285}
    286286
    287 FILE *fopen_node(fdi_node_t *node, const char *mode)
    288 {
    289         int flags;
    290         if (!parse_mode(mode, &flags))
    291                 return NULL;
    292        
    293         /* Open file. */
    294         FILE *stream = malloc(sizeof(FILE));
    295         if (stream == NULL) {
    296                 errno = ENOMEM;
    297                 return NULL;
    298         }
    299        
    300         stream->fd = open_node(node, flags);
    301         if (stream->fd < 0) {
    302                 /* errno was set by open_node() */
    303                 free(stream);
    304                 return NULL;
    305         }
    306        
    307         stream->error = false;
    308         stream->eof = false;
    309         stream->klog = false;
    310         stream->sess = NULL;
    311         stream->need_sync = false;
    312         _setvbuf(stream);
    313        
    314         list_append(&stream->link, &files);
    315        
    316         return stream;
    317 }
    318 
    319287int fclose(FILE *stream)
    320288{
     
    780748}
    781749
    782 int fnode(FILE *stream, fdi_node_t *node)
    783 {
    784         if (stream->fd >= 0)
    785                 return fd_node(stream->fd, node);
     750int fhandle(FILE *stream, int *handle)
     751{
     752        if (stream->fd >= 0) {
     753                *handle = stream->fd;
     754                return EOK;
     755        }
    786756       
    787757        return ENOENT;
  • uspace/lib/c/generic/io/printf_core.c

    r0cf27ee r07b39338  
    206206        }
    207207       
    208         return (int) (counter + 1);
     208        return (int) (counter);
    209209}
    210210
     
    244244        }
    245245       
    246         return (int) (counter + 1);
     246        return (int) (counter);
    247247}
    248248
  • uspace/lib/c/generic/libc.c

    r0cf27ee r07b39338  
    9191                argc = 0;
    9292                argv = NULL;
    93                 __stdio_init(0, NULL);
     93                __stdio_init(0);
    9494        } else {
    9595                argc = __pcb->argc;
    9696                argv = __pcb->argv;
    97                 __stdio_init(__pcb->filc, __pcb->filv);
     97                __stdio_init(__pcb->filc);
    9898                (void) chdir(__pcb->cwd);
    9999        }
  • uspace/lib/c/generic/loader.c

    r0cf27ee r07b39338  
    256256 *
    257257 */
    258 int loader_set_files(loader_t *ldr, fdi_node_t *const files[])
    259 {
    260         /*
    261          * Serialize the arguments into a single array. First
    262          * compute size of the buffer needed.
    263          */
    264         fdi_node_t *const *ap = files;
    265         size_t count = 0;
    266         while (*ap != NULL) {
    267                 count++;
    268                 ap++;
    269         }
    270        
    271         fdi_node_t *files_buf;
    272         files_buf = (fdi_node_t *) malloc(count * sizeof(fdi_node_t));
    273         if (files_buf == NULL)
    274                 return ENOMEM;
    275        
    276         /* Fill the buffer */
    277         size_t i;
    278         for (i = 0; i < count; i++)
    279                 files_buf[i] = *files[i];
    280        
     258int loader_set_files(loader_t *ldr, int * const files[])
     259{
    281260        /* Send serialized files to the loader */
    282261        async_exch_t *exch = async_exchange_begin(ldr->sess);
    283        
    284         ipc_call_t answer;
    285         aid_t req = async_send_0(exch, LOADER_SET_FILES, &answer);
    286         sysarg_t rc = async_data_write_start(exch, (void *) files_buf,
    287             count * sizeof(fdi_node_t));
    288        
    289         async_exchange_end(exch);
    290         free(files_buf);
    291        
     262        async_exch_t *vfs_exch = vfs_exchange_begin();
     263       
     264        int i;
     265        for (i = 0; files[i]; i++);
     266
     267        ipc_call_t answer;
     268        aid_t req = async_send_1(exch, LOADER_SET_FILES, i, &answer);
     269
     270        sysarg_t rc = EOK;
     271       
     272        for (i = 0; files[i]; i++) {
     273                rc = async_state_change_start(exch, VFS_PASS_HANDLE, *files[i],
     274                    0, vfs_exch);
     275                if (rc != EOK)
     276                        break;
     277        }
     278       
     279        vfs_exchange_end(vfs_exch);
     280        async_exchange_end(exch);
     281
    292282        if (rc != EOK) {
    293283                async_wait_for(req, NULL);
  • uspace/lib/c/generic/loc.c

    r0cf27ee r07b39338  
    4545static FIBRIL_MUTEX_INITIALIZE(loc_consumer_mutex);
    4646
     47static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex);
     48static bool loc_callback_created = false;
     49
    4750static async_sess_t *loc_supp_block_sess = NULL;
    4851static async_sess_t *loc_cons_block_sess = NULL;
     
    5154static async_sess_t *loc_consumer_sess = NULL;
    5255
     56static loc_cat_change_cb_t cat_change_cb = NULL;
     57
     58static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     59{
     60        loc_cat_change_cb_t cb_fun;
     61       
     62        while (true) {
     63                ipc_call_t call;
     64                ipc_callid_t callid = async_get_call(&call);
     65               
     66                if (!IPC_GET_IMETHOD(call)) {
     67                        /* TODO: Handle hangup */
     68                        return;
     69                }
     70               
     71                int retval;
     72               
     73                switch (IPC_GET_IMETHOD(call)) {
     74                case LOC_EVENT_CAT_CHANGE:
     75                        fibril_mutex_lock(&loc_callback_mutex);
     76                        cb_fun = cat_change_cb;
     77                        if (cb_fun != NULL) {
     78                                (*cb_fun)();
     79                        }
     80                        fibril_mutex_unlock(&loc_callback_mutex);
     81                        retval = 0;
     82                        break;
     83                default:
     84                        retval = ENOTSUP;
     85                }
     86               
     87                async_answer_0(callid, retval);
     88        }
     89}
     90
     91
    5392static void clone_session(fibril_mutex_t *mtx, async_sess_t *src,
    5493    async_sess_t **dst)
     
    6099       
    61100        fibril_mutex_unlock(mtx);
     101}
     102
     103static int loc_callback_create(void)
     104{
     105        async_exch_t *exch;
     106        sysarg_t retval;
     107        int rc = EOK;
     108
     109        fibril_mutex_lock(&loc_callback_mutex);
     110       
     111        if (!loc_callback_created) {
     112                exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     113               
     114                ipc_call_t answer;
     115                aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer);
     116                async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
     117                loc_exchange_end(exch);
     118               
     119                async_wait_for(req, &retval);
     120                if (rc != EOK)
     121                        goto done;
     122               
     123                if (retval != EOK) {
     124                        rc = retval;
     125                        goto done;
     126                }
     127               
     128                loc_callback_created = true;
     129        }
     130       
     131        rc = EOK;
     132done:
     133        fibril_mutex_unlock(&loc_callback_mutex);
     134        return rc;
    62135}
    63136
     
    194267}
    195268
    196 /** Register new device.
    197  *
    198  * The @p interface is used when forwarding connection to the driver.
     269/** Register new service.
     270 *
     271 * The @p interface is used when forwarding connection to the server.
    199272 * If not 0, the first argument is the interface and the second argument
    200273 * is the service ID.
     
    203276 * the handle (to ensure backward compatibility).
    204277 *
    205  * @param      fqdn      Fully qualified device name.
    206  * @param[out] handle    Handle to the created instance of device.
    207  * @param      interface Interface when forwarding.
    208  *
    209  */
    210 int loc_service_register_with_iface(const char *fqdn,
    211     service_id_t *handle, sysarg_t interface)
     278 * @param      fqsn      Fully qualified service name
     279 * @param[out] sid       Service ID of new service
     280 * @param      interface Interface when forwarding
     281 *
     282 */
     283int loc_service_register_with_iface(const char *fqsn,
     284    service_id_t *sid, sysarg_t interface)
    212285{
    213286        async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER);
     
    216289        aid_t req = async_send_2(exch, LOC_SERVICE_REGISTER, interface, 0,
    217290            &answer);
    218         sysarg_t retval = async_data_write_start(exch, fqdn, str_size(fqdn));
     291        sysarg_t retval = async_data_write_start(exch, fqsn, str_size(fqsn));
    219292       
    220293        loc_exchange_end(exch);
     
    228301       
    229302        if (retval != EOK) {
    230                 if (handle != NULL)
    231                         *handle = -1;
    232                
    233                 return retval;
    234         }
    235        
    236         if (handle != NULL)
    237                 *handle = (service_id_t) IPC_GET_ARG1(answer);
     303                if (sid != NULL)
     304                        *sid = -1;
     305               
     306                return retval;
     307        }
     308       
     309        if (sid != NULL)
     310                *sid = (service_id_t) IPC_GET_ARG1(answer);
    238311       
    239312        return retval;
    240313}
    241314
    242 /** Register new device.
    243  *
    244  * @param fqdn   Fully qualified device name.
    245  * @param handle Output: Handle to the created instance of device.
    246  *
    247  */
    248 int loc_service_register(const char *fqdn, service_id_t *handle)
    249 {
    250         return loc_service_register_with_iface(fqdn, handle, 0);
     315/** Register new service.
     316 *
     317 * @param fqsn Fully qualified service name
     318 * @param sid  Output: ID of new service
     319 *
     320 */
     321int loc_service_register(const char *fqdn, service_id_t *sid)
     322{
     323        return loc_service_register_with_iface(fqdn, sid, 0);
     324}
     325
     326/** Unregister service.
     327 *
     328 * @param sid   Service ID
     329 */
     330int loc_service_unregister(service_id_t sid)
     331{
     332        async_exch_t *exch;
     333        sysarg_t retval;
     334       
     335        exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER);
     336        retval = async_req_1_0(exch, LOC_SERVICE_UNREGISTER, sid);
     337        loc_exchange_end(exch);
     338       
     339        return (int)retval;
    251340}
    252341
     
    291380}
    292381
    293 /** Get service name.
    294  *
    295  * Provided ID of a service, return its name.
    296  *
    297  * @param svc_id        Service ID
     382/** Get object name.
     383 *
     384 * Provided ID of an object, return its name.
     385 *
     386 * @param method        IPC method
     387 * @param id            Object ID
    298388 * @param name          Place to store pointer to new string. Caller should
    299389 *                      free it using free().
    300390 * @return              EOK on success or negative error code
    301391 */
    302 int loc_service_get_name(service_id_t svc_id, char **name)
     392static int loc_get_name_internal(sysarg_t method, sysarg_t id, char **name)
    303393{
    304394        async_exch_t *exch;
     
    312402       
    313403        ipc_call_t answer;
    314         aid_t req = async_send_1(exch, LOC_SERVICE_GET_NAME, svc_id, &answer);
     404        aid_t req = async_send_1(exch, method, id, &answer);
    315405        aid_t dreq = async_data_read(exch, name_buf, LOC_NAME_MAXLEN,
    316406            &dreply);
     
    341431}
    342432
     433/** Get category name.
     434 *
     435 * Provided ID of a service, return its name.
     436 *
     437 * @param cat_id        Category ID
     438 * @param name          Place to store pointer to new string. Caller should
     439 *                      free it using free().
     440 * @return              EOK on success or negative error code
     441 */
     442int loc_category_get_name(category_id_t cat_id, char **name)
     443{
     444        return loc_get_name_internal(LOC_CATEGORY_GET_NAME, cat_id, name);
     445}
     446
     447/** Get service name.
     448 *
     449 * Provided ID of a service, return its name.
     450 *
     451 * @param svc_id        Service ID
     452 * @param name          Place to store pointer to new string. Caller should
     453 *                      free it using free().
     454 * @return              EOK on success or negative error code
     455 */
     456int loc_service_get_name(service_id_t svc_id, char **name)
     457{
     458        return loc_get_name_internal(LOC_SERVICE_GET_NAME, svc_id, name);
     459}
    343460
    344461int loc_namespace_get_id(const char *name, service_id_t *handle,
     
    749866            data, count);
    750867}
     868
     869int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun)
     870{
     871        if (loc_callback_create() != EOK)
     872                return EIO;
     873
     874        cat_change_cb = cb_fun;
     875        return EOK;
     876}
  • uspace/lib/c/generic/private/async.h

    r0cf27ee r07b39338  
    3636#define LIBC_PRIVATE_ASYNC_H_
    3737
     38#include <ipc/common.h>
    3839#include <adt/list.h>
    3940#include <fibril.h>
  • uspace/lib/c/generic/private/io.h

    r0cf27ee r07b39338  
    3636#define LIBC_PRIVATE_IO_H_
    3737
    38 #include <vfs/vfs.h>
    39 
    40 extern void __stdio_init(int filc, fdi_node_t *filv[]);
     38extern void __stdio_init(int);
    4139extern void __stdio_done(void);
    4240
  • uspace/lib/c/generic/task.c

    r0cf27ee r07b39338  
    4646#include <libc.h>
    4747#include "private/ns.h"
     48#include <vfs/vfs.h>
    4849
    4950task_id_t task_get_id(void)
     
    102103{
    103104        /* Send default files */
    104         fdi_node_t *files[4];
    105         fdi_node_t stdin_node;
    106         fdi_node_t stdout_node;
    107         fdi_node_t stderr_node;
    108        
    109         if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK))
    110                 files[0] = &stdin_node;
     105        int *files[4];
     106        int fd_stdin;
     107        int fd_stdout;
     108        int fd_stderr;
     109       
     110        if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
     111                files[0] = &fd_stdin;
    111112        else
    112113                files[0] = NULL;
    113114       
    114         if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK))
    115                 files[1] = &stdout_node;
     115        if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
     116                files[1] = &fd_stdout;
    116117        else
    117118                files[1] = NULL;
    118119       
    119         if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK))
    120                 files[2] = &stderr_node;
     120        if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
     121                files[2] = &fd_stderr;
    121122        else
    122123                files[2] = NULL;
     
    142143 */
    143144int task_spawnvf(task_id_t *id, const char *path, const char *const args[],
    144     fdi_node_t *const files[])
     145    int *const files[])
    145146{
    146147        /* Connect to a program loader. */
  • uspace/lib/c/generic/vfs/vfs.c

    r0cf27ee r07b39338  
    6969 *
    7070 */
    71 static async_exch_t *vfs_exchange_begin(void)
     71async_exch_t *vfs_exchange_begin(void)
    7272{
    7373        fibril_mutex_lock(&vfs_mutex);
     
    8787 *
    8888 */
    89 static void vfs_exchange_end(async_exch_t *exch)
     89void vfs_exchange_end(async_exch_t *exch)
    9090{
    9191        async_exchange_end(exch);
     
    329329}
    330330
    331 int open_node(fdi_node_t *node, int oflag)
    332 {
    333         async_exch_t *exch = vfs_exchange_begin();
    334        
    335         ipc_call_t answer;
    336         aid_t req = async_send_4(exch, VFS_IN_OPEN_NODE, node->fs_handle,
    337             node->service_id, node->index, oflag, &answer);
    338        
    339         vfs_exchange_end(exch);
    340 
    341         sysarg_t rc;
    342         async_wait_for(req, &rc);
    343        
    344         if (rc != EOK)
    345                 return (int) rc;
    346        
    347         return (int) IPC_GET_ARG1(answer);
    348 }
    349 
    350331int close(int fildes)
    351332{
     
    819800}
    820801
    821 int fd_node(int fildes, fdi_node_t *node)
    822 {
    823         struct stat stat;
    824         int rc = fstat(fildes, &stat);
    825        
    826         if (rc == EOK) {
    827                 node->fs_handle = stat.fs_handle;
    828                 node->service_id = stat.service_id;
    829                 node->index = stat.index;
    830         }
    831        
    832         return rc;
    833 }
    834 
    835802int dup2(int oldfd, int newfd)
    836803{
     
    848815}
    849816
     817int fd_wait(void)
     818{
     819        async_exch_t *exch = vfs_exchange_begin();
     820       
     821        sysarg_t ret;
     822        sysarg_t rc = async_req_0_1(exch, VFS_IN_WAIT_HANDLE, &ret);
     823       
     824        vfs_exchange_end(exch);
     825       
     826        if (rc == EOK)
     827                return (int) ret;
     828       
     829        return (int) rc;
     830}
     831
    850832/** @}
    851833 */
  • uspace/lib/c/include/async.h

    r0cf27ee r07b39338  
    176176extern int async_wait_timeout(aid_t, sysarg_t *, suseconds_t);
    177177
    178 extern fid_t async_new_connection(sysarg_t, sysarg_t, ipc_callid_t,
     178extern fid_t async_new_connection(task_id_t, sysarg_t, ipc_callid_t,
    179179    ipc_call_t *, async_client_conn_t, void *);
    180180
     
    186186extern void async_set_client_data_destructor(async_client_data_dtor_t);
    187187extern void *async_get_client_data(void);
     188extern void *async_get_client_data_by_id(task_id_t);
     189extern void async_put_client_data_by_id(task_id_t);
    188190
    189191extern void async_set_client_connection(async_client_conn_t);
     
    477479extern async_sess_t *async_callback_receive_start(exch_mgmt_t, ipc_call_t *);
    478480
     481extern int async_state_change_start(async_exch_t *, sysarg_t, sysarg_t,
     482    sysarg_t, async_exch_t *);
     483extern bool async_state_change_receive(ipc_callid_t *, sysarg_t *, sysarg_t *,
     484    sysarg_t *);
     485extern int async_state_change_finalize(ipc_callid_t, async_exch_t *);
     486
    479487#endif
    480488
  • uspace/lib/c/include/devman.h

    r0cf27ee r07b39338  
    3838
    3939#include <ipc/devman.h>
     40#include <ipc/loc.h>
    4041#include <async.h>
    4142#include <bool.h>
     
    4849extern int devman_add_function(const char *, fun_type_t, match_id_list_t *,
    4950    devman_handle_t, devman_handle_t *);
     51extern int devman_remove_function(devman_handle_t);
    5052
    5153extern async_sess_t *devman_device_connect(exch_mgmt_t, devman_handle_t,
     
    5456    unsigned int);
    5557
    56 extern int devman_device_get_handle(const char *, devman_handle_t *,
     58extern int devman_fun_get_handle(const char *, devman_handle_t *,
    5759    unsigned int);
    58 extern int devman_device_get_handle_by_class(const char *, const char *,
    59     devman_handle_t *, unsigned int);
    60 extern int devman_get_device_path(devman_handle_t, char *, size_t);
     60extern int devman_fun_get_child(devman_handle_t, devman_handle_t *);
     61extern int devman_dev_get_functions(devman_handle_t, devman_handle_t **,
     62    size_t *);
     63extern int devman_fun_get_name(devman_handle_t, char *, size_t);
     64extern int devman_fun_get_path(devman_handle_t, char *, size_t);
    6165
    62 extern int devman_add_device_to_class(devman_handle_t, const char *);
     66extern int devman_add_device_to_category(devman_handle_t, const char *);
     67extern int devman_fun_sid_to_handle(service_id_t, devman_handle_t *);
    6368
    6469#endif
  • uspace/lib/c/include/event.h

    r0cf27ee r07b39338  
    3737
    3838#include <abi/ipc/event.h>
     39#include <libarch/types.h>
    3940
    4041extern int event_subscribe(event_type_t, sysarg_t);
     42extern int event_task_subscribe(event_task_type_t, sysarg_t);
    4143extern int event_unmask(event_type_t);
     44extern int event_task_unmask(event_task_type_t);
    4245
    4346#endif
  • uspace/lib/c/include/ipc/common.h

    r0cf27ee r07b39338  
    3939#include <abi/ipc/ipc.h>
    4040#include <atomic.h>
     41#include <task.h>
    4142
    4243#define IPC_FLAG_BLOCKING  0x01
     
    4445typedef struct {
    4546        sysarg_t args[IPC_CALL_LEN];
    46         sysarg_t in_task_hash;
     47        task_id_t in_task_id;
    4748        sysarg_t in_phone_hash;
    4849} ipc_call_t;
  • uspace/lib/c/include/ipc/devman.h

    r0cf27ee r07b39338  
    138138        DEVMAN_ADD_FUNCTION,
    139139        DEVMAN_ADD_MATCH_ID,
    140         DEVMAN_ADD_DEVICE_TO_CLASS
    141 
     140        DEVMAN_ADD_DEVICE_TO_CATEGORY,
     141        DEVMAN_REMOVE_FUNCTION
    142142} driver_to_devman_t;
    143143
     
    149149typedef enum {
    150150        DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
    151         DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
    152         DEVMAN_DEVICE_GET_DEVICE_PATH
     151        DEVMAN_DEV_GET_FUNCTIONS,
     152        DEVMAN_FUN_GET_CHILD,
     153        DEVMAN_FUN_GET_NAME,
     154        DEVMAN_FUN_GET_PATH,
     155        DEVMAN_FUN_SID_TO_HANDLE
    153156} client_to_devman_t;
    154157
  • uspace/lib/c/include/ipc/loc.h

    r0cf27ee r07b39338  
    5757        LOC_SERVICE_GET_NAME,
    5858        LOC_NAMESPACE_GET_ID,
     59        LOC_CALLBACK_CREATE,
    5960        LOC_CATEGORY_GET_ID,
     61        LOC_CATEGORY_GET_NAME,
    6062        LOC_CATEGORY_GET_SVCS,
    6163        LOC_ID_PROBE,
     
    6870        LOC_GET_SERVICES
    6971} loc_request_t;
     72
     73typedef enum {
     74        LOC_EVENT_CAT_CHANGE = IPC_FIRST_USER_METHOD
     75} loc_event_t;
    7076
    7177/** Ports provided by location service.
  • uspace/lib/c/include/ipc/vfs.h

    r0cf27ee r07b39338  
    6262typedef enum {
    6363        VFS_IN_OPEN = IPC_FIRST_USER_METHOD,
    64         VFS_IN_OPEN_NODE,
    6564        VFS_IN_READ,
    6665        VFS_IN_WRITE,
     
    7877        VFS_IN_RENAME,
    7978        VFS_IN_STAT,
    80         VFS_IN_DUP
     79        VFS_IN_DUP,
     80        VFS_IN_WAIT_HANDLE,
    8181} vfs_in_request_t;
    8282
  • uspace/lib/c/include/loader/loader.h

    r0cf27ee r07b39338  
    3838
    3939#include <task.h>
    40 #include <vfs/vfs.h>
    4140
    4241/** Forward declararion */
     
    5049extern int loader_set_pathname(loader_t *, const char *);
    5150extern int loader_set_args(loader_t *, const char *const[]);
    52 extern int loader_set_files(loader_t *, fdi_node_t *const[]);
     51extern int loader_set_files(loader_t *, int *const[]);
    5352extern int loader_load_program(loader_t *);
    5453extern int loader_run(loader_t *);
  • uspace/lib/c/include/loader/pcb.h

    r0cf27ee r07b39338  
    3838
    3939#include <sys/types.h>
    40 #include <vfs/vfs.h>
    4140
    4241typedef void (*entry_point_t)(void);
     
    6261       
    6362        /** Number of preset files. */
    64         int filc;
    65         /** Preset files. */
    66         fdi_node_t **filv;
     63        unsigned int filc;
    6764       
    6865        /*
  • uspace/lib/c/include/loc.h

    r0cf27ee r07b39338  
    4040#include <bool.h>
    4141
     42typedef void (*loc_cat_change_cb_t)(void);
     43
    4244extern async_exch_t *loc_exchange_begin_blocking(loc_interface_t);
    4345extern async_exch_t *loc_exchange_begin(loc_interface_t);
     
    4850extern int loc_service_register_with_iface(const char *, service_id_t *,
    4951    sysarg_t);
     52extern int loc_service_unregister(service_id_t);
    5053extern int loc_service_add_to_cat(service_id_t, category_id_t);
    5154
     
    7376extern size_t loc_get_services(service_id_t, loc_sdesc_t **);
    7477extern int loc_get_categories(category_id_t **, size_t *);
     78extern int loc_register_cat_change_cb(loc_cat_change_cb_t);
    7579
    7680
  • uspace/lib/c/include/task.h

    r0cf27ee r07b39338  
    3737
    3838#include <sys/types.h>
    39 #include <vfs/vfs.h>
    4039
    4140typedef uint64_t task_id_t;
     
    5352extern int task_spawnv(task_id_t *, const char *path, const char *const []);
    5453extern int task_spawnvf(task_id_t *, const char *path, const char *const [],
    55     fdi_node_t *const []);
     54    int *const []);
    5655extern int task_spawnl(task_id_t *, const char *path, ...);
    5756
  • uspace/lib/c/include/vfs/vfs.h

    r0cf27ee r07b39338  
    4040#include <ipc/loc.h>
    4141#include <stdio.h>
     42#include <async.h>
    4243
    43 /** Libc version of the VFS triplet.
    44  *
    45  * Unique identification of a file system node
    46  * within a file system instance.
    47  *
    48  */
    49 typedef struct {
    50         fs_handle_t fs_handle;
    51         service_id_t service_id;
    52         fs_index_t index;
    53 } fdi_node_t;
     44enum vfs_change_state_type {
     45        VFS_PASS_HANDLE
     46};
    5447
    5548extern char *absolutize(const char *, size_t *);
     
    5952extern int unmount(const char *);
    6053
    61 extern int open_node(fdi_node_t *, int);
    62 extern int fd_node(int, fdi_node_t *);
     54extern int fhandle(FILE *, int *);
    6355
    64 extern FILE *fopen_node(fdi_node_t *, const char *);
    65 extern int fnode(FILE *, fdi_node_t *);
     56extern int fd_wait(void);
     57
     58extern async_exch_t *vfs_exchange_begin(void);
     59extern void vfs_exchange_end(async_exch_t *);
    6660
    6761#endif
  • uspace/lib/drv/generic/driver.c

    r0cf27ee r07b39338  
    428428static void driver_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    429429{
     430        sysarg_t conn_type;
     431
     432        if (iid == 0) {
     433                /* Callback connection from devman */
     434                /* XXX Use separate handler for this type of connection */
     435                conn_type = DRIVER_DEVMAN;
     436        } else {
     437                conn_type = IPC_GET_ARG1(*icall);
     438        }
     439
    430440        /* Select interface */
    431         switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {
     441        switch (conn_type) {
    432442        case DRIVER_DEVMAN:
    433443                /* Handle request from device manager */
     
    582592int ddf_fun_bind(ddf_fun_t *fun)
    583593{
     594        assert(fun->bound == false);
    584595        assert(fun->name != NULL);
    585596       
     
    598609}
    599610
     611/** Unbind a function node.
     612 *
     613 * Unbind the specified function from the system. This effectively makes
     614 * the function invisible to the system.
     615 *
     616 * @param fun           Function to bind
     617 * @return              EOK on success or negative error code
     618 */
     619int ddf_fun_unbind(ddf_fun_t *fun)
     620{
     621        int res;
     622       
     623        assert(fun->bound == true);
     624       
     625        add_to_functions_list(fun);
     626        res = devman_remove_function(fun->handle);
     627        if (res != EOK)
     628                return res;
     629
     630        remove_from_functions_list(fun);
     631       
     632        fun->bound = false;
     633        return EOK;
     634}
     635
    600636/** Add single match ID to inner function.
    601637 *
     
    635671}
    636672
    637 /** Add exposed function to class.
     673/** Add exposed function to category.
    638674 *
    639675 * Must only be called when the function is bound.
    640676 */
    641 int ddf_fun_add_to_class(ddf_fun_t *fun, const char *class_name)
     677int ddf_fun_add_to_category(ddf_fun_t *fun, const char *cat_name)
    642678{
    643679        assert(fun->bound == true);
    644680        assert(fun->ftype == fun_exposed);
    645681       
    646         return devman_add_device_to_class(fun->handle, class_name);
     682        return devman_add_device_to_category(fun->handle, cat_name);
    647683}
    648684
  • uspace/lib/drv/include/ddf/driver.h

    r0cf27ee r07b39338  
    149149extern void ddf_fun_destroy(ddf_fun_t *);
    150150extern int ddf_fun_bind(ddf_fun_t *);
     151extern int ddf_fun_unbind(ddf_fun_t *);
    151152extern int ddf_fun_add_match_id(ddf_fun_t *, const char *, int);
    152153
    153 extern int ddf_fun_add_to_class(ddf_fun_t *, const char *);
     154extern int ddf_fun_add_to_category(ddf_fun_t *, const char *);
    154155
    155156#endif
  • uspace/lib/posix/ctype.c

    r0cf27ee r07b39338  
    3737
    3838#include "ctype.h"
    39 
    40 // TODO: propose for inclusion in libc
    4139
    4240/**
  • uspace/lib/posix/errno.h

    r0cf27ee r07b39338  
    5757 * redefinition for such error codes.
    5858 *
    59  * FIXME: maybe all HOS error codes should be redefined
     59 * XXX: maybe all HOS error codes should be redefined
    6060 *
    6161 * NOTE: This redefinition is slightly POSIX incompatible, since the
  • uspace/lib/posix/fcntl.c

    r0cf27ee r07b39338  
    5252int posix_fcntl(int fd, int cmd, ...)
    5353{
    54         int rc;
    5554        int flags;
    5655
    5756        switch (cmd) {
    5857        case F_DUPFD:
    59         case F_DUPFD_CLOEXEC: /* FD_CLOEXEC is not supported. */
    60                 /* VFS does not provide means to express constraints on the new
    61                  * file descriptor so the third argument is ignored. */
    62 
    63                 /* Retrieve node triplet corresponding to the file descriptor. */
    64                 /* Empty statement after label. */;
    65                 fdi_node_t node;
    66                 rc = fd_node(fd, &node);
    67                 if (rc != EOK) {
    68                         errno = -rc;
    69                         return -1;
    70                 }
    71 
    72                 /* Reopen the node so the fresh file descriptor is generated. */
    73                 int newfd = open_node(&node, 0);
    74                 if (newfd < 0) {
    75                         errno = -newfd;
    76                         return -1;
    77                 }
    78 
    79                 /* Associate the newly generated descriptor to the file description
    80                  * of the old file descriptor. Just reopened node will be automatically
    81                  * closed. */
    82                 rc = dup2(fd, newfd);
    83                 if (rc != EOK) {
    84                         errno = -rc;
    85                         return -1;
    86                 }
    87 
    88                 return newfd;
     58        case F_DUPFD_CLOEXEC:
     59                /* VFS currently does not provide the functionality to duplicate
     60                 * opened file descriptor. */
     61                // FIXME: implement this once dup() is available
     62                errno = ENOTSUP;
     63                return -1;
    8964        case F_GETFD:
    9065                /* FD_CLOEXEC is not supported. There are no other flags. */
  • uspace/lib/posix/fnmatch.c

    r0cf27ee r07b39338  
    6666#define COLL_ELM_INVALID -1
    6767
    68 /** Get collating element matching a string.
    69  *
    70  * @param str
     68/**
     69 * Get collating element matching a string.
     70 *
     71 * @param str String representation of the element.
    7172 * @return Matching collating element or COLL_ELM_INVALID.
    7273 */
     
    7980}
    8081
    81 /** Get collating element matching a single character.
    82  *
    83  * @param c
    84  * @return
     82/**
     83 * Get collating element matching a single character.
     84 *
     85 * @param c Character representation of the element.
     86 * @return Matching collating element.
    8587 */
    8688static coll_elm_t _coll_elm_char(int c)
     
    8991}
    9092
    91 /** Match collating element with a beginning of a string.
    92  *
    93  * @param elm
    94  * @param str
     93/**
     94 * Match collating element with a beginning of a string.
     95 *
     96 * @param elm Collating element to match.
     97 * @param str String which beginning should match the element.
    9598 * @return 0 if the element doesn't match, or the number of characters matched.
    9699 */
     
    100103}
    101104
    102 /** Checks whether a string begins with a collating element in the given range.
    103  *  Ordering depends on the locale (if locales are supported).
     105/**
     106 * Checks whether a string begins with a collating element in the given range.
     107 * Ordering depends on the locale (if locales are supported).
    104108 *
    105109 * @param first First element of the range.
     
    114118}
    115119
    116 /** Read a string delimited by [? and ?].
     120/**
     121 * Read a string delimited by [? and ?].
    117122 *
    118123 * @param pattern Pointer to the string to read from. Its position is moved
     
    189194};
    190195
    191 /** Compare function for binary search in the _char_classes array.
     196/**
     197 * Compare function for binary search in the _char_classes array.
    192198 *
    193  * @param key
    194  * @param elem
    195  * @return
     199 * @param key Key of the searched element.
     200 * @param elem Element of _char_classes array.
     201 * @return Ordering indicator (-1 less than, 0 equal, 1 greater than).
    196202 */
    197203static int _class_compare(const void *key, const void *elem)
     
    201207}
    202208
    203 /** Returns whether the given character belongs to the specified character class.
     209/**
     210 * Returns whether the given character belongs to the specified character class.
    204211 *
    205212 * @param cname Name of the character class.
     
    223230}
    224231
    225 /** Tries to parse an initial part of the pattern as a character class pattern,
    226  *  and if successful, matches the beginning of the given string against the class.
     232/**
     233 * Tries to parse an initial part of the pattern as a character class pattern,
     234 * and if successful, matches the beginning of the given string against the class.
    227235 *
    228236 * @param pattern Pointer to the pattern to match. Must begin with a class
     
    248256/************** END CHARACTER CLASSES ****************/
    249257
    250 /** Reads the next collating element in the pattern, taking into account
    251  *  locale (if supported) and flags (see fnmatch()).
     258/**
     259 * Reads the next collating element in the pattern, taking into account
     260 * locale (if supported) and flags (see fnmatch()).
    252261 *
    253262 * @param pattern Pattern.
     
    299308}
    300309
    301 /** Matches the beginning of the given string against a bracket expression
    302  *  the pattern begins with.
     310/**
     311 * Matches the beginning of the given string against a bracket expression
     312 * the pattern begins with.
    303313 *
    304314 * @param pattern Pointer to the beginning of a bracket expression in a pattern.
     
    394404}
    395405
    396 /** Matches a portion of the pattern containing no asterisks (*) against
    397  *  the given string.
     406/**
     407 * Matches a portion of the pattern containing no asterisks (*) against
     408 * the given string.
    398409 *
    399410 * @param pattern Pointer to the unmatched portion of the pattern.
     
    497508}
    498509
    499 /** Match string against a pattern.
     510/**
     511 * Match string against a pattern.
    500512 *
    501513 * @param pattern Pattern.
     
    559571}
    560572
    561 /** Transform the entire string to lowercase.
     573/**
     574 * Transform the entire string to lowercase.
    562575 *
    563576 * @param s Input string.
     
    578591 * Filename pattern matching.
    579592 *
    580  * @param pattern
    581  * @param string
    582  * @param flags
    583  * @return
     593 * @param pattern Pattern to match the string against.
     594 * @param string Matched string.
     595 * @param flags Flags altering the matching of special characters
     596 *     (mainly for dot and slash).
     597 * @return Zero if the string matches the pattern, FNM_NOMATCH otherwise.
    584598 */
    585599int posix_fnmatch(const char *pattern, const char *string, int flags)
     
    610624}
    611625
    612 // FIXME: put the testcases somewhere else
     626// FIXME: put the testcases to the app/tester after fnmatch is included into libc
    613627
    614628#if 0
  • uspace/lib/posix/locale.c

    r0cf27ee r07b39338  
    7979};
    8080
    81 /** Set program locale.
     81/**
     82 * Set program locale.
    8283 *
    8384 * @param category What category to set.
     
    9596}
    9697
    97 /** Return locale-specific information.
     98/**
     99 * Return locale-specific information.
    98100 *
    99101 * @return Information about the current locale.
     
    105107}
    106108
    107 /** Duplicate locale object.
     109/**
     110 * Duplicate locale object.
    108111 *
    109112 * @param locobj Object to duplicate.
     
    125128}
    126129
    127 /** Free locale object.
     130/**
     131 * Free locale object.
    128132 *
    129133 * @param locobj Object to free.
     
    136140}
    137141
    138 /** Create or modify a locale object.
     142/**
     143 * Create or modify a locale object.
    139144 *
    140145 * @param category_mask Mask of categories to be set or modified.
     
    163168}
    164169
    165 /** Set locale for the current thread.
     170/**
     171 * Set locale for the current thread.
    166172 *
    167173 * @param newloc Locale to use.
  • uspace/lib/posix/pwd.c

    r0cf27ee r07b39338  
    5151
    5252/**
     53 * Retrieve next broken-down entry from the user database.
     54 *
    5355 * Since HelenOS doesn't have user accounts, this always returns
    5456 * the same made-up entry.
    5557 *
    56  * @return
     58 * @return Next user database entry or NULL if not possible. Since HelenOS
     59 *     doesn't have user accounts, this always returns the same made-up entry.
    5760 */
    5861struct posix_passwd *posix_getpwent(void)
     
    6770
    6871/**
    69  * "Rewind the user list".
     72 * Rewind the user list.
    7073 */
    7174void posix_setpwent(void)
     
    8689 *
    8790 * @param name Name of the entry.
    88  * @return
     91 * @return Either found entry or NULL if no such entry exists.
    8992 */
    9093struct posix_passwd *posix_getpwnam(const char *name)
     
    103106 *
    104107 * @param name Name of the entry.
    105  * @param pwd
    106  * @param buffer
    107  * @param bufsize
    108  * @param result
    109  * @return
     108 * @param pwd Original structure.
     109 * @param buffer Buffer for the strings referenced from the result structure.
     110 * @param bufsize Length of the buffer.
     111 * @param result Where to store updated structure.
     112 * @return Zero on success (either found or not found, but without an error),
     113 *     non-zero error number if error occured.
    110114 */
    111115int posix_getpwnam_r(const char *name, struct posix_passwd *pwd,
     
    129133 *
    130134 * @param uid UID of the entry.
    131  * @return
     135 * @return Either found entry or NULL if no such entry exists.
    132136 */
    133137struct posix_passwd *posix_getpwuid(posix_uid_t uid)
     
    144148 *
    145149 * @param uid UID of the entry.
    146  * @param pwd
    147  * @param buffer
    148  * @param bufsize
    149  * @param result
    150  * @return
     150 * @param pwd Original structure.
     151 * @param buffer Buffer for the strings referenced from the result structure.
     152 * @param bufsize Length of the buffer.
     153 * @param result Where to store updated structure.
     154 * @return Zero on success (either found or not found, but without an error),
     155 *     non-zero error number if error occured.
    151156 */
    152157int posix_getpwuid_r(posix_uid_t uid, struct posix_passwd *pwd,
  • uspace/lib/posix/signal.c

    r0cf27ee r07b39338  
    136136}
    137137
    138 /** Just an empty function to get an unique pointer value for comparison.
    139  *
    140  * @param signo
     138/**
     139 * Just an empty function to get an unique pointer value for comparison.
     140 *
     141 * @param signo Signal number.
    141142 */
    142143void __posix_hold_signal_handler(int signo)
     
    145146}
    146147
    147 /** Empty function to be used as ignoring handler.
    148  *
    149  * @param signo
     148/**
     149 * Empty function to be used as ignoring handler.
     150 *
     151 * @param signo Signal number.
    150152 */
    151153void __posix_ignore_signal_handler(int signo)
     
    154156}
    155157
    156 /** Clear the signal set.
     158/**
     159 * Clear the signal set.
    157160 *
    158161 * @param set Pointer to the signal set.
     
    167170}
    168171
    169 /** Fill the signal set (i.e. add all signals).
     172/**
     173 * Fill the signal set (i.e. add all signals).
    170174 *
    171175 * @param set Pointer to the signal set.
     
    180184}
    181185
    182 /** Add a signal to the set.
     186/**
     187 * Add a signal to the set.
    183188 *
    184189 * @param set Pointer to the signal set.
     
    194199}
    195200
    196 /** Delete a signal from the set.
     201/**
     202 * Delete a signal from the set.
    197203 *
    198204 * @param set Pointer to the signal set.
     
    208214}
    209215
    210 /** Inclusion test for a signal set.
     216/**
     217 * Inclusion test for a signal set.
    211218 *
    212219 * @param set Pointer to the signal set.
     
    221228}
    222229
    223 /** Unsafe variant of the sigaction() function.
    224  *  Doesn't do any checking of its arguments and
    225  *  does not deal with thread-safety.
     230/**
     231 * Unsafe variant of the sigaction() function.
     232 * Doesn't do any checking of its arguments and
     233 * does not deal with thread-safety.
    226234 *
    227235 * @param sig
     
    243251}
    244252
    245 /** Sets a new action for the given signal number.
     253/**
     254 * Sets a new action for the given signal number.
    246255 *
    247256 * @param sig Signal number to set action for.
     
    276285}
    277286
    278 /** Sets a new handler for the given signal number.
     287/**
     288 * Sets a new handler for the given signal number.
    279289 *
    280290 * @param sig Signal number to set handler for.
     
    304314} signal_queue_item;
    305315
    306 /** Queue blocked signal.
     316/**
     317 * Queue blocked signal.
    307318 *
    308319 * @param signo Signal number.
     
    322333
    323334
    324 /** Executes an action associated with the given signal.
     335/**
     336 * Executes an action associated with the given signal.
    325337 *
    326338 * @param signo Signal number.
     
    366378}
    367379
    368 /** Raise all unblocked previously queued signals.
     380/**
     381 * Raise all unblocked previously queued signals.
    369382 */
    370383static void _dequeue_unblocked_signals()
     
    390403}
    391404
    392 /** Raise a signal for the calling process.
     405/**
     406 * Raise a signal for the calling process.
    393407 *
    394408 * @param sig Signal number.
     
    409423}
    410424
    411 /** Raises a signal for a selected process.
     425/**
     426 * Raises a signal for a selected process.
    412427 *
    413428 * @param pid PID of the process for which the signal shall be raised.
     
    446461}
    447462
    448 /** Send a signal to a process group. Always fails at the moment because of
    449  *  lack of this functionality in HelenOS.
     463/**
     464 * Send a signal to a process group. Always fails at the moment because of
     465 * lack of this functionality in HelenOS.
    450466 *
    451467 * @param pid PID of the process group.
     
    459475}
    460476
    461 /** Outputs information about the signal to the standard error stream.
     477/**
     478 * Outputs information about the signal to the standard error stream.
    462479 *
    463480 * @param pinfo SigInfo struct to write.
     
    471488}
    472489
    473 /** Outputs information about the signal to the standard error stream.
     490/**
     491 * Outputs information about the signal to the standard error stream.
    474492 *
    475493 * @param signum Signal number.
     
    486504}
    487505
    488 /** Manipulate the signal mask of the calling thread.
     506/**
     507 * Manipulate the signal mask of the calling thread.
    489508 *
    490509 * @param how What to do with the mask.
     
    525544}
    526545
    527 /** Manipulate the signal mask of the process.
     546/**
     547 * Manipulate the signal mask of the process.
    528548 *
    529549 * @param how What to do with the mask.
  • uspace/lib/posix/stdbool.h

    r0cf27ee r07b39338  
    3636#define POSIX_STDBOOL_H_
    3737
    38 // TODO: propose for inclusion in libc and drop bool.h,
    39 //       it's a very silly incompatibility with standard C
    40 
    4138#ifdef LIBC_BOOL_H_
    4239        #error "You can't include bool.h and stdbool.h at the same time."
  • uspace/lib/posix/stdint.h

    r0cf27ee r07b39338  
    103103typedef uint64_t posix_uintmax_t;
    104104
    105 // FIXME: should be integrated into build process similarly to uintptr_t
    106 typedef ssize_t posix_intptr_t;
    107 
    108105#ifndef LIBPOSIX_INTERNAL
    109106        #define intmax_t posix_intmax_t
    110107        #define uintmax_t posix_uintmax_t
    111 
    112         #define intptr_t posix_intptr_t
    113108#endif
    114109
  • uspace/lib/posix/stdio.c

    r0cf27ee r07b39338  
    257257        assert(stream != NULL);
    258258       
    259         /* Retrieve the node. */
    260         struct stat st;
    261         int rc;
    262        
    263259        if (filename == NULL) {
    264                 rc = fstat(stream->fd, &st);
    265         } else {
    266                 rc = stat(filename, &st);
    267                 if (-rc == ENOENT) {
    268                         /* file does not exist, create new file */
    269                         FILE* tmp = fopen(filename, mode);
    270                         if (tmp != NULL) {
    271                                 fclose(tmp);
    272                                 /* try again */
    273                                 rc = stat(filename, &st);
    274                         }
    275                 }
    276         }
    277        
    278         if (rc != EOK) {
    279                 fclose(stream);
    280                 errno = -rc;
    281                 return NULL;
    282         }
    283        
    284         fdi_node_t node = {
    285                 .fs_handle = st.fs_handle,
    286                 .service_id = st.service_id,
    287                 .index = st.index
    288         };
     260                /* POSIX allows this to be imlementation-defined. HelenOS currently
     261                 * does not support changing the mode. */
     262                // FIXME: handle mode change once it is supported
     263                return stream;
     264        }
    289265       
    290266        /* Open a new stream. */
    291         FILE* new = fopen_node(&node, mode);
     267        FILE* new = fopen(filename, mode);
    292268        if (new == NULL) {
    293269                fclose(stream);
    294                 /* fopen_node() sets errno. */
     270                /* errno was set by fopen() */
    295271                return NULL;
    296272        }
  • uspace/lib/posix/stdio.h

    r0cf27ee r07b39338  
    140140
    141141        #define freopen posix_freopen
    142         #define fmemopen posix_fmemopen
    143         #define open_memstream posix_open_memstream
    144142
    145143        #define perror posix_perror
  • uspace/lib/posix/stdio/scanf.c

    r0cf27ee r07b39338  
    707707                                                        break;
    708708                                                case LMOD_t: ;
    709                                                         // FIXME: What is unsigned counterpart of the ptrdiff_t?
     709                                                        // XXX: What is unsigned counterpart of the ptrdiff_t?
    710710                                                        size_t *pt = va_arg(arg, size_t *);
    711711                                                        *pt = (size_t) ures;
     
    12211221}
    12221222
    1223 // FIXME: put the testcases somewhere else
     1223// FIXME: put the testcases to the app/tester after scanf is included into libc
    12241224
    12251225#if 0
  • uspace/lib/posix/string.c

    r0cf27ee r07b39338  
    4848
    4949/**
    50  * Decides whether s2 is a prefix of s1.
    51  *
    52  * @param s1 String in which to look for a prefix.
    53  * @param s2 Prefix string to look for.
    54  * @return True if s2 is a prefix of s1, false otherwise.
    55  */
    56 static bool begins_with(const char *s1, const char *s2)
    57 {
    58         while (*s1 == *s2 && *s2 != '\0') {
    59                 s1++;
    60                 s2++;
    61         }
    62        
    63         /* true if the end was reached */
    64         return *s2 == '\0';
    65 }
    66 
    67 /**
    6850 * The same as strpbrk, except it returns pointer to the nul terminator
    6951 * if no occurence is found.
     
    471453
    472454/**
    473  * Find a substring.
     455 * Find a substring. Uses Knuth-Morris-Pratt algorithm.
    474456 *
    475457 * @param s1 String in which to look for a substring.
     
    478460 *     not found.
    479461 */
    480 char *posix_strstr(const char *s1, const char *s2)
    481 {
    482         assert(s1 != NULL);
    483         assert(s2 != NULL);
    484 
    485         /* special case - needle is an empty string */
    486         if (*s2 == '\0') {
    487                 return (char *) s1;
    488         }
    489 
    490         // TODO: use faster algorithm
    491         /* check for prefix from every position - quadratic complexity */
    492         while (*s1 != '\0') {
    493                 if (begins_with(s1, s2)) {
    494                         return (char *) s1;
    495                 }
     462char *posix_strstr(const char *haystack, const char *needle)
     463{
     464        assert(haystack != NULL);
     465        assert(needle != NULL);
     466       
     467        /* Special case - needle is an empty string. */
     468        if (needle[0] == '\0') {
     469                return (char *) haystack;
     470        }
     471       
     472        /* Preprocess needle. */
     473        size_t nlen = posix_strlen(needle);
     474        size_t prefix_table[nlen + 1];
     475       
     476        {
     477                size_t i = 0;
     478                ssize_t j = -1;
    496479               
    497                 s1++;
     480                prefix_table[i] = j;
     481               
     482                while (i < nlen) {
     483                        while (j >= 0 && needle[i] != needle[j]) {
     484                                j = prefix_table[j];
     485                        }
     486                        i++; j++;
     487                        prefix_table[i] = j;
     488                }
     489        }
     490       
     491        /* Search needle using the precomputed table. */
     492        size_t npos = 0;
     493       
     494        for (size_t hpos = 0; haystack[hpos] != '\0'; ++hpos) {
     495                while (npos != 0 && haystack[hpos] != needle[npos]) {
     496                        npos = prefix_table[npos];
     497                }
     498               
     499                if (haystack[hpos] == needle[npos]) {
     500                        npos++;
     501                       
     502                        if (npos == nlen) {
     503                                return (char *) (haystack + hpos - nlen + 1);
     504                        }
     505                }
    498506        }
    499507       
  • uspace/lib/posix/string.h

    r0cf27ee r07b39338  
    5151 * void *memmove(void *, const void *, size_t);
    5252 *
    53  * unimplemented due to missing locales
     53 * TODO: not implemented due to missing locale support
    5454 *
    5555 * int      strcoll_l(const char *, const char *, locale_t);
    5656 * char    *strerror_l(int, locale_t);
    5757 * size_t   strxfrm_l(char *restrict, const char *restrict, size_t, locale_t);
    58  *
    5958 */
    60 
    61 // TODO: provide *_l once there is locale.h
    6259
    6360#ifndef NULL
     
    8986extern size_t posix_strcspn(const char *s1, const char *s2);
    9087extern size_t posix_strspn(const char *s1, const char *s2);
    91 extern char *posix_strstr(const char *s1, const char *s2);
     88extern char *posix_strstr(const char *haystack, const char *needle);
    9289
    9390/* Collation Functions */
  • uspace/lib/posix/strings.h

    r0cf27ee r07b39338  
    4848#endif
    4949
    50 /* TODO: not implemented due to missing locale.h
     50/* TODO: not implemented due to missing locale support
    5151 *
    5252 * int strcasecmp_l(const char *, const char *, locale_t);
  • uspace/lib/posix/time.c

    r0cf27ee r07b39338  
    5151#include "libc/sys/time.h"
    5252
    53 // TODO: documentation
    5453// TODO: test everything in this file
    5554
     
    7271#define SECS_PER_DAY (SECS_PER_HOUR * HOURS_PER_DAY)
    7372
    74 /** Checks whether the year is a leap year.
     73/**
     74 * Checks whether the year is a leap year.
    7575 *
    7676 * @param year Year since 1900 (e.g. for 1970, the value is 70).
     
    9090}
    9191
    92 /** Returns how many days there are in the given month of the given year.
    93  *  Note that year is only taken into account if month is February.
     92/**
     93 * Returns how many days there are in the given month of the given year.
     94 * Note that year is only taken into account if month is February.
    9495 *
    9596 * @param year Year since 1900 (can be negative).
     
    113114}
    114115
    115 /** For specified year, month and day of month, returns which day of that year
    116  *  it is.
     116/**
     117 * For specified year, month and day of month, returns which day of that year
     118 * it is.
    117119 *
    118120 * For example, given date 2011-01-03, the corresponding expression is:
     
    134136}
    135137
    136 /** Integer division that rounds to negative infinity.
    137  *  Used by some functions in this file.
    138  *
    139  * @param op1
    140  * @param op2
    141  * @return
     138/**
     139 * Integer division that rounds to negative infinity.
     140 * Used by some functions in this file.
     141 *
     142 * @param op1 Divident.
     143 * @param op2 Divisor.
     144 * @return Rounded quotient.
    142145 */
    143146static time_t _floor_div(time_t op1, time_t op2)
     
    150153}
    151154
    152 /** Modulo that rounds to negative infinity.
    153  *  Used by some functions in this file.
    154  *
    155  * @param op1
    156  * @param op2
    157  * @return
     155/**
     156 * Modulo that rounds to negative infinity.
     157 * Used by some functions in this file.
     158 *
     159 * @param op1 Divident.
     160 * @param op2 Divisor.
     161 * @return Remainder.
    158162 */
    159163static time_t _floor_mod(time_t op1, time_t op2)
     
    174178}
    175179
    176 /** Number of days since the Epoch.
    177  *  Epoch is 1970-01-01, which is also equal to day 0.
     180/**
     181 * Number of days since the Epoch.
     182 * Epoch is 1970-01-01, which is also equal to day 0.
    178183 *
    179184 * @param year Year (year 1900 = 0, may be negative).
     
    189194}
    190195
    191 /** Seconds since the Epoch. see also _days_since_epoch().
     196/**
     197 * Seconds since the Epoch. see also _days_since_epoch().
    192198 *
    193199 * @param tm Normalized broken-down time.
     
    201207}
    202208
    203 /** Which day of week the specified date is.
     209/**
     210 * Which day of week the specified date is.
    204211 *
    205212 * @param year Year (year 1900 = 0).
     
    214221}
    215222
    216 /** Normalizes the broken-down time and optionally adds specified amount of
    217  *  seconds.
     223/**
     224 * Normalizes the broken-down time and optionally adds specified amount of
     225 * seconds.
    218226 *
    219227 * @param tm Broken-down time to normalize.
     
    297305}
    298306
    299 /** Which day the week-based year starts on, relative to the first calendar day.
    300  *  E.g. if the year starts on December 31st, the return value is -1.
     307/**
     308 * Which day the week-based year starts on, relative to the first calendar day.
     309 * E.g. if the year starts on December 31st, the return value is -1.
    301310 *
    302311 * @param Year since 1900.
     
    309318}
    310319
    311 /** Returns week-based year of the specified time.
     320/**
     321 * Returns week-based year of the specified time.
    312322 *
    313323 * @param tm Normalized broken-down time.
     
    329339}
    330340
    331 /** Week number of the year, assuming weeks start on sunday.
    332  *  The first Sunday of January is the first day of week 1;
    333  *  days in the new year before this are in week 0.
     341/**
     342 * Week number of the year, assuming weeks start on sunday.
     343 * The first Sunday of January is the first day of week 1;
     344 * days in the new year before this are in week 0.
    334345 *
    335346 * @param tm Normalized broken-down time.
     
    342353}
    343354
    344 /** Week number of the year, assuming weeks start on monday.
    345  *  If the week containing January 1st has four or more days in the new year,
    346  *  then it is considered week 1. Otherwise, it is the last week of the previous
    347  *  year, and the next week is week 1. Both January 4th and the first Thursday
    348  *  of January are always in week 1.
     355/**
     356 * Week number of the year, assuming weeks start on monday.
     357 * If the week containing January 1st has four or more days in the new year,
     358 * then it is considered week 1. Otherwise, it is the last week of the previous
     359 * year, and the next week is week 1. Both January 4th and the first Thursday
     360 * of January are always in week 1.
    349361 *
    350362 * @param tm Normalized broken-down time.
     
    366378}
    367379
    368 /** Week number of the year, assuming weeks start on monday.
    369  *  The first Monday of January is the first day of week 1;
    370  *  days in the new year before this are in week 0.
     380/**
     381 * Week number of the year, assuming weeks start on monday.
     382 * The first Monday of January is the first day of week 1;
     383 * days in the new year before this are in week 0.
    371384 *
    372385 * @param tm Normalized broken-down time.
     
    385398char *posix_tzname[2];
    386399
    387 /** Set timezone conversion information.
    388  *
     400/**
     401 * Set timezone conversion information.
    389402 */
    390403void posix_tzset(void)
     
    397410}
    398411
    399 /** Calculate the difference between two times, in seconds.
    400  *
    401  * @param time1
    402  * @param time0
     412/**
     413 * Calculate the difference between two times, in seconds.
     414 *
     415 * @param time1 First time.
     416 * @param time0 Second time.
    403417 * @return Time in seconds.
    404418 */
     
    408422}
    409423
    410 /** This function first normalizes the provided broken-down time
    411  *  (moves all values to their proper bounds) and then tries to
    412  *  calculate the appropriate time_t representation.
     424/**
     425 * This function first normalizes the provided broken-down time
     426 * (moves all values to their proper bounds) and then tries to
     427 * calculate the appropriate time_t representation.
    413428 *
    414429 * @param tm Broken-down time.
    415  * @return time_t representation of the time, undefined value on overflow
     430 * @return time_t representation of the time, undefined value on overflow.
    416431 */
    417432time_t posix_mktime(struct posix_tm *tm)
     
    424439}
    425440
    426 /** Converts a time value to a broken-down UTC time.
     441/**
     442 * Converts a time value to a broken-down UTC time.
    427443 *
    428444 * @param timer Time to convert.
     
    437453}
    438454
    439 /** Converts a time value to a broken-down UTC time.
     455/**
     456 * Converts a time value to a broken-down UTC time.
    440457 *
    441458 * @param timer Time to convert.
     
    465482}
    466483
    467 /** Converts a time value to a broken-down local time.
     484/**
     485 * Converts a time value to a broken-down local time.
    468486 *
    469487 * @param timer Time to convert.
     
    476494}
    477495
    478 /** Converts a time value to a broken-down local time.
     496/**
     497 * Converts a time value to a broken-down local time.
    479498 *
    480499 * @param timer Time to convert.
     
    490509}
    491510
    492 /** Converts broken-down time to a string in format
    493  *  "Sun Jan 1 00:00:00 1970\n". (Obsolete)
     511/**
     512 * Converts broken-down time to a string in format
     513 * "Sun Jan 1 00:00:00 1970\n". (Obsolete)
    494514 *
    495515 * @param timeptr Broken-down time structure.
     
    502522}
    503523
    504 /** Converts broken-down time to a string in format
    505  *  "Sun Jan 1 00:00:00 1970\n". (Obsolete)
     524/**
     525 * Converts broken-down time to a string in format
     526 * "Sun Jan 1 00:00:00 1970\n". (Obsolete)
    506527 *
    507528 * @param timeptr Broken-down time structure.
     
    534555}
    535556
    536 /** Equivalent to asctime(localtime(clock)).
     557/**
     558 * Equivalent to asctime(localtime(clock)).
    537559 *
    538560 * @param timer Time to convert.
     
    548570}
    549571
    550 /** Reentrant variant of ctime().
     572/**
     573 * Reentrant variant of ctime().
    551574 *
    552575 * @param timer Time to convert.
     
    564587}
    565588
    566 /** Convert time and date to a string, based on a specified format and
    567  *  current locale.
     589/**
     590 * Convert time and date to a string, based on a specified format and
     591 * current locale.
    568592 *
    569593 * @param s Buffer to write string to.
     
    755779}
    756780
    757 /** Get clock resolution. Only CLOCK_REALTIME is supported.
     781/**
     782 * Get clock resolution. Only CLOCK_REALTIME is supported.
    758783 *
    759784 * @param clock_id Clock ID.
     
    776801}
    777802
    778 /** Get time. Only CLOCK_REALTIME is supported.
     803/**
     804 * Get time. Only CLOCK_REALTIME is supported.
    779805 *
    780806 * @param clock_id ID of the clock to query.
    781807 * @param tp Pointer to the variable where the time is to be written.
    782  * @return
     808 * @return 0 on success, -1 with errno on failure.
    783809 */
    784810int posix_clock_gettime(posix_clockid_t clock_id, struct posix_timespec *tp)
     
    800826}
    801827
    802 /** Set time on a specified clock. As HelenOS doesn't support this yet,
    803  *  this function always fails.
     828/**
     829 * Set time on a specified clock. As HelenOS doesn't support this yet,
     830 * this function always fails.
    804831 *
    805832 * @param clock_id ID of the clock to set.
     
    825852}
    826853
    827 /** Sleep on a specified clock.
     854/**
     855 * Sleep on a specified clock.
    828856 *
    829857 * @param clock_id ID of the clock to sleep on (only CLOCK_REALTIME supported).
     
    855883}
    856884
    857 /** Get CPU time used since the process invocation.
     885/**
     886 * Get CPU time used since the process invocation.
    858887 *
    859888 * @return Consumed CPU cycles by this process or -1 if not available.
  • uspace/lib/posix/time.h

    r0cf27ee r07b39338  
    162162        #define clock_settime posix_clock_settime
    163163        #define clock_nanosleep posix_clock_nanosleep
    164        
    165         #define timer_create posix_timer_create
    166         #define timer_delete posix_timer_delete
    167         #define timer_getoverrun posix_timer_getoverrun
    168         #define timer_gettime posix_timer_gettime
    169         #define timer_settime posix_timer_settime
    170        
     164
    171165        #define clock posix_clock
    172166#endif
  • uspace/lib/usb/include/usb/hc.h

    r0cf27ee r07b39338  
    3838#include <sys/types.h>
    3939#include <ipc/devman.h>
     40#include <ipc/loc.h>
    4041#include <ddf/driver.h>
    4142#include <bool.h>
     
    6869    devman_handle_t *);
    6970
    70 int usb_ddf_get_hc_handle_by_class(size_t, devman_handle_t *);
     71int usb_ddf_get_hc_handle_by_sid(service_id_t, devman_handle_t *);
    7172
    7273
  • uspace/lib/usb/include/usb/usb.h

    r0cf27ee r07b39338  
    174174} usb_packet_id;
    175175
    176 /** Class name for USB host controllers. */
    177 #define USB_HC_DDF_CLASS_NAME "usbhc"
     176/** Category for USB host controllers. */
     177#define USB_HC_CATEGORY "usbhc"
    178178
    179179#endif
  • uspace/lib/usb/src/hc.c

    r0cf27ee r07b39338  
    201201/** Get host controller handle by its class index.
    202202 *
    203  * @param class_index Class index for the host controller.
     203 * @param sid Service ID of the HC function.
    204204 * @param hc_handle Where to store the HC handle
    205205 *      (can be NULL for existence test only).
    206206 * @return Error code.
    207207 */
    208 int usb_ddf_get_hc_handle_by_class(size_t class_index,
    209     devman_handle_t *hc_handle)
    210 {
    211         char *class_index_str;
    212         devman_handle_t hc_handle_tmp;
     208int usb_ddf_get_hc_handle_by_sid(service_id_t sid, devman_handle_t *hc_handle)
     209{
     210        devman_handle_t handle;
    213211        int rc;
    214 
    215         rc = asprintf(&class_index_str, "%zu", class_index);
    216         if (rc < 0) {
    217                 return ENOMEM;
    218         }
    219         rc = devman_device_get_handle_by_class("usbhc", class_index_str,
    220             &hc_handle_tmp, 0);
    221         free(class_index_str);
    222         if (rc != EOK) {
    223                 return rc;
    224         }
    225 
    226         if (hc_handle != NULL) {
    227                 *hc_handle = hc_handle_tmp;
    228         }
    229 
    230         return EOK;
     212       
     213        rc = devman_fun_sid_to_handle(sid, &handle);
     214        if (hc_handle != NULL)
     215                *hc_handle = handle;
     216       
     217        return rc;
    231218}
    232219
  • uspace/lib/usb/src/resolve.c

    r0cf27ee r07b39338  
    4646    devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
    4747{
    48         size_t class_index;
     48        uint64_t sid;
    4949        size_t address;
    5050        int rc;
    5151        char *ptr;
    5252
    53         rc = str_size_t(path, &ptr, 10, false, &class_index);
     53        rc = str_uint64(path, &ptr, 10, false, &sid);
    5454        if (rc != EOK) {
    5555                return false;
     
    6464                return false;
    6565        }
    66         rc = usb_ddf_get_hc_handle_by_class(class_index, out_hc_handle);
     66        rc = usb_ddf_get_hc_handle_by_sid(sid, out_hc_handle);
    6767        if (rc != EOK) {
    6868                return false;
     
    152152                if (str_length(func_start) > 0) {
    153153                        char tmp_path[MAX_DEVICE_PATH ];
    154                         rc = devman_get_device_path(dev_handle,
     154                        rc = devman_fun_get_path(dev_handle,
    155155                            tmp_path, MAX_DEVICE_PATH);
    156156                        if (rc != EOK) {
     
    173173
    174174        /* First try to get the device handle. */
    175         rc = devman_device_get_handle(path, &dev_handle, 0);
     175        rc = devman_fun_get_handle(path, &dev_handle, 0);
    176176        if (rc != EOK) {
    177177                free(path);
     
    184184                /* Get device handle first. */
    185185                devman_handle_t tmp_handle;
    186                 rc = devman_device_get_handle(path, &tmp_handle, 0);
     186                rc = devman_fun_get_handle(path, &tmp_handle, 0);
    187187                if (rc != EOK) {
    188188                        free(path);
  • uspace/lib/usbvirt/src/device.c

    r0cf27ee r07b39338  
    8787       
    8888        devman_handle_t handle;
    89         int rc = devman_device_get_handle(vhc_path, &handle, 0);
     89        int rc = devman_fun_get_handle(vhc_path, &handle, 0);
    9090        if (rc != EOK)
    9191                return rc;
Note: See TracChangeset for help on using the changeset viewer.