[Toybox] lsusb: add -t option for tree format display
Rob Landley
rob at landley.net
Sun Jul 20 19:25:37 PDT 2025
On 7/20/25 08:00, Patel, Jignesh1 wrote:
> Hi Rob,
>
> Please find attached a patch adding tree format display to lsusb,
> similar to usbutils lsusb -t. The implementation:
>
> - Uses only toybox infrastructure functions.
> - Minimal memory footprint.> - Gracefully handles missing usb.ids file.
> - Shows USB device hierarchy from sysfs.
>
> The patch is ready for review.
Roughly doubles the size of the command (diffstat says it adds 200 lines
to a command that previously had ~220 lines after the header), and does
not seem to share any infrastructure outside the main() function except
get_names()...
Hmmm, looking at debian's version...
> /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
> |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
> |__ Port 4: Dev 66, If 2, Class=Vendor Specific Class, Driver=btusb, 12M
Vs...
> Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 001 Device 066: ID 413c:8197 Dell Computer Corp. BCM20702A0 Bluetooth Module
> Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Not just the order changing but what it's outputting. Pity there isn't a
standard format for this information...
As for the code... read_sysfs_uint() only has one caller (so could be
inlined at its call site) and it's logically just something like:
strtoul(readfile(path, toybuf, sizeof(toybuf)) ? : "", 0, 10);
Except dirtree functions mostly use openat to have a dirfd so they don't
need to concatenate paths so it would be readfileat()...
I can change it here, let me take a closer look this evening. (I'm in
tokyo at the moment juggling other commitments...)
Thanks,
Rob
More information about the Toybox
mailing list