Changeset 431d6d6 in mainline


Ignore:
Timestamp:
2011-05-07T11:10:17Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e5165a3
Parents:
8594505
Message:

Devman can tell device path by its handle

This patch might go into mainline rightaway.

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/devman.c

    r8594505 r431d6d6  
    374374}
    375375
     376int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size)
     377{
     378        int phone = devman_get_phone(DEVMAN_CLIENT, 0);
     379
     380        if (phone < 0)
     381                return phone;
     382
     383        async_serialize_start();
     384
     385        ipc_call_t answer;
     386        aid_t req = async_send_1(phone, DEVMAN_DEVICE_GET_DEVICE_PATH,
     387            handle, &answer);
     388
     389        ipc_call_t data_request_call;
     390        aid_t data_request = async_data_read(phone, path, path_size,
     391            &data_request_call);
     392        if (data_request == 0) {
     393                async_wait_for(req, NULL);
     394                async_serialize_end();
     395                return ENOMEM;
     396        }
     397
     398        sysarg_t data_request_rc;
     399        sysarg_t opening_request_rc;
     400        async_wait_for(data_request, &data_request_rc);
     401        async_wait_for(req, &opening_request_rc);
     402
     403        async_serialize_end();
     404
     405        if (data_request_rc != EOK) {
     406                /* Prefer the return code of the opening request. */
     407                if (opening_request_rc != EOK) {
     408                        return (int) opening_request_rc;
     409                } else {
     410                        return (int) data_request_rc;
     411                }
     412        }
     413        if (opening_request_rc != EOK) {
     414                return (int) opening_request_rc;
     415        }
     416
     417        path[path_size - 1] = 0;
     418
     419        if (IPC_GET_ARG2(data_request_call) >= path_size) {
     420                return ELIMIT;
     421        }
     422
     423        return EOK;
     424}
     425
    376426
    377427/** @}
  • uspace/lib/c/include/devman.h

    r8594505 r431d6d6  
    5555extern int devman_device_get_handle_by_class(const char *, const char *,
    5656    devman_handle_t *, unsigned int);
     57extern int devman_get_device_path(devman_handle_t, char *, size_t);
    5758
    5859extern int devman_add_device_to_class(devman_handle_t, const char *);
  • uspace/lib/c/include/ipc/devman.h

    r8594505 r431d6d6  
    149149typedef enum {
    150150        DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
    151         DEVMAN_DEVICE_GET_HANDLE_BY_CLASS
     151        DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
     152        DEVMAN_DEVICE_GET_DEVICE_PATH
    152153} client_to_devman_t;
    153154
  • uspace/srv/devman/main.c

    r8594505 r431d6d6  
    515515}
    516516
     517/** Find device path by its handle. */
     518static void devman_get_device_path_by_handle(ipc_callid_t iid,
     519    ipc_call_t *icall)
     520{
     521        devman_handle_t handle = IPC_GET_ARG1(*icall);
     522
     523        fun_node_t *fun = find_fun_node(&device_tree, handle);
     524        if (fun == NULL) {
     525                async_answer_0(iid, ENOMEM);
     526                return;
     527        }
     528
     529        ipc_callid_t data_callid;
     530        size_t data_len;
     531        if (!async_data_read_receive(&data_callid, &data_len)) {
     532                async_answer_0(iid, EINVAL);
     533                return;
     534        }
     535
     536        void *buffer = malloc(data_len);
     537        if (buffer == NULL) {
     538                async_answer_0(data_callid, ENOMEM);
     539                async_answer_0(iid, ENOMEM);
     540                return;
     541        }
     542
     543        size_t sent_length = str_size(fun->pathname);
     544        if (sent_length > data_len) {
     545                sent_length = data_len;
     546        }
     547
     548        async_data_read_finalize(data_callid, fun->pathname, sent_length);
     549        async_answer_0(iid, EOK);
     550
     551        free(buffer);
     552}
     553
    517554
    518555/** Function for handling connections from a client to the device manager. */
     
    536573                case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
    537574                        devman_function_get_handle_by_class(callid, &call);
     575                        break;
     576                case DEVMAN_DEVICE_GET_DEVICE_PATH:
     577                        devman_get_device_path_by_handle(callid, &call);
    538578                        break;
    539579                default:
Note: See TracChangeset for help on using the changeset viewer.