source: MondoRescue/branches/2.2.9/mindi-busybox/util-linux/lsusb.c@ 3320

Last change on this file since 3320 was 3320, checked in by Bruno Cornec, 9 years ago
  • Re-add (thanks git BTW) the 2.2.9 branch which had been destroyed in the move to 3.0
  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
3 * lsusb implementation for busybox
4 *
5 * Copyright (C) 2009 Malek Degachi <malek-degachi@laposte.net>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */
9#include "libbb.h"
10
11static int FAST_FUNC fileAction(
12 const char *fileName,
13 struct stat *statbuf UNUSED_PARAM,
14 void *userData UNUSED_PARAM,
15 int depth UNUSED_PARAM)
16{
17 parser_t *parser;
18 char *tokens[4];
19 char *busnum = NULL, *devnum = NULL;
20 int product_vid = 0, product_did = 0;
21 char *uevent_filename = concat_path_file(fileName, "/uevent");
22
23 parser = config_open2(uevent_filename, fopen_for_read);
24 free(uevent_filename);
25
26 while (config_read(parser, tokens, 4, 2, "\\/=", PARSE_NORMAL)) {
27 if ((parser->lineno == 1) && strcmp(tokens[0], "DEVTYPE") == 0) {
28 break;
29 }
30
31 if (strcmp(tokens[0], "PRODUCT") == 0) {
32 product_vid = xstrtou(tokens[1], 16);
33 product_did = xstrtou(tokens[2], 16);
34 continue;
35 }
36
37 if (strcmp(tokens[0], "BUSNUM") == 0) {
38 busnum = xstrdup(tokens[1]);
39 continue;
40 }
41
42 if (strcmp(tokens[0], "DEVNUM") == 0) {
43 devnum = xstrdup(tokens[1]);
44 continue;
45 }
46 }
47 config_close(parser);
48
49 if (busnum) {
50 printf("Bus %s Device %s: ID %04x:%04x\n", busnum, devnum, product_vid, product_did);
51 free(busnum);
52 free(devnum);
53 }
54
55 return TRUE;
56}
57
58int lsusb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
59int lsusb_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
60{
61 /* no options, no getopt */
62
63 recursive_action("/sys/bus/usb/devices",
64 ACTION_RECURSE,
65 fileAction,
66 NULL, /* dirAction */
67 NULL, /* userData */
68 0 /* depth */);
69
70 return EXIT_SUCCESS;
71}
Note: See TracBrowser for help on using the repository browser.