How creation of new USB device file in /dev/bus/usb/001/ directory work

devicesroot-filesystemusb

I noticed that every time I connect a USB device, a new device gets created in the /dev/bus/usb/001/ directory. Further on each reconnection of the same device, the "Device Number" and "ID" change.

So, I'd like to know how the creation of new device file (in /dev/bus/usb/001/) work? Can I control the behaviour, say limit the device number to 002, by making changes in some configuration file (if any)?

Here's a the output for reference:

$ ls /dev/bus/usb/001
001  002
$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 0781:5406 SanDisk Corp. Cruzer Micro U3
$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 003: ID 08ec:0015 M-Systems Flash Disk Pioneers Kingston DataTraveler ELITE
$ lsusb 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 008: ID 0781:5406 SanDisk Corp. Cruzer Micro U3
$ ls /dev/bus/usb/001/
001  008

( Also I don't know why Kingston Flash Disk was shown in the output. I don't have a Kingston device!… Maybe it's just a glitch, or is it? )

Another contextual topic of interest:

Best Answer

The devices in /dev/bus/usb/XXX/YYY follow naming policies in the kernel as noted Gilles in the comments. XXX is the bus number which is quite stable, but YYY changes every time the USB device gets enumerated (when a device just got inserted or reset). This cannot be changed and you shouldn't have to change this either.

If you need to change permissions on the device (for example, to make an unprivileged userspace USB driver possible for testing purposes), then you could make a udev rule. An example where I use udev to control the permissions such that adb is able to connect to the device:

# /etc/udev/rules.d/42-usb-permissions.rules
SUBSYSTEM!="usb", GOTO="end_skip_usb"

# CWM 6.0.4.3 in recovery mode
ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="d001", GROUP="peter"

# CM 10.2 with MTP disabled
ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="d002", GROUP="peter"

ATTRS{idVendor}=="148f", ATTRS{idProduct}=="5372", GROUP="peter"

LABEL="end_skip_usb"
Related Question