# lsusb does not show devices that have udev rules

## jchau

lsusb does not show devices with udev rules for me.  I am using sys-fs/udev-104-r12 and sys-apps/usbutils-0.71-r1.  

For example, when I comment the following for my USB flash drive in /etc/udev/rules.d/10-local.rules (which I created to name my devices),

```
#BUS=="usb", SYSFS{idVendor}=="0930", SYSFS{idProduct}=="6533", NAME="%k", SYMLINK+="ums/kingston", GROUP:="plugdev"
```

the command 

```
lsusb
```

 shows 

```
Bus 005 Device 004: ID 0930:6533 Toshiba Corp. 512M USB Stick

Bus 005 Device 001: ID 0000:0000  

Bus 002 Device 002: ID 062a:0001 Creative Labs Notebook Optical Mouse

Bus 002 Device 001: ID 0000:0000  

Bus 003 Device 001: ID 0000:0000  

Bus 004 Device 001: ID 0000:0000  

Bus 001 Device 001: ID 0000:0000  

```

However, when I uncomment the line in /etc/udev/rules.d/10-local.rules and remove & reinsert the flash drive, lsusb just displays 

```
Bus 005 Device 001: ID 0000:0000  

Bus 002 Device 002: ID 062a:0001 Creative Labs Notebook Optical Mouse

Bus 002 Device 001: ID 0000:0000  

Bus 003 Device 001: ID 0000:0000  

Bus 004 Device 001: ID 0000:0000  

Bus 001 Device 001: ID 0000:0000  

```

Notice that the "Toshiba Corp. 512M USB Stick" disappears.

Strangely, 

```
lsusb -t
```

 continues to show the flash drive regardless of the udev rules.  

```
Bus#  5

`-Dev#   1 Vendor 0x0000 Product 0x0000

  |-Dev#   2 Vendor 0x413c Product 0x9001

  `-Dev#   5 Vendor 0x0930 Product 0x6533

Bus#  4

`-Dev#   1 Vendor 0x0000 Product 0x0000

Bus#  3

`-Dev#   1 Vendor 0x0000 Product 0x0000

Bus#  2

`-Dev#   1 Vendor 0x0000 Product 0x0000

  `-Dev#   2 Vendor 0x062a Product 0x0001

Bus#  1

`-Dev#   1 Vendor 0x0000 Product 0x0000

```

(The device "Vendor 0x413c Product 0x9001" is my CDRW drive from Dell.  It also has a udev rule.)

I also tested this with my camera (Kodak C330) and the same thing happened when I used this rule:

```
BUS=="usb", SYSFS{idVendor}=="040a", SYSFS{idProduct}=="058c", NAME="%k", SYMLINK+="kodak", GROUP:="plugdev"

```

Is this a bug or a strange feature.  Does this happen to anyone else?

----------

## wynn

Curious.

I can't say I followed all the code in usbutils-0.71/lsusb.c but it seems to have something to do with vendor and product being initialized to -1.

Could you try (with the name change)

```
lsusb -d '0930:6533'
```

I thought there might be something which balks at a different name but I can't see it.

Perhaps it's worth a bug report.

----------

## jchau

wynn, here is the result of your suggestion:

```

Jimmy-Laptop jimmy # lsusb -d '0930:6533'

Jimmy-Laptop jimmy # lsusb -t

Bus#  5

`-Dev#   1 Vendor 0x0000 Product 0x0000

  `-Dev#  21 Vendor 0x0930 Product 0x6533

Bus#  4

`-Dev#   1 Vendor 0x0000 Product 0x0000

Bus#  3

`-Dev#   1 Vendor 0x0000 Product 0x0000

Bus#  2

`-Dev#   1 Vendor 0x0000 Product 0x0000

  `-Dev#   2 Vendor 0x062a Product 0x0001

Bus#  1

`-Dev#   1 Vendor 0x0000 Product 0x0000

```

I did some more digging into the issue.  It seems that removing the NAME= portion of the udev rules restores the functionality of lsusb.  

For example, if I change the rule to

```
BUS=="usb", SYSFS{idVendor}=="0930", SYSFS{idProduct}=="6533", SYMLINK+="ums/kingston", GROUP:="plugdev"
```

then 

```
lsusb -d '0930:6533'
```

 returns

```
Jimmy-Laptop jimmy # lsusb -d '0930:6533'

Bus 005 Device 022: ID 0930:6533 Toshiba Corp. 512M USB Stick

```

I'm not sure why this happens, but I'm guessing that the NAME action of the udev rule prevents a future udev rule from running (only the first udev rule with the name action runs according to the manual page).  

Would this be the udev rule (from /etc/udev/rules.d/50-udev.rules) that allows lsusb to work properly?

```
# usbfs-like device nodes

SUBSYSTEM=="usb_device", PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", NAME="%c", GROUP="usb", MODE="0664"

```

----------

## wynn

I'm not that hot on udev rules but now you point it out is does seem to explain it.

lsusb just loops though the devices printing what it finds but if putting a NAME= removes information it looks for then ...

You also had NAME="%k" but in the rule you posted it has NAME="%c" and %k appears to be used for something else.

----------

## jchau

I'm not sure I understand the udev rule too well either.  It seems like the PROGRAM in the udev rule just outputs a string.  %c is  *Quote:*   

>        $result, %c
> 
>            The string returned by the external program requested with PROGRAM.
> 
>            A single part of the string, separated by a space character may be
> ...

  according to the udev manual.  %k is the name that the kernel calls the device.  

It seems like that udev rule places the usb devices into /dev/bus/usb/{number}/{anothernumber} where {number} and {anothernumber} are numbers.

Strange though.  I thought lsusb looks in /proc/bus/usb instead of /dev/bus/usb.  Perhaps one affects the other.  

So I guess the behavior before was normal.  Thanks for your help.  I wonder if defining NAME in udev breaks anything else.

----------

## wynn

 *jchau wrote:*   

> Strange though.  I thought lsusb looks in /proc/bus/usb instead of /dev/bus/usb.

 Well, that was a pleasant ramble through the woods !

It turns out, as you surmised, that libusb (called by lsusb to do the work) tries "/dev/bus/usb" first and then, if that doesn't work, "/proc/bus/usb".

----------

## jchau

 *jchau wrote:*   

> I wonder if defining NAME in udev breaks anything else.

 

Just a followup:

defining your own NAME in udev for USB devices also breaks gphoto2 for me; it will not detect the camera (Kodak C330) (this was the reason I was trying to get lsusb to work in the first place).  Since I removed the NAME part of my customized rules, gphoto2 worked again.  

I would suggest that everyone avoid using the NAME action for USB devices in udev and just define only the symlinks instead.

----------

