Changeset 07b39338 in mainline for uspace/app


Ignore:
Timestamp:
2011-08-20T18:21:49Z (15 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6ab014d
Parents:
0cf27ee (diff), f00af83 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libposix.

Location:
uspace/app
Files:
2 added
2 deleted
8 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/exec.c

    r0cf27ee r07b39338  
    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/devctl/devctl.c

    r0cf27ee r07b39338  
    11/*
    2  * Copyright (c) 2011 Vojtech Horky
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup tester
    30  * @brief Test devman service.
     29/** @addtogroup devctl
    3130 * @{
    3231 */
    33 /**
    34  * @file
     32/** @file Control device framework (devman server).
    3533 */
    3634
    37 #include <inttypes.h>
     35#include <devman.h>
    3836#include <errno.h>
    39 #include <str_error.h>
    40 #include <sys/types.h>
    41 #include <async.h>
    42 #include <devman.h>
    43 #include <str.h>
    44 #include <async.h>
    45 #include <vfs/vfs.h>
    46 #include <vfs/vfs_sess.h>
    47 #include <sys/stat.h>
    48 #include <fcntl.h>
    49 #include "../tester.h"
     37#include <stdio.h>
     38#include <stdlib.h>
     39#include <sys/typefmt.h>
    5040
    51 #define DEVICE_CLASS "test3"
     41#define NAME "devctl"
    5242
    53 const char *test_devman2(void)
     43#define MAX_NAME_LENGTH 1024
     44
     45static int fun_tree_print(devman_handle_t funh, int lvl)
    5446{
    55         size_t idx = 1;
    56         int rc = EOK;
    57         const char *err_msg = NULL;
    58         char *path = NULL;
    59         while (rc == EOK) {
    60                 rc = asprintf(&path, "/loc/class/%s\\%zu", DEVICE_CLASS, idx);
    61                 if (rc < 0) {
    62                         continue;
    63                 }
    64                 int fd = open(path, O_RDONLY);
    65                 if (fd < 0) {
    66                         TPRINTF("Failed opening `%s': %s.\n",
    67                             path, str_error(fd));
    68                         rc = fd;
    69                         err_msg = "Failed opening file";
    70                         continue;
    71                 }
    72                 async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd);
    73                 close(fd);
    74                 if (sess == NULL) {
    75                         TPRINTF("Failed opening phone: %s.\n", str_error(errno));
    76                         rc = errno;
    77                         err_msg = "Failed opening file descriptor phone";
    78                         continue;
    79                 }
    80                 async_hangup(sess);
    81                 TPRINTF("Path `%s' okay.\n", path);
    82                 free(path);
    83                 idx++;
    84                 rc = EOK;
     47        char name[MAX_NAME_LENGTH];
     48        devman_handle_t devh;
     49        devman_handle_t *cfuns;
     50        size_t count, i;
     51        int rc;
     52        int j;
     53
     54        for (j = 0; j < lvl; j++)
     55                printf("    ");
     56
     57        rc = devman_fun_get_name(funh, name, MAX_NAME_LENGTH);
     58        if (rc != EOK) {
     59                str_cpy(name, MAX_NAME_LENGTH, "unknown");
     60                return ENOMEM;
    8561        }
    86        
    87         if (path != NULL)
    88                 free(path);
    89        
    90         return err_msg;
     62
     63        if (name[0] == '\0')
     64                str_cpy(name, MAX_NAME_LENGTH, "/");
     65
     66        printf("%s (%" PRIun ")\n", name, funh);
     67
     68        rc = devman_fun_get_child(funh, &devh);
     69        if (rc == ENOENT)
     70                return EOK;
     71
     72        if (rc != EOK) {
     73                printf(NAME ": Failed getting child device for function "
     74                    "%s.\n", "xxx");
     75                return rc;
     76        }
     77
     78        rc = devman_dev_get_functions(devh, &cfuns, &count);
     79        if (rc != EOK) {
     80                printf(NAME ": Failed getting list of functions for "
     81                    "device %s.\n", "xxx");
     82                return rc;
     83        }
     84
     85        for (i = 0; i < count; i++)
     86                fun_tree_print(cfuns[i], lvl + 1);
     87
     88        free(cfuns);
     89        return EOK;
     90}
     91
     92int main(int argc, char *argv[])
     93{
     94        devman_handle_t root_fun;
     95        int rc;
     96
     97        rc = devman_fun_get_handle("/", &root_fun, 0);
     98        if (rc != EOK) {
     99                printf(NAME ": Error resolving root function.\n");
     100                return 1;
     101        }
     102
     103        rc = fun_tree_print(root_fun, 0);
     104        if (rc != EOK)
     105                return 1;
     106
     107        return 0;
    91108}
    92109
  • uspace/app/locinfo/locinfo.c

    r0cf27ee r07b39338  
    11/*
    2  * Copyright (c) 2011 Vojtech Horky
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup tester
    30  * @brief Test devman service.
     29/** @addtogroup locinfo
    3130 * @{
    3231 */
    33 /**
    34  * @file
     32/** @file locinfo.c Print information from location service.
    3533 */
    3634
    37 #include <inttypes.h>
    3835#include <errno.h>
    39 #include <str_error.h>
     36#include <loc.h>
     37#include <stdio.h>
     38#include <stdlib.h>
     39#include <str.h>
    4040#include <sys/types.h>
    41 #include <async.h>
    42 #include <devman.h>
    43 #include <str.h>
    44 #include <vfs/vfs.h>
    45 #include <sys/stat.h>
    46 #include <fcntl.h>
    47 #include "../tester.h"
     41#include <sys/typefmt.h>
    4842
    49 #define DEVICE_PATH_NORMAL "/virt/null/a"
    50 #define DEVICE_CLASS "virt-null"
    51 #define DEVICE_CLASS_NAME "1"
    52 #define DEVICE_PATH_CLASSES DEVICE_CLASS "/" DEVICE_CLASS_NAME
     43#define NAME "locinfo"
    5344
    54 const char *test_devman1(void)
     45int main(int argc, char *argv[])
    5546{
    56         devman_handle_t handle_primary;
    57         devman_handle_t handle_class;
    58        
     47        category_id_t *cat_ids;
     48        size_t cat_cnt;
     49        service_id_t *svc_ids;
     50        size_t svc_cnt;
     51
     52        size_t i, j;
     53        char *cat_name;
     54        char *svc_name;
    5955        int rc;
    60        
    61         TPRINTF("Asking for handle of `%s'...\n", DEVICE_PATH_NORMAL);
    62         rc = devman_device_get_handle(DEVICE_PATH_NORMAL, &handle_primary, 0);
     56
     57        rc = loc_get_categories(&cat_ids, &cat_cnt);
    6358        if (rc != EOK) {
    64                 TPRINTF(" ...failed: %s.\n", str_error(rc));
    65                 if (rc == ENOENT) {
    66                         TPRINTF("Have you compiled the test drivers?\n");
    67                 }
    68                 return "Failed getting device handle";
     59                printf(NAME ": Error getting list of categories.\n");
     60                return 1;
    6961        }
    7062
    71         TPRINTF("Asking for handle of `%s' by class..\n", DEVICE_PATH_CLASSES);
    72         rc = devman_device_get_handle_by_class(DEVICE_CLASS, DEVICE_CLASS_NAME,
    73             &handle_class, 0);
    74         if (rc != EOK) {
    75                 TPRINTF(" ...failed: %s.\n", str_error(rc));
    76                 return "Failed getting device class handle";
     63        for (i = 0; i < cat_cnt; i++) {
     64                rc = loc_category_get_name(cat_ids[i], &cat_name);
     65                if (rc != EOK)
     66                        cat_name = str_dup("<unknown>");
     67
     68                if (cat_name == NULL) {
     69                        printf(NAME ": Error allocating memory.\n");
     70                        return 1;
     71                }
     72
     73                printf("%s (%" PRIun "):\n", cat_name, cat_ids[i]);
     74
     75                rc = loc_category_get_svcs(cat_ids[i], &svc_ids, &svc_cnt);
     76                if (rc != EOK) {
     77                        printf(NAME ": Failed getting list of services in "
     78                            "category %s, skipping.\n", cat_name);
     79                        free(cat_name);
     80                        continue;
     81                }
     82
     83                for (j = 0; j < svc_cnt; j++) {
     84                        rc = loc_service_get_name(svc_ids[j], &svc_name);
     85                        if (rc != EOK) {
     86                                printf(NAME ": Unknown service name (SID %"
     87                                    PRIun ").\n", svc_ids[j]);
     88                                continue;
     89                        }
     90                        printf("\t%s (%" PRIun ")\n", svc_name, svc_ids[j]);
     91                }
     92
     93                free(svc_ids);
     94                free(cat_name);
    7795        }
    7896
    79         TPRINTF("Received handles %" PRIun " and %" PRIun ".\n",
    80             handle_primary, handle_class);
    81         if (handle_primary != handle_class) {
    82                 return "Retrieved different handles for the same device";
    83         }
    84 
    85         return NULL;
     97        free(cat_ids);
     98        return 0;
    8699}
    87100
  • uspace/app/lsusb/main.c

    r0cf27ee r07b39338  
    5050
    5151#define MAX_USB_ADDRESS USB11_ADDRESS_MAX
    52 #define MAX_FAILED_ATTEMPTS 10
    5352#define MAX_PATH_LENGTH 1024
    5453
    55 static void print_found_hc(size_t class_index, const char *path)
     54static void print_found_hc(service_id_t sid, const char *path)
    5655{
    57         // printf(NAME ": host controller %zu is `%s'.\n", class_index, path);
    58         printf("Bus %02zu: %s\n", class_index, path);
     56        printf("Bus %" PRIun ": %s\n", sid, path);
    5957}
    6058static void print_found_dev(usb_address_t addr, const char *path)
    6159{
    62         // printf(NAME ":     device with address %d is `%s'.\n", addr, path);
    6360        printf("  Device %02d: %s\n", addr, path);
    6461}
     
    8481                }
    8582                char path[MAX_PATH_LENGTH];
    86                 rc = devman_get_device_path(dev_handle, path, MAX_PATH_LENGTH);
     83                rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH);
    8784                if (rc != EOK) {
    8885                        continue;
     
    9592int main(int argc, char *argv[])
    9693{
    97         size_t class_index = 0;
    98         size_t failed_attempts = 0;
     94        category_id_t usbhc_cat;
     95        service_id_t *svcs;
     96        size_t count;
     97        size_t i;
     98        int rc;
    9999
    100         while (failed_attempts < MAX_FAILED_ATTEMPTS) {
    101                 class_index++;
     100        rc = loc_category_get_id(USB_HC_CATEGORY, &usbhc_cat, 0);
     101        if (rc != EOK) {
     102                printf(NAME ": Error resolving category '%s'",
     103                    USB_HC_CATEGORY);
     104                return 1;
     105        }
     106
     107        rc = loc_category_get_svcs(usbhc_cat, &svcs, &count);
     108        if (rc != EOK) {
     109                printf(NAME ": Error getting list of host controllers.\n");
     110                return 1;
     111        }
     112
     113        for (i = 0; i < count; i++) {
    102114                devman_handle_t hc_handle = 0;
    103                 int rc = usb_ddf_get_hc_handle_by_class(class_index, &hc_handle);
     115                int rc = usb_ddf_get_hc_handle_by_sid(svcs[i], &hc_handle);
    104116                if (rc != EOK) {
    105                         failed_attempts++;
     117                        printf(NAME ": Error resolving handle of HC with SID %"
     118                            PRIun ", skipping.\n", svcs[i]);
    106119                        continue;
    107120                }
    108121                char path[MAX_PATH_LENGTH];
    109                 rc = devman_get_device_path(hc_handle, path, MAX_PATH_LENGTH);
     122                rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH);
    110123                if (rc != EOK) {
     124                        printf(NAME ": Error resolving path of HC with SID %"
     125                            PRIun ", skipping.\n", svcs[i]);
    111126                        continue;
    112127                }
    113                 print_found_hc(class_index, path);
     128                print_found_hc(svcs[i], path);
    114129                print_hc_devices(hc_handle);
    115130        }
     131
     132        free(svcs);
    116133
    117134        return 0;
  • uspace/app/mkbd/main.c

    r0cf27ee r07b39338  
    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/Makefile

    r0cf27ee r07b39338  
    5656        mm/malloc3.c \
    5757        mm/mapping1.c \
    58         devs/devman1.c \
    59         devs/devman2.c \
    6058        hw/misc/virtchar1.c \
    6159        hw/serial/serial1.c \
  • uspace/app/tester/hw/misc/virtchar1.c

    r0cf27ee r07b39338  
    4949
    5050#define DEVICE_PATH_NORMAL "/loc/devices/\\virt\\null\\a"
    51 #define DEVICE_PATH_CLASSES "/loc/class/virt-null\\1"
    5251#define BUFFER_SIZE 64
    5352
     
    105104        }
    106105
    107         res = test_virtchar1_internal(DEVICE_PATH_CLASSES);
    108         if (res != NULL) {
    109                 return res;
    110         }
    111 
    112106        return NULL;
    113107}
  • uspace/app/tester/hw/serial/serial1.c

    r0cf27ee r07b39338  
    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/tester/tester.c

    r0cf27ee r07b39338  
    6868#include "hw/misc/virtchar1.def"
    6969#include "libext2/libext2_1.def"
    70 #include "devs/devman1.def"
    71 #include "devs/devman2.def"
    7270        {NULL, NULL, NULL, false}
    7371};
  • uspace/app/trace/trace.c

    r0cf27ee r07b39338  
    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);
Note: See TracChangeset for help on using the changeset viewer.