Re: [PATCH] util-linux/lsusb.c: print manufacturer/product strings if available

2023-12-13 Thread Peter Korsgaard
> "Aleksander" == Aleksander Mazur  writes:

 > Hi,
 > AFAIR similar problem applies to util-linux/lspci.c.
 > Do you build busybox with shell enabled?
 > Instead of busybox's lspci/lsusb I use 2 quite simple shell scripts (working 
 > in hush).

Yes, lsusb/lspci are really simple applets, but given that they already
exist we might as well make them more useful.

-- 
Bye, Peter Korsgaard
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] util-linux/lsusb.c: print manufacturer/product strings if available

2023-12-13 Thread Aleksander Mazur
Hi,

AFAIR similar problem applies to util-linux/lspci.c.
Do you build busybox with shell enabled?
Instead of busybox's lspci/lsusb I use 2 quite simple shell scripts (working in 
hush).

-- 
Aleksander Mazur

Dnia 2023-12-13, o godz. 16:04:02
Peter Korsgaard  napisaƂ(a):

> Just listing the vendor/product IDs is not always very helpful, so add logic
> to print the manufacturer and product strings similar to the "big" usbutils
> versions.
> 
> Not all devices provide sensible strings though.  The usbutils version works
> around this by falling back to looking up the vendor/product IDs in the hwdb
> and using those strings instead, which is not an option here - Instead
> simply trim() the strings for readability.
> 
> lsusb | sort
> Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 001 Device 002: ID 0bda:5539 Realtek Semiconductor Corp.
> Integrated_Webcam_HD Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp. 58200
> Bus 001 Device 030: ID 8087:0aaa Intel Corp. Bluetooth 9460/9560 Jefferson
> Peak (JfP) Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 006 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 006 Device 002: ID 0bda:5487 Realtek Semiconductor Corp. Dell dock
> Bus 006 Device 003: ID 0bda:5413 Realtek Semiconductor Corp. Dell dock
> Bus 006 Device 004: ID 413c:b06e Dell Computer Corp. Dell dock
> Bus 006 Device 005: ID 0451:8142 Texas Instruments, Inc. TUSB8041 4-Port Hub
> Bus 006 Device 006: ID 0bda:402e Realtek Semiconductor Corp. USB Audio
> Bus 006 Device 007: ID 413c:1010 Dell Computer Corp. USB 2.0 Hub [MTT]
> Bus 006 Device 008: ID 413c:b06f Dell Computer Corp. Dell dock
> Bus 006 Device 009: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
> Bus 006 Device 010: ID 413c:2110 Dell Computer Corp. Dell Wired Multimedia
> Keyboard Bus 006 Device 011: ID 0451:8142 Texas Instruments, Inc. TUSB8041
> 4-Port Hub Bus 006 Device 012: ID 0451:3410 Texas Instruments, Inc. TUSB3410
> Microcontroller Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> Bus 007 Device 002: ID 0bda:0487 Realtek Semiconductor Corp. Dell dock
> Bus 007 Device 003: ID 0bda:0413 Realtek Semiconductor Corp. Dell dock
> Bus 007 Device 004: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit
> Ethernet Adapter
> 
> ./busybox lsusb | sort
> Bus 001 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host
> Controller Bus 001 Device 002: ID 0bda:5539 CNFHH53Q0324300ACA10
> Integrated_Webcam_HD Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp 58200
> Bus 001 Device 030: ID 8087:0aaa
> Bus 002 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host
> Controller Bus 003 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd
> xHCI Host Controller Bus 004 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64
> xhci-hcd xHCI Host Controller Bus 005 Device 001: ID 1d6b:0002 Linux
> 6.1.0-13-amd64 dummy_hcd Dummy host controller Bus 006 Device 001: ID
> 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller Bus 006 Device
> 002: ID 0bda:5487 Dell Inc. Dell dock Bus 006 Device 003: ID 0bda:5413 Dell
> Inc. Dell dock Bus 006 Device 004: ID 413c:b06e Dell dock
> Bus 006 Device 005: ID 0451:8142
> Bus 006 Device 006: ID 0bda:402e Generic USB Audio
> Bus 006 Device 007: ID 413c:1010 USB 2.0 Hub [MTT]
> Bus 006 Device 008: ID 413c:b06f Dell dock
> Bus 006 Device 009: ID 046d:c016 Logitech Optical USB Mouse
> Bus 006 Device 010: ID 413c:2110 Dell Dell Wired Multimedia Keyboard
> Bus 006 Device 011: ID 0451:8142
> Bus 006 Device 012: ID 0451:3410 Texas Instruments TUSB3410 Boot Device
> Bus 007 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host
> Controller Bus 007 Device 002: ID 0bda:0487 Dell Inc. Dell dock
> Bus 007 Device 003: ID 0bda:0413 Dell Inc. Dell dock
> Bus 007 Device 004: ID 0bda:8153 Realtek USB 10/100/1000 LAN
> 
> ./scripts/bloat-o-meter busybox_unstripped{_orig,}
> function old new   delta
> trim   - 101+101
> fileAction   338 431 +93
> add_sysfs_prop -  70 +70
> open_read_close-  54 +54
> read_close -  35 +35
> .rodata 32683294 +26
> --
> (add/remove: 5/0 grow/shrink: 2/0 up/down: 379/0) Total: 379 bytes
> 
> Signed-off-by: Peter Korsgaard 
> ---
>  util-linux/lsusb.c | 28 +++-
>  1 file changed, 27 insertions(+), 1 deletion(-)
> 
> diff --git a/util-linux/lsusb.c b/util-linux/lsusb.c
> inde

