Changeset ff381a7 in mainline for uspace/lib/c


Ignore:
Timestamp:
2015-11-02T20:54:19Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d8513177
Parents:
3feeab2 (diff), 5265eea4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
uspace/lib/c
Files:
18 added
2 deleted
62 edited
3 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    r3feeab2 rff381a7  
    6767        generic/bd_srv.c \
    6868        generic/cap.c \
    69         generic/cfg.c \
    7069        generic/clipboard.c \
    7170        generic/corecfg.c \
  • uspace/lib/c/arch/abs32le/include/libarch/stddef.h

    r3feeab2 rff381a7  
    11/*
    2  * Copyright (c) 2012 Frantisek Princ
     2 * Copyright (c) 2006 Ondrej Palkovsky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libext4
     29/** @addtogroup libcabs32
    3030 * @{
    3131 */
    32 
    33 /**
    34  * @file  libext4_crc.c
     32/** @file
    3533 */
    3634
    37 #include "libext4.h"
     35#ifndef LIBC_abs32_STDDEF_H_
     36#define LIBC_abs32_STDDEF_H_
    3837
    39 uint16_t crc16(uint16_t crc, const uint8_t *buffer, size_t len)
    40 {
    41         // TODO
    42         return 0;
    43 }
     38#include <libarch/common.h>
    4439
    45 /**
    46  * @}
     40typedef uint32_t size_t;
     41typedef int32_t ptrdiff_t;
     42
     43#endif
     44
     45/** @}
    4746 */
  • uspace/lib/c/arch/abs32le/include/libarch/types.h

    r3feeab2 rff381a7  
    3636#define LIBC_abs32le_TYPES_H_
    3737
     38#include <libarch/common.h>
     39#include <libarch/stddef.h>
     40#include <libarch/stdint.h>
     41
    3842#define __32_BITS__
    39 
    40 #include <libarch/common.h>
    41 
    42 #define SIZE_MIN  UINT32_MIN
    43 #define SIZE_MAX  UINT32_MAX
    4443
    4544#define SSIZE_MIN  INT32_MIN
     
    5049
    5150typedef int32_t ssize_t;
    52 typedef uint32_t size_t;
    5351
    54 typedef uint32_t uintptr_t;
    55 typedef int32_t intptr_t;
    5652typedef uint32_t atomic_count_t;
    5753typedef int32_t atomic_signed_t;
  • uspace/lib/c/arch/amd64/include/libarch/types.h

    r3feeab2 rff381a7  
    3636#define LIBC_amd64_TYPES_H_
    3737
     38#include <libarch/common.h>
     39#include <libarch/stddef.h>
     40#include <libarch/stdint.h>
     41
    3842#define __64_BITS__
    39 
    40 #include <libarch/common.h>
    41 
    42 #define SIZE_MIN  UINT64_MIN
    43 #define SIZE_MAX  UINT64_MAX
    4443
    4544#define SSIZE_MIN  INT64_MIN
     
    5049
    5150typedef int64_t ssize_t;
    52 typedef uint64_t size_t;
    5351
    54 typedef uint64_t uintptr_t;
    55 typedef int64_t intptr_t;
    5652typedef uint64_t atomic_count_t;
    5753typedef int64_t atomic_signed_t;
  • uspace/lib/c/arch/arm32/include/libarch/types.h

    r3feeab2 rff381a7  
    3737#define LIBC_arm32_TYPES_H_
    3838
     39#include <libarch/common.h>
     40#include <libarch/stddef.h>
     41#include <libarch/stdint.h>
     42
    3943#define __32_BITS__
    40 
    41 #include <libarch/common.h>
    42 
    43 #define SIZE_MIN  UINT32_MIN
    44 #define SIZE_MAX  UINT32_MAX
    4544
    4645#define SSIZE_MIN  INT32_MIN
     
    5150
    5251typedef int32_t ssize_t;
    53 typedef uint32_t size_t;
    5452
    55 typedef uint32_t uintptr_t;
    56 typedef int32_t intptr_t;
    5753typedef uint32_t atomic_count_t;
    5854typedef int32_t atomic_signed_t;
  • uspace/lib/c/arch/ia32/include/libarch/stddef.h

    r3feeab2 rff381a7  
    11/*
    2  * Copyright (c) 2010 Lenka Trochtova
     2 * Copyright (c) 2006 Ondrej Palkovsky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libdrv
     29/** @addtogroup libcia32
    3030 * @{
    3131 */
     
    3333 */
    3434
    35 #ifndef IPC_DRIVER_H_
    36 #define IPC_DRIVER_H_
     35#ifndef LIBC_ia32_STDDEF_H_
     36#define LIBC_ia32_STDDEF_H_
    3737
    38 typedef enum {
    39         DRIVER_DEVMAN = 1,
    40         DRIVER_CLIENT,
    41         DRIVER_DRIVER
    42 } driver_interface_t;
     38#include <libarch/common.h>
    4339
     40typedef uint32_t size_t;
     41typedef int32_t ptrdiff_t;
    4442
    4543#endif
    4644
    47 
    48 /**
    49  * @}
     45/** @}
    5046 */
  • uspace/lib/c/arch/ia32/include/libarch/types.h

    r3feeab2 rff381a7  
    3636#define LIBC_ia32_TYPES_H_
    3737
     38#include <libarch/common.h>
     39#include <libarch/stddef.h>
     40#include <libarch/stdint.h>
     41
    3842#define __32_BITS__
    39 
    40 #include <libarch/common.h>
    41 
    42 #define SIZE_MIN  UINT32_MIN
    43 #define SIZE_MAX  UINT32_MAX
    4443
    4544#define SSIZE_MIN  INT32_MIN
     
    5251typedef uint32_t size_t;
    5352
    54 typedef uint32_t uintptr_t;
    55 typedef int32_t intptr_t;
    5653typedef uint32_t atomic_count_t;
    5754typedef int32_t atomic_signed_t;
  • uspace/lib/c/arch/ia64/include/libarch/stddef.h

    r3feeab2 rff381a7  
    11/*
    2  * Copyright (c) 2012 Frantisek Princ
     2 * Copyright (c) 2006 Ondrej Palkovsky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libext4
     29/** @addtogroup libcia64
    3030 * @{
    3131 */
     32/** @file
     33 */
    3234
    33 #ifndef LIBEXT4_LIBEXT4_CRC_H_
    34 #define LIBEXT4_LIBEXT4_CRC_H_
     35#ifndef LIBC_ia64_STDDEF_H_
     36#define LIBC_ia64_STDDEF_H_
    3537
    36 extern uint16_t crc16(uint16_t, const uint8_t *, size_t);
     38#include <libarch/common.h>
     39
     40typedef uint64_t size_t;
     41typedef int64_t ptrdiff_t;
    3742
    3843#endif
    3944
    40 /**
    41  * @}
     45/** @}
    4246 */
  • uspace/lib/c/arch/ia64/include/libarch/types.h

    r3feeab2 rff381a7  
    3636#define LIBC_ia64_TYPES_H_
    3737
     38#include <libarch/common.h>
     39#include <libarch/stddef.h>
     40#include <libarch/stdint.h>
     41
    3842#define __64_BITS__
    39 
    40 #include <libarch/common.h>
    41 
    42 #define SIZE_MIN  UINT64_MIN
    43 #define SIZE_MAX  UINT64_MAX
    4443
    4544#define SSIZE_MIN  INT64_MIN
     
    5049
    5150typedef int64_t ssize_t;
    52 typedef uint64_t size_t;
    5351
    54 typedef uint64_t uintptr_t;
    55 typedef int64_t intptr_t;
    5652typedef uint64_t atomic_count_t;
    5753typedef int64_t atomic_signed_t;
  • uspace/lib/c/arch/mips32/include/libarch/types.h

    r3feeab2 rff381a7  
    3737#define LIBC_mips32_TYPES_H_
    3838
     39#include <libarch/common.h>
     40#include <libarch/stddef.h>
     41#include <libarch/stdint.h>
     42
    3943#define __32_BITS__
    40 
    41 #include <libarch/common.h>
    42 
    43 #define SIZE_MIN  UINT32_MIN
    44 #define SIZE_MAX  UINT32_MAX
    4544
    4645#define SSIZE_MIN  INT32_MIN
     
    5150
    5251typedef int32_t ssize_t;
    53 typedef uint32_t size_t;
    5452
    55 typedef uint32_t uintptr_t;
    56 typedef int32_t intptr_t;
    5753typedef uint32_t atomic_count_t;
    5854typedef int32_t atomic_signed_t;
  • uspace/lib/c/arch/ppc32/include/libarch/types.h

    r3feeab2 rff381a7  
    3636#define LIBC_ppc32_TYPES_H_
    3737
     38#include <libarch/common.h>
     39#include <libarch/stddef.h>
     40#include <libarch/stdint.h>
     41
    3842#define __32_BITS__
    39 
    40 #include <libarch/common.h>
    41 
    42 #define SIZE_MIN  UINT32_MIN
    43 #define SIZE_MAX  UINT32_MAX
    4443
    4544#define SSIZE_MIN  INT32_MIN
     
    5049
    5150typedef int32_t ssize_t;
    52 typedef uint32_t size_t;
    5351
    54 typedef uint32_t uintptr_t;
    55 typedef int32_t intptr_t;
    5652typedef uint32_t atomic_count_t;
    5753typedef int32_t atomic_signed_t;
  • uspace/lib/c/arch/sparc32/include/libarch/types.h

    r3feeab2 rff381a7  
    3636#define LIBC_sparc32_TYPES_H_
    3737
     38#include <libarch/common.h>
     39#include <libarch/stddef.h>
     40#include <libarch/stdint.h>
     41
    3842#define __32_BITS__
    39 
    40 #include <libarch/common.h>
    41 
    42 #define SIZE_MIN  UINT32_MIN
    43 #define SIZE_MAX  UINT32_MAX
    4443
    4544#define SSIZE_MIN  INT32_MIN
     
    5049
    5150typedef int32_t ssize_t;
    52 typedef uint32_t size_t;
    5351
    54 typedef uint32_t uintptr_t;
    55 typedef int32_t intptr_t;
    5652typedef uint32_t atomic_count_t;
    5753typedef int32_t atomic_signed_t;
  • uspace/lib/c/arch/sparc64/include/libarch/types.h

    r3feeab2 rff381a7  
    3636#define LIBC_sparc64_TYPES_H_
    3737
     38#include <libarch/common.h>
     39#include <libarch/stddef.h>
     40#include <libarch/stdint.h>
     41
    3842#define __64_BITS__
    39 
    40 #include <libarch/common.h>
    41 
    42 #define SIZE_MIN  UINT64_MIN
    43 #define SIZE_MAX  UINT64_MAX
    4443
    4544#define SSIZE_MIN  INT64_MIN
     
    5049
    5150typedef int64_t ssize_t;
    52 typedef uint64_t size_t;
    5351
    54 typedef uint64_t uintptr_t;
    55 typedef int64_t intptr_t;
    5652typedef uint64_t atomic_count_t;
    5753typedef int64_t atomic_signed_t;
  • uspace/lib/c/generic/adt/list.c

    r3feeab2 rff381a7  
    5353 *
    5454 */
    55 int list_member(const link_t *link, const list_t *list)
     55bool list_member(const link_t *link, const list_t *list)
    5656{
    5757        bool found = false;
     
    9898 * @return              Number of items in the list.
    9999 */
    100 unsigned int list_count(const list_t *list)
     100unsigned long list_count(const list_t *list)
    101101{
    102         unsigned int count = 0;
     102        unsigned long count = 0;
    103103       
    104104        link_t *link = list_first(list);
  • uspace/lib/c/generic/async.c

    r3feeab2 rff381a7  
    7777 *   }
    7878 *
    79  *   my_client_connection(icallid, *icall)
     79 *   port_handler(icallid, *icall)
    8080 *   {
    8181 *     if (want_refuse) {
     
    123123        list_t exch_list;
    124124       
     125        /** Session interface */
     126        iface_t iface;
     127       
    125128        /** Exchange management style */
    126129        exch_mgmt_t mgmt;
     
    189192        /** If reply was received. */
    190193        bool done;
    191 
     194       
    192195        /** If the message / reply should be discarded on arrival. */
    193196        bool forget;
    194 
     197       
    195198        /** If already destroyed. */
    196199        bool destroyed;
     
    232235        /** Identification of the opening call. */
    233236        ipc_callid_t callid;
     237       
    234238        /** Call data of the opening call. */
    235239        ipc_call_t call;
    236         /** Local argument or NULL if none. */
    237         void *carg;
    238240       
    239241        /** Identification of the closing call. */
     
    241243       
    242244        /** Fibril function that will be used to handle the connection. */
    243         async_client_conn_t cfibril;
     245        async_port_handler_t handler;
     246       
     247        /** Client data */
     248        void *data;
    244249} connection_t;
     250
     251/** Interface data */
     252typedef struct {
     253        ht_link_t link;
     254       
     255        /** Interface ID */
     256        iface_t iface;
     257       
     258        /** Futex protecting the hash table */
     259        futex_t futex;
     260       
     261        /** Interface ports */
     262        hash_table_t port_hash_table;
     263       
     264        /** Next available port ID */
     265        port_id_t port_id_avail;
     266} interface_t;
     267
     268/* Port data */
     269typedef struct {
     270        ht_link_t link;
     271       
     272        /** Port ID */
     273        port_id_t id;
     274       
     275        /** Port connection handler */
     276        async_port_handler_t handler;
     277       
     278        /** Client data */
     279        void *data;
     280} port_t;
    245281
    246282/* Notification data */
     
    264300{
    265301        struct timeval tv = { 0, 0 };
    266 
     302       
    267303        to->inlist = false;
    268304        to->occurred = false;
     
    287323static amsg_t *amsg_create(void)
    288324{
    289         amsg_t *msg;
    290 
    291         msg = malloc(sizeof(amsg_t));
     325        amsg_t *msg = malloc(sizeof(amsg_t));
    292326        if (msg) {
    293327                msg->done = false;
     
    298332                awaiter_initialize(&msg->wdata);
    299333        }
    300 
     334       
    301335        return msg;
    302336}
     
    335369}
    336370
    337 /** Default fibril function that gets called to handle new connection.
    338  *
    339  * This function is defined as a weak symbol - to be redefined in user code.
     371/** Default fallback fibril function.
     372 *
     373 * This fallback fibril function gets called on incomming
     374 * connections that do not have a specific handler defined.
    340375 *
    341376 * @param callid Hash of the incoming call.
     
    344379 *
    345380 */
    346 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call,
     381static void default_fallback_port_handler(ipc_callid_t callid, ipc_call_t *call,
    347382    void *arg)
    348383{
     
    350385}
    351386
    352 static async_client_conn_t client_connection = default_client_connection;
     387static async_port_handler_t fallback_port_handler =
     388    default_fallback_port_handler;
     389static void *fallback_port_data = NULL;
     390
     391static hash_table_t interface_hash_table;
     392
     393static size_t interface_key_hash(void *key)
     394{
     395        iface_t iface = *(iface_t *) key;
     396        return iface;
     397}
     398
     399static size_t interface_hash(const ht_link_t *item)
     400{
     401        interface_t *interface = hash_table_get_inst(item, interface_t, link);
     402        return interface_key_hash(&interface->iface);
     403}
     404
     405static bool interface_key_equal(void *key, const ht_link_t *item)
     406{
     407        iface_t iface = *(iface_t *) key;
     408        interface_t *interface = hash_table_get_inst(item, interface_t, link);
     409        return iface == interface->iface;
     410}
     411
     412/** Operations for the port hash table. */
     413static hash_table_ops_t interface_hash_table_ops = {
     414        .hash = interface_hash,
     415        .key_hash = interface_key_hash,
     416        .key_equal = interface_key_equal,
     417        .equal = NULL,
     418        .remove_callback = NULL
     419};
     420
     421static size_t port_key_hash(void *key)
     422{
     423        port_id_t port_id = *(port_id_t *) key;
     424        return port_id;
     425}
     426
     427static size_t port_hash(const ht_link_t *item)
     428{
     429        port_t *port = hash_table_get_inst(item, port_t, link);
     430        return port_key_hash(&port->id);
     431}
     432
     433static bool port_key_equal(void *key, const ht_link_t *item)
     434{
     435        port_id_t port_id = *(port_id_t *) key;
     436        port_t *port = hash_table_get_inst(item, port_t, link);
     437        return port_id == port->id;
     438}
     439
     440/** Operations for the port hash table. */
     441static hash_table_ops_t port_hash_table_ops = {
     442        .hash = port_hash,
     443        .key_hash = port_key_hash,
     444        .key_equal = port_key_equal,
     445        .equal = NULL,
     446        .remove_callback = NULL
     447};
     448
     449static interface_t *async_new_interface(iface_t iface)
     450{
     451        interface_t *interface =
     452            (interface_t *) malloc(sizeof(interface_t));
     453        if (!interface)
     454                return NULL;
     455       
     456        bool ret = hash_table_create(&interface->port_hash_table, 0, 0,
     457            &port_hash_table_ops);
     458        if (!ret) {
     459                free(interface);
     460                return NULL;
     461        }
     462       
     463        interface->iface = iface;
     464        futex_initialize(&interface->futex, 1);
     465        interface->port_id_avail = 0;
     466       
     467        hash_table_insert(&interface_hash_table, &interface->link);
     468       
     469        return interface;
     470}
     471
     472static port_t *async_new_port(interface_t *interface,
     473    async_port_handler_t handler, void *data)
     474{
     475        port_t *port = (port_t *) malloc(sizeof(port_t));
     476        if (!port)
     477                return NULL;
     478       
     479        futex_down(&interface->futex);
     480       
     481        port_id_t id = interface->port_id_avail;
     482        interface->port_id_avail++;
     483       
     484        port->id = id;
     485        port->handler = handler;
     486        port->data = data;
     487       
     488        hash_table_insert(&interface->port_hash_table, &port->link);
     489       
     490        futex_up(&interface->futex);
     491       
     492        return port;
     493}
     494
    353495static size_t notification_handler_stksz = FIBRIL_DFLT_STK_SIZE;
    354496
    355 /** Setter for client_connection function pointer.
    356  *
    357  * @param conn Function that will implement a new connection fibril.
    358  *
    359  */
    360 void async_set_client_connection(async_client_conn_t conn)
    361 {
    362         assert(client_connection == default_client_connection);
    363         client_connection = conn;
    364 }
    365 
    366497/** Set the stack size for the notification handler notification fibrils.
    367498 *
     
    387518 */
    388519static FIBRIL_CONDVAR_INITIALIZE(avail_phone_cv);
     520
     521int async_create_port(iface_t iface, async_port_handler_t handler,
     522    void *data, port_id_t *port_id)
     523{
     524        if ((iface & IFACE_MOD_MASK) == IFACE_MOD_CALLBACK)
     525                return EINVAL;
     526       
     527        interface_t *interface;
     528       
     529        futex_down(&async_futex);
     530       
     531        ht_link_t *link = hash_table_find(&interface_hash_table, &iface);
     532        if (link)
     533                interface = hash_table_get_inst(link, interface_t, link);
     534        else
     535                interface = async_new_interface(iface);
     536       
     537        if (!interface) {
     538                futex_up(&async_futex);
     539                return ENOMEM;
     540        }
     541       
     542        port_t *port = async_new_port(interface, handler, data);
     543        if (!port) {
     544                futex_up(&async_futex);
     545                return ENOMEM;
     546        }
     547       
     548        *port_id = port->id;
     549       
     550        futex_up(&async_futex);
     551       
     552        return EOK;
     553}
     554
     555void async_set_fallback_port_handler(async_port_handler_t handler, void *data)
     556{
     557        assert(handler != NULL);
     558       
     559        fallback_port_handler = handler;
     560        fallback_port_data = data;
     561}
    389562
    390563static hash_table_t client_hash_table;
     
    457630        .remove_callback = NULL
    458631};
     632
     633static client_t *async_client_get(task_id_t client_id, bool create)
     634{
     635        client_t *client = NULL;
     636       
     637        futex_down(&async_futex);
     638        ht_link_t *link = hash_table_find(&client_hash_table, &client_id);
     639        if (link) {
     640                client = hash_table_get_inst(link, client_t, link);
     641                atomic_inc(&client->refcnt);
     642        } else if (create) {
     643                client = malloc(sizeof(client_t));
     644                if (client) {
     645                        client->in_task_id = client_id;
     646                        client->data = async_client_data_create();
     647                       
     648                        atomic_set(&client->refcnt, 1);
     649                        hash_table_insert(&client_hash_table, &client->link);
     650                }
     651        }
     652       
     653        futex_up(&async_futex);
     654        return client;
     655}
     656
     657static void async_client_put(client_t *client)
     658{
     659        bool destroy;
     660       
     661        futex_down(&async_futex);
     662       
     663        if (atomic_predec(&client->refcnt) == 0) {
     664                hash_table_remove(&client_hash_table, &client->in_task_id);
     665                destroy = true;
     666        } else
     667                destroy = false;
     668       
     669        futex_up(&async_futex);
     670       
     671        if (destroy) {
     672                if (client->data)
     673                        async_client_data_destroy(client->data);
     674               
     675                free(client);
     676        }
     677}
     678
     679/** Wrapper for client connection fibril.
     680 *
     681 * When a new connection arrives, a fibril with this implementing
     682 * function is created.
     683 *
     684 * @param arg Connection structure pointer.
     685 *
     686 * @return Always zero.
     687 *
     688 */
     689static int connection_fibril(void *arg)
     690{
     691        assert(arg);
     692       
     693        /*
     694         * Setup fibril-local connection pointer.
     695         */
     696        fibril_connection = (connection_t *) arg;
     697       
     698        /*
     699         * Add our reference for the current connection in the client task
     700         * tracking structure. If this is the first reference, create and
     701         * hash in a new tracking structure.
     702         */
     703       
     704        client_t *client = async_client_get(fibril_connection->in_task_id, true);
     705        if (!client) {
     706                ipc_answer_0(fibril_connection->callid, ENOMEM);
     707                return 0;
     708        }
     709       
     710        fibril_connection->client = client;
     711       
     712        /*
     713         * Call the connection handler function.
     714         */
     715        fibril_connection->handler(fibril_connection->callid,
     716            &fibril_connection->call, fibril_connection->data);
     717       
     718        /*
     719         * Remove the reference for this client task connection.
     720         */
     721        async_client_put(client);
     722       
     723        /*
     724         * Remove myself from the connection hash table.
     725         */
     726        futex_down(&async_futex);
     727        hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash);
     728        futex_up(&async_futex);
     729       
     730        /*
     731         * Answer all remaining messages with EHANGUP.
     732         */
     733        while (!list_empty(&fibril_connection->msg_queue)) {
     734                msg_t *msg =
     735                    list_get_instance(list_first(&fibril_connection->msg_queue),
     736                    msg_t, link);
     737               
     738                list_remove(&msg->link);
     739                ipc_answer_0(msg->callid, EHANGUP);
     740                free(msg);
     741        }
     742       
     743        /*
     744         * If the connection was hung-up, answer the last call,
     745         * i.e. IPC_M_PHONE_HUNGUP.
     746         */
     747        if (fibril_connection->close_callid)
     748                ipc_answer_0(fibril_connection->close_callid, EOK);
     749       
     750        free(fibril_connection);
     751        return 0;
     752}
     753
     754/** Create a new fibril for a new connection.
     755 *
     756 * Create new fibril for connection, fill in connection structures
     757 * and insert it into the hash table, so that later we can easily
     758 * do routing of messages to particular fibrils.
     759 *
     760 * @param in_task_id    Identification of the incoming connection.
     761 * @param in_phone_hash Identification of the incoming connection.
     762 * @param callid        Hash of the opening IPC_M_CONNECT_ME_TO call.
     763 *                      If callid is zero, the connection was opened by
     764 *                      accepting the IPC_M_CONNECT_TO_ME call and this
     765 *                      function is called directly by the server.
     766 * @param call          Call data of the opening call.
     767 * @param handler       Connection handler.
     768 * @param data          Client argument to pass to the connection handler.
     769 *
     770 * @return New fibril id or NULL on failure.
     771 *
     772 */
     773static fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash,
     774    ipc_callid_t callid, ipc_call_t *call, async_port_handler_t handler,
     775    void *data)
     776{
     777        connection_t *conn = malloc(sizeof(*conn));
     778        if (!conn) {
     779                if (callid)
     780                        ipc_answer_0(callid, ENOMEM);
     781               
     782                return (uintptr_t) NULL;
     783        }
     784       
     785        conn->in_task_id = in_task_id;
     786        conn->in_phone_hash = in_phone_hash;
     787        list_initialize(&conn->msg_queue);
     788        conn->callid = callid;
     789        conn->close_callid = 0;
     790        conn->handler = handler;
     791        conn->data = data;
     792       
     793        if (call)
     794                conn->call = *call;
     795       
     796        /* We will activate the fibril ASAP */
     797        conn->wdata.active = true;
     798        conn->wdata.fid = fibril_create(connection_fibril, conn);
     799       
     800        if (conn->wdata.fid == 0) {
     801                free(conn);
     802               
     803                if (callid)
     804                        ipc_answer_0(callid, ENOMEM);
     805               
     806                return (uintptr_t) NULL;
     807        }
     808       
     809        /* Add connection to the connection hash table */
     810       
     811        futex_down(&async_futex);
     812        hash_table_insert(&conn_hash_table, &conn->link);
     813        futex_up(&async_futex);
     814       
     815        fibril_add_ready(conn->wdata.fid);
     816       
     817        return conn->wdata.fid;
     818}
     819
     820/** Wrapper for making IPC_M_CONNECT_TO_ME calls using the async framework.
     821 *
     822 * Ask through phone for a new connection to some service.
     823 *
     824 * @param exch    Exchange for sending the message.
     825 * @param iface   Callback interface.
     826 * @param arg1    User defined argument.
     827 * @param arg2    User defined argument.
     828 * @param handler Callback handler.
     829 * @param data    Handler data.
     830 * @param port_id ID of the newly created port.
     831 *
     832 * @return Zero on success or a negative error code.
     833 *
     834 */
     835int async_create_callback_port(async_exch_t *exch, iface_t iface, sysarg_t arg1,
     836    sysarg_t arg2, async_port_handler_t handler, void *data, port_id_t *port_id)
     837{
     838        if ((iface & IFACE_MOD_CALLBACK) != IFACE_MOD_CALLBACK)
     839                return EINVAL;
     840       
     841        if (exch == NULL)
     842                return ENOENT;
     843       
     844        ipc_call_t answer;
     845        aid_t req = async_send_3(exch, IPC_M_CONNECT_TO_ME, iface, arg1, arg2,
     846            &answer);
     847       
     848        sysarg_t ret;
     849        async_wait_for(req, &ret);
     850        if (ret != EOK)
     851                return (int) ret;
     852       
     853        sysarg_t phone_hash = IPC_GET_ARG5(answer);
     854        interface_t *interface;
     855       
     856        futex_down(&async_futex);
     857       
     858        ht_link_t *link = hash_table_find(&interface_hash_table, &iface);
     859        if (link)
     860                interface = hash_table_get_inst(link, interface_t, link);
     861        else
     862                interface = async_new_interface(iface);
     863       
     864        if (!interface) {
     865                futex_up(&async_futex);
     866                return ENOMEM;
     867        }
     868       
     869        port_t *port = async_new_port(interface, handler, data);
     870        if (!port) {
     871                futex_up(&async_futex);
     872                return ENOMEM;
     873        }
     874       
     875        *port_id = port->id;
     876       
     877        futex_up(&async_futex);
     878       
     879        fid_t fid = async_new_connection(answer.in_task_id, phone_hash,
     880            0, NULL, handler, data);
     881        if (fid == (uintptr_t) NULL)
     882                return ENOMEM;
     883       
     884        return EOK;
     885}
    459886
    460887static size_t notification_key_hash(void *key)
     
    8661293        }
    8671294       
    868         msg_t *msg = list_get_instance(list_first(&conn->msg_queue), msg_t, link);
     1295        msg_t *msg = list_get_instance(list_first(&conn->msg_queue),
     1296            msg_t, link);
    8691297        list_remove(&msg->link);
    8701298       
     
    8771305}
    8781306
    879 static client_t *async_client_get(task_id_t client_id, bool create)
    880 {
    881         client_t *client = NULL;
    882 
    883         futex_down(&async_futex);
    884         ht_link_t *link = hash_table_find(&client_hash_table, &client_id);
    885         if (link) {
    886                 client = hash_table_get_inst(link, client_t, link);
    887                 atomic_inc(&client->refcnt);
    888         } else if (create) {
    889                 client = malloc(sizeof(client_t));
    890                 if (client) {
    891                         client->in_task_id = client_id;
    892                         client->data = async_client_data_create();
    893                
    894                         atomic_set(&client->refcnt, 1);
    895                         hash_table_insert(&client_hash_table, &client->link);
    896                 }
    897         }
    898 
    899         futex_up(&async_futex);
    900         return client;
    901 }
    902 
    903 static void async_client_put(client_t *client)
    904 {
    905         bool destroy;
    906 
    907         futex_down(&async_futex);
    908        
    909         if (atomic_predec(&client->refcnt) == 0) {
    910                 hash_table_remove(&client_hash_table, &client->in_task_id);
    911                 destroy = true;
    912         } else
    913                 destroy = false;
    914        
    915         futex_up(&async_futex);
    916        
    917         if (destroy) {
    918                 if (client->data)
    919                         async_client_data_destroy(client->data);
    920                
    921                 free(client);
    922         }
    923 }
    924 
    9251307void *async_get_client_data(void)
    9261308{
     
    9341316        if (!client)
    9351317                return NULL;
     1318       
    9361319        if (!client->data) {
    9371320                async_client_put(client);
    9381321                return NULL;
    9391322        }
    940 
     1323       
    9411324        return client->data;
    9421325}
     
    9451328{
    9461329        client_t *client = async_client_get(client_id, false);
    947 
     1330       
    9481331        assert(client);
    9491332        assert(client->data);
    950 
     1333       
    9511334        /* Drop the reference we got in async_get_client_data_by_hash(). */
    9521335        async_client_put(client);
    953 
     1336       
    9541337        /* Drop our own reference we got at the beginning of this function. */
    9551338        async_client_put(client);
    9561339}
    9571340
    958 /** Wrapper for client connection fibril.
    959  *
    960  * When a new connection arrives, a fibril with this implementing function is
    961  * created. It calls client_connection() and does the final cleanup.
    962  *
    963  * @param arg Connection structure pointer.
    964  *
    965  * @return Always zero.
    966  *
    967  */
    968 static int connection_fibril(void *arg)
    969 {
    970         assert(arg);
    971        
    972         /*
    973          * Setup fibril-local connection pointer.
    974          */
    975         fibril_connection = (connection_t *) arg;
    976        
    977         /*
    978          * Add our reference for the current connection in the client task
    979          * tracking structure. If this is the first reference, create and
    980          * hash in a new tracking structure.
    981          */
    982 
    983         client_t *client = async_client_get(fibril_connection->in_task_id, true);
    984         if (!client) {
    985                 ipc_answer_0(fibril_connection->callid, ENOMEM);
    986                 return 0;
    987         }
    988 
    989         fibril_connection->client = client;
    990        
    991         /*
    992          * Call the connection handler function.
    993          */
    994         fibril_connection->cfibril(fibril_connection->callid,
    995             &fibril_connection->call, fibril_connection->carg);
    996        
    997         /*
    998          * Remove the reference for this client task connection.
    999          */
    1000         async_client_put(client);
    1001        
    1002         /*
    1003          * Remove myself from the connection hash table.
    1004          */
     1341static port_t *async_find_port(iface_t iface, port_id_t port_id)
     1342{
     1343        port_t *port = NULL;
     1344       
    10051345        futex_down(&async_futex);
    1006         hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash);
     1346       
     1347        ht_link_t *link = hash_table_find(&interface_hash_table, &iface);
     1348        if (link) {
     1349                interface_t *interface =
     1350                    hash_table_get_inst(link, interface_t, link);
     1351               
     1352                link = hash_table_find(&interface->port_hash_table, &port_id);
     1353                if (link)
     1354                        port = hash_table_get_inst(link, port_t, link);
     1355        }
     1356       
    10071357        futex_up(&async_futex);
    10081358       
    1009         /*
    1010          * Answer all remaining messages with EHANGUP.
    1011          */
    1012         while (!list_empty(&fibril_connection->msg_queue)) {
    1013                 msg_t *msg =
    1014                     list_get_instance(list_first(&fibril_connection->msg_queue),
    1015                     msg_t, link);
    1016                
    1017                 list_remove(&msg->link);
    1018                 ipc_answer_0(msg->callid, EHANGUP);
    1019                 free(msg);
    1020         }
    1021        
    1022         /*
    1023          * If the connection was hung-up, answer the last call,
    1024          * i.e. IPC_M_PHONE_HUNGUP.
    1025          */
    1026         if (fibril_connection->close_callid)
    1027                 ipc_answer_0(fibril_connection->close_callid, EOK);
    1028        
    1029         free(fibril_connection);
    1030         return 0;
    1031 }
    1032 
    1033 /** Create a new fibril for a new connection.
    1034  *
    1035  * Create new fibril for connection, fill in connection structures and insert
    1036  * it into the hash table, so that later we can easily do routing of messages to
    1037  * particular fibrils.
    1038  *
    1039  * @param in_task_id    Identification of the incoming connection.
    1040  * @param in_phone_hash Identification of the incoming connection.
    1041  * @param callid        Hash of the opening IPC_M_CONNECT_ME_TO call.
    1042  *                      If callid is zero, the connection was opened by
    1043  *                      accepting the IPC_M_CONNECT_TO_ME call and this function
    1044  *                      is called directly by the server.
    1045  * @param call          Call data of the opening call.
    1046  * @param cfibril       Fibril function that should be called upon opening the
    1047  *                      connection.
    1048  * @param carg          Extra argument to pass to the connection fibril
    1049  *
    1050  * @return New fibril id or NULL on failure.
    1051  *
    1052  */
    1053 fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash,
    1054     ipc_callid_t callid, ipc_call_t *call,
    1055     async_client_conn_t cfibril, void *carg)
    1056 {
    1057         connection_t *conn = malloc(sizeof(*conn));
    1058         if (!conn) {
    1059                 if (callid)
    1060                         ipc_answer_0(callid, ENOMEM);
    1061                
    1062                 return (uintptr_t) NULL;
    1063         }
    1064        
    1065         conn->in_task_id = in_task_id;
    1066         conn->in_phone_hash = in_phone_hash;
    1067         list_initialize(&conn->msg_queue);
    1068         conn->callid = callid;
    1069         conn->close_callid = 0;
    1070         conn->carg = carg;
    1071        
    1072         if (call)
    1073                 conn->call = *call;
    1074        
    1075         /* We will activate the fibril ASAP */
    1076         conn->wdata.active = true;
    1077         conn->cfibril = cfibril;
    1078         conn->wdata.fid = fibril_create(connection_fibril, conn);
    1079        
    1080         if (conn->wdata.fid == 0) {
    1081                 free(conn);
    1082                
    1083                 if (callid)
    1084                         ipc_answer_0(callid, ENOMEM);
    1085                
    1086                 return (uintptr_t) NULL;
    1087         }
    1088        
    1089         /* Add connection to the connection hash table */
    1090        
    1091         futex_down(&async_futex);
    1092         hash_table_insert(&conn_hash_table, &conn->link);
    1093         futex_up(&async_futex);
    1094        
    1095         fibril_add_ready(conn->wdata.fid);
    1096        
    1097         return conn->wdata.fid;
     1359        return port;
    10981360}
    10991361
     
    11111373        assert(call);
    11121374       
    1113         /* Unrouted call - take some default action */
     1375        /* Kernel notification */
    11141376        if ((callid & IPC_CALLID_NOTIFICATION)) {
    11151377                process_notification(callid, call);
     
    11171379        }
    11181380       
    1119         switch (IPC_GET_IMETHOD(*call)) {
    1120         case IPC_M_CLONE_ESTABLISH:
    1121         case IPC_M_CONNECT_ME_TO:
     1381        /* New connection */
     1382        if (IPC_GET_IMETHOD(*call) == IPC_M_CONNECT_ME_TO) {
     1383                iface_t iface = (iface_t) IPC_GET_ARG1(*call);
     1384                sysarg_t in_phone_hash = IPC_GET_ARG5(*call);
     1385               
     1386                async_notification_handler_t handler = fallback_port_handler;
     1387                void *data = fallback_port_data;
     1388               
     1389                // TODO: Currently ignores all ports but the first one
     1390                port_t *port = async_find_port(iface, 0);
     1391                if (port) {
     1392                        handler = port->handler;
     1393                        data = port->data;
     1394                }
     1395               
     1396                async_new_connection(call->in_task_id, in_phone_hash, callid,
     1397                    call, handler, data);
     1398                return;
     1399        }
     1400       
     1401        /* Cloned connection */
     1402        if (IPC_GET_IMETHOD(*call) == IPC_M_CLONE_ESTABLISH) {
     1403                // TODO: Currently ignores ports altogether
     1404               
    11221405                /* Open new connection with fibril, etc. */
    11231406                async_new_connection(call->in_task_id, IPC_GET_ARG5(*call),
    1124                     callid, call, client_connection, NULL);
     1407                    callid, call, fallback_port_handler, fallback_port_data);
    11251408                return;
    11261409        }
     
    12831566void __async_init(void)
    12841567{
     1568        if (!hash_table_create(&interface_hash_table, 0, 0,
     1569            &interface_hash_table_ops))
     1570                abort();
     1571       
    12851572        if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops))
    12861573                abort();
     
    12971584                abort();
    12981585       
     1586        session_ns->iface = 0;
    12991587        session_ns->mgmt = EXCHANGE_ATOMIC;
    13001588        session_ns->phone = PHONE_NS;
     
    13431631       
    13441632        msg->done = true;
    1345 
     1633       
    13461634        if (msg->forget) {
    13471635                assert(msg->wdata.active);
     
    13511639                fibril_add_ready(msg->wdata.fid);
    13521640        }
    1353 
     1641       
    13541642        futex_up(&async_futex);
    13551643}
     
    14431731       
    14441732        futex_down(&async_futex);
    1445 
     1733       
    14461734        assert(!msg->forget);
    14471735        assert(!msg->destroyed);
    1448 
     1736       
    14491737        if (msg->done) {
    14501738                futex_up(&async_futex);
     
    14871775       
    14881776        amsg_t *msg = (amsg_t *) amsgid;
    1489 
     1777       
    14901778        futex_down(&async_futex);
    1491 
     1779       
    14921780        assert(!msg->forget);
    14931781        assert(!msg->destroyed);
    1494 
     1782       
    14951783        if (msg->done) {
    14961784                futex_up(&async_futex);
     
    15041792        if (timeout < 0)
    15051793                timeout = 0;
    1506 
     1794       
    15071795        getuptime(&msg->wdata.to_event.expires);
    15081796        tv_add_diff(&msg->wdata.to_event.expires, timeout);
     
    15571845{
    15581846        amsg_t *msg = (amsg_t *) amsgid;
    1559 
     1847       
    15601848        assert(msg);
    15611849        assert(!msg->forget);
    15621850        assert(!msg->destroyed);
    1563 
     1851       
    15641852        futex_down(&async_futex);
     1853       
    15651854        if (msg->done) {
    15661855                amsg_destroy(msg);
     
    15691858                msg->forget = true;
    15701859        }
     1860       
    15711861        futex_up(&async_futex);
    15721862}
     
    18142104 * @param arg2            User defined argument.
    18152105 * @param arg3            User defined argument.
    1816  * @param client_receiver Connection handing routine.
    18172106 *
    18182107 * @return Zero on success or a negative error code.
     
    18202109 */
    18212110int async_connect_to_me(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2,
    1822     sysarg_t arg3, async_client_conn_t client_receiver, void *carg)
     2111    sysarg_t arg3)
    18232112{
    18242113        if (exch == NULL)
    18252114                return ENOENT;
    18262115       
    1827         sysarg_t phone_hash;
     2116        ipc_call_t answer;
     2117        aid_t req = async_send_3(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
     2118            &answer);
     2119       
    18282120        sysarg_t rc;
    1829 
    1830         aid_t req;
    1831         ipc_call_t answer;
    1832         req = async_send_3(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
    1833             &answer);
    18342121        async_wait_for(req, &rc);
    18352122        if (rc != EOK)
    18362123                return (int) rc;
    1837 
    1838         phone_hash = IPC_GET_ARG5(answer);
    1839 
    1840         if (client_receiver != NULL)
    1841                 async_new_connection(answer.in_task_id, phone_hash, 0, NULL,
    1842                     client_receiver, carg);
    18432124       
    18442125        return EOK;
     
    19002181        }
    19012182       
     2183        sess->iface = 0;
    19022184        sess->mgmt = mgmt;
    19032185        sess->phone = phone;
     
    19692251        int phone = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3,
    19702252            0);
    1971        
    19722253        if (phone < 0) {
    19732254                errno = phone;
     
    19762257        }
    19772258       
     2259        sess->iface = 0;
    19782260        sess->mgmt = mgmt;
    19792261        sess->phone = phone;
     
    19922274}
    19932275
     2276/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
     2277 *
     2278 * Ask through phone for a new connection to some service and block until
     2279 * success.
     2280 *
     2281 * @param exch  Exchange for sending the message.
     2282 * @param iface Connection interface.
     2283 * @param arg2  User defined argument.
     2284 * @param arg3  User defined argument.
     2285 *
     2286 * @return New session on success or NULL on error.
     2287 *
     2288 */
     2289async_sess_t *async_connect_me_to_iface(async_exch_t *exch, iface_t iface,
     2290    sysarg_t arg2, sysarg_t arg3)
     2291{
     2292        if (exch == NULL) {
     2293                errno = ENOENT;
     2294                return NULL;
     2295        }
     2296       
     2297        async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
     2298        if (sess == NULL) {
     2299                errno = ENOMEM;
     2300                return NULL;
     2301        }
     2302       
     2303        int phone = async_connect_me_to_internal(exch->phone, iface, arg2,
     2304            arg3, 0);
     2305        if (phone < 0) {
     2306                errno = phone;
     2307                free(sess);
     2308                return NULL;
     2309        }
     2310       
     2311        sess->iface = iface;
     2312        sess->phone = phone;
     2313        sess->arg1 = iface;
     2314        sess->arg2 = arg2;
     2315        sess->arg3 = arg3;
     2316       
     2317        fibril_mutex_initialize(&sess->remote_state_mtx);
     2318        sess->remote_state_data = NULL;
     2319       
     2320        list_initialize(&sess->exch_list);
     2321        fibril_mutex_initialize(&sess->mutex);
     2322        atomic_set(&sess->refcnt, 0);
     2323       
     2324        return sess;
     2325}
     2326
    19942327/** Set arguments for new connections.
    19952328 *
     
    20472380        }
    20482381       
     2382        sess->iface = 0;
    20492383        sess->mgmt = mgmt;
    20502384        sess->phone = phone;
     
    20632397}
    20642398
     2399/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
     2400 *
     2401 * Ask through phone for a new connection to some service and block until
     2402 * success.
     2403 *
     2404 * @param exch  Exchange for sending the message.
     2405 * @param iface Connection interface.
     2406 * @param arg2  User defined argument.
     2407 * @param arg3  User defined argument.
     2408 *
     2409 * @return New session on success or NULL on error.
     2410 *
     2411 */
     2412async_sess_t *async_connect_me_to_blocking_iface(async_exch_t *exch, iface_t iface,
     2413    sysarg_t arg2, sysarg_t arg3)
     2414{
     2415        if (exch == NULL) {
     2416                errno = ENOENT;
     2417                return NULL;
     2418        }
     2419       
     2420        async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
     2421        if (sess == NULL) {
     2422                errno = ENOMEM;
     2423                return NULL;
     2424        }
     2425       
     2426        int phone = async_connect_me_to_internal(exch->phone, iface, arg2,
     2427            arg3, IPC_FLAG_BLOCKING);
     2428        if (phone < 0) {
     2429                errno = phone;
     2430                free(sess);
     2431                return NULL;
     2432        }
     2433       
     2434        sess->iface = iface;
     2435        sess->phone = phone;
     2436        sess->arg1 = iface;
     2437        sess->arg2 = arg2;
     2438        sess->arg3 = arg3;
     2439       
     2440        fibril_mutex_initialize(&sess->remote_state_mtx);
     2441        sess->remote_state_data = NULL;
     2442       
     2443        list_initialize(&sess->exch_list);
     2444        fibril_mutex_initialize(&sess->mutex);
     2445        atomic_set(&sess->refcnt, 0);
     2446       
     2447        return sess;
     2448}
     2449
    20652450/** Connect to a task specified by id.
    20662451 *
     
    20812466        }
    20822467       
     2468        sess->iface = 0;
    20832469        sess->mgmt = EXCHANGE_ATOMIC;
    20842470        sess->phone = phone;
     
    21582544                return NULL;
    21592545       
    2160         async_exch_t *exch;
     2546        exch_mgmt_t mgmt = sess->mgmt;
     2547        if (sess->iface != 0)
     2548                mgmt = sess->iface & IFACE_EXCHANGE_MASK;
     2549       
     2550        async_exch_t *exch = NULL;
    21612551       
    21622552        fibril_mutex_lock(&async_sess_mutex);
     
    21772567                 */
    21782568               
    2179                 if ((sess->mgmt == EXCHANGE_ATOMIC) ||
    2180                     (sess->mgmt == EXCHANGE_SERIALIZE)) {
     2569                if ((mgmt == EXCHANGE_ATOMIC) ||
     2570                    (mgmt == EXCHANGE_SERIALIZE)) {
    21812571                        exch = (async_exch_t *) malloc(sizeof(async_exch_t));
    21822572                        if (exch != NULL) {
     
    21862576                                exch->phone = sess->phone;
    21872577                        }
    2188                 } else {  /* EXCHANGE_PARALLEL */
     2578                } else if (mgmt == EXCHANGE_PARALLEL) {
     2579                        int phone;
     2580                       
     2581                retry:
    21892582                        /*
    21902583                         * Make a one-time attempt to connect a new data phone.
    21912584                         */
    2192                        
    2193                         int phone;
    2194                        
    2195 retry:
    21962585                        phone = async_connect_me_to_internal(sess->phone, sess->arg1,
    21972586                            sess->arg2, sess->arg3, 0);
     
    22352624                atomic_inc(&sess->refcnt);
    22362625               
    2237                 if (sess->mgmt == EXCHANGE_SERIALIZE)
     2626                if (mgmt == EXCHANGE_SERIALIZE)
    22382627                        fibril_mutex_lock(&sess->mutex);
    22392628        }
     
    22552644        assert(sess != NULL);
    22562645       
     2646        exch_mgmt_t mgmt = sess->mgmt;
     2647        if (sess->iface != 0)
     2648                mgmt = sess->iface & IFACE_EXCHANGE_MASK;
     2649       
    22572650        atomic_dec(&sess->refcnt);
    22582651       
    2259         if (sess->mgmt == EXCHANGE_SERIALIZE)
     2652        if (mgmt == EXCHANGE_SERIALIZE)
    22602653                fibril_mutex_unlock(&sess->mutex);
    22612654       
     
    26943087        }
    26953088       
    2696         void *_data;
     3089        void *arg_data;
    26973090       
    26983091        if (nullterm)
    2699                 _data = malloc(size + 1);
     3092                arg_data = malloc(size + 1);
    27003093        else
    2701                 _data = malloc(size);
    2702        
    2703         if (_data == NULL) {
     3094                arg_data = malloc(size);
     3095       
     3096        if (arg_data == NULL) {
    27043097                ipc_answer_0(callid, ENOMEM);
    27053098                return ENOMEM;
    27063099        }
    27073100       
    2708         int rc = async_data_write_finalize(callid, _data, size);
     3101        int rc = async_data_write_finalize(callid, arg_data, size);
    27093102        if (rc != EOK) {
    2710                 free(_data);
     3103                free(arg_data);
    27113104                return rc;
    27123105        }
    27133106       
    27143107        if (nullterm)
    2715                 ((char *) _data)[size] = 0;
    2716        
    2717         *data = _data;
     3108                ((char *) arg_data)[size] = 0;
     3109       
     3110        *data = arg_data;
    27183111        if (received != NULL)
    27193112                *received = size;
     
    28133206        }
    28143207       
     3208        sess->iface = 0;
    28153209        sess->mgmt = mgmt;
    28163210        sess->phone = phone;
     
    28623256        }
    28633257       
     3258        sess->iface = 0;
    28643259        sess->mgmt = mgmt;
    28653260        sess->phone = phone;
     
    29073302                return NULL;
    29083303       
     3304        sess->iface = 0;
    29093305        sess->mgmt = mgmt;
    29103306        sess->phone = phone;
     
    29343330{
    29353331        assert(callid);
    2936 
     3332       
    29373333        ipc_call_t call;
    29383334        *callid = async_get_call(&call);
    2939 
     3335       
    29403336        if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE)
    29413337                return false;
     
    29473343        if (arg3)
    29483344                *arg3 = IPC_GET_ARG3(call);
    2949 
     3345       
    29503346        return true;
    29513347}
  • uspace/lib/c/generic/bd.c

    r3feeab2 rff381a7  
    5757        async_exch_t *exch = async_exchange_begin(sess);
    5858       
    59         int rc = async_connect_to_me(exch, 0, 0, 0, bd_cb_conn, bd);
     59        port_id_t port;
     60        int rc = async_create_callback_port(exch, INTERFACE_BLOCK_CB, 0, 0,
     61            bd_cb_conn, bd, &port);
     62       
    6063        async_exchange_end(exch);
    6164       
  • uspace/lib/c/generic/clipboard.c

    r3feeab2 rff381a7  
    6161       
    6262        while (clip_sess == NULL)
    63                 clip_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
    64                     SERVICE_CLIPBOARD, 0, 0);
     63                clip_sess = service_connect_blocking(SERVICE_CLIPBOARD,
     64                    INTERFACE_CLIPBOARD, 0);
    6565       
    6666        fibril_mutex_unlock(&clip_mutex);
  • uspace/lib/c/generic/corecfg.c

    r3feeab2 rff381a7  
    5050                return ENOENT;
    5151
    52         corecfg_sess = loc_service_connect(EXCHANGE_SERIALIZE, corecfg_svc,
     52        corecfg_sess = loc_service_connect(corecfg_svc, INTERFACE_CORECFG,
    5353            IPC_FLAG_BLOCKING);
    5454        if (corecfg_sess == NULL)
  • uspace/lib/c/generic/devman.c

    r3feeab2 rff381a7  
    7777 *
    7878 */
    79 async_exch_t *devman_exchange_begin_blocking(devman_interface_t iface)
     79async_exch_t *devman_exchange_begin_blocking(iface_t iface)
    8080{
    8181        switch (iface) {
    82         case DEVMAN_DRIVER:
     82        case INTERFACE_DDF_DRIVER:
    8383                fibril_mutex_lock(&devman_driver_block_mutex);
    8484               
     
    8989                        if (devman_driver_block_sess == NULL)
    9090                                devman_driver_block_sess =
    91                                     service_connect_blocking(EXCHANGE_PARALLEL,
    92                                     SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
     91                                    service_connect_blocking(SERVICE_DEVMAN,
     92                                    INTERFACE_DDF_DRIVER, 0);
    9393                }
    9494               
     
    9999               
    100100                return async_exchange_begin(devman_driver_block_sess);
    101         case DEVMAN_CLIENT:
     101        case INTERFACE_DDF_CLIENT:
    102102                fibril_mutex_lock(&devman_client_block_mutex);
    103103               
     
    108108                        if (devman_client_block_sess == NULL)
    109109                                devman_client_block_sess =
    110                                     service_connect_blocking(EXCHANGE_SERIALIZE,
    111                                     SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
     110                                    service_connect_blocking(SERVICE_DEVMAN,
     111                                    INTERFACE_DDF_CLIENT, 0);
    112112                }
    113113               
     
    130130 *
    131131 */
    132 async_exch_t *devman_exchange_begin(devman_interface_t iface)
     132async_exch_t *devman_exchange_begin(iface_t iface)
    133133{
    134134        switch (iface) {
    135         case DEVMAN_DRIVER:
     135        case INTERFACE_DDF_DRIVER:
    136136                fibril_mutex_lock(&devman_driver_mutex);
    137137               
    138138                if (devman_driver_sess == NULL)
    139139                        devman_driver_sess =
    140                             service_connect(EXCHANGE_PARALLEL, SERVICE_DEVMAN,
    141                             DEVMAN_DRIVER, 0);
     140                            service_connect(SERVICE_DEVMAN,
     141                            INTERFACE_DDF_DRIVER, 0);
    142142               
    143143                fibril_mutex_unlock(&devman_driver_mutex);
     
    147147               
    148148                return async_exchange_begin(devman_driver_sess);
    149         case DEVMAN_CLIENT:
     149        case INTERFACE_DDF_CLIENT:
    150150                fibril_mutex_lock(&devman_client_mutex);
    151151               
    152152                if (devman_client_sess == NULL)
    153153                        devman_client_sess =
    154                             service_connect(EXCHANGE_SERIALIZE, SERVICE_DEVMAN,
    155                             DEVMAN_CLIENT, 0);
     154                            service_connect(SERVICE_DEVMAN,
     155                            INTERFACE_DDF_CLIENT, 0);
    156156               
    157157                fibril_mutex_unlock(&devman_client_mutex);
     
    179179int devman_driver_register(const char *name)
    180180{
    181         async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
     181        async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER);
    182182       
    183183        ipc_call_t answer;
     
    192192        }
    193193       
    194         exch = devman_exchange_begin(DEVMAN_DRIVER);
    195         async_connect_to_me(exch, 0, 0, 0, NULL, NULL);
     194        exch = devman_exchange_begin(INTERFACE_DDF_DRIVER);
     195        async_connect_to_me(exch, 0, 0, 0);
    196196        devman_exchange_end(exch);
    197197       
     
    217217    match_id_list_t *match_ids, devman_handle_t devh, devman_handle_t *funh)
    218218{
    219         int match_count = list_count(&match_ids->ids);
    220         async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
     219        unsigned long match_count = list_count(&match_ids->ids);
     220        async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER);
    221221       
    222222        ipc_call_t answer;
     
    268268    const char *cat_name)
    269269{
    270         async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
     270        async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER);
    271271       
    272272        ipc_call_t answer;
     
    287287}
    288288
    289 async_sess_t *devman_device_connect(exch_mgmt_t mgmt, devman_handle_t handle,
    290     unsigned int flags)
     289async_sess_t *devman_device_connect(devman_handle_t handle, unsigned int flags)
    291290{
    292291        async_sess_t *sess;
    293292       
    294293        if (flags & IPC_FLAG_BLOCKING)
    295                 sess = service_connect_blocking(mgmt, SERVICE_DEVMAN,
    296                             DEVMAN_CONNECT_TO_DEVICE, handle);
     294                sess = service_connect_blocking(SERVICE_DEVMAN,
     295                    INTERFACE_DEVMAN_DEVICE, handle);
    297296        else
    298                 sess = service_connect(mgmt, SERVICE_DEVMAN,
    299                             DEVMAN_CONNECT_TO_DEVICE, handle);
     297                sess = service_connect(SERVICE_DEVMAN,
     298                    INTERFACE_DEVMAN_DEVICE, handle);
    300299       
    301300        return sess;
     
    314313        sysarg_t retval;
    315314       
    316         exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
     315        exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER);
    317316        retval = async_req_1_0(exch, DEVMAN_REMOVE_FUNCTION, (sysarg_t) funh);
    318317        devman_exchange_end(exch);
     
    323322int devman_drv_fun_online(devman_handle_t funh)
    324323{
    325         async_exch_t *exch = devman_exchange_begin(DEVMAN_DRIVER);
     324        async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_DRIVER);
    326325        if (exch == NULL)
    327326                return ENOMEM;
     
    335334int devman_drv_fun_offline(devman_handle_t funh)
    336335{
    337         async_exch_t *exch = devman_exchange_begin(DEVMAN_DRIVER);
     336        async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_DRIVER);
    338337        if (exch == NULL)
    339338                return ENOMEM;
     
    345344}
    346345
    347 async_sess_t *devman_parent_device_connect(exch_mgmt_t mgmt,
    348     devman_handle_t handle, unsigned int flags)
     346async_sess_t *devman_parent_device_connect(devman_handle_t handle,
     347    unsigned int flags)
    349348{
    350349        async_sess_t *sess;
    351350       
    352351        if (flags & IPC_FLAG_BLOCKING)
    353                 sess = service_connect_blocking(mgmt, SERVICE_DEVMAN,
    354                             DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);
     352                sess = service_connect_blocking(SERVICE_DEVMAN,
     353                    INTERFACE_DEVMAN_PARENT, handle);
    355354        else
    356                 sess = service_connect(mgmt, SERVICE_DEVMAN,
    357                             DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);
     355                sess = service_connect_blocking(SERVICE_DEVMAN,
     356                    INTERFACE_DEVMAN_PARENT, handle);
    358357       
    359358        return sess;
     
    366365       
    367366        if (flags & IPC_FLAG_BLOCKING)
    368                 exch = devman_exchange_begin_blocking(DEVMAN_CLIENT);
     367                exch = devman_exchange_begin_blocking(INTERFACE_DDF_CLIENT);
    369368        else {
    370                 exch = devman_exchange_begin(DEVMAN_CLIENT);
     369                exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
    371370                if (exch == NULL)
    372371                        return ENOMEM;
     
    409408        sysarg_t dretval;
    410409       
    411         exch = devman_exchange_begin_blocking(DEVMAN_CLIENT);
     410        exch = devman_exchange_begin_blocking(INTERFACE_DDF_CLIENT);
    412411       
    413412        ipc_call_t answer;
     
    474473int devman_fun_online(devman_handle_t funh)
    475474{
    476         async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     475        async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
    477476        if (exch == NULL)
    478477                return ENOMEM;
     
    486485int devman_fun_offline(devman_handle_t funh)
    487486{
    488         async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     487        async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
    489488        if (exch == NULL)
    490489                return ENOMEM;
     
    499498    devman_handle_t *handle_buf, size_t buf_size, size_t *act_size)
    500499{
    501         async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_CLIENT);
     500        async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_CLIENT);
    502501
    503502        ipc_call_t answer;
     
    578577int devman_fun_get_child(devman_handle_t funh, devman_handle_t *devh)
    579578{
    580         async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     579        async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
    581580        if (exch == NULL)
    582581                return ENOMEM;
     
    598597int devman_dev_get_parent(devman_handle_t devh, devman_handle_t *funh)
    599598{
    600         async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     599        async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
    601600        if (exch == NULL)
    602601                return ENOMEM;
     
    611610int devman_fun_sid_to_handle(service_id_t sid, devman_handle_t *handle)
    612611{
    613         async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     612        async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
    614613        if (exch == NULL)
    615614                return ENOMEM;
     
    639638        async_exch_t *exch;
    640639
    641         exch = devman_exchange_begin(DEVMAN_CLIENT);
     640        exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
    642641        if (exch == NULL)
    643642                return ENOMEM;
     
    694693{
    695694        sysarg_t state;
    696         async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     695        async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
    697696        if (exch == NULL)
    698697                return ENOMEM;
     
    711710int devman_driver_load(devman_handle_t drvh)
    712711{
    713         async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     712        async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
    714713        if (exch == NULL)
    715714                return ENOMEM;
  • uspace/lib/c/generic/dhcp.c

    r3feeab2 rff381a7  
    5656                return ENOENT;
    5757
    58         dhcp_sess = loc_service_connect(EXCHANGE_SERIALIZE, dhcp_svc,
     58        dhcp_sess = loc_service_connect(dhcp_svc, INTERFACE_DHCP,
    5959            IPC_FLAG_BLOCKING);
    6060        if (dhcp_sess == NULL)
  • uspace/lib/c/generic/dnsr.c

    r3feeab2 rff381a7  
    5252                    IPC_FLAG_BLOCKING);
    5353               
    54                 dnsr_sess = loc_service_connect(EXCHANGE_SERIALIZE, dnsr_svc,
     54                dnsr_sess = loc_service_connect(dnsr_svc, INTERFACE_DNSR,
    5555                    IPC_FLAG_BLOCKING);
    5656        }
  • uspace/lib/c/generic/elf/elf_load.c

    r3feeab2 rff381a7  
    9797        int fd;
    9898        int rc;
    99        
     99
    100100        fd = open(file_name, O_RDONLY);
    101101        if (fd < 0) {
     
    147147        int i, rc;
    148148
    149         rc = read_all(elf->fd, header, sizeof(elf_header_t));
     149        rc = read(elf->fd, header, sizeof(elf_header_t));
    150150        if (rc != sizeof(elf_header_t)) {
    151151                DPRINTF("Read error.\n");
     
    209209                        + i * sizeof(elf_segment_header_t), SEEK_SET);
    210210
    211                 rc = read_all(elf->fd, &segment_hdr,
     211                rc = read(elf->fd, &segment_hdr,
    212212                    sizeof(elf_segment_header_t));
    213213                if (rc != sizeof(elf_segment_header_t)) {
     
    231231                    + i * sizeof(elf_section_header_t), SEEK_SET);
    232232
    233                 rc = read_all(elf->fd, &section_hdr,
     233                rc = read(elf->fd, &section_hdr,
    234234                    sizeof(elf_section_header_t));
    235235                if (rc != sizeof(elf_section_header_t)) {
     
    399399                if (now > left) now = left;
    400400
    401                 rc = read_all(elf->fd, dp, now);
     401                rc = read(elf->fd, dp, now);
    402402
    403403                if (rc != (ssize_t) now) {
  • uspace/lib/c/generic/inet.c

    r3feeab2 rff381a7  
    4848        ipc_call_t answer;
    4949        aid_t req = async_send_0(exch, INET_CALLBACK_CREATE, &answer);
    50         int rc = async_connect_to_me(exch, 0, 0, 0, inet_cb_conn, NULL);
     50       
     51        port_id_t port;
     52        int rc = async_create_callback_port(exch, INTERFACE_INET_CB, 0, 0,
     53            inet_cb_conn, NULL, &port);
     54       
    5155        async_exchange_end(exch);
    5256       
     
    8387                return ENOENT;
    8488       
    85         inet_sess = loc_service_connect(EXCHANGE_SERIALIZE, inet_svc,
     89        inet_sess = loc_service_connect(inet_svc, INTERFACE_INET,
    8690            IPC_FLAG_BLOCKING);
    8791        if (inet_sess == NULL)
  • uspace/lib/c/generic/inet/addr.c

    r3feeab2 rff381a7  
    306306                i++;
    307307
    308                 if (*cur == '\0')
     308                if (*cur == '\0' || *cur == '/')
    309309                        break;
    310310
     
    317317
    318318        if (prefix != NULL) {
     319                if (*cur != '/')
     320                        return EINVAL;
     321                cur++;
     322
    319323                *prefix = strtoul(cur, &cur, 10);
    320324                if (*prefix > 32)
  • uspace/lib/c/generic/inet/endpoint.c

    r3feeab2 rff381a7  
    3636#include <mem.h>
    3737
     38/** Initialize endpoint structure.
     39 *
     40 * Sets any address, any port number.
     41 *
     42 * @param ep Endpoint
     43 */
    3844void inet_ep_init(inet_ep_t *ep)
    3945{
     
    4147}
    4248
     49/** Initialize endpoint pair structure.
     50 *
     51 * Sets any address, any port number for both local and remote sides.
     52 *
     53 * @param ep2 Endpoint pair
     54 */
    4355void inet_ep2_init(inet_ep2_t *ep2)
    4456{
  • uspace/lib/c/generic/inet/tcp.c

    r3feeab2 rff381a7  
    4444static int tcp_conn_fibril(void *);
    4545
    46 /** Incoming TCP connection info */
     46/** Incoming TCP connection info
     47 *
     48 * Used to pass information about incoming TCP connection to the connection
     49 * fibril
     50 */
    4751typedef struct {
     52        /** Listener who received the connection */
    4853        tcp_listener_t *lst;
     54        /** Incoming connection */
    4955        tcp_conn_t *conn;
    5056} tcp_in_conn_t;
    5157
     58/** Create callback connection from TCP service.
     59 *
     60 * @param tcp TCP service
     61 * @return EOK on success or negative error code
     62 */
    5263static int tcp_callback_create(tcp_t *tcp)
    5364{
     
    5566
    5667        aid_t req = async_send_0(exch, TCP_CALLBACK_CREATE, NULL);
    57         int rc = async_connect_to_me(exch, 0, 0, 0, tcp_cb_conn, tcp);
     68       
     69        port_id_t port;
     70        int rc = async_create_callback_port(exch, INTERFACE_TCP_CB, 0, 0,
     71            tcp_cb_conn, tcp, &port);
     72       
    5873        async_exchange_end(exch);
    5974
     
    6782}
    6883
     84/** Create TCP client instance.
     85 *
     86 * @param  rtcp Place to store pointer to new TCP client
     87 * @return EOK on success, ENOMEM if out of memory, EIO if service
     88 *         cannot be contacted
     89 */
    6990int tcp_create(tcp_t **rtcp)
    7091{
     
    91112        }
    92113
    93         tcp->sess = loc_service_connect(EXCHANGE_SERIALIZE, tcp_svcid,
     114        tcp->sess = loc_service_connect(tcp_svcid, INTERFACE_TCP,
    94115            IPC_FLAG_BLOCKING);
    95116        if (tcp->sess == NULL) {
     
    111132}
    112133
     134/** Destroy TCP client instance.
     135 *
     136 * @param tcp TCP client
     137 */
    113138void tcp_destroy(tcp_t *tcp)
    114139{
     
    126151}
    127152
     153/** Create new TCP connection
     154 *
     155 * @param tcp   TCP client instance
     156 * @param id    Connection ID
     157 * @param cb    Callbacks
     158 * @param arg   Callback argument
     159 * @param rconn Place to store pointer to new connection
     160 *
     161 * @return EOK on success, ENOMEM if out of memory
     162 */
    128163static int tcp_conn_new(tcp_t *tcp, sysarg_t id, tcp_cb_t *cb, void *arg,
    129164    tcp_conn_t **rconn)
     
    150185}
    151186
     187/** Create new TCP connection.
     188 *
     189 * Open a connection to the specified destination. This function returns
     190 * even before the connection is established (or not). When the connection
     191 * is established, @a cb->connected is called. If the connection fails,
     192 * @a cb->conn_failed is called. Alternatively, the caller can call
     193 * @c tcp_conn_wait_connected() to wait for connection to complete or fail.
     194 * Other callbacks are available to monitor the changes in connection state.
     195 *
     196 * @a epp must specify the remote address and port. Both local address and
     197 * port are optional. If local address is not specified, address selection
     198 * will take place. If local port number is not specified, a suitable
     199 * free dynamic port number will be allocated.
     200 *
     201 * @param tcp   TCP client
     202 * @param epp   Internet endpoint pair
     203 * @param cb    Callbacks
     204 * @param arg   Argument to callbacks
     205 * @param rconn Place to store pointer to new connection
     206 *
     207 * @return EOK on success or negative error code.
     208 */
    152209int tcp_conn_create(tcp_t *tcp, inet_ep2_t *epp, tcp_cb_t *cb, void *arg,
    153210    tcp_conn_t **rconn)
     
    186243}
    187244
     245/** Destroy TCP connection.
     246 *
     247 * Destroy TCP connection. The caller should destroy all connections
     248 * he created before destroying the TCP client and before terminating.
     249 *
     250 * @param conn TCP connection
     251 */
    188252void tcp_conn_destroy(tcp_conn_t *conn)
    189253{
     
    203267}
    204268
     269/** Get connection based on its ID.
     270 *
     271 * @param tcp   TCP client
     272 * @param id    Connection ID
     273 * @param rconn Place to store pointer to connection
     274 *
     275 * @return EOK on success, EINVAL if no connection with the given ID exists
     276 */
    205277static int tcp_conn_get(tcp_t *tcp, sysarg_t id, tcp_conn_t **rconn)
    206278{
     
    215287}
    216288
     289/** Get the user/callback argument for a connection.
     290 *
     291 * @param conn TCP connection
     292 * @return User argument associated with connection
     293 */
    217294void *tcp_conn_userptr(tcp_conn_t *conn)
    218295{
     
    220297}
    221298
     299/** Create a TCP connection listener.
     300 *
     301 * A listener listens for connections on the set of endpoints specified
     302 * by @a ep. Each time a new incoming connection is established,
     303 * @a lcb->new_conn is called (and passed @a larg). Also, the new connection
     304 * will have callbacks set to @a cb and argument to @a arg.
     305 *
     306 * @a ep must specify a valid port number. @a ep may specify an address
     307 * or link to listen on. If it does not, the listener will listen on
     308 * all links/addresses.
     309 *
     310 * @param tcp  TCP client
     311 * @param ep   Internet endpoint
     312 * @param lcb  Listener callbacks
     313 * @param larg Listener callback argument
     314 * @param cb   Connection callbacks for every new connection
     315 * @param arg  Connection argument for every new connection
     316 * @param rlst Place to store pointer to new listener
     317 *
     318 * @return EOK on success or negative error code
     319 */
    222320int tcp_listener_create(tcp_t *tcp, inet_ep_t *ep, tcp_listen_cb_t *lcb,
    223321    void *larg, tcp_cb_t *cb, void *arg, tcp_listener_t **rlst)
     
    265363}
    266364
     365/** Destroy TCP connection listener.
     366 *
     367 * @param lst Listener
     368 */
    267369void tcp_listener_destroy(tcp_listener_t *lst)
    268370{
     
    282384}
    283385
     386/** Get TCP connection listener based on its ID.
     387 *
     388 * @param tcp TCP client
     389 * @param id  Listener ID
     390 * @param rlst Place to store pointer to listener
     391 *
     392 * @return EOK on success, EINVAL if no listener with the given ID is found
     393 */
    284394static int tcp_listener_get(tcp_t *tcp, sysarg_t id, tcp_listener_t **rlst)
    285395{
     
    294404}
    295405
     406/** Get callback/user argument associated with listener.
     407 *
     408 * @param lst Listener
     409 * @return Callback/user argument
     410 */
    296411void *tcp_listener_userptr(tcp_listener_t *lst)
    297412{
     
    299414}
    300415
     416/** Wait until connection is either established or connection fails.
     417 *
     418 * Can be called after calling tcp_conn_create() to block until connection
     419 * either completes or fails. If the connection fails, EIO is returned.
     420 * In this case the connection still exists, but is in a failed
     421 * state.
     422 *
     423 * @param conn Connection
     424 * @return EOK if connection is established, EIO otherwise
     425 */
    301426int tcp_conn_wait_connected(tcp_conn_t *conn)
    302427{
     
    315440}
    316441
     442/** Send data over TCP connection.
     443 *
     444 * @param conn  Connection
     445 * @param data  Data
     446 * @param bytes Data size in bytes
     447 *
     448 * @return EOK on success or negative error code
     449 */
    317450int tcp_conn_send(tcp_conn_t *conn, const void *data, size_t bytes)
    318451{
     
    340473}
    341474
    342 
     475/** Send FIN.
     476 *
     477 * Send FIN, indicating no more data will be send over the connection.
     478 *
     479 * @param conn Connection
     480 * @return EOK on success or negative error code
     481 */
    343482int tcp_conn_send_fin(tcp_conn_t *conn)
    344483{
     
    352491}
    353492
     493/** Push connection.
     494 *
     495 * @param conn Connection
     496 * @return EOK on success or negative error code
     497 */
    354498int tcp_conn_push(tcp_conn_t *conn)
    355499{
     
    363507}
    364508
     509/** Reset connection.
     510 *
     511 * @param conn Connection
     512 * @return EOK on success or negative error code
     513 */
    365514int tcp_conn_reset(tcp_conn_t *conn)
    366515{
     
    374523}
    375524
     525/** Read received data from connection without blocking.
     526 *
     527 * If any received data is pending on the connection, up to @a bsize bytes
     528 * are copied to @a buf and the acutal number is stored in @a *nrecv.
     529 * The entire buffer of @a bsize bytes is filled except when less data
     530 * is currently available or FIN is received. EOK is returned.
     531 *
     532 * If no received data is pending, returns EAGAIN.
     533 *
     534 * @param conn Connection
     535 * @param buf  Buffer
     536 * @param bsize Buffer size
     537 * @param nrecv Place to store actual number of received bytes
     538 *
     539 * @return EOK on success, EAGAIN if no received data is pending, or other
     540 *         negative error code in case of other error
     541 */
    376542int tcp_conn_recv(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv)
    377543{
     
    408574}
    409575
    410 int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv)
     576/** Read received data from connection with blocking.
     577 *
     578 * Wait for @a bsize bytes of data to be received and copy them to
     579 * @a buf. Less data may be returned if FIN is received on the connection.
     580 * The actual If any received data is written to @a *nrecv and EOK
     581 * is returned on success.
     582 *
     583 * @param conn Connection
     584 * @param buf  Buffer
     585 * @param bsize Buffer size
     586 * @param nrecv Place to store actual number of received bytes
     587 *
     588 * @return EOK on success or negative error code
     589 */
     590int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize,
     591    size_t *nrecv)
    411592{
    412593        async_exch_t *exch;
     
    450631}
    451632
     633/** Connection established event.
     634 *
     635 * @param tcp TCP client
     636 * @param iid Call ID
     637 * @param icall Call data
     638 */
    452639static void tcp_ev_connected(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    453640{
     
    472659}
    473660
     661/** Connection failed event.
     662 *
     663 * @param tcp TCP client
     664 * @param iid Call ID
     665 * @param icall Call data
     666 */
    474667static void tcp_ev_conn_failed(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    475668{
     
    494687}
    495688
     689/** Connection reset event.
     690 *
     691 * @param tcp TCP client
     692 * @param iid Call ID
     693 * @param icall Call data
     694 */
    496695static void tcp_ev_conn_reset(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    497696{
     
    516715}
    517716
     717/** Data available event.
     718 *
     719 * @param tcp TCP client
     720 * @param iid Call ID
     721 * @param icall Call data
     722 */
    518723static void tcp_ev_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    519724{
     
    539744}
    540745
     746/** Urgent data event.
     747 *
     748 * @param tcp TCP client
     749 * @param iid Call ID
     750 * @param icall Call data
     751 */
    541752static void tcp_ev_urg_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    542753{
     
    544755}
    545756
     757/** New connection event.
     758 *
     759 * @param tcp TCP client
     760 * @param iid Call ID
     761 * @param icall Call data
     762 */
    546763static void tcp_ev_new_conn(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
    547764{
     
    590807}
    591808
     809/** Callback connection handler.
     810 *
     811 * @param iid Connect call ID
     812 * @param icall Connect call data
     813 * @param arg Argument, TCP client
     814 */
    592815static void tcp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    593816{
     
    636859}
    637860
    638 /** Fibril for handling incoming TCP connection in background */
     861/** Fibril for handling incoming TCP connection in background.
     862 *
     863 * @param arg Argument, incoming connection information (@c tcp_in_conn_t)
     864 */
    639865static int tcp_conn_fibril(void *arg)
    640866{
  • uspace/lib/c/generic/inet/udp.c

    r3feeab2 rff381a7  
    4343static void udp_cb_conn(ipc_callid_t, ipc_call_t *, void *);
    4444
     45/** Create callback connection from UDP service.
     46 *
     47 * @param udp UDP service
     48 * @return EOK on success or negative error code
     49 */
    4550static int udp_callback_create(udp_t *udp)
    4651{
     
    4853
    4954        aid_t req = async_send_0(exch, UDP_CALLBACK_CREATE, NULL);
    50         int rc = async_connect_to_me(exch, 0, 0, 0, udp_cb_conn, udp);
     55       
     56        port_id_t port;
     57        int rc = async_create_callback_port(exch, INTERFACE_UDP_CB, 0, 0,
     58            udp_cb_conn, udp, &port);
     59       
    5160        async_exchange_end(exch);
    5261
     
    6069}
    6170
     71/** Create UDP client instance.
     72 *
     73 * @param  rudp Place to store pointer to new UDP client
     74 * @return EOK on success, ENOMEM if out of memory, EIO if service
     75 *         cannot be contacted
     76 */
    6277int udp_create(udp_t **rudp)
    6378{
     
    8398        }
    8499
    85         udp->sess = loc_service_connect(EXCHANGE_SERIALIZE, udp_svcid,
     100        udp->sess = loc_service_connect(udp_svcid, INTERFACE_UDP,
    86101            IPC_FLAG_BLOCKING);
    87102        if (udp->sess == NULL) {
     
    103118}
    104119
     120/** Destroy UDP client instance.
     121 *
     122 * @param udp UDP client
     123 */
    105124void udp_destroy(udp_t *udp)
    106125{
     
    118137}
    119138
    120 int udp_assoc_create(udp_t *udp, inet_ep2_t *ep2, udp_cb_t *cb, void *arg,
     139/** Create new UDP association.
     140 *
     141 * Create a UDP association that allows sending and receiving messages.
     142 *
     143 * @a epp may specify remote address and port, in which case only messages
     144 * from that remote endpoint will be received. Also, that remote endpoint
     145 * is used as default when @c NULL is passed as destination to
     146 * udp_assoc_send_msg.
     147 *
     148 * @a epp may specify a local link or address. If it does not, the association
     149 * will listen on all local links/addresses. If @a epp does not specify
     150 * a local port number, a free dynamic port number will be allocated.
     151 *
     152 * The caller is informed about incoming data by invoking @a cb->recv_msg
     153 *
     154 * @param udp    UDP client
     155 * @param epp    Internet endpoint pair
     156 * @param cb     Callbacks
     157 * @param arg    Argument to callbacks
     158 * @param rassoc Place to store pointer to new association
     159 *
     160 * @return EOK on success or negative error code.
     161 */
     162int udp_assoc_create(udp_t *udp, inet_ep2_t *epp, udp_cb_t *cb, void *arg,
    121163    udp_assoc_t **rassoc)
    122164{
     
    131173        exch = async_exchange_begin(udp->sess);
    132174        aid_t req = async_send_0(exch, UDP_ASSOC_CREATE, &answer);
    133         sysarg_t rc = async_data_write_start(exch, (void *)ep2,
     175        sysarg_t rc = async_data_write_start(exch, (void *)epp,
    134176            sizeof(inet_ep2_t));
    135177        async_exchange_end(exch);
     
    161203}
    162204
     205/** Destroy UDP association.
     206 *
     207 * Destroy UDP association. The caller should destroy all associations
     208 * he created before destroying the UDP client and before terminating.
     209 *
     210 * @param assoc UDP association
     211 */
    163212void udp_assoc_destroy(udp_assoc_t *assoc)
    164213{
     
    178227}
    179228
     229/** Send message via UDP association.
     230 *
     231 * @param assoc Association
     232 * @param dest  Destination endpoint or @c NULL to use association's remote ep.
     233 * @param data  Message data
     234 * @param bytes Message size in bytes
     235 *
     236 * @return EOK on success or negative error code
     237 */
    180238int udp_assoc_send_msg(udp_assoc_t *assoc, inet_ep_t *dest, void *data,
    181239    size_t bytes)
     
    211269}
    212270
     271/** Get the user/callback argument for an association.
     272 *
     273 * @param assoc UDP association
     274 * @return User argument associated with association
     275 */
    213276void *udp_assoc_userptr(udp_assoc_t *assoc)
    214277{
     
    216279}
    217280
     281/** Get size of received message in bytes.
     282 *
     283 * Assuming jumbo messages can be received, the caller first needs to determine
     284 * the size of the received message by calling this function, then they can
     285 * read the message piece-wise using udp_rmsg_read().
     286 *
     287 * @param rmsg Received message
     288 * @return Size of received message in bytes
     289 */
    218290size_t udp_rmsg_size(udp_rmsg_t *rmsg)
    219291{
     
    221293}
    222294
     295/** Read part of received message.
     296 *
     297 * @param rmsg  Received message
     298 * @param off   Start offset
     299 * @param buf   Buffer for storing data
     300 * @param bsize Buffer size
     301 *
     302 * @return EOK on success or negative error code.
     303 */
    223304int udp_rmsg_read(udp_rmsg_t *rmsg, size_t off, void *buf, size_t bsize)
    224305{
     
    245326}
    246327
     328/** Get remote endpoint of received message.
     329 *
     330 * Place the remote endpoint (the one from which the message was supposedly
     331 * sent) to @a ep.
     332 *
     333 * @param rmsg Received message
     334 * @param ep   Place to store remote endpoint
     335 */
    247336void udp_rmsg_remote_ep(udp_rmsg_t *rmsg, inet_ep_t *ep)
    248337{
     
    250339}
    251340
     341/** Get type of received ICMP error message.
     342 *
     343 * @param rerr Received error message
     344 * @return Error message type
     345 */
    252346uint8_t udp_rerr_type(udp_rerr_t *rerr)
    253347{
     
    255349}
    256350
     351/** Get code of received ICMP error message.
     352 *
     353 * @param rerr Received error message
     354 * @return Error message code
     355 */
    257356uint8_t udp_rerr_code(udp_rerr_t *rerr)
    258357{
     
    260359}
    261360
     361/** Get information about the next received message from UDP service.
     362 *
     363 * @param udp  UDP client
     364 * @param rmsg Place to store message information
     365 *
     366 * @return EOK on success or negative error code
     367 */
    262368static int udp_rmsg_info(udp_t *udp, udp_rmsg_t *rmsg)
    263369{
     
    288394}
    289395
     396/** Discard next received message in UDP service.
     397 *
     398 * @param udp UDP client
     399 * @return EOK on success or negative error code
     400 */
    290401static int udp_rmsg_discard(udp_t *udp)
    291402{
     
    299410}
    300411
     412/** Get association based on its ID.
     413 *
     414 * @param udp    UDP client
     415 * @param id     Association ID
     416 * @param rassoc Place to store pointer to association
     417 *
     418 * @return EOK on success, EINVAL if no association with the given ID exists
     419 */
    301420static int udp_assoc_get(udp_t *udp, sysarg_t id, udp_assoc_t **rassoc)
    302421{
     
    311430}
    312431
     432/** Handle 'data' event, i.e. some message(s) arrived.
     433 *
     434 * For each received message, get information about it, call @c recv_msg
     435 * callback and discard it.
     436 *
     437 * @param udp UDP client
     438 * @param iid IPC message ID
     439 * @param icall IPC message
     440 */
    313441static void udp_ev_data(udp_t *udp, ipc_callid_t iid, ipc_call_t *icall)
    314442{
     
    340468}
    341469
     470/** UDP service callback connection.
     471 *
     472 * @param iid Connect message ID
     473 * @param icall Connect message
     474 * @param arg Argument, UDP client
     475 */
    342476static void udp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    343477{
  • uspace/lib/c/generic/inetcfg.c

    r3feeab2 rff381a7  
    120120        assert(inetcfg_sess == NULL);
    121121       
    122         rc = loc_service_get_id(SERVICE_NAME_INETCFG, &inet_svc,
     122        rc = loc_service_get_id(SERVICE_NAME_INET, &inet_svc,
    123123            IPC_FLAG_BLOCKING);
    124124        if (rc != EOK)
    125125                return ENOENT;
    126126       
    127         inetcfg_sess = loc_service_connect(EXCHANGE_SERIALIZE, inet_svc,
     127        inetcfg_sess = loc_service_connect(inet_svc, INTERFACE_INETCFG,
    128128            IPC_FLAG_BLOCKING);
    129129        if (inetcfg_sess == NULL)
  • uspace/lib/c/generic/inetping.c

    r3feeab2 rff381a7  
    5353        inetping_ev_ops = ev_ops;
    5454
    55         rc = loc_service_get_id(SERVICE_NAME_INETPING, &inetping_svc,
     55        rc = loc_service_get_id(SERVICE_NAME_INET, &inetping_svc,
    5656            IPC_FLAG_BLOCKING);
    5757        if (rc != EOK)
    5858                return ENOENT;
    5959
    60         inetping_sess = loc_service_connect(EXCHANGE_SERIALIZE, inetping_svc,
     60        inetping_sess = loc_service_connect(inetping_svc, INTERFACE_INETPING,
    6161            IPC_FLAG_BLOCKING);
    6262        if (inetping_sess == NULL)
     
    6565        async_exch_t *exch = async_exchange_begin(inetping_sess);
    6666
    67         rc = async_connect_to_me(exch, 0, 0, 0, inetping_cb_conn, NULL);
     67        port_id_t port;
     68        rc = async_create_callback_port(exch, INTERFACE_INETPING_CB, 0, 0,
     69            inetping_cb_conn, NULL, &port);
     70       
    6871        async_exchange_end(exch);
    6972
  • uspace/lib/c/generic/io/console.c

    r3feeab2 rff381a7  
    4949                return NULL;
    5050       
    51         ctrl->input_sess = fsession(EXCHANGE_SERIALIZE, ifile);
     51        ctrl->input_sess = vfs_fsession(ifile, INTERFACE_CONSOLE);
    5252        if (!ctrl->input_sess) {
    5353                free(ctrl);
     
    5555        }
    5656       
    57         ctrl->output_sess = fsession(EXCHANGE_SERIALIZE, ofile);
     57        ctrl->output_sess = vfs_fsession(ofile, INTERFACE_CONSOLE);
    5858        if (!ctrl->output_sess) {
    5959                free(ctrl);
  • uspace/lib/c/generic/io/input.c

    r3feeab2 rff381a7  
    5858        async_exch_t *exch = async_exchange_begin(sess);
    5959
    60         int rc = async_connect_to_me(exch, 0, 0, 0, input_cb_conn, input);
     60        port_id_t port;
     61        int rc = async_create_callback_port(exch, INTERFACE_INPUT_CB, 0, 0,
     62            input_cb_conn, input, &port);
     63       
    6164        async_exchange_end(exch);
    6265
  • uspace/lib/c/generic/io/io.c

    r3feeab2 rff381a7  
    231231        if (stream->buf == NULL) {
    232232                errno = ENOMEM;
    233                 return -1;
     233                return EOF;
    234234        }
    235235       
     
    299299}
    300300
    301 int fclose(FILE *stream)
     301
     302static int _fclose_nofree(FILE *stream)
    302303{
    303304        int rc = 0;
     
    312313       
    313314        list_remove(&stream->link);
     315       
     316        if (rc != 0) {
     317                /* errno was set by close() */
     318                return EOF;
     319        }
     320       
     321        return 0;
     322}
     323
     324int fclose(FILE *stream)
     325{
     326        int rc = _fclose_nofree(stream);
    314327       
    315328        if ((stream != &stdin_null)
     
    318331                free(stream);
    319332       
    320         stream = NULL;
    321        
    322         if (rc != 0) {
    323                 /* errno was set by close() */
    324                 return EOF;
    325         }
    326        
    327         return 0;
     333        return rc;
     334}
     335
     336FILE *freopen(const char *path, const char *mode, FILE *stream)
     337{
     338        FILE *nstr;
     339       
     340        if (path == NULL) {
     341                /* Changing mode is not supported */
     342                return NULL;
     343        }
     344       
     345        (void) _fclose_nofree(stream);
     346        nstr = fopen(path, mode);
     347        if (nstr == NULL) {
     348                free(stream);
     349                return NULL;
     350        }
     351       
     352        list_remove(&nstr->link);
     353        *stream = *nstr;
     354        list_append(&stream->link, &files);
     355       
     356        free(nstr);
     357       
     358        return stream;
    328359}
    329360
     
    334365 * @param nmemb  Number of records to read.
    335366 * @param stream Pointer to the stream.
     367 *
     368 * @return Number of elements successfully read. On error this is less than
     369 *         nmemb, stream error indicator is set and errno is set.
    336370 */
    337371static size_t _fread(void *buf, size_t size, size_t nmemb, FILE *stream)
     
    348382                ssize_t rd = read(stream->fd, buf + done, left);
    349383               
    350                 if (rd < 0)
     384                if (rd < 0) {
     385                        /* errno was set by read() */
    351386                        stream->error = true;
    352                 else if (rd == 0)
     387                } else if (rd == 0) {
    353388                        stream->eof = true;
    354                 else {
     389                } else {
    355390                        left -= rd;
    356391                        done += rd;
     
    367402 * @param nmemb  Number of records to write.
    368403 * @param stream Pointer to the stream.
     404 *
     405 * @return Number of elements successfully written. On error this is less than
     406 *         nmemb, stream error indicator is set and errno is set.
    369407 */
    370408static size_t _fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream)
     
    372410        size_t left;
    373411        size_t done;
     412        int rc;
    374413
    375414        if (size == 0 || nmemb == 0)
     
    381420        while ((left > 0) && (!stream->error)) {
    382421                ssize_t wr;
     422                size_t uwr;
    383423               
    384                 if (stream->kio)
    385                         wr = kio_write(buf + done, left);
    386                 else
     424                if (stream->kio) {
     425                        uwr = 0;
     426                        rc = kio_write(buf + done, left, &uwr);
     427                        if (rc != EOK)
     428                                errno = rc;
     429                } else {
    387430                        wr = write(stream->fd, buf + done, left);
     431                        if (wr >= 0) {
     432                                uwr = (size_t)wr;
     433                                rc = EOK;
     434                        } else {
     435                                /* errno was set by write */
     436                                uwr = 0;
     437                                rc = errno;
     438                        }
     439                }
    388440               
    389                 if (wr <= 0)
     441                if (rc != EOK) {
     442                        /* errno was set above */
    390443                        stream->error = true;
    391                 else {
    392                         left -= wr;
    393                         done += wr;
     444                } else {
     445                        left -= uwr;
     446                        done += uwr;
    394447                }
    395448        }
     
    401454}
    402455
    403 /** Read some data in stream buffer. */
     456/** Read some data in stream buffer.
     457 *
     458 * On error, stream error indicator is set and errno is set.
     459 */
    404460static void _ffillbuf(FILE *stream)
    405461{
     
    410466        rc = read(stream->fd, stream->buf, stream->buf_size);
    411467        if (rc < 0) {
     468                /* errno was set by read() */
    412469                stream->error = true;
    413470                return;
     
    434491
    435492        /* If buffer has prefetched read data, we need to seek back. */
    436         if (bytes_used > 0 && stream->buf_state == _bs_read)
    437                 lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR);
     493        if (bytes_used > 0 && stream->buf_state == _bs_read) {
     494                off64_t rc;
     495                rc = lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR);
     496                if (rc == (off64_t)-1) {
     497                        /* errno was set by lseek */
     498                        stream->error = 1;
     499                        return;
     500                }
     501        }
    438502
    439503        /* If buffer has unwritten data, we need to write them out. */
    440         if (bytes_used > 0 && stream->buf_state == _bs_write)
     504        if (bytes_used > 0 && stream->buf_state == _bs_write) {
    441505                (void) _fwrite(stream->buf_tail, 1, bytes_used, stream);
     506                /* On error stream error indicator and errno are set by _fwrite */
     507                if (stream->error)
     508                        return;
     509        }
    442510
    443511        stream->buf_head = stream->buf;
     
    466534                return 0;
    467535
     536        bytes_left = size * nmemb;
     537        total_read = 0;
     538        dp = (uint8_t *) dest;
     539
     540        /* Bytes from ungetc() buffer */
     541        while (stream->ungetc_chars > 0 && bytes_left > 0) {
     542                *dp++ = stream->ungetc_buf[--stream->ungetc_chars];
     543                ++total_read;
     544                --bytes_left;
     545        }
     546
    468547        /* If not buffered stream, read in directly. */
    469548        if (stream->btype == _IONBF) {
    470                 now = _fread(dest, size, nmemb, stream);
    471                 return now;
     549                total_read += _fread(dest, 1, bytes_left, stream);
     550                return total_read / size;
    472551        }
    473552
     
    482561        }
    483562
    484         bytes_left = size * nmemb;
    485         total_read = 0;
    486         dp = (uint8_t *) dest;
    487 
    488563        while ((!stream->error) && (!stream->eof) && (bytes_left > 0)) {
    489564                if (stream->buf_head == stream->buf_tail)
    490565                        _ffillbuf(stream);
    491566
    492                 if (stream->error || stream->eof)
     567                if (stream->error || stream->eof) {
     568                        /* On error errno was set by _ffillbuf() */
    493569                        break;
     570                }
    494571
    495572                data_avail = stream->buf_head - stream->buf_tail;
     
    546623        if (stream->buf_state == _bs_read)
    547624                _fflushbuf(stream);
    548 
    549625
    550626        /* Perform lazy allocation of stream buffer. */
     
    584660                        /* Only need to drain buffer. */
    585661                        _fflushbuf(stream);
    586                         need_flush = false;
     662                        if (!stream->error)
     663                                need_flush = false;
    587664                }
    588665        }
     
    618695int fputs(const char *str, FILE *stream)
    619696{
    620         return fwrite(str, str_size(str), 1, stream);
     697        (void) fwrite(str, str_size(str), 1, stream);
     698        if (ferror(stream))
     699                return EOF;
     700        return 0;
    621701}
    622702
     
    674754}
    675755
     756int ungetc(int c, FILE *stream)
     757{
     758        if (c == EOF)
     759                return EOF;
     760
     761        if (stream->ungetc_chars >= UNGETC_MAX)
     762                return EOF;
     763
     764        stream->ungetc_buf[stream->ungetc_chars++] =
     765            (uint8_t)c;
     766
     767        stream->eof = false;
     768        return (uint8_t)c;
     769}
     770
    676771int fseek(FILE *stream, off64_t offset, int whence)
    677772{
    678773        off64_t rc;
    679774
     775        if (stream->error)
     776                return EOF;
     777
    680778        _fflushbuf(stream);
     779        if (stream->error) {
     780                /* errno was set by _fflushbuf() */
     781                return EOF;
     782        }
     783
     784        stream->ungetc_chars = 0;
    681785
    682786        rc = lseek(stream->fd, offset, whence);
    683787        if (rc == (off64_t) (-1)) {
    684                 /* errno has been set by lseek64. */
    685                 return -1;
     788                /* errno has been set by lseek() */
     789                return EOF;
    686790        }
    687791
     
    692796off64_t ftell(FILE *stream)
    693797{
     798        off64_t pos;
     799       
     800        if (stream->error)
     801                return EOF;
     802       
    694803        _fflushbuf(stream);
    695         return lseek(stream->fd, 0, SEEK_CUR);
     804        if (stream->error) {
     805                /* errno was set by _fflushbuf() */
     806                return EOF;
     807        }
     808
     809        pos = lseek(stream->fd, 0, SEEK_CUR);
     810        if (pos == (off64_t) -1) {
     811                /* errno was set by lseek */
     812                return (off64_t) -1;
     813        }
     814       
     815        return pos - stream->ungetc_chars;
    696816}
    697817
     
    703823int fflush(FILE *stream)
    704824{
     825        if (stream->error)
     826                return EOF;
     827       
    705828        _fflushbuf(stream);
     829        if (stream->error) {
     830                /* errno was set by _fflushbuf() */
     831                return EOF;
     832        }
    706833       
    707834        if (stream->kio) {
    708835                kio_update();
    709                 return EOK;
     836                return 0;
    710837        }
    711838       
     
    716843                 */
    717844                stream->need_sync = false;
    718                 return fsync(stream->fd);
    719         }
    720        
    721         return ENOENT;
     845                if (fsync(stream->fd) != 0) {
     846                        /* errno was set by fsync() */
     847                        return EOF;
     848                }
     849
     850                return 0;
     851        }
     852       
     853        return 0;
    722854}
    723855
     
    742874        if (stream->kio) {
    743875                errno = EBADF;
    744                 return -1;
     876                return EOF;
    745877        }
    746878       
     
    748880}
    749881
    750 async_sess_t *fsession(exch_mgmt_t mgmt, FILE *stream)
     882async_sess_t *vfs_fsession(FILE *stream, iface_t iface)
    751883{
    752884        if (stream->fd >= 0) {
    753885                if (stream->sess == NULL)
    754                         stream->sess = fd_session(mgmt, stream->fd);
     886                        stream->sess = vfs_fd_session(stream->fd, iface);
    755887               
    756888                return stream->sess;
     
    760892}
    761893
    762 int fhandle(FILE *stream, int *handle)
     894int vfs_fhandle(FILE *stream, int *handle)
    763895{
    764896        if (stream->fd >= 0) {
  • uspace/lib/c/generic/io/kio.c

    r3feeab2 rff381a7  
    4343#include <io/printf_core.h>
    4444
    45 size_t kio_write(const void *buf, size_t size)
     45int kio_write(const void *buf, size_t size, size_t *nwritten)
    4646{
    47         ssize_t ret = (ssize_t) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) buf, size);
     47        int rc = (int) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) buf, size);
    4848       
    49         if (ret >= 0)
    50                 return (size_t) ret;
    51        
    52         return 0;
     49        if (rc == EOK)
     50                *nwritten = size;
     51        return rc;
    5352}
    5453
     
    8483static int kio_vprintf_str_write(const char *str, size_t size, void *data)
    8584{
    86         size_t wr = kio_write(str, size);
     85        size_t wr;
     86       
     87        wr = 0;
     88        (void) kio_write(str, size, &wr);
    8789        return str_nlength(str, wr);
    8890}
     
    9294        size_t offset = 0;
    9395        size_t chars = 0;
     96        size_t wr;
    9497       
    9598        while (offset < size) {
     
    98101               
    99102                if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK)
    100                         kio_write(buf, sz);
     103                        kio_write(buf, sz, &wr);
    101104               
    102105                chars++;
  • uspace/lib/c/generic/io/log.c

    r3feeab2 rff381a7  
    166166                return ENOMEM;
    167167
    168         logger_session = service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_LOGGER, LOGGER_INTERFACE_WRITER, 0);
     168        logger_session = service_connect_blocking(SERVICE_LOGGER,
     169            INTERFACE_LOGGER_WRITER, 0);
    169170        if (logger_session == NULL) {
    170171                return ENOMEM;
  • uspace/lib/c/generic/io/logctl.c

    r3feeab2 rff381a7  
    4848
    4949        if (logger_session == NULL) {
    50                 logger_session = service_connect_blocking(EXCHANGE_SERIALIZE,
    51                     SERVICE_LOGGER, LOGGER_INTERFACE_CONTROL, 0);
     50                logger_session = service_connect_blocking(SERVICE_LOGGER,
     51                    INTERFACE_LOGGER_CONTROL, 0);
    5252                if (logger_session == NULL)
    5353                        return ENOMEM;
  • uspace/lib/c/generic/iplink.c

    r3feeab2 rff381a7  
    5959       
    6060        async_exch_t *exch = async_exchange_begin(sess);
    61        
    62         int rc = async_connect_to_me(exch, 0, 0, 0, iplink_cb_conn, iplink);
     61
     62        port_id_t port;
     63        int rc = async_create_callback_port(exch, INTERFACE_IPLINK_CB, 0, 0,
     64            iplink_cb_conn, iplink, &port);
     65       
    6366        async_exchange_end(exch);
    6467       
  • uspace/lib/c/generic/irc.c

    r3feeab2 rff381a7  
    5151        assert(irc_sess == NULL);
    5252
    53         irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
    54             SERVICE_IRC, 0, 0);
     53        irc_sess = service_connect_blocking(SERVICE_IRC, INTERFACE_IRC, 0);
    5554
    5655        if (irc_sess == NULL)
  • uspace/lib/c/generic/loader.c

    r3feeab2 rff381a7  
    6969       
    7070        async_sess_t *sess =
    71             service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_LOAD, 0, 0);
     71            service_connect_blocking(SERVICE_LOADER, INTERFACE_LOADER, 0);
    7272        if (sess == NULL) {
    7373                free(ldr);
     
    124124                return ENOMEM;
    125125       
    126         if (!getcwd(cwd, MAX_PATH_LEN + 1))
     126        if (getcwd(cwd, MAX_PATH_LEN + 1) == NULL)
    127127                str_cpy(cwd, MAX_PATH_LEN + 1, "/");
    128128       
     
    162162{
    163163        size_t pa_len;
    164         char *pa = absolutize(path, &pa_len);
     164        char *pa = vfs_absolutize(path, &pa_len);
    165165        if (!pa)
    166166                return ENOMEM;
  • uspace/lib/c/generic/loc.c

    r3feeab2 rff381a7  
    107107        if (!loc_callback_created) {
    108108                async_exch_t *exch =
    109                     loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     109                    loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    110110               
    111111                ipc_call_t answer;
    112112                aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer);
    113                 int rc = async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
     113               
     114                port_id_t port;
     115                int rc = async_create_callback_port(exch, INTERFACE_LOC_CB, 0, 0,
     116                    loc_cb_conn, NULL, &port);
     117               
    114118                loc_exchange_end(exch);
    115119               
     
    135139 *
    136140 */
    137 async_exch_t *loc_exchange_begin_blocking(loc_interface_t iface)
     141async_exch_t *loc_exchange_begin_blocking(iface_t iface)
    138142{
    139143        switch (iface) {
    140         case LOC_PORT_SUPPLIER:
     144        case INTERFACE_LOC_SUPPLIER:
    141145                fibril_mutex_lock(&loc_supp_block_mutex);
    142146               
     
    147151                        if (loc_supp_block_sess == NULL)
    148152                                loc_supp_block_sess =
    149                                     service_connect_blocking(EXCHANGE_SERIALIZE,
    150                                     SERVICE_LOC, LOC_PORT_SUPPLIER, 0);
     153                                    service_connect_blocking(SERVICE_LOC,
     154                                    INTERFACE_LOC_SUPPLIER, 0);
    151155                }
    152156               
     
    157161               
    158162                return async_exchange_begin(loc_supp_block_sess);
    159         case LOC_PORT_CONSUMER:
     163        case INTERFACE_LOC_CONSUMER:
    160164                fibril_mutex_lock(&loc_cons_block_mutex);
    161165               
     
    166170                        if (loc_cons_block_sess == NULL)
    167171                                loc_cons_block_sess =
    168                                     service_connect_blocking(EXCHANGE_SERIALIZE,
    169                                     SERVICE_LOC, LOC_PORT_CONSUMER, 0);
     172                                    service_connect_blocking(SERVICE_LOC,
     173                                    INTERFACE_LOC_CONSUMER, 0);
    170174                }
    171175               
     
    188192 *
    189193 */
    190 async_exch_t *loc_exchange_begin(loc_interface_t iface)
     194async_exch_t *loc_exchange_begin(iface_t iface)
    191195{
    192196        switch (iface) {
    193         case LOC_PORT_SUPPLIER:
     197        case INTERFACE_LOC_SUPPLIER:
    194198                fibril_mutex_lock(&loc_supplier_mutex);
    195199               
    196200                if (loc_supplier_sess == NULL)
    197201                        loc_supplier_sess =
    198                             service_connect(EXCHANGE_SERIALIZE, SERVICE_LOC,
    199                             LOC_PORT_SUPPLIER, 0);
     202                            service_connect(SERVICE_LOC,
     203                            INTERFACE_LOC_SUPPLIER, 0);
    200204               
    201205                fibril_mutex_unlock(&loc_supplier_mutex);
     
    205209               
    206210                return async_exchange_begin(loc_supplier_sess);
    207         case LOC_PORT_CONSUMER:
     211        case INTERFACE_LOC_CONSUMER:
    208212                fibril_mutex_lock(&loc_consumer_mutex);
    209213               
    210214                if (loc_consumer_sess == NULL)
    211215                        loc_consumer_sess =
    212                             service_connect(EXCHANGE_SERIALIZE, SERVICE_LOC,
    213                             LOC_PORT_CONSUMER, 0);
     216                            service_connect(SERVICE_LOC,
     217                            INTERFACE_LOC_CONSUMER, 0);
    214218               
    215219                fibril_mutex_unlock(&loc_consumer_mutex);
     
    237241int loc_server_register(const char *name)
    238242{
    239         async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER);
     243        async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
    240244       
    241245        ipc_call_t answer;
     
    250254        }
    251255       
    252         exch = loc_exchange_begin(LOC_PORT_SUPPLIER);
    253         async_connect_to_me(exch, 0, 0, 0, NULL, NULL);
     256        exch = loc_exchange_begin(INTERFACE_LOC_SUPPLIER);
     257        async_connect_to_me(exch, 0, 0, 0);
    254258        loc_exchange_end(exch);
    255259       
     
    260264/** Register new service.
    261265 *
    262  * The @p interface is used when forwarding connection to the server.
    263  * If not 0, the first argument is the interface and the second argument
    264  * is the service ID.
    265  *
    266  * When the interface is zero (default), the first argument is directly
    267  * the handle (to ensure backward compatibility).
    268  *
    269  * @param      fqsn      Fully qualified service name
    270  * @param[out] sid       Service ID of new service
    271  * @param      interface Interface when forwarding
    272  *
    273  */
    274 int loc_service_register_with_iface(const char *fqsn,
    275     service_id_t *sid, sysarg_t interface)
    276 {
    277         async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER);
     266 * @param      fqsn  Fully qualified service name
     267 * @param[out] sid   Service ID of new service
     268 *
     269 */
     270int loc_service_register(const char *fqsn, service_id_t *sid)
     271{
     272        async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
    278273       
    279274        ipc_call_t answer;
    280         aid_t req = async_send_2(exch, LOC_SERVICE_REGISTER, interface, 0,
    281             &answer);
     275        aid_t req = async_send_0(exch, LOC_SERVICE_REGISTER, &answer);
    282276        sysarg_t retval = async_data_write_start(exch, fqsn, str_size(fqsn));
    283277       
     
    304298}
    305299
    306 /** Register new service.
    307  *
    308  * @param fqsn Fully qualified service name
    309  * @param sid  Output: ID of new service
    310  *
    311  */
    312 int loc_service_register(const char *fqdn, service_id_t *sid)
    313 {
    314         return loc_service_register_with_iface(fqdn, sid, 0);
    315 }
    316 
    317300/** Unregister service.
    318301 *
     
    324307        sysarg_t retval;
    325308       
    326         exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER);
     309        exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
    327310        retval = async_req_1_0(exch, LOC_SERVICE_UNREGISTER, sid);
    328311        loc_exchange_end(exch);
     
    337320       
    338321        if (flags & IPC_FLAG_BLOCKING)
    339                 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     322                exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    340323        else {
    341                 exch = loc_exchange_begin(LOC_PORT_CONSUMER);
     324                exch = loc_exchange_begin(INTERFACE_LOC_CONSUMER);
    342325                if (exch == NULL)
    343326                        return errno;
     
    390373       
    391374        *name = NULL;
    392         exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     375        exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    393376       
    394377        ipc_call_t answer;
     
    470453       
    471454        if (flags & IPC_FLAG_BLOCKING)
    472                 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     455                exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    473456        else {
    474                 exch = loc_exchange_begin(LOC_PORT_CONSUMER);
     457                exch = loc_exchange_begin(INTERFACE_LOC_CONSUMER);
    475458                if (exch == NULL)
    476459                        return errno;
     
    519502       
    520503        if (flags & IPC_FLAG_BLOCKING)
    521                 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     504                exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    522505        else {
    523                 exch = loc_exchange_begin(LOC_PORT_CONSUMER);
     506                exch = loc_exchange_begin(INTERFACE_LOC_CONSUMER);
    524507                if (exch == NULL)
    525508                        return errno;
     
    556539loc_object_type_t loc_id_probe(service_id_t handle)
    557540{
    558         async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     541        async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    559542       
    560543        sysarg_t type;
     
    569552}
    570553
    571 async_sess_t *loc_service_connect(exch_mgmt_t mgmt, service_id_t handle,
     554async_sess_t *loc_service_connect(service_id_t handle, iface_t iface,
    572555    unsigned int flags)
    573556{
     
    575558       
    576559        if (flags & IPC_FLAG_BLOCKING)
    577                 sess = service_connect_blocking(mgmt, SERVICE_LOC,
    578                     LOC_CONNECT_TO_SERVICE, handle);
     560                sess = service_connect_blocking(SERVICE_LOC, iface, handle);
    579561        else
    580                 sess = service_connect(mgmt, SERVICE_LOC,
    581                     LOC_CONNECT_TO_SERVICE, handle);
     562                sess = service_connect(SERVICE_LOC, iface, handle);
    582563       
    583564        return sess;
     
    586567int loc_null_create(void)
    587568{
    588         async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     569        async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    589570       
    590571        sysarg_t null_id;
     
    601582void loc_null_destroy(int null_id)
    602583{
    603         async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     584        async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    604585        async_req_1_0(exch, LOC_NULL_DESTROY, (sysarg_t) null_id);
    605586        loc_exchange_end(exch);
     
    627608        sysarg_t retval;
    628609       
    629         exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER);
     610        exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
    630611        retval = async_req_2_0(exch, LOC_SERVICE_ADD_TO_CAT, svc_id, cat_id);
    631612        loc_exchange_end(exch);
     
    648629size_t loc_count_namespaces(void)
    649630{
    650         async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     631        async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    651632        size_t size = loc_count_namespaces_internal(exch);
    652633        loc_exchange_end(exch);
     
    657638size_t loc_count_services(service_id_t ns_handle)
    658639{
    659         async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     640        async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    660641        size_t size = loc_count_services_internal(exch, ns_handle);
    661642        loc_exchange_end(exch);
     
    668649        /* Loop until read is succesful */
    669650        while (true) {
    670                 async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     651                async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    671652                size_t count = loc_count_namespaces_internal(exch);
    672653                loc_exchange_end(exch);
     
    679660                        return 0;
    680661               
    681                 exch = loc_exchange_begin(LOC_PORT_CONSUMER);
     662                exch = loc_exchange_begin(INTERFACE_LOC_CONSUMER);
    682663               
    683664                ipc_call_t answer;
     
    717698        /* Loop until read is succesful */
    718699        while (true) {
    719                 async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     700                async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    720701                size_t count = loc_count_services_internal(exch, ns_handle);
    721702                loc_exchange_end(exch);
     
    728709                        return 0;
    729710               
    730                 exch = loc_exchange_begin(LOC_PORT_CONSUMER);
     711                exch = loc_exchange_begin(INTERFACE_LOC_CONSUMER);
    731712               
    732713                ipc_call_t answer;
     
    765746    sysarg_t *id_buf, size_t buf_size, size_t *act_size)
    766747{
    767         async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     748        async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    768749
    769750        ipc_call_t answer;
  • uspace/lib/c/generic/ns.c

    r3feeab2 rff381a7  
    4040#include "private/ns.h"
    4141
    42 int service_register(sysarg_t service)
     42int service_register(service_t service)
    4343{
    4444        async_exch_t *exch = async_exchange_begin(session_ns);
    45         int rc = async_connect_to_me(exch, service, 0, 0, NULL, NULL);
     45        int rc = async_connect_to_me(exch, 0, service, 0);
    4646        async_exchange_end(exch);
    4747       
     
    4949}
    5050
    51 async_sess_t *service_connect(exch_mgmt_t mgmt, services_t service, sysarg_t arg2,
    52     sysarg_t arg3)
     51
     52async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
    5353{
    5454        async_exch_t *exch = async_exchange_begin(session_ns);
     
    5757       
    5858        async_sess_t *sess =
    59             async_connect_me_to(mgmt, exch, service, arg2, arg3);
     59            async_connect_me_to_iface(exch, iface, service, arg3);
    6060        async_exchange_end(exch);
    6161       
     
    6868         * first argument for non-initial connections.
    6969         */
    70         async_sess_args_set(sess, arg2, arg3, 0);
     70        async_sess_args_set(sess, iface, arg3, 0);
    7171       
    7272        return sess;
    7373}
    7474
    75 async_sess_t *service_connect_blocking(exch_mgmt_t mgmt, services_t service,
    76     sysarg_t arg2, sysarg_t arg3)
     75async_sess_t *service_connect_blocking(service_t service, iface_t iface,
     76    sysarg_t arg3)
    7777{
    7878        async_exch_t *exch = async_exchange_begin(session_ns);
    79         if (!exch)
    80                 return NULL;
    8179        async_sess_t *sess =
    82             async_connect_me_to_blocking(mgmt, exch, service, arg2, arg3);
     80            async_connect_me_to_blocking_iface(exch, iface, service, arg3);
    8381        async_exchange_end(exch);
    8482       
     
    9189         * first argument for non-initial connections.
    9290         */
    93         async_sess_args_set(sess, arg2, arg3, 0);
     91        async_sess_args_set(sess, iface, arg3, 0);
    9492       
    9593        return sess;
    9694}
    9795
    98 /** Create bidirectional connection with a service
    99  *
    100  * @param[in] service         Service.
    101  * @param[in] arg1            First parameter.
    102  * @param[in] arg2            Second parameter.
    103  * @param[in] arg3            Third parameter.
    104  * @param[in] client_receiver Message receiver.
    105  *
    106  * @return Session to the service.
    107  * @return Other error codes as defined by async_connect_to_me().
    108  *
    109  */
    110 async_sess_t *service_bind(services_t service, sysarg_t arg1, sysarg_t arg2,
    111     sysarg_t arg3, async_client_conn_t client_receiver)
    112 {
    113         /* Connect to the needed service */
    114         async_sess_t *sess =
    115             service_connect_blocking(EXCHANGE_SERIALIZE, service, 0, 0);
    116         if (sess != NULL) {
    117                 /* Request callback connection */
    118                 async_exch_t *exch = async_exchange_begin(sess);
    119                 int rc = async_connect_to_me(exch, arg1, arg2, arg3,
    120                     client_receiver, NULL);
    121                 async_exchange_end(exch);
    122                
    123                 if (rc != EOK) {
    124                         async_hangup(sess);
    125                         errno = rc;
    126                         return NULL;
    127                 }
    128         }
    129        
    130         return sess;
    131 }
    13296
    13397int ns_ping(void)
  • uspace/lib/c/generic/private/stdio.h

    r3feeab2 rff381a7  
    3939#include <stdio.h>
    4040#include <async.h>
     41
     42/** Maximum characters that can be pushed back by ungetc() */
     43#define UNGETC_MAX 1
    4144
    4245struct _IO_FILE {
     
    8285        /** Points to end of occupied space when in read mode. */
    8386        uint8_t *buf_tail;
     87
     88        /** Pushed back characters */
     89        uint8_t ungetc_buf[UNGETC_MAX];
     90
     91        /** Number of pushed back characters */
     92        int ungetc_chars;
    8493};
    8594
  • uspace/lib/c/generic/task.c

    r3feeab2 rff381a7  
    112112        int fd_stderr;
    113113       
    114         if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
     114        if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK))
    115115                files[0] = &fd_stdin;
    116116        else
    117117                files[0] = NULL;
    118118       
    119         if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
     119        if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK))
    120120                files[1] = &fd_stdout;
    121121        else
    122122                files[1] = NULL;
    123123       
    124         if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
     124        if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK))
    125125                files[2] = &fd_stderr;
    126126        else
  • uspace/lib/c/generic/time.c

    r3feeab2 rff381a7  
    611611                        goto fallback;
    612612               
    613                 clock_conn = loc_service_connect(EXCHANGE_SERIALIZE,
    614                     svc_id, IPC_FLAG_BLOCKING);
     613                clock_conn = loc_service_connect(svc_id, INTERFACE_DDF,
     614                    IPC_FLAG_BLOCKING);
    615615                if (!clock_conn)
    616616                        goto fallback;
  • uspace/lib/c/generic/vbd.c

    r3feeab2 rff381a7  
    3333 */
    3434
     35#include <abi/ipc/interfaces.h>
    3536#include <errno.h>
    3637#include <ipc/services.h>
     
    6566        }
    6667
    67         vbd->sess = loc_service_connect(EXCHANGE_SERIALIZE, vbd_svcid,
     68        vbd->sess = loc_service_connect(vbd_svcid, INTERFACE_VBD,
    6869            IPC_FLAG_BLOCKING);
    6970        if (vbd->sess == NULL) {
  • uspace/lib/c/generic/vfs/vfs.c

    r3feeab2 rff381a7  
    7575       
    7676        while (vfs_sess == NULL)
    77                 vfs_sess = service_connect_blocking(EXCHANGE_PARALLEL, SERVICE_VFS,
    78                     0, 0);
     77                vfs_sess = service_connect_blocking(SERVICE_VFS, INTERFACE_VFS,
     78                    0);
    7979       
    8080        fibril_mutex_unlock(&vfs_mutex);
     
    9393}
    9494
    95 char *absolutize(const char *path, size_t *retlen)
     95char *vfs_absolutize(const char *path, size_t *retlen)
    9696{
    9797        char *ncwd_path;
     
    101101        size_t size = str_size(path);
    102102        if (*path != '/') {
    103                 if (!cwd_path) {
     103                if (cwd_path == NULL) {
    104104                        fibril_mutex_unlock(&cwd_mutex);
    105105                        return NULL;
    106106                }
    107107                ncwd_path_nc = malloc(cwd_size + 1 + size + 1);
    108                 if (!ncwd_path_nc) {
     108                if (ncwd_path_nc == NULL) {
    109109                        fibril_mutex_unlock(&cwd_mutex);
    110110                        return NULL;
     
    115115        } else {
    116116                ncwd_path_nc = malloc(size + 1);
    117                 if (!ncwd_path_nc) {
     117                if (ncwd_path_nc == NULL) {
    118118                        fibril_mutex_unlock(&cwd_mutex);
    119119                        return NULL;
     
    123123        str_append(ncwd_path_nc, cwd_size + 1 + size + 1, path);
    124124        ncwd_path = canonify(ncwd_path_nc, retlen);
    125         if (!ncwd_path) {
     125        if (ncwd_path == NULL) {
    126126                fibril_mutex_unlock(&cwd_mutex);
    127127                free(ncwd_path_nc);
     
    135135        ncwd_path = str_dup(ncwd_path);
    136136        free(ncwd_path_nc);
    137         if (!ncwd_path) {
     137        if (ncwd_path == NULL) {
    138138                fibril_mutex_unlock(&cwd_mutex);
    139139                return NULL;
     
    143143}
    144144
    145 int mount(const char *fs_name, const char *mp, const char *fqsn,
     145int vfs_mount(const char *fs_name, const char *mp, const char *fqsn,
    146146    const char *opts, unsigned int flags, unsigned int instance)
    147147{
     
    171171       
    172172        size_t mpa_size;
    173         char *mpa = absolutize(mp, &mpa_size);
    174         if (!mpa) {
     173        char *mpa = vfs_absolutize(mp, &mpa_size);
     174        if (mpa == NULL) {
    175175                if (null_id != -1)
    176176                        loc_null_destroy(null_id);
     
    255255}
    256256
    257 int unmount(const char *mp)
     257int vfs_unmount(const char *mp)
    258258{
    259259        sysarg_t rc;
     
    263263        char *mpa;
    264264       
    265         mpa = absolutize(mp, &mpa_size);
    266         if (!mpa)
     265        mpa = vfs_absolutize(mp, &mpa_size);
     266        if (mpa == NULL)
    267267                return ENOMEM;
    268268       
     
    289289}
    290290
    291 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag)
     291/** Open file (internal).
     292 *
     293 * @param abs Absolute path to file
     294 * @param abs_size Size of @a abs string
     295 * @param lflag L_xxx flags
     296 * @param oflag O_xxx flags
     297 * @param fd Place to store new file descriptor
     298 *
     299 * @return EOK on success, non-zero error code on error
     300 */
     301static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag,
     302    int *fd)
    292303{
    293304        async_exch_t *exch = vfs_exchange_begin();
     
    315326            return (int) rc;
    316327       
    317         return (int) IPC_GET_ARG1(answer);
    318 }
    319 
     328        *fd = (int) IPC_GET_ARG1(answer);
     329        return EOK;
     330}
     331
     332/** Open file.
     333 *
     334 * @param path File path
     335 * @param oflag O_xxx flags
     336 * @param mode File mode (only with O_CREAT)
     337 *
     338 * @return Nonnegative file descriptor on success. On error -1 is returned
     339 *         and errno is set.
     340 */
    320341int open(const char *path, int oflag, ...)
    321342{
    322343        size_t abs_size;
    323         char *abs = absolutize(path, &abs_size);
    324         if (!abs)
    325                 return ENOMEM;
    326        
    327         int ret = open_internal(abs, abs_size, L_FILE, oflag);
     344        char *abs = vfs_absolutize(path, &abs_size);
     345        int fd = -1;
     346       
     347        if (abs == NULL) {
     348                errno = ENOMEM;
     349                return -1;
     350        }
     351       
     352        int rc = open_internal(abs, abs_size, L_FILE, oflag, &fd);
    328353        free(abs);
    329354       
    330         return ret;
    331 }
    332 
     355        if (rc != EOK) {
     356                errno = rc;
     357                return -1;
     358        }
     359       
     360        return fd;
     361}
     362
     363/** Close file.
     364 *
     365 * @param fildes File descriptor
     366 * @return Zero on success. On error -1 is returned and errno is set.
     367 */
    333368int close(int fildes)
    334369{
     
    339374        vfs_exchange_end(exch);
    340375       
    341         return (int) rc;
    342 }
    343 
    344 ssize_t read(int fildes, void *buf, size_t nbyte)
     376        if (rc != EOK) {
     377                errno = rc;
     378                return -1;
     379        }
     380       
     381        return 0;
     382}
     383
     384/** Read bytes from file.
     385 *
     386 * Read up to @a nbyte bytes from file. The actual number of bytes read
     387 * may be lower, but greater than zero if there are any bytes available.
     388 * If there are no bytes available for reading, then the function will
     389 * return success with zero bytes read.
     390 *
     391 * @param fildes File descriptor
     392 * @param buf Buffer
     393 * @param nbyte Maximum number of bytes to read
     394 * @param nread Place to store actual number of bytes read (0 or more)
     395 *
     396 * @return EOK on success, non-zero error code on error.
     397 */
     398static int _read_short(int fildes, void *buf, size_t nbyte, ssize_t *nread)
    345399{
    346400        sysarg_t rc;
     
    357411        if (rc != EOK) {
    358412                vfs_exchange_end(exch);
    359 
     413               
    360414                sysarg_t rc_orig;
    361415                async_wait_for(req, &rc_orig);
    362 
     416               
    363417                if (rc_orig == EOK)
    364                         return (ssize_t) rc;
     418                        return rc;
    365419                else
    366                         return (ssize_t) rc_orig;
    367         }
     420                        return rc_orig;
     421        }
     422       
    368423        vfs_exchange_end(exch);
    369424        async_wait_for(req, &rc);
    370         if (rc == EOK)
    371                 return (ssize_t) IPC_GET_ARG1(answer);
    372         else
     425       
     426        if (rc != EOK)
    373427                return rc;
    374 }
    375 
    376 ssize_t write(int fildes, const void *buf, size_t nbyte)
     428       
     429        *nread = (ssize_t) IPC_GET_ARG1(answer);
     430        return EOK;
     431}
     432
     433/** Write bytes to file.
     434 *
     435 * Write up to @a nbyte bytes from file. The actual number of bytes written
     436 * may be lower, but greater than zero.
     437 *
     438 * @param fildes File descriptor
     439 * @param buf Buffer
     440 * @param nbyte Maximum number of bytes to write
     441 * @param nread Place to store actual number of bytes written (0 or more)
     442 *
     443 * @return EOK on success, non-zero error code on error.
     444 */
     445static int _write_short(int fildes, const void *buf, size_t nbyte,
     446    ssize_t *nwritten)
    377447{
    378448        sysarg_t rc;
     
    389459        if (rc != EOK) {
    390460                vfs_exchange_end(exch);
    391 
     461               
    392462                sysarg_t rc_orig;
    393463                async_wait_for(req, &rc_orig);
    394 
     464               
    395465                if (rc_orig == EOK)
    396                         return (ssize_t) rc;
     466                        return rc;
    397467                else
    398                         return (ssize_t) rc_orig;
    399         }
     468                        return rc_orig;
     469        }
     470       
    400471        vfs_exchange_end(exch);
    401472        async_wait_for(req, &rc);
    402         if (rc == EOK)
    403                 return (ssize_t) IPC_GET_ARG1(answer);
    404         else
    405                 return -1;
    406 }
    407 
    408 /** Read entire buffer.
    409  *
    410  * In face of short reads this function continues reading until either
    411  * the entire buffer is read or no more data is available (at end of file).
     473       
     474        if (rc != EOK)
     475                return rc;
     476       
     477        *nwritten = (ssize_t) IPC_GET_ARG1(answer);
     478        return EOK;
     479}
     480
     481/** Read data.
     482 *
     483 * Read up to @a nbytes bytes from file if available. This function always reads
     484 * all the available bytes up to @a nbytes.
    412485 *
    413486 * @param fildes        File descriptor
     
    415488 * @param nbytes        Number of bytes to read
    416489 *
    417  * @return              On success, positive number of bytes read.
    418  *                      On failure, negative error code from read().
    419  */
    420 ssize_t read_all(int fildes, void *buf, size_t nbyte)
     490 * @return              On success, nonnegative number of bytes read.
     491 *                      On failure, -1 and sets errno.
     492 */
     493ssize_t read(int fildes, void *buf, size_t nbyte)
    421494{
    422495        ssize_t cnt = 0;
    423496        size_t nread = 0;
    424497        uint8_t *bp = (uint8_t *) buf;
    425 
     498        int rc;
     499       
    426500        do {
    427501                bp += cnt;
    428502                nread += cnt;
    429                 cnt = read(fildes, bp, nbyte - nread);
    430         } while (cnt > 0 && (nbyte - nread - cnt) > 0);
    431 
    432         if (cnt < 0)
    433                 return cnt;
    434 
     503                rc = _read_short(fildes, bp, nbyte - nread, &cnt);
     504        } while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0);
     505       
     506        if (rc != EOK) {
     507                errno = rc;
     508                return -1;
     509        }
     510       
    435511        return nread + cnt;
    436512}
    437513
    438 /** Write entire buffer.
     514/** Write data.
    439515 *
    440516 * This function fails if it cannot write exactly @a len bytes to the file.
     
    444520 * @param nbytes        Number of bytes to write
    445521 *
    446  * @return              EOK on error, return value from write() if writing
    447  *                      failed.
    448  */
    449 ssize_t write_all(int fildes, const void *buf, size_t nbyte)
     522 * @return              On success, nonnegative number of bytes written.
     523 *                      On failure, -1 and sets errno.
     524 */
     525ssize_t write(int fildes, const void *buf, size_t nbyte)
    450526{
    451527        ssize_t cnt = 0;
    452528        ssize_t nwritten = 0;
    453529        const uint8_t *bp = (uint8_t *) buf;
     530        int rc;
    454531
    455532        do {
    456533                bp += cnt;
    457534                nwritten += cnt;
    458                 cnt = write(fildes, bp, nbyte - nwritten);
    459         } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0);
    460 
    461         if (cnt < 0)
    462                 return cnt;
    463 
    464         if ((ssize_t)nbyte - nwritten - cnt > 0)
    465                 return EIO;
     535                rc = _write_short(fildes, bp, nbyte - nwritten, &cnt);
     536        } while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0);
     537
     538        if (rc != EOK) {
     539                errno = rc;
     540                return -1;
     541        }
    466542
    467543        return nbyte;
    468544}
    469545
     546/** Synchronize file.
     547 *
     548 * @param fildes File descriptor
     549 * @return 0 on success. On error returns -1 and sets errno.
     550 */
    470551int fsync(int fildes)
    471552{
     
    474555        vfs_exchange_end(exch);
    475556       
    476         return (int) rc;
    477 }
    478 
     557        if (rc != EOK) {
     558                errno = rc;
     559                return -1;
     560        }
     561       
     562        return 0;
     563}
     564
     565/** Seek to a position.
     566 *
     567 * @param fildes File descriptor
     568 * @param offset Offset
     569 * @param whence SEEK_SET, SEEK_CUR or SEEK_END
     570 *
     571 * @return On success the nonnegative offset from start of file. On error
     572 *         returns (off64_t)-1 and sets errno.
     573 */
    479574off64_t lseek(int fildes, off64_t offset, int whence)
    480575{
     
    489584        vfs_exchange_end(exch);
    490585       
    491         if (rc != EOK)
     586        if (rc != EOK) {
     587                errno = rc;
    492588                return (off64_t) -1;
     589        }
    493590       
    494591        return (off64_t) MERGE_LOUP32(newoff_lo, newoff_hi);
    495592}
    496593
     594/** Truncate file to a specified length.
     595 *
     596 * Truncate file so that its size is exactly @a length
     597 *
     598 * @param fildes File descriptor
     599 * @param length Length
     600 *
     601 * @return 0 on success, -1 on error and sets errno.
     602 */
    497603int ftruncate(int fildes, aoff64_t length)
    498604{
     
    504610        vfs_exchange_end(exch);
    505611       
    506         return (int) rc;
    507 }
    508 
     612        if (rc != EOK) {
     613                errno = rc;
     614                return -1;
     615        }
     616       
     617        return 0;
     618}
     619
     620/** Get file status.
     621 *
     622 * @param fildes File descriptor
     623 * @param stat Place to store file information
     624 *
     625 * @return 0 on success, -1 on error and sets errno.
     626 */
    509627int fstat(int fildes, struct stat *stat)
    510628{
     
    518636        if (rc != EOK) {
    519637                vfs_exchange_end(exch);
    520 
     638               
    521639                sysarg_t rc_orig;
    522640                async_wait_for(req, &rc_orig);
    523 
    524                 if (rc_orig == EOK)
    525                         return (ssize_t) rc;
    526                 else
    527                         return (ssize_t) rc_orig;
    528         }
     641               
     642                if (rc_orig != EOK)
     643                        rc = rc_orig;
     644                if (rc != EOK) {
     645                        errno = rc;
     646                        return -1;
     647                }
     648               
     649                return 0;
     650        }
     651       
    529652        vfs_exchange_end(exch);
    530653        async_wait_for(req, &rc);
    531 
    532         return rc;
    533 }
    534 
     654       
     655        if (rc != EOK) {
     656                errno = rc;
     657                return -1;
     658        }
     659       
     660        return 0;
     661}
     662
     663/** Get file status.
     664 *
     665 * @param path Path to file
     666 * @param stat Place to store file information
     667 *
     668 * @return 0 on success, -1 on error and sets errno.
     669 */
    535670int stat(const char *path, struct stat *stat)
    536671{
     
    540675       
    541676        size_t pa_size;
    542         char *pa = absolutize(path, &pa_size);
    543         if (!pa)
    544                 return ENOMEM;
     677        char *pa = vfs_absolutize(path, &pa_size);
     678        if (pa == NULL) {
     679                errno = ENOMEM;
     680                return -1;
     681        }
    545682       
    546683        async_exch_t *exch = vfs_exchange_begin();
     
    552689                free(pa);
    553690                async_wait_for(req, &rc_orig);
     691                if (rc_orig != EOK)
     692                        rc = rc_orig;
     693                if (rc != EOK) {
     694                        errno = rc;
     695                        return -1;
     696                }
     697        }
     698        rc = async_data_read_start(exch, stat, sizeof(struct stat));
     699        if (rc != EOK) {
     700                vfs_exchange_end(exch);
     701                free(pa);
     702                async_wait_for(req, &rc_orig);
     703                if (rc_orig != EOK)
     704                        rc = rc_orig;
     705                if (rc != EOK) {
     706                        errno = rc;
     707                        return -1;
     708                }
     709        }
     710        vfs_exchange_end(exch);
     711        free(pa);
     712        async_wait_for(req, &rc);
     713        if (rc != EOK) {
     714                errno = rc;
     715                return -1;
     716        }
     717        return 0;
     718}
     719
     720/** Open directory.
     721 *
     722 * @param dirname Directory pathname
     723 *
     724 * @return Non-NULL pointer on success. On error returns @c NULL and sets errno.
     725 */
     726DIR *opendir(const char *dirname)
     727{
     728        DIR *dirp = malloc(sizeof(DIR));
     729        int fd = -1;
     730       
     731        if (dirp == NULL) {
     732                errno = ENOMEM;
     733                return NULL;
     734        }
     735       
     736        size_t abs_size;
     737        char *abs = vfs_absolutize(dirname, &abs_size);
     738        if (abs == NULL) {
     739                free(dirp);
     740                errno = ENOMEM;
     741                return NULL;
     742        }
     743       
     744        int rc = open_internal(abs, abs_size, L_DIRECTORY, 0, &fd);
     745        free(abs);
     746       
     747        if (rc != EOK) {
     748                free(dirp);
     749                errno = rc;
     750                return NULL;
     751        }
     752       
     753        dirp->fd = fd;
     754        return dirp;
     755}
     756
     757/** Read directory entry.
     758 *
     759 * @param dirp Open directory
     760 * @return Non-NULL pointer to directory entry on success. On error returns
     761 *         @c NULL and sets errno.
     762 */
     763struct dirent *readdir(DIR *dirp)
     764{
     765        int rc;
     766        ssize_t len;
     767       
     768        rc = _read_short(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1, &len);
     769        if (rc != EOK) {
     770                errno = rc;
     771                return NULL;
     772        }
     773       
     774        (void) len;
     775        return &dirp->res;
     776}
     777
     778/** Rewind directory position to the beginning.
     779 *
     780 * @param dirp Open directory
     781 */
     782void rewinddir(DIR *dirp)
     783{
     784        (void) lseek(dirp->fd, 0, SEEK_SET);
     785}
     786
     787/** Close directory.
     788 *
     789 * @param dirp Open directory
     790 * @return 0 on success. On error returns -1 and sets errno.
     791 */
     792int closedir(DIR *dirp)
     793{
     794        int rc;
     795       
     796        rc = close(dirp->fd);
     797        free(dirp);
     798
     799        /* On error errno was set by close() */
     800        return rc;
     801}
     802
     803/** Create directory.
     804 *
     805 * @param path Path
     806 * @param mode File mode
     807 * @return 0 on success. On error returns -1 and sets errno.
     808 */
     809int mkdir(const char *path, mode_t mode)
     810{
     811        sysarg_t rc;
     812        aid_t req;
     813       
     814        size_t pa_size;
     815        char *pa = vfs_absolutize(path, &pa_size);
     816        if (pa == NULL) {
     817                errno = ENOMEM;
     818                return -1;
     819        }
     820       
     821        async_exch_t *exch = vfs_exchange_begin();
     822       
     823        req = async_send_1(exch, VFS_IN_MKDIR, mode, NULL);
     824        rc = async_data_write_start(exch, pa, pa_size);
     825        if (rc != EOK) {
     826                vfs_exchange_end(exch);
     827                free(pa);
     828               
     829                sysarg_t rc_orig;
     830                async_wait_for(req, &rc_orig);
     831               
     832                if (rc_orig != EOK)
     833                        rc = rc_orig;
     834               
     835                if (rc != EOK) {
     836                        errno = rc;
     837                        return -1;
     838                }
     839               
     840                return 0;
     841        }
     842       
     843        vfs_exchange_end(exch);
     844        free(pa);
     845        async_wait_for(req, &rc);
     846       
     847        if (rc != EOK) {
     848                errno = rc;
     849                return -1;
     850        }
     851       
     852        return 0;
     853}
     854
     855/** Unlink a file or directory.
     856 *
     857 * @param path Path to file or empty directory
     858 * @param lflag L_xxx flag (L_NONE, L_FILE or L_DIRECTORY)
     859 * @return EOK on success, non-zero error code on error
     860 */
     861static int _unlink(const char *path, int lflag)
     862{
     863        sysarg_t rc;
     864        aid_t req;
     865       
     866        size_t pa_size;
     867        char *pa = vfs_absolutize(path, &pa_size);
     868        if (pa == NULL)
     869                return ENOMEM;
     870       
     871        async_exch_t *exch = vfs_exchange_begin();
     872       
     873        req = async_send_1(exch, VFS_IN_UNLINK, lflag, NULL);
     874        rc = async_data_write_start(exch, pa, pa_size);
     875        if (rc != EOK) {
     876                vfs_exchange_end(exch);
     877                free(pa);
     878
     879                sysarg_t rc_orig;
     880                async_wait_for(req, &rc_orig);
     881
    554882                if (rc_orig == EOK)
    555883                        return (int) rc;
     
    557885                        return (int) rc_orig;
    558886        }
    559         rc = async_data_read_start(exch, stat, sizeof(struct stat));
    560         if (rc != EOK) {
    561                 vfs_exchange_end(exch);
    562                 free(pa);
    563                 async_wait_for(req, &rc_orig);
    564                 if (rc_orig == EOK)
    565                         return (int) rc;
    566                 else
    567                         return (int) rc_orig;
    568         }
    569887        vfs_exchange_end(exch);
    570888        free(pa);
     
    573891}
    574892
    575 DIR *opendir(const char *dirname)
    576 {
    577         DIR *dirp = malloc(sizeof(DIR));
    578         if (!dirp)
    579                 return NULL;
    580        
    581         size_t abs_size;
    582         char *abs = absolutize(dirname, &abs_size);
    583         if (!abs) {
    584                 free(dirp);
    585                 return NULL;
    586         }
    587        
    588         int ret = open_internal(abs, abs_size, L_DIRECTORY, 0);
    589         free(abs);
    590        
    591         if (ret < 0) {
    592                 free(dirp);
    593                 return NULL;
    594         }
    595        
    596         dirp->fd = ret;
    597         return dirp;
    598 }
    599 
    600 struct dirent *readdir(DIR *dirp)
    601 {
    602         ssize_t len = read(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1);
    603         if (len <= 0)
    604                 return NULL;
    605         return &dirp->res;
    606 }
    607 
    608 void rewinddir(DIR *dirp)
    609 {
    610         (void) lseek(dirp->fd, 0, SEEK_SET);
    611 }
    612 
    613 int closedir(DIR *dirp)
    614 {
    615         (void) close(dirp->fd);
    616         free(dirp);
     893/** Unlink file or directory.
     894 *
     895 * @param path Path
     896 * @return EOk on success, error code on error
     897 */
     898int unlink(const char *path)
     899{
     900        int rc;
     901
     902        rc = _unlink(path, L_NONE);
     903        if (rc != EOK) {
     904                errno = rc;
     905                return -1;
     906        }
     907
    617908        return 0;
    618909}
    619910
    620 int mkdir(const char *path, mode_t mode)
    621 {
    622         sysarg_t rc;
    623         aid_t req;
    624        
    625         size_t pa_size;
    626         char *pa = absolutize(path, &pa_size);
    627         if (!pa)
    628                 return ENOMEM;
    629        
    630         async_exch_t *exch = vfs_exchange_begin();
    631        
    632         req = async_send_1(exch, VFS_IN_MKDIR, mode, NULL);
    633         rc = async_data_write_start(exch, pa, pa_size);
    634         if (rc != EOK) {
    635                 vfs_exchange_end(exch);
    636                 free(pa);
    637 
    638                 sysarg_t rc_orig;
    639                 async_wait_for(req, &rc_orig);
    640 
    641                 if (rc_orig == EOK)
    642                         return (int) rc;
    643                 else
    644                         return (int) rc_orig;
    645         }
    646         vfs_exchange_end(exch);
    647         free(pa);
    648         async_wait_for(req, &rc);
    649         return rc;
    650 }
    651 
    652 static int _unlink(const char *path, int lflag)
    653 {
    654         sysarg_t rc;
    655         aid_t req;
    656        
    657         size_t pa_size;
    658         char *pa = absolutize(path, &pa_size);
    659         if (!pa)
    660                 return ENOMEM;
    661        
    662         async_exch_t *exch = vfs_exchange_begin();
    663        
    664         req = async_send_1(exch, VFS_IN_UNLINK, lflag, NULL);
    665         rc = async_data_write_start(exch, pa, pa_size);
    666         if (rc != EOK) {
    667                 vfs_exchange_end(exch);
    668                 free(pa);
    669 
    670                 sysarg_t rc_orig;
    671                 async_wait_for(req, &rc_orig);
    672 
    673                 if (rc_orig == EOK)
    674                         return (int) rc;
    675                 else
    676                         return (int) rc_orig;
    677         }
    678         vfs_exchange_end(exch);
    679         free(pa);
    680         async_wait_for(req, &rc);
    681         return rc;
    682 }
    683 
    684 int unlink(const char *path)
    685 {
    686         return _unlink(path, L_NONE);
    687 }
    688 
     911/** Remove empty directory.
     912 *
     913 * @param path Path
     914 * @return 0 on success. On error returns -1 and sets errno.
     915 */
    689916int rmdir(const char *path)
    690917{
    691         return _unlink(path, L_DIRECTORY);
    692 }
    693 
     918        int rc;
     919
     920        rc = _unlink(path, L_DIRECTORY);
     921        if (rc != EOK) {
     922                errno = rc;
     923                return -1;
     924        }
     925
     926        return 0;
     927}
     928
     929/** Rename directory entry.
     930 *
     931 * @param old Old name
     932 * @param new New name
     933 *
     934 * @return 0 on success. On error returns -1 and sets errno.
     935 */
    694936int rename(const char *old, const char *new)
    695937{
     
    699941       
    700942        size_t olda_size;
    701         char *olda = absolutize(old, &olda_size);
    702         if (!olda)
    703                 return ENOMEM;
     943        char *olda = vfs_absolutize(old, &olda_size);
     944        if (olda == NULL) {
     945                errno = ENOMEM;
     946                return -1;
     947        }
    704948
    705949        size_t newa_size;
    706         char *newa = absolutize(new, &newa_size);
    707         if (!newa) {
     950        char *newa = vfs_absolutize(new, &newa_size);
     951        if (newa == NULL) {
    708952                free(olda);
    709                 return ENOMEM;
     953                errno = ENOMEM;
     954                return -1;
    710955        }
    711956       
     
    719964                free(newa);
    720965                async_wait_for(req, &rc_orig);
    721                 if (rc_orig == EOK)
    722                         return (int) rc;
    723                 else
    724                         return (int) rc_orig;
     966                if (rc_orig != EOK)
     967                        rc = rc_orig;
     968                if (rc != EOK) {
     969                        errno = rc;
     970                        return -1;
     971                }
     972                return 0;
    725973        }
    726974        rc = async_data_write_start(exch, newa, newa_size);
     
    730978                free(newa);
    731979                async_wait_for(req, &rc_orig);
    732                 if (rc_orig == EOK)
    733                         return (int) rc;
    734                 else
    735                         return (int) rc_orig;
     980                if (rc_orig != EOK)
     981                        rc = rc_orig;
     982                if (rc != EOK) {
     983                        errno = rc;
     984                        return -1;
     985                }
     986                return 0;
    736987        }
    737988        vfs_exchange_end(exch);
     
    739990        free(newa);
    740991        async_wait_for(req, &rc);
    741         return rc;
    742 }
    743 
     992
     993        if (rc != EOK) {
     994                errno = rc;
     995                return -1;
     996        }
     997
     998        return 0;
     999}
     1000
     1001/** Remove directory entry.
     1002 *
     1003 * @param path Path
     1004 * @return 0 on success. On error returns -1 and sets errno.
     1005 */
    7441006int remove(const char *path)
    7451007{
     
    7471009}
    7481010
     1011/** Change working directory.
     1012 *
     1013 * @param path Path
     1014 * @return 0 on success. On error returns -1 and sets errno.
     1015 */
    7491016int chdir(const char *path)
    7501017{
    7511018        size_t abs_size;
    752         char *abs = absolutize(path, &abs_size);
    753         if (!abs)
    754                 return ENOMEM;
    755        
    756         int fd = open_internal(abs, abs_size, L_DIRECTORY, O_DESC);
    757        
    758         if (fd < 0) {
     1019        char *abs = vfs_absolutize(path, &abs_size);
     1020        int fd = -1;
     1021       
     1022        if (abs == NULL) {
     1023                errno = ENOMEM;
     1024                return -1;
     1025        }
     1026       
     1027        int rc = open_internal(abs, abs_size, L_DIRECTORY, O_DESC, &fd);
     1028       
     1029        if (rc != EOK) {
    7591030                free(abs);
    760                 return ENOENT;
     1031                errno = rc;
     1032                return -1;
    7611033        }
    7621034       
     
    7651037        if (cwd_fd >= 0)
    7661038                close(cwd_fd);
    767        
    7681039       
    7691040        if (cwd_path)
     
    7751046       
    7761047        fibril_mutex_unlock(&cwd_mutex);
    777         return EOK;
    778 }
    779 
     1048        return 0;
     1049}
     1050
     1051/** Get current working directory path.
     1052 *
     1053 * @param buf Buffer
     1054 * @param size Size of @a buf
     1055 * @return On success returns @a buf. On failure returns @c NULL and sets errno.
     1056 */
    7801057char *getcwd(char *buf, size_t size)
    7811058{
    782         if (size == 0)
     1059        if (size == 0) {
     1060                errno = EINVAL;
    7831061                return NULL;
     1062        }
    7841063       
    7851064        fibril_mutex_lock(&cwd_mutex);
     
    7871066        if ((cwd_size == 0) || (size < cwd_size + 1)) {
    7881067                fibril_mutex_unlock(&cwd_mutex);
     1068                errno = ERANGE;
    7891069                return NULL;
    7901070        }
     
    7961076}
    7971077
    798 async_sess_t *fd_session(exch_mgmt_t mgmt, int fildes)
     1078/** Open session to service represented by a special file.
     1079 *
     1080 * Given that the file referred to by @a fildes represents a service,
     1081 * open a session to that service.
     1082 *
     1083 * @param fildes File descriptor
     1084 * @param iface Interface to connect to (XXX Should be automatic)
     1085 * @return On success returns session pointer. On error returns @c NULL.
     1086 */
     1087async_sess_t *vfs_fd_session(int fildes, iface_t iface)
    7991088{
    8001089        struct stat stat;
    8011090        int rc = fstat(fildes, &stat);
    802         if (rc != 0) {
    803                 errno = rc;
     1091        if (rc != 0)
    8041092                return NULL;
    805         }
    806        
    807         if (!stat.service) {
    808                 errno = ENOENT;
     1093       
     1094        if (stat.service == 0)
    8091095                return NULL;
    810         }
    811        
    812         return loc_service_connect(mgmt, stat.service, 0);
    813 }
    814 
     1096       
     1097        return loc_service_connect(stat.service, iface, 0);
     1098}
     1099
     1100/** Duplicate open file.
     1101 *
     1102 * Duplicate open file under a new file descriptor.
     1103 *
     1104 * @param oldfd Old file descriptor
     1105 * @param newfd New file descriptor
     1106 * @return 0 on success. On error -1 is returned and errno is set
     1107 */
    8151108int dup2(int oldfd, int newfd)
    8161109{
     
    8231116       
    8241117        if (rc == EOK)
    825                 return (int) ret;
    826        
    827         return (int) rc;
    828 }
    829 
    830 int fd_wait(void)
     1118                rc = ret;
     1119       
     1120        if (rc != EOK) {
     1121                errno = rc;
     1122                return -1;
     1123        }
     1124       
     1125        return 0;
     1126}
     1127
     1128int vfs_fd_wait(void)
    8311129{
    8321130        async_exch_t *exch = vfs_exchange_begin();
     
    8431141}
    8441142
    845 int get_mtab_list(list_t *mtab_list)
     1143int vfs_get_mtab_list(list_t *mtab_list)
    8461144{
    8471145        sysarg_t rc;
     
    8631161
    8641162                mtab_ent = malloc(sizeof(mtab_ent_t));
    865                 if (!mtab_ent) {
     1163                if (mtab_ent == NULL) {
    8661164                        rc = ENOMEM;
    8671165                        goto exit;
     
    9041202}
    9051203
     1204/** Get filesystem statistics.
     1205 *
     1206 * @param path Mount point path
     1207 * @param st Buffer for storing information
     1208 * @return 0 on success. On error -1 is returned and errno is set.
     1209 */
    9061210int statfs(const char *path, struct statfs *st)
    9071211{
     
    9101214        size_t pa_size;
    9111215
    912         char *pa = absolutize(path, &pa_size);
    913         if (!pa)
    914                 return ENOMEM;
     1216        char *pa = vfs_absolutize(path, &pa_size);
     1217        if (pa == NULL) {
     1218                errno = ENOMEM;
     1219                return -1;
     1220        }
    9151221
    9161222        async_exch_t *exch = vfs_exchange_begin();
     
    9271233        free(pa);
    9281234        async_wait_for(req, &rc_orig);
    929         return (int) (rc_orig != EOK ? rc_orig : rc);
     1235        rc = (rc_orig != EOK ? rc_orig : rc);
     1236
     1237        if (rc != EOK) {
     1238                errno = rc;
     1239                return -1;
     1240        }
     1241
     1242        return 0;
    9301243}
    9311244
  • uspace/lib/c/generic/vol.c

    r3feeab2 rff381a7  
    3333 */
    3434
     35#include <abi/ipc/interfaces.h>
    3536#include <errno.h>
    3637#include <ipc/services.h>
     
    6061        rc = loc_service_get_id(SERVICE_NAME_VOLSRV, &vol_svcid, 0);
    6162        if (rc != EOK) {
    62                 rc = EIO;
     63                rc = ENOENT;
    6364                goto error;
    6465        }
    6566
    66         vol->sess = loc_service_connect(EXCHANGE_SERIALIZE, vol_svcid, 0);
     67        vol->sess = loc_service_connect(vol_svcid, INTERFACE_VOL, 0);
    6768        if (vol->sess == NULL) {
    6869                rc = EIO;
  • uspace/lib/c/include/adt/list.h

    r3feeab2 rff381a7  
    133133
    134134/** Returns true if the link is definitely part of a list. False if not sure. */
    135 static inline int link_in_use(link_t *link)
     135static inline bool link_in_use(link_t *link)
    136136{
    137137        return link->prev != NULL && link->next != NULL;
     
    237237 *
    238238 */
    239 static inline int list_empty(const list_t *list)
     239static inline bool list_empty(const list_t *list)
    240240{
    241241        return (list->head.next == &list->head);
     
    357357 *
    358358 */
    359 static inline link_t *list_nth(list_t *list, unsigned int n)
    360 {
    361         unsigned int cnt = 0;
     359static inline link_t *list_nth(list_t *list, unsigned long n)
     360{
     361        unsigned long cnt = 0;
    362362       
    363363        link_t *link = list_first(list);
     
    396396}
    397397
    398 extern int list_member(const link_t *, const list_t *);
     398extern bool list_member(const link_t *, const list_t *);
    399399extern void list_concat(list_t *, list_t *);
    400 extern unsigned int list_count(const list_t *);
     400extern unsigned long list_count(const list_t *);
    401401
    402402#endif
  • uspace/lib/c/include/async.h

    r3feeab2 rff381a7  
    4848#include <abi/ddi/irq.h>
    4949#include <abi/ipc/event.h>
     50#include <abi/ipc/interfaces.h>
    5051
    5152typedef ipc_callid_t aid_t;
     53typedef sysarg_t port_id_t;
    5254
    5355typedef void *(*async_client_data_ctor_t)(void);
    5456typedef void (*async_client_data_dtor_t)(void *);
    5557
    56 /** Client connection handler
     58/** Port connection handler
    5759 *
    5860 * @param callid ID of incoming call or 0 if connection initiated from
    59  *               inside using async_connect_to_me()
     61 *               inside using async_create_callback_port()
    6062 * @param call   Incoming call or 0 if connection initiated from inside
    61  * @param arg    Local argument passed from async_new_connection() or
    62  *               async_connect_to_me()
    63  */
    64 typedef void (*async_client_conn_t)(ipc_callid_t, ipc_call_t *, void *);
     63 *               using async_create_callback_port()
     64 * @param arg    Local argument.
     65 *
     66 */
     67typedef void (*async_port_handler_t)(ipc_callid_t, ipc_call_t *, void *);
    6568
    6669/** Notification handler */
     
    8083        EXCHANGE_ATOMIC = 0,
    8184       
     85        /** Exchange management via mutual exclusion
     86         *
     87         * Suitable for any kind of client/server communication,
     88         * but can limit parallelism.
     89         *
     90         */
     91        EXCHANGE_SERIALIZE = 1,
     92       
    8293        /** Exchange management via phone cloning
    8394         *
     
    8798         *
    8899         */
    89         EXCHANGE_PARALLEL,
    90        
    91         /** Exchange management via mutual exclusion
    92          *
    93          * Suitable for any kind of client/server communication,
    94          * but can limit parallelism.
    95          *
    96          */
    97         EXCHANGE_SERIALIZE
     100        EXCHANGE_PARALLEL = 2
    98101} exch_mgmt_t;
    99102
     
    147150extern void async_forget(aid_t);
    148151
    149 extern fid_t async_new_connection(task_id_t, sysarg_t, ipc_callid_t,
    150     ipc_call_t *, async_client_conn_t, void *);
    151 
    152152extern void async_usleep(suseconds_t);
    153153extern void async_create_manager(void);
     
    160160extern void async_put_client_data_by_id(task_id_t);
    161161
    162 extern void async_set_client_connection(async_client_conn_t);
     162extern int async_create_port(iface_t, async_port_handler_t, void *,
     163    port_id_t *);
     164extern void async_set_fallback_port_handler(async_port_handler_t, void *);
     165extern int async_create_callback_port(async_exch_t *, iface_t, sysarg_t,
     166    sysarg_t, async_port_handler_t, void *, port_id_t *);
     167
    163168extern void async_set_notification_handler_stack_size(size_t);
    164169
     
    343348extern async_sess_t *async_connect_me_to(exch_mgmt_t, async_exch_t *, sysarg_t,
    344349    sysarg_t, sysarg_t);
     350extern async_sess_t *async_connect_me_to_iface(async_exch_t *, iface_t,
     351    sysarg_t, sysarg_t);
    345352extern async_sess_t *async_connect_me_to_blocking(exch_mgmt_t, async_exch_t *,
    346353    sysarg_t, sysarg_t, sysarg_t);
     354extern async_sess_t *async_connect_me_to_blocking_iface(async_exch_t *, iface_t,
     355    sysarg_t, sysarg_t);
    347356extern async_sess_t *async_connect_kbox(task_id_t);
    348357
    349 extern int async_connect_to_me(async_exch_t *, sysarg_t, sysarg_t, sysarg_t,
    350     async_client_conn_t, void *);
     358extern int async_connect_to_me(async_exch_t *, sysarg_t, sysarg_t, sysarg_t);
    351359
    352360extern int async_hangup(async_sess_t *);
  • uspace/lib/c/include/devman.h

    r3feeab2 rff381a7  
    4242#include <stdbool.h>
    4343
    44 extern async_exch_t *devman_exchange_begin_blocking(devman_interface_t);
    45 extern async_exch_t *devman_exchange_begin(devman_interface_t);
     44extern async_exch_t *devman_exchange_begin_blocking(iface_t);
     45extern async_exch_t *devman_exchange_begin(iface_t);
    4646extern void devman_exchange_end(async_exch_t *);
    4747
     
    5353extern int devman_drv_fun_offline(devman_handle_t);
    5454
    55 extern async_sess_t *devman_device_connect(exch_mgmt_t, devman_handle_t,
    56     unsigned int);
    57 extern async_sess_t *devman_parent_device_connect(exch_mgmt_t, devman_handle_t,
     55extern async_sess_t *devman_device_connect(devman_handle_t, unsigned int);
     56extern async_sess_t *devman_parent_device_connect(devman_handle_t,
    5857    unsigned int);
    5958
  • uspace/lib/c/include/errno.h

    r3feeab2 rff381a7  
    4747#define ENOTDIR       (-258)
    4848#define ENOSPC        (-259)
    49 #define EEXIST        (-260)
    5049#define ENOTEMPTY     (-261)
    5150#define EBADF         (-262)
    52 #define ERANGE        (-263)
    53 #define EXDEV         (-264)
    54 #define EIO           (-265)
    55 #define EMLINK        (-266)
    56 #define ENXIO         (-267)
     51#define EDOM          (-263)
     52#define ERANGE        (-264)
     53#define EXDEV         (-265)
     54#define EIO           (-266)
     55#define EMLINK        (-267)
     56#define ENXIO         (-268)
    5757
    5858/** Bad checksum. */
  • uspace/lib/c/include/io/kio.h

    r3feeab2 rff381a7  
    4040#include <io/verify.h>
    4141
    42 extern size_t kio_write(const void *, size_t);
     42extern int kio_write(const void *, size_t, size_t *);
    4343extern void kio_update(void);
    4444extern void kio_command(const void *, size_t);
  • uspace/lib/c/include/ipc/devman.h

    r3feeab2 rff381a7  
    141141
    142142typedef enum {
    143         DEVMAN_DRIVER = 1,
    144         DEVMAN_CLIENT,
    145         DEVMAN_CONNECT_TO_DEVICE,
    146         DEVMAN_CONNECT_FROM_LOC,
    147         DEVMAN_CONNECT_TO_PARENTS_DEVICE
    148 } devman_interface_t;
    149 
    150 typedef enum {
    151143        DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
    152144        DEVMAN_ADD_FUNCTION,
  • uspace/lib/c/include/ipc/inet.h

    r3feeab2 rff381a7  
    3737
    3838#include <ipc/common.h>
    39 
    40 /** Inet ports */
    41 typedef enum {
    42         /** Default port */
    43         INET_PORT_DEFAULT = 1,
    44         /** Configuration port */
    45         INET_PORT_CFG,
    46         /** Ping service port */
    47         INET_PORT_PING,
    48         /** Ping6 service port */
    49         INET_PORT_PING6
    50 } inet_port_t;
    5139
    5240/** Requests on Inet default port */
  • uspace/lib/c/include/ipc/loc.h

    r3feeab2 rff381a7  
    7676} loc_event_t;
    7777
    78 /** Ports provided by location service.
    79  *
    80  * Every process that connects to loc must ask one of following
    81  * ports, otherwise connection will be refused.
    82  *
    83  */
    84 typedef enum {
    85         /** Service supplier (server) port */
    86         LOC_PORT_SUPPLIER = 1,
    87         /** Service consumer (client) port */
    88         LOC_PORT_CONSUMER,
    89         /** Create new connection to instance of device that
    90             is specified by second argument of call. */
    91         LOC_CONNECT_TO_SERVICE
    92 } loc_interface_t;
    93 
    9478typedef struct {
    9579        service_id_t id;
  • uspace/lib/c/include/ipc/logger.h

    r3feeab2 rff381a7  
    6969} logger_writer_request_t;
    7070
    71 typedef enum {
    72         /** Interface for controlling logger behavior. */
    73         LOGGER_INTERFACE_CONTROL,
    74         /** Interface for servers writing to the log. */
    75         LOGGER_INTERFACE_WRITER
    76 } logger_interface_t;
    77 
    7871#endif
    7972
  • uspace/lib/c/include/ipc/services.h

    r3feeab2 rff381a7  
    3838#define LIBC_SERVICES_H_
    3939
    40 #include <fourcc.h>
     40#include <sys/types.h>
     41#include <abi/fourcc.h>
    4142
    4243typedef enum {
    4344        SERVICE_NONE       = 0,
    44         SERVICE_LOAD       = FOURCC('l', 'o', 'a', 'd'),
     45        SERVICE_LOADER     = FOURCC('l', 'o', 'a', 'd'),
    4546        SERVICE_VFS        = FOURCC('v', 'f', 's', ' '),
    4647        SERVICE_LOC        = FOURCC('l', 'o', 'c', ' '),
     
    4950        SERVICE_IRC        = FOURCC('i', 'r', 'c', ' '),
    5051        SERVICE_CLIPBOARD  = FOURCC('c', 'l', 'i', 'p'),
    51 } services_t;
     52} service_t;
    5253
    53 #define SERVICE_NAME_CORECFG    "corecfg"
    54 #define SERVICE_NAME_DHCP       "net/dhcp"
    55 #define SERVICE_NAME_DNSR       "net/dnsr"
    56 #define SERVICE_NAME_INET       "net/inet"
    57 #define SERVICE_NAME_INETCFG    "net/inetcfg"
    58 #define SERVICE_NAME_INETPING   "net/inetping"
    59 #define SERVICE_NAME_INETPING6  "net/inetping6"
    60 #define SERVICE_NAME_NETCONF    "net/netconf"
    61 #define SERVICE_NAME_UDP        "net/udp"
    62 #define SERVICE_NAME_TCP        "net/tcp"
    63 #define SERVICE_NAME_VBD        "vbd"
    64 #define SERVICE_NAME_VOLSRV     "volsrv"
     54#define SERVICE_NAME_CORECFG  "corecfg"
     55#define SERVICE_NAME_DHCP     "net/dhcp"
     56#define SERVICE_NAME_DNSR     "net/dnsr"
     57#define SERVICE_NAME_INET     "net/inet"
     58#define SERVICE_NAME_NETCONF  "net/netconf"
     59#define SERVICE_NAME_UDP      "net/udp"
     60#define SERVICE_NAME_TCP      "net/tcp"
     61#define SERVICE_NAME_VBD      "vbd"
     62#define SERVICE_NAME_VOLSRV   "volsrv"
    6563
    6664#endif
  • uspace/lib/c/include/loc.h

    r3feeab2 rff381a7  
    4242typedef void (*loc_cat_change_cb_t)(void);
    4343
    44 extern async_exch_t *loc_exchange_begin_blocking(loc_interface_t);
    45 extern async_exch_t *loc_exchange_begin(loc_interface_t);
     44extern async_exch_t *loc_exchange_begin_blocking(iface_t);
     45extern async_exch_t *loc_exchange_begin(iface_t);
    4646extern void loc_exchange_end(async_exch_t *);
    4747
    4848extern int loc_server_register(const char *);
    4949extern int loc_service_register(const char *, service_id_t *);
    50 extern int loc_service_register_with_iface(const char *, service_id_t *,
    51     sysarg_t);
    5250extern int loc_service_unregister(service_id_t);
    5351extern int loc_service_add_to_cat(service_id_t, category_id_t);
     
    6563extern loc_object_type_t loc_id_probe(service_id_t);
    6664
    67 extern async_sess_t *loc_service_connect(exch_mgmt_t, service_id_t,
     65extern async_sess_t *loc_service_connect(service_id_t, iface_t,
    6866    unsigned int);
    6967
  • uspace/lib/c/include/ns.h

    r3feeab2 rff381a7  
    4141#include <async.h>
    4242
    43 extern int service_register(sysarg_t);
    44 extern async_sess_t *service_connect(exch_mgmt_t, services_t, sysarg_t, sysarg_t);
    45 extern async_sess_t *service_connect_blocking(exch_mgmt_t, services_t, sysarg_t,
    46     sysarg_t);
    47 extern async_sess_t *service_bind(services_t, sysarg_t, sysarg_t, sysarg_t,
    48     async_client_conn_t);
     43extern int service_register(service_t);
     44extern async_sess_t *service_connect(service_t, iface_t, sysarg_t);
     45extern async_sess_t *service_connect_blocking(service_t, iface_t, sysarg_t);
    4946
    5047extern int ns_ping(void);
  • uspace/lib/c/include/stdint.h

    r3feeab2 rff381a7  
    6060#define UINT64_MAX  UINT64_C(0xFFFFFFFFFFFFFFFF)
    6161
    62 #include <libarch/types.h>
     62#include <libarch/stdint.h>
    6363
    6464/* off64_t */
  • uspace/lib/c/include/stdio.h

    r3feeab2 rff381a7  
    109109extern int puts(const char *);
    110110
     111extern int ungetc(int, FILE *);
     112
    111113/* Formatted string output functions */
    112114extern int fprintf(FILE *, const char*, ...)
     
    132134extern FILE *fopen(const char *, const char *);
    133135extern FILE *fdopen(int, const char *);
     136extern FILE *freopen(const char *, const char *, FILE *);
    134137extern int fclose(FILE *);
    135138
  • uspace/lib/c/include/sys/statfs.h

    r3feeab2 rff381a7  
    4646
    4747extern int statfs(const char *, struct statfs *);
     48
    4849#endif
    4950
  • uspace/lib/c/include/sys/types.h

    r3feeab2 rff381a7  
    4646typedef uint64_t aoff64_t;
    4747
     48typedef uint32_t fourcc_t;
     49
    4850typedef volatile uint8_t ioport8_t;
    4951typedef volatile uint16_t ioport16_t;
  • uspace/lib/c/include/unistd.h

    r3feeab2 rff381a7  
    6363extern ssize_t read(int, void *, size_t);
    6464
    65 extern ssize_t read_all(int, void *, size_t);
    66 extern ssize_t write_all(int, const void *, size_t);
    67 
    6865extern off64_t lseek(int, off64_t, int);
    6966extern int ftruncate(int, aoff64_t);
  • uspace/lib/c/include/vfs/vfs.h

    r3feeab2 rff381a7  
    5050
    5151
    52 extern char *absolutize(const char *, size_t *);
     52extern char *vfs_absolutize(const char *, size_t *);
    5353
    54 extern int mount(const char *, const char *, const char *, const char *,
     54extern int vfs_mount(const char *, const char *, const char *, const char *,
    5555    unsigned int, unsigned int);
    56 extern int unmount(const char *);
     56extern int vfs_unmount(const char *);
    5757
    58 extern int fhandle(FILE *, int *);
     58extern int vfs_fhandle(FILE *, int *);
    5959
    60 extern int fd_wait(void);
    61 extern int get_mtab_list(list_t *mtab_list);
     60extern int vfs_fd_wait(void);
     61extern int vfs_get_mtab_list(list_t *mtab_list);
    6262
    6363extern async_exch_t *vfs_exchange_begin(void);
    6464extern void vfs_exchange_end(async_exch_t *);
     65
    6566#endif
    6667
  • uspace/lib/c/include/vfs/vfs_sess.h

    r3feeab2 rff381a7  
    3939#include <stdio.h>
    4040
    41 extern async_sess_t *fd_session(exch_mgmt_t, int);
    42 extern async_sess_t *fsession(exch_mgmt_t, FILE *);
     41extern async_sess_t *vfs_fd_session(int, iface_t);
     42extern async_sess_t *vfs_fsession(FILE *, iface_t);
    4343
    4444#endif
Note: See TracChangeset for help on using the changeset viewer.