/dev/bus/usb/*/* lists all the usb devices connected on Alpine Linux. For example a phone could be /dev/bus/usb/001/009. When that phone is reconnected it will be /dev/bus/usb/001/010, i.e. it increments.

My question is what happens after 1001 connections?


Would the ??? go to 1000? Would it create a new folder say 003 under /dev/bus/usb/?

This is for manipulating the output of usb-devices and lsusb. Getting the Vendor and ProdID is not unique in my case.

I'd rather not plug in/out a usb cable 1000 times!


If I read correctly https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/drivers/usb/core/hub.c#n2030 (code for a function called choose_devnum), it may wrap far earlier than that, at value 127 in fact, and then going back to 1:

    /* Try to allocate the next devnum beginning at
     * bus->devnum_next. */
    devnum = find_next_zero_bit(bus->devmap.devicemap, 128,
    if (devnum >= 128)
        devnum = find_next_zero_bit(bus->devmap.devicemap,
                        128, 1);
    bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1);

And later on the bus->devnum property is really set only if devnum is less than 128.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.