Changeset 921b84f in mainline for uspace


Ignore:
Timestamp:
2011-08-19T17:36:25Z (14 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5fb32c5
Parents:
ea186c6 (diff), f00af83 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libposix changes.

Location:
uspace
Files:
2 added
48 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/Makefile

    rea186c6 r921b84f  
    3737        app/blkdump \
    3838        app/bnchmark \
     39        app/devctl \
    3940        app/edit \
    4041        app/ext2info \
  • uspace/app/bdsh/exec.c

    rea186c6 r921b84f  
    4040#include <str_error.h>
    4141#include <errno.h>
     42#include <vfs/vfs.h>
    4243
    4344#include "config.h"
     
    99100        char *tmp;
    100101        int rc, retval, i;
    101         fdi_node_t file_nodes[3];
    102         fdi_node_t *file_nodes_p[4];
     102        int file_handles[3];
     103        int *file_handles_p[4];
    103104        FILE *files[3];
    104105
     
    111112       
    112113        for (i = 0; i < 3 && files[i] != NULL; i++) {
    113                 if (fnode(files[i], &file_nodes[i]) == EOK) {
    114                         file_nodes_p[i] = &file_nodes[i];
     114                if (fhandle(files[i], &file_handles[i]) == EOK) {
     115                        file_handles_p[i] = &file_handles[i];
    115116                }
    116117                else {
    117                         file_nodes_p[i] = NULL;
     118                        file_handles_p[i] = NULL;
    118119                }
    119120        }
    120         file_nodes_p[i] = NULL;
     121        file_handles_p[i] = NULL;
    121122
    122         rc = task_spawnvf(&tid, tmp, (const char **) argv, file_nodes_p);
     123        rc = task_spawnvf(&tid, tmp, (const char **) argv, file_handles_p);
    123124        free(tmp);
    124125
  • uspace/app/lsusb/main.c

    rea186c6 r921b84f  
    8181                }
    8282                char path[MAX_PATH_LENGTH];
    83                 rc = devman_get_device_path(dev_handle, path, MAX_PATH_LENGTH);
     83                rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH);
    8484                if (rc != EOK) {
    8585                        continue;
     
    120120                }
    121121                char path[MAX_PATH_LENGTH];
    122                 rc = devman_get_device_path(hc_handle, path, MAX_PATH_LENGTH);
     122                rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH);
    123123                if (rc != EOK) {
    124124                        printf(NAME ": Error resolving path of HC with SID %"
  • uspace/app/mkbd/main.c

    rea186c6 r921b84f  
    240240       
    241241        char path[MAX_PATH_LENGTH];
    242         rc = devman_get_device_path(dev_handle, path, MAX_PATH_LENGTH);
     242        rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH);
    243243        if (rc != EOK) {
    244244                return ENOMEM;
  • uspace/app/tester/hw/serial/serial1.c

    rea186c6 r921b84f  
    7272       
    7373        devman_handle_t handle;
    74         int res = devman_device_get_handle("/hw/pci0/00:01.0/com1/a", &handle,
     74        int res = devman_fun_get_handle("/hw/pci0/00:01.0/com1/a", &handle,
    7575            IPC_FLAG_BLOCKING);
    7676        if (res != EOK)
  • uspace/app/trace/trace.c

    rea186c6 r921b84f  
    5050#include <sys/types.h>
    5151#include <sys/typefmt.h>
     52#include <vfs/vfs.h>
    5253
    5354#include <libc.h>
     
    586587
    587588        /* Send default files */
    588         fdi_node_t *files[4];
    589         fdi_node_t stdin_node;
    590         fdi_node_t stdout_node;
    591         fdi_node_t stderr_node;
    592        
    593         if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK))
    594                 files[0] = &stdin_node;
     589        int *files[4];
     590        int fd_stdin;
     591        int fd_stdout;
     592        int fd_stderr;
     593       
     594        if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
     595                files[0] = &fd_stdin;
    595596        else
    596597                files[0] = NULL;
    597598       
    598         if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK))
    599                 files[1] = &stdout_node;
     599        if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
     600                files[1] = &fd_stdout;
    600601        else
    601602                files[1] = NULL;
    602603       
    603         if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK))
    604                 files[2] = &stderr_node;
     604        if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
     605                files[2] = &fd_stderr;
    605606        else
    606607                files[2] = NULL;
     
    761762        o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def);
    762763        proto_add_oper(p, VFS_IN_OPEN, o);
    763         o = oper_new("open_node", 4, arg_def, V_INT_ERRNO, 0, resp_def);
    764         proto_add_oper(p, VFS_IN_OPEN_NODE, o);
    765764        o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
    766765        proto_add_oper(p, VFS_IN_READ, o);
  • uspace/lib/c/arch/ia32/Makefile.common

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

    rea186c6 r921b84f  
    2828
    2929ARCH_SOURCES = \
    30         arch/$(UARCH)/src/entry.s \
     30        arch/$(UARCH)/src/entry.S \
    3131        arch/$(UARCH)/src/entryjmp.s \
    3232        arch/$(UARCH)/src/thread_entry.s \
  • uspace/lib/c/arch/ia32/src/entry.S

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

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

    rea186c6 r921b84f  
    11/*
    22 * Copyright (c) 2007 Josef Cejka
    3  * Copyright (c) 2009 Jiri Svoboda
     3 * Copyright (c) 2011 Jiri Svoboda
    44 * Copyright (c) 2010 Lenka Trochtova
    55 * All rights reserved.
     
    195195       
    196196        exch = devman_exchange_begin(DEVMAN_DRIVER);
    197         async_connect_to_me(exch, 0, 0, 0, NULL, NULL);
     197        async_connect_to_me(exch, 0, 0, 0, conn, NULL);
    198198        devman_exchange_end(exch);
    199199       
     
    342342}
    343343
    344 int devman_device_get_handle(const char *pathname, devman_handle_t *handle,
     344int devman_fun_get_handle(const char *pathname, devman_handle_t *handle,
    345345    unsigned int flags)
    346346{
     
    383383}
    384384
    385 int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size)
     385static int devman_get_str_internal(sysarg_t method, sysarg_t arg1, char *buf,
     386    size_t buf_size)
     387{
     388        async_exch_t *exch;
     389        ipc_call_t dreply;
     390        size_t act_size;
     391        sysarg_t dretval;
     392       
     393        exch = devman_exchange_begin_blocking(LOC_PORT_CONSUMER);
     394       
     395        ipc_call_t answer;
     396        aid_t req = async_send_1(exch, method, arg1, &answer);
     397        aid_t dreq = async_data_read(exch, buf, buf_size - 1, &dreply);
     398        async_wait_for(dreq, &dretval);
     399       
     400        devman_exchange_end(exch);
     401       
     402        if (dretval != EOK) {
     403                async_wait_for(req, NULL);
     404                return dretval;
     405        }
     406       
     407        sysarg_t retval;
     408        async_wait_for(req, &retval);
     409       
     410        if (retval != EOK)
     411                return retval;
     412       
     413        act_size = IPC_GET_ARG2(dreply);
     414        assert(act_size <= buf_size - 1);
     415        buf[act_size] = '\0';
     416       
     417        return EOK;
     418}
     419
     420int devman_fun_get_path(devman_handle_t handle, char *buf, size_t buf_size)
     421{
     422        return devman_get_str_internal(DEVMAN_FUN_GET_PATH, handle, buf,
     423            buf_size);
     424}
     425
     426int devman_fun_get_name(devman_handle_t handle, char *buf, size_t buf_size)
     427{
     428        return devman_get_str_internal(DEVMAN_FUN_GET_NAME, handle, buf,
     429            buf_size);
     430}
     431
     432static int devman_get_handles_once(sysarg_t method, sysarg_t arg1,
     433    devman_handle_t *handle_buf, size_t buf_size, size_t *act_size)
     434{
     435        async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_CLIENT);
     436
     437        ipc_call_t answer;
     438        aid_t req = async_send_1(exch, method, arg1, &answer);
     439        int rc = async_data_read_start(exch, handle_buf, buf_size);
     440       
     441        devman_exchange_end(exch);
     442       
     443        if (rc != EOK) {
     444                async_wait_for(req, NULL);
     445                return rc;
     446        }
     447       
     448        sysarg_t retval;
     449        async_wait_for(req, &retval);
     450       
     451        if (retval != EOK) {
     452                return retval;
     453        }
     454       
     455        *act_size = IPC_GET_ARG1(answer);
     456        return EOK;
     457}
     458
     459/** Get list of handles.
     460 *
     461 * Returns an allocated array of handles.
     462 *
     463 * @param method        IPC method
     464 * @param arg1          IPC argument 1
     465 * @param data          Place to store pointer to array of handles
     466 * @param count         Place to store number of handles
     467 * @return              EOK on success or negative error code
     468 */
     469static int devman_get_handles_internal(sysarg_t method, sysarg_t arg1,
     470    devman_handle_t **data, size_t *count)
     471{
     472        devman_handle_t *handles;
     473        size_t act_size;
     474        size_t alloc_size;
     475        int rc;
     476
     477        *data = NULL;
     478        act_size = 0;   /* silence warning */
     479
     480        rc = devman_get_handles_once(method, arg1, NULL, 0,
     481            &act_size);
     482        if (rc != EOK)
     483                return rc;
     484
     485        alloc_size = act_size;
     486        handles = malloc(alloc_size);
     487        if (handles == NULL)
     488                return ENOMEM;
     489
     490        while (true) {
     491                rc = devman_get_handles_once(method, arg1, handles, alloc_size,
     492                    &act_size);
     493                if (rc != EOK)
     494                        return rc;
     495
     496                if (act_size <= alloc_size)
     497                        break;
     498
     499                alloc_size *= 2;
     500                free(handles);
     501
     502                handles = malloc(alloc_size);
     503                if (handles == NULL)
     504                        return ENOMEM;
     505        }
     506
     507        *count = act_size / sizeof(devman_handle_t);
     508        *data = handles;
     509        return EOK;
     510}
     511
     512int devman_fun_get_child(devman_handle_t funh, devman_handle_t *devh)
    386513{
    387514        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     
    389516                return ENOMEM;
    390517       
    391         ipc_call_t answer;
    392         aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_DEVICE_PATH,
    393             handle, &answer);
    394        
    395         ipc_call_t data_request_call;
    396         aid_t data_request = async_data_read(exch, path, path_size,
    397             &data_request_call);
    398        
    399         devman_exchange_end(exch);
    400        
    401         if (data_request == 0) {
    402                 async_wait_for(req, NULL);
    403                 return ENOMEM;
    404         }
    405        
    406         sysarg_t data_request_rc;
    407         async_wait_for(data_request, &data_request_rc);
    408        
    409         sysarg_t opening_request_rc;
    410         async_wait_for(req, &opening_request_rc);
    411        
    412         if (data_request_rc != EOK) {
    413                 /* Prefer the return code of the opening request. */
    414                 if (opening_request_rc != EOK)
    415                         return (int) opening_request_rc;
    416                 else
    417                         return (int) data_request_rc;
    418         }
    419        
    420         if (opening_request_rc != EOK)
    421                 return (int) opening_request_rc;
    422        
    423         /* To be on the safe-side. */
    424         path[path_size - 1] = 0;
    425         size_t transferred_size = IPC_GET_ARG2(data_request_call);
    426         if (transferred_size >= path_size)
    427                 return ELIMIT;
    428        
    429         /* Terminate the string (trailing 0 not send over IPC). */
    430         path[transferred_size] = 0;
    431         return EOK;
     518        sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_GET_CHILD,
     519            funh, devh);
     520       
     521        devman_exchange_end(exch);
     522        return (int) retval;
     523}
     524
     525int devman_dev_get_functions(devman_handle_t devh, devman_handle_t **funcs,
     526    size_t *count)
     527{
     528        return devman_get_handles_internal(DEVMAN_DEV_GET_FUNCTIONS,
     529            devh, funcs, count);
    432530}
    433531
  • uspace/lib/c/generic/event.c

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

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

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

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

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

    rea186c6 r921b84f  
    315315/** Register new service.
    316316 *
    317  * @param fqsn  Fully qualified service name
    318  * @param sid   Output: ID of new service
     317 * @param fqsn Fully qualified service name
     318 * @param sid  Output: ID of new service
    319319 *
    320320 */
  • uspace/lib/c/generic/private/async.h

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

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

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

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

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

    rea186c6 r921b84f  
    5656    unsigned int);
    5757
    58 extern int devman_device_get_handle(const char *, devman_handle_t *,
     58extern int devman_fun_get_handle(const char *, devman_handle_t *,
    5959    unsigned int);
    60 extern int devman_get_device_path(devman_handle_t, char *, size_t);
     60extern int devman_fun_get_child(devman_handle_t, devman_handle_t *);
     61extern int devman_dev_get_functions(devman_handle_t, devman_handle_t **,
     62    size_t *);
     63extern int devman_fun_get_name(devman_handle_t, char *, size_t);
     64extern int devman_fun_get_path(devman_handle_t, char *, size_t);
    6165
    6266extern int devman_add_device_to_category(devman_handle_t, const char *);
  • uspace/lib/c/include/event.h

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

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

    rea186c6 r921b84f  
    149149typedef enum {
    150150        DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
    151         DEVMAN_DEVICE_GET_DEVICE_PATH,
     151        DEVMAN_DEV_GET_FUNCTIONS,
     152        DEVMAN_FUN_GET_CHILD,
     153        DEVMAN_FUN_GET_NAME,
     154        DEVMAN_FUN_GET_PATH,
    152155        DEVMAN_FUN_SID_TO_HANDLE
    153156} client_to_devman_t;
  • uspace/lib/c/include/ipc/vfs.h

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

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

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

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

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

    rea186c6 r921b84f  
    428428static void driver_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    429429{
     430        sysarg_t conn_type;
     431
     432        if (iid == 0) {
     433                /* Callback connection from devman */
     434                /* XXX Use separate handler for this type of connection */
     435                conn_type = DRIVER_DEVMAN;
     436        } else {
     437                conn_type = IPC_GET_ARG1(*icall);
     438        }
     439
    430440        /* Select interface */
    431         switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {
     441        switch (conn_type) {
    432442        case DRIVER_DEVMAN:
    433443                /* Handle request from device manager */
  • uspace/lib/posix/fcntl.c

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

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

    rea186c6 r921b84f  
    152152                if (str_length(func_start) > 0) {
    153153                        char tmp_path[MAX_DEVICE_PATH ];
    154                         rc = devman_get_device_path(dev_handle,
     154                        rc = devman_fun_get_path(dev_handle,
    155155                            tmp_path, MAX_DEVICE_PATH);
    156156                        if (rc != EOK) {
     
    173173
    174174        /* First try to get the device handle. */
    175         rc = devman_device_get_handle(path, &dev_handle, 0);
     175        rc = devman_fun_get_handle(path, &dev_handle, 0);
    176176        if (rc != EOK) {
    177177                free(path);
     
    184184                /* Get device handle first. */
    185185                devman_handle_t tmp_handle;
    186                 rc = devman_device_get_handle(path, &tmp_handle, 0);
     186                rc = devman_fun_get_handle(path, &tmp_handle, 0);
    187187                if (rc != EOK) {
    188188                        free(path);
  • uspace/lib/usbvirt/src/device.c

    rea186c6 r921b84f  
    8787       
    8888        devman_handle_t handle;
    89         int rc = devman_device_get_handle(vhc_path, &handle, 0);
     89        int rc = devman_fun_get_handle(vhc_path, &handle, 0);
    9090        if (rc != EOK)
    9191                return rc;
  • uspace/srv/devman/devman.c

    rea186c6 r921b84f  
    548548
    549549        fibril_mutex_lock(&driver->driver_mutex);
    550        
    551         async_exch_t *exch = async_exchange_begin(driver->sess);
    552         async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch,
    553             DRIVER_DEVMAN, 0, 0);
    554         async_exchange_end(exch);
    555 
    556         if (!sess) {
    557                 fibril_mutex_unlock(&driver->driver_mutex);
    558                 return;
    559         }
    560550
    561551        /*
     
    583573                fibril_mutex_unlock(&driver->driver_mutex);
    584574
    585                 add_device(sess, driver, dev, tree);
     575                add_device(driver, dev, tree);
    586576
    587577                /*
     
    603593                link = driver->devices.head.next;
    604594        }
    605 
    606         async_hangup(sess);
    607595
    608596        /*
     
    718706 * @param node          The device's node in the device tree.
    719707 */
    720 void add_device(async_sess_t *sess, driver_t *drv, dev_node_t *dev,
    721     dev_tree_t *tree)
     708void add_device(driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
    722709{
    723710        /*
     
    736723        }
    737724       
    738         async_exch_t *exch = async_exchange_begin(sess);
     725        async_exch_t *exch = async_exchange_begin(drv->sess);
    739726       
    740727        ipc_call_t answer;
     
    806793        fibril_mutex_unlock(&drv->driver_mutex);
    807794
    808         if (is_running) {
    809                 /* Notify the driver about the new device. */
    810                 async_exch_t *exch = async_exchange_begin(drv->sess);
    811                 async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch,
    812                     DRIVER_DEVMAN, 0, 0);
    813                 async_exchange_end(exch);
    814                
    815                 if (sess) {
    816                         add_device(sess, drv, dev, tree);
    817                         async_hangup(sess);
    818                 }
    819         }
     795        /* Notify the driver about the new device. */
     796        if (is_running)
     797                add_device(drv, dev, tree);
    820798       
    821799        return true;
     
    919897        return dev;
    920898}
     899
     900/** Get list of device functions. */
     901int dev_get_functions(dev_tree_t *tree, dev_node_t *dev,
     902    devman_handle_t *hdl_buf, size_t buf_size, size_t *act_size)
     903{
     904        size_t act_cnt;
     905        size_t buf_cnt;
     906
     907        assert(fibril_rwlock_is_locked(&tree->rwlock));
     908
     909        buf_cnt = buf_size / sizeof(devman_handle_t);
     910
     911        act_cnt = list_count(&dev->functions);
     912        *act_size = act_cnt * sizeof(devman_handle_t);
     913
     914        if (buf_size % sizeof(devman_handle_t) != 0)
     915                return EINVAL;
     916
     917        size_t pos = 0;
     918        list_foreach(dev->functions, item) {
     919                fun_node_t *fun =
     920                    list_get_instance(item, fun_node_t, dev_functions);
     921
     922                if (pos < buf_cnt)
     923                        hdl_buf[pos] = fun->handle;
     924                pos++;
     925        }
     926
     927        return EOK;
     928}
     929
    921930
    922931/* Function nodes */
     
    11451154        char *rel_path = path;
    11461155        char *next_path_elem = NULL;
    1147         bool cont = true;
     1156        bool cont = (rel_path[1] != '\0');
    11481157       
    11491158        while (cont && fun != NULL) {
  • uspace/srv/devman/devman.h

    rea186c6 r921b84f  
    235235extern void add_driver(driver_list_t *, driver_t *);
    236236extern void attach_driver(dev_node_t *, driver_t *);
    237 extern void add_device(async_sess_t *, driver_t *, dev_node_t *, dev_tree_t *);
     237extern void add_device(driver_t *, dev_node_t *, dev_tree_t *);
    238238extern bool start_driver(driver_t *);
    239239
     
    253253extern dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle);
    254254extern dev_node_t *find_dev_function(dev_node_t *, const char *);
     255extern int dev_get_functions(dev_tree_t *tree, dev_node_t *, devman_handle_t *,
     256    size_t, size_t *);
    255257
    256258extern fun_node_t *create_fun_node(void);
  • uspace/srv/devman/main.c

    rea186c6 r921b84f  
    497497}
    498498
    499 /** Find device path by its handle. */
    500 static void devman_get_device_path_by_handle(ipc_callid_t iid,
    501     ipc_call_t *icall)
     499/** Get device name. */
     500static void devman_fun_get_name(ipc_callid_t iid, ipc_call_t *icall)
    502501{
    503502        devman_handle_t handle = IPC_GET_ARG1(*icall);
     
    523522        }
    524523
     524        size_t sent_length = str_size(fun->name);
     525        if (sent_length > data_len) {
     526                sent_length = data_len;
     527        }
     528
     529        async_data_read_finalize(data_callid, fun->name, sent_length);
     530        async_answer_0(iid, EOK);
     531
     532        free(buffer);
     533}
     534
     535
     536/** Get device path. */
     537static void devman_fun_get_path(ipc_callid_t iid, ipc_call_t *icall)
     538{
     539        devman_handle_t handle = IPC_GET_ARG1(*icall);
     540
     541        fun_node_t *fun = find_fun_node(&device_tree, handle);
     542        if (fun == NULL) {
     543                async_answer_0(iid, ENOMEM);
     544                return;
     545        }
     546
     547        ipc_callid_t data_callid;
     548        size_t data_len;
     549        if (!async_data_read_receive(&data_callid, &data_len)) {
     550                async_answer_0(iid, EINVAL);
     551                return;
     552        }
     553
     554        void *buffer = malloc(data_len);
     555        if (buffer == NULL) {
     556                async_answer_0(data_callid, ENOMEM);
     557                async_answer_0(iid, ENOMEM);
     558                return;
     559        }
     560
    525561        size_t sent_length = str_size(fun->pathname);
    526562        if (sent_length > data_len) {
     
    532568
    533569        free(buffer);
     570}
     571
     572static void devman_dev_get_functions(ipc_callid_t iid, ipc_call_t *icall)
     573{
     574        ipc_callid_t callid;
     575        size_t size;
     576        size_t act_size;
     577        int rc;
     578       
     579        if (!async_data_read_receive(&callid, &size)) {
     580                async_answer_0(callid, EREFUSED);
     581                async_answer_0(iid, EREFUSED);
     582                return;
     583        }
     584       
     585        fibril_rwlock_read_lock(&device_tree.rwlock);
     586       
     587        dev_node_t *dev = find_dev_node_no_lock(&device_tree,
     588            IPC_GET_ARG1(*icall));
     589        if (dev == NULL) {
     590                fibril_rwlock_read_unlock(&device_tree.rwlock);
     591                async_answer_0(callid, ENOENT);
     592                async_answer_0(iid, ENOENT);
     593                return;
     594        }
     595       
     596        devman_handle_t *hdl_buf = (devman_handle_t *) malloc(size);
     597        if (hdl_buf == NULL) {
     598                fibril_rwlock_read_unlock(&device_tree.rwlock);
     599                async_answer_0(callid, ENOMEM);
     600                async_answer_0(iid, ENOMEM);
     601                return;
     602        }
     603       
     604        rc = dev_get_functions(&device_tree, dev, hdl_buf, size, &act_size);
     605        if (rc != EOK) {
     606                fibril_rwlock_read_unlock(&device_tree.rwlock);
     607                async_answer_0(callid, rc);
     608                async_answer_0(iid, rc);
     609                return;
     610        }
     611       
     612        fibril_rwlock_read_unlock(&device_tree.rwlock);
     613       
     614        sysarg_t retval = async_data_read_finalize(callid, hdl_buf, size);
     615        free(hdl_buf);
     616       
     617        async_answer_1(iid, retval, act_size);
     618}
     619
     620
     621/** Get handle for child device of a function. */
     622static void devman_fun_get_child(ipc_callid_t iid, ipc_call_t *icall)
     623{
     624        fun_node_t *fun;
     625       
     626        fibril_rwlock_read_lock(&device_tree.rwlock);
     627       
     628        fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall));
     629        if (fun == NULL) {
     630                fibril_rwlock_read_unlock(&device_tree.rwlock);
     631                async_answer_0(iid, ENOENT);
     632                return;
     633        }
     634       
     635        if (fun->child == NULL) {
     636                fibril_rwlock_read_unlock(&device_tree.rwlock);
     637                async_answer_0(iid, ENOENT);
     638                return;
     639        }
     640       
     641        async_answer_1(iid, EOK, fun->child->handle);
     642       
     643        fibril_rwlock_read_unlock(&device_tree.rwlock);
    534644}
    535645
     
    566676                        devman_function_get_handle(callid, &call);
    567677                        break;
    568                 case DEVMAN_DEVICE_GET_DEVICE_PATH:
    569                         devman_get_device_path_by_handle(callid, &call);
     678                case DEVMAN_DEV_GET_FUNCTIONS:
     679                        devman_dev_get_functions(callid, &call);
     680                        break;
     681                case DEVMAN_FUN_GET_CHILD:
     682                        devman_fun_get_child(callid, &call);
     683                        break;
     684                case DEVMAN_FUN_GET_NAME:
     685                        devman_fun_get_name(callid, &call);
     686                        break;
     687                case DEVMAN_FUN_GET_PATH:
     688                        devman_fun_get_path(callid, &call);
    570689                        break;
    571690                case DEVMAN_FUN_SID_TO_HANDLE:
  • uspace/srv/hid/input/port/adb_mouse.c

    rea186c6 r921b84f  
    4242#include <errno.h>
    4343#include <loc.h>
     44#include <stdio.h>
    4445
    4546static mouse_dev_t *mouse_dev;
  • uspace/srv/hw/irc/apic/apic.c

    rea186c6 r921b84f  
    4545#include <errno.h>
    4646#include <async.h>
     47#include <stdio.h>
    4748
    4849#define NAME  "apic"
  • uspace/srv/loader/main.c

    rea186c6 r921b84f  
    6161#include <elf/elf.h>
    6262#include <elf/elf_load.h>
     63#include <vfs/vfs.h>
    6364
    6465#ifdef CONFIG_RTLD
     
    8990
    9091/** Number of preset files */
    91 static int filc = 0;
    92 /** Preset files vector */
    93 static fdi_node_t **filv = NULL;
    94 /** Buffer holding all preset files */
    95 static fdi_node_t *fil_buf = NULL;
     92static unsigned int filc = 0;
    9693
    9794static elf_info_t prog_info;
     
    239236static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request)
    240237{
    241         fdi_node_t *buf;
    242         size_t buf_size;
    243         int rc = async_data_write_accept((void **) &buf, false, 0, 0,
    244             sizeof(fdi_node_t), &buf_size);
    245        
    246         if (rc == EOK) {
    247                 int count = buf_size / sizeof(fdi_node_t);
    248                
    249                 /*
    250                  * Allocate new filv
    251                  */
    252                 fdi_node_t **_filv = (fdi_node_t **) calloc(count + 1, sizeof(fdi_node_t *));
    253                 if (_filv == NULL) {
    254                         free(buf);
    255                         async_answer_0(rid, ENOMEM);
    256                         return;
     238        size_t count = IPC_GET_ARG1(*request);
     239
     240        async_exch_t *vfs_exch = vfs_exchange_begin();
     241
     242        for (filc = 0; filc < count; filc++) {
     243                ipc_callid_t callid;
     244                int fd;
     245
     246                if (!async_state_change_receive(&callid, NULL, NULL, NULL)) {
     247                        async_answer_0(callid, EINVAL);
     248                        break;
    257249                }
    258                
    259                 /*
    260                  * Fill the new filv with argument pointers
    261                  */
    262                 int i;
    263                 for (i = 0; i < count; i++)
    264                         _filv[i] = &buf[i];
    265                
    266                 _filv[count] = NULL;
    267                
    268                 /*
    269                  * Copy temporary data to global variables
    270                  */
    271                 if (fil_buf != NULL)
    272                         free(fil_buf);
    273                
    274                 if (filv != NULL)
    275                         free(filv);
    276                
    277                 filc = count;
    278                 fil_buf = buf;
    279                 filv = _filv;
    280         }
    281        
     250                async_state_change_finalize(callid, vfs_exch);
     251                fd = fd_wait();
     252                assert(fd == (int) filc);
     253        }
     254
     255        vfs_exchange_end(vfs_exch);
     256
    282257        async_answer_0(rid, EOK);
    283258}
     
    308283       
    309284        pcb.filc = filc;
    310         pcb.filv = filv;
    311285       
    312286        if (prog_info.interp == NULL) {
  • uspace/srv/loc/loc.h

    rea186c6 r921b84f  
    3636#define LOC_H_
    3737
     38#include <ipc/loc.h>
    3839#include <async.h>
    3940#include <fibril_synch.h>
  • uspace/srv/vfs/vfs.c

    rea186c6 r921b84f  
    3636 */
    3737
     38#include <vfs/vfs.h>
    3839#include <ipc/services.h>
     40#include <abi/ipc/event.h>
     41#include <event.h>
    3942#include <ns.h>
    4043#include <async.h>
     
    4548#include <as.h>
    4649#include <atomic.h>
     50#include <macros.h>
    4751#include "vfs.h"
    4852
    4953#define NAME  "vfs"
     54
     55enum {
     56        VFS_TASK_STATE_CHANGE
     57};
    5058
    5159static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     
    8088                        vfs_open(callid, &call);
    8189                        break;
    82                 case VFS_IN_OPEN_NODE:
    83                         vfs_open_node(callid, &call);
    84                         break;
    8590                case VFS_IN_CLOSE:
    8691                        vfs_close(callid, &call);
     
    118123                case VFS_IN_DUP:
    119124                        vfs_dup(callid, &call);
     125                        break;
     126                case VFS_IN_WAIT_HANDLE:
     127                        vfs_wait_handle(callid, &call);
     128                        break;
    120129                default:
    121130                        async_answer_0(callid, ENOTSUP);
     
    128137         * connection fibril terminates.
    129138         */
     139}
     140
     141static void notification_received(ipc_callid_t callid, ipc_call_t *call)
     142{
     143        switch (IPC_GET_IMETHOD(*call)) {
     144        case VFS_TASK_STATE_CHANGE:
     145                if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE)
     146                        vfs_pass_handle(
     147                            (task_id_t) MERGE_LOUP32(IPC_GET_ARG4(*call),
     148                            IPC_GET_ARG5(*call)), call->in_task_id,
     149                            (int) IPC_GET_ARG2(*call));
     150                break;
     151        default:
     152                break;
     153        }
    130154}
    131155
     
    170194
    171195        /*
     196         * Set notification handler and subscribe to notifications.
     197         */
     198        async_set_interrupt_received(notification_received);
     199        event_task_subscribe(EVENT_TASK_STATE_CHANGE, VFS_TASK_STATE_CHANGE);
     200
     201        /*
    172202         * Register at the naming service.
    173203         */
  • uspace/srv/vfs/vfs.h

    rea186c6 r921b84f  
    4141#include <bool.h>
    4242#include <ipc/vfs.h>
     43#include <task.h>
    4344
    4445#ifndef dprintf
     
    175176extern int vfs_lookup_internal(char *, int, vfs_lookup_res_t *,
    176177    vfs_pair_t *, ...);
    177 extern int vfs_open_node_internal(vfs_lookup_res_t *);
    178178
    179179extern bool vfs_nodes_init(void);
     
    189189extern void vfs_client_data_destroy(void *);
    190190
     191extern void vfs_pass_handle(task_id_t, task_id_t, int);
     192extern int vfs_wait_handle_internal(void);
     193
    191194extern vfs_file_t *vfs_file_get(int);
    192195extern void vfs_file_put(vfs_file_t *);
     
    197200extern void vfs_node_addref(vfs_node_t *);
    198201extern void vfs_node_delref(vfs_node_t *);
     202extern int vfs_open_node_remote(vfs_node_t *);
    199203
    200204extern void vfs_register(ipc_callid_t, ipc_call_t *);
     
    202206extern void vfs_unmount(ipc_callid_t, ipc_call_t *);
    203207extern void vfs_open(ipc_callid_t, ipc_call_t *);
    204 extern void vfs_open_node(ipc_callid_t, ipc_call_t *);
    205208extern void vfs_sync(ipc_callid_t, ipc_call_t *);
    206209extern void vfs_dup(ipc_callid_t, ipc_call_t *);
     
    215218extern void vfs_unlink(ipc_callid_t, ipc_call_t *);
    216219extern void vfs_rename(ipc_callid_t, ipc_call_t *);
     220extern void vfs_wait_handle(ipc_callid_t, ipc_call_t *);
    217221
    218222#endif
  • uspace/srv/vfs/vfs_file.c

    rea186c6 r921b84f  
    4343#include <fibril.h>
    4444#include <fibril_synch.h>
     45#include <adt/list.h>
     46#include <task.h>
    4547#include "vfs.h"
    4648
     
    5052typedef struct {
    5153        fibril_mutex_t lock;
     54        fibril_condvar_t cv;
     55        list_t passed_handles;
    5256        vfs_file_t **files;
    5357} vfs_client_data_t;
    5458
     59typedef struct {
     60        link_t link;
     61        int handle;
     62} vfs_boxed_handle_t;
     63
     64static int _vfs_fd_free(vfs_client_data_t *, int);
     65
    5566/** Initialize the table of open files. */
    56 static bool vfs_files_init(void)
    57 {
    58         fibril_mutex_lock(&VFS_DATA->lock);
    59         if (!FILES) {
    60                 FILES = malloc(MAX_OPEN_FILES * sizeof(vfs_file_t *));
    61                 if (!FILES) {
    62                         fibril_mutex_unlock(&VFS_DATA->lock);
     67static bool vfs_files_init(vfs_client_data_t *vfs_data)
     68{
     69        fibril_mutex_lock(&vfs_data->lock);
     70        if (!vfs_data->files) {
     71                vfs_data->files = malloc(MAX_OPEN_FILES * sizeof(vfs_file_t *));
     72                if (!vfs_data->files) {
     73                        fibril_mutex_unlock(&vfs_data->lock);
    6374                        return false;
    6475                }
    65                 memset(FILES, 0, MAX_OPEN_FILES * sizeof(vfs_file_t *));
    66         }
    67         fibril_mutex_unlock(&VFS_DATA->lock);
     76                memset(vfs_data->files, 0, MAX_OPEN_FILES * sizeof(vfs_file_t *));
     77        }
     78        fibril_mutex_unlock(&vfs_data->lock);
    6879        return true;
    6980}
    7081
    7182/** Cleanup the table of open files. */
    72 static void vfs_files_done(void)
     83static void vfs_files_done(vfs_client_data_t *vfs_data)
    7384{
    7485        int i;
    7586
    76         if (!FILES)
     87        if (!vfs_data->files)
    7788                return;
    7889
    7990        for (i = 0; i < MAX_OPEN_FILES; i++) {
    80                 if (FILES[i]) {
    81                         (void) vfs_fd_free(i);
    82                 }
    83         }
    84        
    85         free(FILES);
     91                if (vfs_data->files[i])
     92                        (void) _vfs_fd_free(vfs_data, i);
     93        }
     94       
     95        free(vfs_data->files);
     96
     97        while (!list_empty(&vfs_data->passed_handles)) {
     98                link_t *lnk;
     99                vfs_boxed_handle_t *bh;
     100               
     101                lnk = list_first(&vfs_data->passed_handles);
     102                list_remove(lnk);
     103
     104                bh = list_get_instance(lnk, vfs_boxed_handle_t, link);
     105                free(bh);
     106        }
    86107}
    87108
     
    93114        if (vfs_data) {
    94115                fibril_mutex_initialize(&vfs_data->lock);
     116                fibril_condvar_initialize(&vfs_data->cv);
     117                list_initialize(&vfs_data->passed_handles);
    95118                vfs_data->files = NULL;
    96119        }
     
    103126        vfs_client_data_t *vfs_data = (vfs_client_data_t *) data;
    104127
    105         vfs_files_done();
     128        vfs_files_done(vfs_data);
    106129        free(vfs_data);
    107130}
     
    131154 *                      incremented.
    132155 */
    133 static void vfs_file_addref(vfs_file_t *file)
    134 {
    135         assert(fibril_mutex_is_locked(&VFS_DATA->lock));
     156static void vfs_file_addref(vfs_client_data_t *vfs_data, vfs_file_t *file)
     157{
     158        assert(fibril_mutex_is_locked(&vfs_data->lock));
    136159
    137160        file->refcnt++;
     
    143166 *                      decremented.
    144167 */
    145 static int vfs_file_delref(vfs_file_t *file)
     168static int vfs_file_delref(vfs_client_data_t *vfs_data, vfs_file_t *file)
    146169{
    147170        int rc = EOK;
    148171
    149         assert(fibril_mutex_is_locked(&VFS_DATA->lock));
     172        assert(fibril_mutex_is_locked(&vfs_data->lock));
    150173
    151174        if (file->refcnt-- == 1) {
     
    162185}
    163186
    164 
    165 /** Allocate a file descriptor.
    166  *
    167  * @param desc If true, look for an available file descriptor
    168  *             in a descending order.
    169  *
    170  * @return First available file descriptor or a negative error
    171  *         code.
    172  */
    173 int vfs_fd_alloc(bool desc)
    174 {
    175         if (!vfs_files_init())
     187static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, bool desc)
     188{
     189        if (!vfs_files_init(vfs_data))
    176190                return ENOMEM;
    177191       
     
    182196                i = 0;
    183197       
    184         fibril_mutex_lock(&VFS_DATA->lock);
     198        fibril_mutex_lock(&vfs_data->lock);
    185199        while (true) {
    186                 if (!FILES[i]) {
    187                         FILES[i] = (vfs_file_t *) malloc(sizeof(vfs_file_t));
    188                         if (!FILES[i]) {
    189                                 fibril_mutex_unlock(&VFS_DATA->lock);
     200                if (!vfs_data->files[i]) {
     201                        vfs_data->files[i] = (vfs_file_t *) malloc(sizeof(vfs_file_t));
     202                        if (!vfs_data->files[i]) {
     203                                fibril_mutex_unlock(&vfs_data->lock);
    190204                                return ENOMEM;
    191205                        }
    192206                       
    193                         memset(FILES[i], 0, sizeof(vfs_file_t));
    194                         fibril_mutex_initialize(&FILES[i]->lock);
    195                         vfs_file_addref(FILES[i]);
    196                         fibril_mutex_unlock(&VFS_DATA->lock);
     207                        memset(vfs_data->files[i], 0, sizeof(vfs_file_t));
     208                        fibril_mutex_initialize(&vfs_data->files[i]->lock);
     209                        vfs_file_addref(vfs_data, vfs_data->files[i]);
     210                        fibril_mutex_unlock(&vfs_data->lock);
    197211                        return (int) i;
    198212                }
     
    210224                }
    211225        }
    212         fibril_mutex_unlock(&VFS_DATA->lock);
     226        fibril_mutex_unlock(&vfs_data->lock);
    213227       
    214228        return EMFILE;
     229}
     230
     231/** Allocate a file descriptor.
     232 *
     233 * @param desc If true, look for an available file descriptor
     234 *             in a descending order.
     235 *
     236 * @return First available file descriptor or a negative error
     237 *         code.
     238 */
     239int vfs_fd_alloc(bool desc)
     240{
     241        return _vfs_fd_alloc(VFS_DATA, desc);
     242}
     243
     244static int _vfs_fd_free(vfs_client_data_t *vfs_data, int fd)
     245{
     246        int rc;
     247
     248        if (!vfs_files_init(vfs_data))
     249                return ENOMEM;
     250
     251        fibril_mutex_lock(&vfs_data->lock);     
     252        if ((fd < 0) || (fd >= MAX_OPEN_FILES) || !vfs_data->files[fd]) {
     253                fibril_mutex_unlock(&vfs_data->lock);
     254                return EBADF;
     255        }
     256       
     257        rc = vfs_file_delref(vfs_data, vfs_data->files[fd]);
     258        vfs_data->files[fd] = NULL;
     259        fibril_mutex_unlock(&vfs_data->lock);
     260       
     261        return rc;
    215262}
    216263
     
    224271int vfs_fd_free(int fd)
    225272{
    226         int rc;
    227 
    228         if (!vfs_files_init())
    229                 return ENOMEM;
    230 
    231         fibril_mutex_lock(&VFS_DATA->lock);     
    232         if ((fd < 0) || (fd >= MAX_OPEN_FILES) || (FILES[fd] == NULL)) {
    233                 fibril_mutex_unlock(&VFS_DATA->lock);
    234                 return EBADF;
    235         }
    236        
    237         rc = vfs_file_delref(FILES[fd]);
    238         FILES[fd] = NULL;
    239         fibril_mutex_unlock(&VFS_DATA->lock);
    240        
    241         return rc;
     273        return _vfs_fd_free(VFS_DATA, fd);
    242274}
    243275
     
    253285int vfs_fd_assign(vfs_file_t *file, int fd)
    254286{
    255         if (!vfs_files_init())
     287        if (!vfs_files_init(VFS_DATA))
    256288                return ENOMEM;
    257289
     
    263295       
    264296        FILES[fd] = file;
    265         vfs_file_addref(FILES[fd]);
     297        vfs_file_addref(VFS_DATA, FILES[fd]);
    266298        fibril_mutex_unlock(&VFS_DATA->lock);
    267299       
     
    269301}
    270302
    271 /** Find VFS file structure for a given file descriptor.
    272  *
    273  * @param fd            File descriptor.
    274  *
    275  * @return              VFS file structure corresponding to fd.
    276  */
    277 vfs_file_t *vfs_file_get(int fd)
    278 {
    279         if (!vfs_files_init())
     303static vfs_file_t *_vfs_file_get(vfs_client_data_t *vfs_data, int fd)
     304{
     305        if (!vfs_files_init(vfs_data))
    280306                return NULL;
    281307       
    282         fibril_mutex_lock(&VFS_DATA->lock);
     308        fibril_mutex_lock(&vfs_data->lock);
    283309        if ((fd >= 0) && (fd < MAX_OPEN_FILES)) {
    284                 vfs_file_t *file = FILES[fd];
     310                vfs_file_t *file = vfs_data->files[fd];
    285311                if (file != NULL) {
    286                         vfs_file_addref(file);
    287                         fibril_mutex_unlock(&VFS_DATA->lock);
     312                        vfs_file_addref(vfs_data, file);
     313                        fibril_mutex_unlock(&vfs_data->lock);
    288314                        return file;
    289315                }
    290316        }
    291         fibril_mutex_unlock(&VFS_DATA->lock);
     317        fibril_mutex_unlock(&vfs_data->lock);
    292318       
    293319        return NULL;
    294320}
    295321
     322/** Find VFS file structure for a given file descriptor.
     323 *
     324 * @param fd            File descriptor.
     325 *
     326 * @return              VFS file structure corresponding to fd.
     327 */
     328vfs_file_t *vfs_file_get(int fd)
     329{
     330        return _vfs_file_get(VFS_DATA, fd);
     331}
     332
     333static void _vfs_file_put(vfs_client_data_t *vfs_data, vfs_file_t *file)
     334{
     335        fibril_mutex_lock(&vfs_data->lock);
     336        vfs_file_delref(vfs_data, file);
     337        fibril_mutex_unlock(&vfs_data->lock);
     338}
     339
    296340/** Stop using a file structure.
    297341 *
     
    300344void vfs_file_put(vfs_file_t *file)
    301345{
    302         fibril_mutex_lock(&VFS_DATA->lock);
    303         vfs_file_delref(file);
    304         fibril_mutex_unlock(&VFS_DATA->lock);
     346        _vfs_file_put(VFS_DATA, file);
     347}
     348
     349void vfs_pass_handle(task_id_t donor_id, task_id_t acceptor_id, int donor_fd)
     350{
     351        vfs_client_data_t *donor_data = NULL;
     352        vfs_client_data_t *acceptor_data = NULL;
     353        vfs_file_t *donor_file = NULL;
     354        vfs_file_t *acceptor_file = NULL;
     355        vfs_boxed_handle_t *bh;
     356        int acceptor_fd;
     357
     358        acceptor_data = async_get_client_data_by_id(acceptor_id);
     359        if (!acceptor_data)
     360                return;
     361
     362        bh = malloc(sizeof(vfs_boxed_handle_t));
     363        assert(bh);
     364
     365        link_initialize(&bh->link);
     366        bh->handle = -1;
     367
     368        donor_data = async_get_client_data_by_id(donor_id);
     369        if (!donor_data)
     370                goto out;
     371
     372        donor_file = _vfs_file_get(donor_data, donor_fd);
     373        if (!donor_file)
     374                goto out;
     375
     376        acceptor_fd = _vfs_fd_alloc(acceptor_data, false);
     377        if (acceptor_fd < 0)
     378                goto out;
     379
     380        bh->handle = acceptor_fd;
     381
     382        /*
     383         * Add a new reference to the underlying VFS node.
     384         */
     385        vfs_node_addref(donor_file->node);
     386        (void) vfs_open_node_remote(donor_file->node);
     387
     388        acceptor_file = _vfs_file_get(acceptor_data, acceptor_fd);
     389        assert(acceptor_file);
     390
     391        /*
     392         * Inherit attributes from the donor.
     393         */
     394        acceptor_file->node = donor_file->node;
     395        acceptor_file->append = donor_file->append;
     396        acceptor_file->pos = donor_file->pos;
     397
     398out:
     399        fibril_mutex_lock(&acceptor_data->lock);
     400        list_append(&bh->link, &acceptor_data->passed_handles);
     401        fibril_condvar_broadcast(&acceptor_data->cv);
     402        fibril_mutex_unlock(&acceptor_data->lock);
     403
     404        if (donor_data)
     405                async_put_client_data_by_id(donor_id);
     406        if (acceptor_data)
     407                async_put_client_data_by_id(acceptor_id);
     408        if (donor_file)
     409                _vfs_file_put(donor_data, donor_file);
     410        if (acceptor_file)
     411                _vfs_file_put(acceptor_data, acceptor_file);
     412
     413}
     414
     415int vfs_wait_handle_internal(void)
     416{
     417        vfs_client_data_t *vfs_data = VFS_DATA;
     418        int fd;
     419       
     420        fibril_mutex_lock(&vfs_data->lock);
     421        while (list_empty(&vfs_data->passed_handles))
     422                fibril_condvar_wait(&vfs_data->cv, &vfs_data->lock);
     423        link_t *lnk = list_first(&vfs_data->passed_handles);
     424        list_remove(lnk);
     425        fibril_mutex_unlock(&vfs_data->lock);
     426
     427        vfs_boxed_handle_t *bh = list_get_instance(lnk, vfs_boxed_handle_t, link);
     428        fd = bh->handle;
     429        free(bh);
     430
     431        return fd;
    305432}
    306433
  • uspace/srv/vfs/vfs_lookup.c

    rea186c6 r921b84f  
    201201}
    202202
    203 /** Perform a node open operation.
    204  *
    205  * @return EOK on success or an error code from errno.h.
    206  *
    207  */
    208 int vfs_open_node_internal(vfs_lookup_res_t *result)
    209 {
    210         async_exch_t *exch = vfs_exchange_grab(result->triplet.fs_handle);
    211        
    212         ipc_call_t answer;
    213         aid_t req = async_send_2(exch, VFS_OUT_OPEN_NODE,
    214             (sysarg_t) result->triplet.service_id,
    215             (sysarg_t) result->triplet.index, &answer);
    216        
    217         sysarg_t rc;
    218         async_wait_for(req, &rc);
    219         vfs_exchange_release(exch);
    220        
    221         if (rc == EOK) {
    222                 result->size =
    223                     MERGE_LOUP32(IPC_GET_ARG1(answer), IPC_GET_ARG2(answer));
    224                 result->lnkcnt = (unsigned int) IPC_GET_ARG3(answer);
    225                 if (IPC_GET_ARG4(answer) & L_FILE)
    226                         result->type = VFS_NODE_FILE;
    227                 else if (IPC_GET_ARG4(answer) & L_DIRECTORY)
    228                         result->type = VFS_NODE_DIRECTORY;
    229                 else
    230                         result->type = VFS_NODE_UNKNOWN;
    231         }
    232        
    233         return rc;
    234 }
    235 
    236203/**
    237204 * @}
  • uspace/srv/vfs/vfs_node.c

    rea186c6 r921b84f  
    293293}
    294294
     295
     296/** Perform a remote node open operation.
     297 *
     298 * @return EOK on success or an error code from errno.h.
     299 *
     300 */
     301int vfs_open_node_remote(vfs_node_t *node)
     302{
     303        async_exch_t *exch = vfs_exchange_grab(node->fs_handle);
     304       
     305        ipc_call_t answer;
     306        aid_t req = async_send_2(exch, VFS_OUT_OPEN_NODE,
     307            (sysarg_t) node->service_id, (sysarg_t) node->index, &answer);
     308       
     309        vfs_exchange_release(exch);
     310
     311        sysarg_t rc;
     312        async_wait_for(req, &rc);
     313       
     314        return rc;
     315}
     316
    295317/**
    296318 * @}
  • uspace/srv/vfs/vfs_ops.c

    rea186c6 r921b84f  
    618618}
    619619
    620 void vfs_open_node(ipc_callid_t rid, ipc_call_t *request)
    621 {
    622         // FIXME: check for sanity of the supplied fs, dev and index
    623        
    624         /*
    625          * The interface is open_node(fs, dev, index, oflag).
    626          */
    627         vfs_lookup_res_t lr;
    628        
    629         lr.triplet.fs_handle = IPC_GET_ARG1(*request);
    630         lr.triplet.service_id = IPC_GET_ARG2(*request);
    631         lr.triplet.index = IPC_GET_ARG3(*request);
    632         int oflag = IPC_GET_ARG4(*request);
    633        
    634         fibril_rwlock_read_lock(&namespace_rwlock);
    635        
    636         int rc = vfs_open_node_internal(&lr);
    637         if (rc != EOK) {
    638                 fibril_rwlock_read_unlock(&namespace_rwlock);
    639                 async_answer_0(rid, rc);
    640                 return;
    641         }
    642        
    643         vfs_node_t *node = vfs_node_get(&lr);
    644         fibril_rwlock_read_unlock(&namespace_rwlock);
    645        
    646         /* Truncate the file if requested and if necessary. */
    647         if (oflag & O_TRUNC) {
    648                 fibril_rwlock_write_lock(&node->contents_rwlock);
    649                 if (node->size) {
    650                         rc = vfs_truncate_internal(node->fs_handle,
    651                             node->service_id, node->index, 0);
    652                         if (rc) {
    653                                 fibril_rwlock_write_unlock(&node->contents_rwlock);
    654                                 vfs_node_put(node);
    655                                 async_answer_0(rid, rc);
    656                                 return;
    657                         }
    658                         node->size = 0;
    659                 }
    660                 fibril_rwlock_write_unlock(&node->contents_rwlock);
    661         }
    662        
    663         /*
    664          * Get ourselves a file descriptor and the corresponding vfs_file_t
    665          * structure.
    666          */
    667         int fd = vfs_fd_alloc((oflag & O_DESC) != 0);
    668         if (fd < 0) {
    669                 vfs_node_put(node);
    670                 async_answer_0(rid, fd);
    671                 return;
    672         }
    673         vfs_file_t *file = vfs_file_get(fd);
    674         file->node = node;
    675         if (oflag & O_APPEND)
    676                 file->append = true;
    677        
    678         /*
    679          * The following increase in reference count is for the fact that the
    680          * file is being opened and that a file structure is pointing to it.
    681          * It is necessary so that the file will not disappear when
    682          * vfs_node_put() is called. The reference will be dropped by the
    683          * respective VFS_IN_CLOSE.
    684          */
    685         vfs_node_addref(node);
    686         vfs_node_put(node);
    687         vfs_file_put(file);
    688        
    689         /* Success! Return the new file descriptor to the client. */
    690         async_answer_1(rid, EOK, fd);
    691 }
    692 
    693620void vfs_sync(ipc_callid_t rid, ipc_call_t *request)
    694621{
     
    13491276}
    13501277
     1278void vfs_wait_handle(ipc_callid_t rid, ipc_call_t *request)
     1279{
     1280        int fd = vfs_wait_handle_internal();
     1281        async_answer_1(rid, EOK, fd);
     1282}
     1283
    13511284/**
    13521285 * @}
Note: See TracChangeset for help on using the changeset viewer.