[PATCH] util-linux/lsusb.c: print manufacturer/product strings if available

2023-12-13 Thread Peter Korsgaard
Just listing the vendor/product IDs is not always very helpful, so add logic
to print the manufacturer and product strings similar to the "big" usbutils
versions.

Not all devices provide sensible strings though.  The usbutils version works
around this by falling back to looking up the vendor/product IDs in the hwdb
and using those strings instead, which is not an option here - Instead
simply trim() the strings for readability.

lsusb | sort
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0bda:5539 Realtek Semiconductor Corp. 
Integrated_Webcam_HD
Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp. 58200
Bus 001 Device 030: ID 8087:0aaa Intel Corp. Bluetooth 9460/9560 Jefferson Peak 
(JfP)
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 002: ID 0bda:5487 Realtek Semiconductor Corp. Dell dock
Bus 006 Device 003: ID 0bda:5413 Realtek Semiconductor Corp. Dell dock
Bus 006 Device 004: ID 413c:b06e Dell Computer Corp. Dell dock
Bus 006 Device 005: ID 0451:8142 Texas Instruments, Inc. TUSB8041 4-Port Hub
Bus 006 Device 006: ID 0bda:402e Realtek Semiconductor Corp. USB Audio
Bus 006 Device 007: ID 413c:1010 Dell Computer Corp. USB 2.0 Hub [MTT]
Bus 006 Device 008: ID 413c:b06f Dell Computer Corp. Dell dock
Bus 006 Device 009: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
Bus 006 Device 010: ID 413c:2110 Dell Computer Corp. Dell Wired Multimedia 
Keyboard
Bus 006 Device 011: ID 0451:8142 Texas Instruments, Inc. TUSB8041 4-Port Hub
Bus 006 Device 012: ID 0451:3410 Texas Instruments, Inc. TUSB3410 
Microcontroller
Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 002: ID 0bda:0487 Realtek Semiconductor Corp. Dell dock
Bus 007 Device 003: ID 0bda:0413 Realtek Semiconductor Corp. Dell dock
Bus 007 Device 004: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit 
Ethernet Adapter

./busybox lsusb | sort
Bus 001 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host 
Controller
Bus 001 Device 002: ID 0bda:5539 CNFHH53Q0324300ACA10 Integrated_Webcam_HD
Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp 58200
Bus 001 Device 030: ID 8087:0aaa
Bus 002 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host 
Controller
Bus 003 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host 
Controller
Bus 004 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host 
Controller
Bus 005 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 dummy_hcd Dummy host 
controller
Bus 006 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host 
Controller
Bus 006 Device 002: ID 0bda:5487 Dell Inc. Dell dock
Bus 006 Device 003: ID 0bda:5413 Dell Inc. Dell dock
Bus 006 Device 004: ID 413c:b06e Dell dock
Bus 006 Device 005: ID 0451:8142
Bus 006 Device 006: ID 0bda:402e Generic USB Audio
Bus 006 Device 007: ID 413c:1010 USB 2.0 Hub [MTT]
Bus 006 Device 008: ID 413c:b06f Dell dock
Bus 006 Device 009: ID 046d:c016 Logitech Optical USB Mouse
Bus 006 Device 010: ID 413c:2110 Dell Dell Wired Multimedia Keyboard
Bus 006 Device 011: ID 0451:8142
Bus 006 Device 012: ID 0451:3410 Texas Instruments TUSB3410 Boot Device
Bus 007 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host 
Controller
Bus 007 Device 002: ID 0bda:0487 Dell Inc. Dell dock
Bus 007 Device 003: ID 0bda:0413 Dell Inc. Dell dock
Bus 007 Device 004: ID 0bda:8153 Realtek USB 10/100/1000 LAN

./scripts/bloat-o-meter busybox_unstripped{_orig,}
function old new   delta
trim   - 101+101
fileAction   338 431 +93
add_sysfs_prop -  70 +70
open_read_close-  54 +54
read_close -  35 +35
.rodata 32683294 +26
--
(add/remove: 5/0 grow/shrink: 2/0 up/down: 379/0) Total: 379 bytes

Signed-off-by: Peter Korsgaard 
---
 util-linux/lsusb.c | 28 +++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/util-linux/lsusb.c b/util-linux/lsusb.c
index 262c70a1b..0a9e505f4 100644
--- a/util-linux/lsusb.c
+++ b/util-linux/lsusb.c
@@ -24,6 +24,24 @@
 
 #include "libbb.h"
 
+static char * FAST_FUNC add_sysfs_prop(const char *dir, const char *suffix,
+   char *buf, size_t size)
+{
+   char *filename;
+   ssize_t len;
+
+   filename = concat_path_file(dir, suffix);
+   len = open_read_close(filename, buf, size - 1);
+   free(filename);
+