volume_id/ext: detect ext4 too
[oweals/busybox.git] / util-linux / lsusb.c
index 7c5b6b947ad0ee3ce023a87fb562eaacf2317ae3..540f21ec6d61cf1f8827fceb65f046d8bf649986 100644 (file)
@@ -1,12 +1,16 @@
 /* vi: set sw=4 ts=4: */
 /*
-* lspci implementation for busybox
-*
-* Copyright (C) 2009  Malek Degachi <malek-degachi@laposte.net>
-*
-* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
-*/
-#include <libbb.h>
+ * lsusb implementation for busybox
+ *
+ * Copyright (C) 2009  Malek Degachi <malek-degachi@laposte.net>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+
+//usage:#define lsusb_trivial_usage NOUSAGE_STR
+//usage:#define lsusb_full_usage ""
+
+#include "libbb.h"
 
 static int FAST_FUNC fileAction(
                const char *fileName,
@@ -15,37 +19,41 @@ static int FAST_FUNC fileAction(
                int depth UNUSED_PARAM)
 {
        parser_t *parser;
-       char *tokens[6];
-       char *bus = NULL, *device = NULL;
+       char *tokens[4];
+       char *busnum = NULL, *devnum = NULL;
        int product_vid = 0, product_did = 0;
-
        char *uevent_filename = concat_path_file(fileName, "/uevent");
+
        parser = config_open2(uevent_filename, fopen_for_read);
        free(uevent_filename);
 
-       while (config_read(parser, tokens, 6, 1, "\\/=", PARSE_NORMAL)) {
+       while (config_read(parser, tokens, 4, 2, "\\/=", PARSE_NORMAL)) {
                if ((parser->lineno == 1) && strcmp(tokens[0], "DEVTYPE") == 0) {
                        break;
                }
 
-               if (strcmp(tokens[0], "DEVICE") == 0) {
-                       bus = xstrdup(tokens[4]);
-                       device = xstrdup(tokens[5]);
-                       continue;
-               }
-
                if (strcmp(tokens[0], "PRODUCT") == 0) {
                        product_vid = xstrtou(tokens[1], 16);
                        product_did = xstrtou(tokens[2], 16);
                        continue;
                }
+
+               if (strcmp(tokens[0], "BUSNUM") == 0) {
+                       busnum = xstrdup(tokens[1]);
+                       continue;
+               }
+
+               if (strcmp(tokens[0], "DEVNUM") == 0) {
+                       devnum = xstrdup(tokens[1]);
+                       continue;
+               }
        }
        config_close(parser);
 
-       if (bus) {
-               printf("Bus %s Device %s: ID %04x:%04x\n", bus, device, product_vid, product_did);
-               free(bus);
-               free(device);
+       if (busnum) {
+               printf("Bus %s Device %s: ID %04x:%04x\n", busnum, devnum, product_vid, product_did);
+               free(busnum);
+               free(devnum);
        }
 
        return TRUE;