source: mainline/uspace/app/usbinfo/list.c@ 5ef16903

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5ef16903 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 * Copyright (c) 2010-2011 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup lsusb
30 * @{
31 */
32/**
33 * @file
34 * Listing of USB host controllers.
35 */
36
37#include <inttypes.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <errno.h>
41#include <str_error.h>
42#include <stdbool.h>
43#include <getopt.h>
44#include <devman.h>
45#include <loc.h>
46#include <usb_iface.h>
47#include <str.h>
48
49#include "usbinfo.h"
50
51#define MAX_PATH_LENGTH 1024
52
53static void print_usb_device(devman_handle_t handle)
54{
55 char path[MAX_PATH_LENGTH];
56 errno_t rc = devman_fun_get_path(handle, path, MAX_PATH_LENGTH);
57 if (rc != EOK) {
58 printf(NAME "Failed to get path for device %"PRIun"\n", handle);
59 return;
60 }
61 printf("\tDevice %" PRIun ": %s\n", handle, path);
62}
63
64static void print_usb_bus(service_id_t svc)
65{
66 devman_handle_t hc_handle = 0;
67 errno_t rc = devman_fun_sid_to_handle(svc, &hc_handle);
68 if (rc != EOK) {
69 printf(NAME ": Error resolving handle of HC with SID %"
70 PRIun ", skipping.\n", svc);
71 return;
72 }
73
74 char path[MAX_PATH_LENGTH];
75 rc = devman_fun_get_path(hc_handle, path, sizeof(path));
76 if (rc != EOK) {
77 printf(NAME ": Error resolving path of HC with SID %"
78 PRIun ", skipping.\n", svc);
79 return;
80 }
81 printf("Bus %" PRIun ": %s\n", svc, path);
82
83 /* Construct device's path.
84 * That's "hc function path" - ( '/' + "hc function name" ) */
85 // TODO replace this with something sane
86
87 /* Get function name */
88 char name[10];
89 rc = devman_fun_get_name(hc_handle, name, sizeof(name));
90 if (rc != EOK) {
91 printf(NAME ": Error resolving name of HC with SID %"
92 PRIun ", skipping.\n", svc);
93 return;
94 }
95
96 /* Get handle of parent device */
97 devman_handle_t fh;
98 path[str_size(path) - str_size(name) - 1] = '\0';
99 rc = devman_fun_get_handle(path, &fh, IPC_FLAG_BLOCKING);
100 if (rc != EOK) {
101 printf(NAME ": Error resolving parent handle of HC with"
102 " SID %" PRIun ", skipping.\n", svc);
103 return;
104 }
105
106 /* Get child handle */
107 devman_handle_t dh;
108 rc = devman_fun_get_child(fh, &dh);
109 if (rc != EOK) {
110 printf(NAME ": Error resolving parent handle of HC with"
111 " SID %" PRIun ", skipping.\n", svc);
112 return;
113 }
114
115 devman_handle_t *fhs = 0;
116 size_t count;
117 rc = devman_dev_get_functions(dh, &fhs, &count);
118 if (rc != EOK) {
119 printf(NAME ": Error siblings of HC with"
120 " SID %" PRIun ", skipping.\n", svc);
121 return;
122 }
123
124 for (size_t i = 0; i < count; ++i) {
125 if (fhs[i] != hc_handle)
126 print_usb_device(fhs[i]);
127 }
128 free(fhs);
129}
130
131void list(void)
132{
133 category_id_t usbhc_cat;
134 service_id_t *svcs;
135 size_t count;
136 errno_t rc;
137
138 rc = loc_category_get_id(USB_HC_CATEGORY, &usbhc_cat, 0);
139 if (rc != EOK) {
140 printf(NAME ": Error resolving category '%s'",
141 USB_HC_CATEGORY);
142 return;
143 }
144
145 rc = loc_category_get_svcs(usbhc_cat, &svcs, &count);
146 if (rc != EOK) {
147 printf(NAME ": Error getting list of host controllers.\n");
148 return;
149 }
150
151 for (unsigned int i = 0; i < count; ++i) {
152 print_usb_bus(svcs[i]);
153 }
154
155 free(svcs);
156}
157
158
159/** @}
160 */
Note: See TracBrowser for help on using the repository browser.