]> git.armaanb.net Git - asd-repo.git/blob - core/busybox/patches/lsusb-vendor-product.patch
Restructure repository
[asd-repo.git] / core / busybox / patches / lsusb-vendor-product.patch
1 diff --git a/util-linux/lsusb.c b/util-linux/lsusb.c
2 index e27aa7f31..b7b7abb99 100644
3 --- a/util-linux/lsusb.c
4 +++ b/util-linux/lsusb.c
5 @@ -15,7 +15,16 @@
6  //config:      system and devices connected to them.
7  //config:
8  //config:      This version uses sysfs (/sys/bus/usb/devices) only.
9 -
10 +//config:
11 +//config:config FEATURE_LSUSB_STRINGS
12 +//config:      bool "Print vendor and product strings if they exist"
13 +//config:      default y
14 +//config:      depends on LSUSB
15 +//config:      help
16 +//config:      lsusb is a utility for displaying information about USB busses in the
17 +//config:      system and devices connected to them. This option prints out the
18 +//config:      vendor and product strings if they are available. This option
19 +//config:      replicates a simpler version of util-linux lsusb output.
20  //applet:IF_LSUSB(APPLET_NOEXEC(lsusb, lsusb, BB_DIR_USR_BIN, BB_SUID_DROP, lsusb))
21  
22  //kbuild:lib-$(CONFIG_LSUSB) += lsusb.o
23 @@ -37,6 +46,16 @@ static int FAST_FUNC fileAction(
24         int product_vid = 0, product_did = 0;
25         char *uevent_filename = concat_path_file(fileName, "/uevent");
26  
27 +#if ENABLE_FEATURE_LSUSB_STRINGS
28 +       ssize_t vlen, plen;
29 +       // max length standard allows, any longer and someones being naughty
30 +       char vendor[256] = { 0 }, product[256] = { 0 };
31 +       vlen = open_read_close(concat_path_file(fileName, "/manufacturer"), vendor, sizeof(vendor));
32 +       vendor[vlen - 1] = '\0';
33 +       plen = open_read_close(concat_path_file(fileName, "/product"), product, sizeof(product));
34 +       product[plen - 1] = '\0';
35 +#endif
36 +
37         parser = config_open2(uevent_filename, fopen_for_read);
38         free(uevent_filename);
39  
40 @@ -64,7 +83,12 @@ static int FAST_FUNC fileAction(
41         config_close(parser);
42  
43         if (busnum) {
44 -               printf("Bus %s Device %s: ID %04x:%04x\n", busnum, devnum, product_vid, product_did);
45 +               printf("Bus %s Device %s: ID %04x:%04x", busnum, devnum, product_vid, product_did);
46 +#if ENABLE_FEATURE_LSUSB_STRINGS
47 +               if(vlen) printf(" %s", vendor);
48 +               if(plen) printf(" %s", product);
49 +#endif
50 +               printf("\n");
51                 free(busnum);
52                 free(devnum);
53         }