Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/devctl/devctl.c

    r1a5b252 r7beb220  
    3737#include <stdio.h>
    3838#include <stdlib.h>
    39 #include <str_error.h>
    4039#include <sys/typefmt.h>
    4140
     
    4443#define MAX_NAME_LENGTH 1024
    4544
    46 static int fun_subtree_print(devman_handle_t funh, int lvl)
     45static int fun_tree_print(devman_handle_t funh, int lvl)
    4746{
    4847        char name[MAX_NAME_LENGTH];
     
    8584
    8685        for (i = 0; i < count; i++)
    87                 fun_subtree_print(cfuns[i], lvl + 1);
     86                fun_tree_print(cfuns[i], lvl + 1);
    8887
    8988        free(cfuns);
     
    9190}
    9291
    93 static int fun_tree_print(void)
     92int main(int argc, char *argv[])
    9493{
    9594        devman_handle_t root_fun;
     
    9998        if (rc != EOK) {
    10099                printf(NAME ": Error resolving root function.\n");
    101                 return EIO;
     100                return 1;
    102101        }
    103102
    104         rc = fun_subtree_print(root_fun, 0);
     103        rc = fun_tree_print(root_fun, 0);
    105104        if (rc != EOK)
    106                 return EIO;
    107 
    108         return EOK;
    109 }
    110 
    111 static int fun_online(const char *path)
    112 {
    113         devman_handle_t funh;
    114         int rc;
    115 
    116         rc = devman_fun_get_handle(path, &funh, 0);
    117         if (rc != EOK) {
    118                 printf(NAME ": Error resolving device function '%s' (%s)\n",
    119                     path, str_error(rc));
    120                 return rc;
    121         }
    122 
    123         rc = devman_fun_online(funh);
    124         if (rc != EOK) {
    125                 printf(NAME ": Failed to online function '%s'.\n", path);
    126                 return rc;
    127         }
    128 
    129         return EOK;
    130 }
    131 
    132 static int fun_offline(const char *path)
    133 {
    134         devman_handle_t funh;
    135         int rc;
    136 
    137         rc = devman_fun_get_handle(path, &funh, 0);
    138         if (rc != EOK) {
    139                 printf(NAME ": Error resolving device function '%s' (%s)\n",
    140                     path, str_error(rc));
    141                 return rc;
    142         }
    143 
    144         rc = devman_fun_offline(funh);
    145         if (rc != EOK) {
    146                 printf(NAME ": Failed to offline function '%s'.\n", path);
    147                 return rc;
    148         }
    149 
    150         return EOK;
    151 }
    152 
    153 static void print_syntax(void)
    154 {
    155         printf("syntax: devctl [(online|offline) <function>]\n");
    156 }
    157 
    158 int main(int argc, char *argv[])
    159 {
    160         int rc;
    161 
    162         if (argc == 1) {
    163                 rc = fun_tree_print();
    164                 if (rc != EOK)
    165                         return 2;
    166         } else if (str_cmp(argv[1], "online") == 0) {
    167                 if (argc < 3) {
    168                         printf(NAME ": Argument missing.\n");
    169                         print_syntax();
    170                         return 1;
    171                 }
    172 
    173                 rc = fun_online(argv[2]);
    174                 if (rc != EOK) {
    175                         return 2;
    176                 }
    177         } else if (str_cmp(argv[1], "offline") == 0) {
    178                 if (argc < 3) {
    179                         printf(NAME ": Argument missing.\n");
    180                         print_syntax();
    181                         return 1;
    182                 }
    183 
    184                 rc = fun_offline(argv[2]);
    185                 if (rc != EOK) {
    186                         return 2;
    187                 }
    188         } else {
    189                 printf(NAME ": Invalid argument '%s'.\n", argv[1]);
    190                 print_syntax();
    191105                return 1;
    192         }
    193106
    194107        return 0;
Note: See TracChangeset for help on using the changeset viewer.