Changeset 1a5b252 in mainline for uspace/app/devctl/devctl.c
- Timestamp:
- 2011-08-21T11:54:15Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8cc4ddb
- Parents:
- e64df9a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/devctl/devctl.c
re64df9a r1a5b252 37 37 #include <stdio.h> 38 38 #include <stdlib.h> 39 #include <str_error.h> 39 40 #include <sys/typefmt.h> 40 41 … … 43 44 #define MAX_NAME_LENGTH 1024 44 45 45 static int fun_ tree_print(devman_handle_t funh, int lvl)46 static int fun_subtree_print(devman_handle_t funh, int lvl) 46 47 { 47 48 char name[MAX_NAME_LENGTH]; … … 84 85 85 86 for (i = 0; i < count; i++) 86 fun_ tree_print(cfuns[i], lvl + 1);87 fun_subtree_print(cfuns[i], lvl + 1); 87 88 88 89 free(cfuns); … … 90 91 } 91 92 92 int main(int argc, char *argv[])93 static int fun_tree_print(void) 93 94 { 94 95 devman_handle_t root_fun; … … 98 99 if (rc != EOK) { 99 100 printf(NAME ": Error resolving root function.\n"); 101 return EIO; 102 } 103 104 rc = fun_subtree_print(root_fun, 0); 105 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(); 100 191 return 1; 101 192 } 102 103 rc = fun_tree_print(root_fun, 0);104 if (rc != EOK)105 return 1;106 193 107 194 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.