Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 50934

Summary: USB hotplug + udev + libusb + sane-backends + scanner produces error during boot "cannot access /proc/bus/usb/002/004: no such file or directory"
Product: Gentoo Linux Reporter: Petr Janda <petrjanda>
Component: Current packagesAssignee: Patrick Kursawe (RETIRED) <phosphan>
Status: RESOLVED WONTFIX    
Severity: normal CC: arthur2shedsjackson, bugs, bzdurqa, chemoelectric, cryos, cyril.baletaud, dberkholz, fuzz, gregkh, I-SAngeli, juan, mig21, neysx, phajdan.jr, phosphan, radek, robin, syscon780, tchiwam
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on: 83738    
Bug Blocks: 126089    
Attachments: modified to check /sys when $DEVICE is not set
/etc/hotplug/usb/usbscanner
udev-usbgentoo.diff
newusbscanner

Description Petr Janda 2004-05-13 06:58:38 UTC
I installed libusb and sane-backends to get my usb scanner (Cannon D660U) to work, and since then I was receiving errors on start up during the "USB hotplugging" stage.

chown: cannot access "/proc/bus/usb/002/004": No such file or directory
chmod: cannot access "/proc/bus/usb/002/004": No such file or directory

On my computer there is no 004 file in /proc/bus/usb/002 since the file "003" is the last one within the directory.

The problem ended up being in /etc/hotplug/usb/libusbscanner where line 20 is:
DEV=$(expr $DEV + 1)
which produces the above mentioned errors.

The bug is is fixed by changing the plus into minus.
DEV=$(expr $DEV - 1)

or by commenting out everything except
if [ -z "$DEVICE" ] ; then
        IF=$(echo $DEVPATH | sed 's:\(bus/usb/devices/\)\(.*\)-\(.*\):\2:')
        DEV=$(echo $DEVPATH | sed 's:\(bus/usb/devices/\)\(.*\)-\(.*\):\3:')
        DEV=$(expr $DEV - 1)
        DEVICE=$(printf '/proc/bus/usb/%.03d/%.03d' $IF $DEV)
fi

Reproducible: Always
Steps to Reproduce:
1. Use udev and hotplug
2. Install sane-backends and libusb
3. Get your scanner to work and restart or run /etc/init.d/hotplug restart
4. Observe usb hotplugging

Im not sure if this bug is unique for my computer

Actual Results:  
During boot up appears this message (the numbers 002/004 might be different for
your computer but you get the point)
chown: cannot access "/proc/bus/usb/002/004": No such file or directory
chmod: cannot access "/proc/bus/usb/002/004": No such file or directory

Expected Results:  
Expected result is of course no error message during USB hotplugging
Comment 1 Xavier Neys (RETIRED) gentoo-dev 2004-05-13 09:04:17 UTC
Dear devs can read the thread that lead to this report at
http://forums.gentoo.org/viewtopic.php?p=1136869
Comment 2 Greg Kroah-Hartman (RETIRED) gentoo-dev 2004-05-14 13:59:18 UTC
The file /etc/hotplug/usb/libusbscanner is not part of the main hotplug
packages.

I suggest you refile this bug based on the package that owns this file.

Oh, and udev has nothing to do with it :)
Comment 3 Xavier Neys (RETIRED) gentoo-dev 2004-05-14 16:11:51 UTC
 /etc/hotplug/usb/libusbscanner is not part of the main hotplug package indeed, it is part of sane-backends and is called by hotplug. It's been added recently.
sane-backends is mentioned on the first line of the poster's report BTW.

The problem is still alive and the solution that seems to work on Petr's udev setup does not work on mine (2.6 kernel, still devfs) and others'. I don't know whether udev really has an influence.
More info is available in the thread mentioned above. Another similar thread is still going on in the French forum.

In short, when /etc/init.d/hotplug is (re)started, it passes an empty DEVICE and some DEVPATH to the /etc/hotplug/usb/libusbscanner script. That's what is tested by the if [ -z "$DEVICE" ]. In my case, the scanner is on /proc/bus/usb/002/003 at startup and IF (bus number) is assigned 2 which is right, but DEV (device number) is assigned 1 (because DEVPATH="bus/usb/devices/2-1") and should become 3. Clearly the +1 is not the right way ;-) In petr's case, DEV was 4 and had to be decreased.
On the other hand, when I switch my scanner off and back on, the script gets a proper value for DEVICE ("/proc/bus/usb/002/004", then 005, and on) and works OK; DEVPATH="/devices/pci0000:00/0000:00:0c.0/usb2/2-1/2-1:1.0" not being used in that case. I had a quick look into the sys file system and could not find any info that could lead to the right /proc/bus/usb/BBB/DDD entry.

Either have hotplug pass consistent information to the sane-backends script, or have the script cope for all possible inputs.

Another issue, a less important one, is that sane-backends now installs its own libsane.usermap next to its libusbscanner, but when the user already had the scanner listed in his own usb.usermap (as suggested in hotplug's documentation iirc) and uses a script called anything else but libusbscanner (like scanner e.g.), _both_ scripts are run by hotplug. That is IMO a normal behaviour, but few users will be aware of that and will be very confused when trying to configure their scanner.

Please do feel free to assign to whoever can solve this bug or change the title to anything you like.

Kind regards.
Comment 4 Greg Kroah-Hartman (RETIRED) gentoo-dev 2004-05-14 16:59:08 UTC
This needs to go to the sane developers.
Comment 5 Artur Brodowski 2004-06-07 14:01:46 UTC
For me it looks like /etc/hotplug/usb/libusbscanner is either not called at all,
or it gets empty variables as an input. I've added simple debug echo line to the script, but after restarting hotplug I got no additional output.
So for now (I also use devfs) I had to edit /etc/hotplug/usb.agent and add
some lines that parse $PRODUCT - if it matches my device id, I use chmod/chown
to change permissions. It's not too clean, but it works.
Comment 6 Xavier Neys (RETIRED) gentoo-dev 2004-06-07 14:55:20 UTC
Artur: what do you chmod/chown ?

In short, when hotplug is (re)started, the script IS called with
  DEVICE undefined
  DEVPATH="bus/usb/devices/2-1"
but when you switch your scanner off and back on, the script IS called with
  DEVICE="/proc/bus/usb/002/004"
  DEVPATH="/devices/pci0000:00/0000:00:0c.0/usb2/2-1/2-1:1.0"

See the aformentioned thread in the forums for more info.

BTW, I have read you could make your life easier by mounting usbfs with options gid=100,mode=660. I haven't tried but why shouldn't it work?
Comment 7 Greg Kroah-Hartman (RETIRED) gentoo-dev 2004-06-07 15:12:22 UTC
Those mount options to not work on 2.6 due to this bug:
http://bugme.osdl.org/show_bug.cgi?id=1418

Sorry :(
Comment 8 Artur Brodowski 2004-06-08 01:41:30 UTC
Xavier:
when DEVICE is empty I get right path like this:
DEV_ID=`echo "$DEVPATH" | sed -e 's/.*\([0-9]\)\-\([0-9]\)/\/proc\/bus\/usb\/00\1\/00\2/'`
Comment 9 Xavier Neys (RETIRED) gentoo-dev 2004-06-08 03:46:00 UTC
That's what the code inside the 
  if [ -z "$DEVICE" ] ; then
does, except it increments the device number. In your case, values should not be changed, on other cases, the device number needs to be decremented or +=2.

In other words, you're just lucky the numbers match.
Comment 10 Artur Brodowski 2004-06-08 03:52:47 UTC
Anyways, it should be fixed in portage and/or upstream. 
Did developers already take care of this?
Comment 11 Patrick Kursawe (RETIRED) gentoo-dev 2004-06-15 22:54:38 UTC
"You're just lucky the numbers match" does not sound like a candidate for portage... that wouldn't be any better than the current status.
There should be some clean solution, so let's try to find it.
Comment 12 Patrick Kursawe (RETIRED) gentoo-dev 2004-06-15 23:11:59 UTC
*** Bug 53950 has been marked as a duplicate of this bug. ***
Comment 13 Patrick Kursawe (RETIRED) gentoo-dev 2004-06-15 23:54:44 UTC
Btw, the hotplug script that makes the trouble comes from bug #49815
Comment 14 Arthur Jackson 2004-06-16 13:16:51 UTC
i have the same problem with a Canon U1240 scanner works as root but (on a fully udev system) shows the error:

chown: cannot access `/proc/bus/usb/003/003': No such file or directory 
chmod: cannot access `/proc/bus/usb/003/003': No such file or directory

A copy of /proc/bus/usb/devices shows:

T:  Bus=05 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.7-rc3-love1 uhci_hcd
S:  Product=Intel Corp. 82801EB/ER (ICH5/ICH5R) USB UHCI #4
S:  SerialNumber=0000:00:1d.3
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms

T:  Bus=04 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.7-rc3-love1 uhci_hcd
S:  Product=Intel Corp. 82801EB/ER (ICH5/ICH5R) USB UHCI #3
S:  SerialNumber=0000:00:1d.2
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms

T:  Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.7-rc3-love1 uhci_hcd
S:  Product=Intel Corp. 82801EB/ER (ICH5/ICH5R) USB UHCI #2
S:  SerialNumber=0000:00:1d.1
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms

T:  Bus=03 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#=  2 Spd=12  MxCh= 0
D:  Ver= 1.10 Cls=ff(vend.) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=04a9 ProdID=220e Rev= 1.00
S:  Manufacturer=Canon
S:  Product=CanoScan
C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=500mA
I:  If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=ff Driver=(none)
E:  Ad=81(I) Atr=03(Int.) MxPS=   1 Ivl=16ms
E:  Ad=82(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=03(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms

T:  Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.7-rc3-love1 uhci_hcd
S:  Product=Intel Corp. 82801EB/ER (ICH5/ICH5R) USB UHCI #1
S:  SerialNumber=0000:00:1d.0
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms

T:  Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=480 MxCh= 8
B:  Alloc=  0/800 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 2.00 Cls=09(hub  ) Sub=00 Prot=01 MxPS= 8 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.7-rc3-love1 ehci_hcd
S:  Product=Intel Corp. 82801EB/ER (ICH5/ICH5R) USB2 EHCI Controller
S:  SerialNumber=0000:00:1d.7
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=256ms

Comment 15 Patrick Kursawe (RETIRED) gentoo-dev 2004-06-17 05:16:10 UTC
Could some of you please try if setting
DEV=$(cat /sys/$DEVPATH/devnum)
does the trick?
Comment 16 Xavier Neys (RETIRED) gentoo-dev 2004-06-17 06:36:51 UTC
Here we go again.

I just switched my scanner on and hotplug called my usbscanner script with the following vars:

 ACTION=add
 DEVICE=/proc/bus/usb/002/005
 DEVPATH=/devices/pci0000:00/0000:00:0c.0/usb2/2-1/2-1:1.0

The script granted expected rights on $DEVICE, all is fine.

Then I restarted hotplug (scanner is still on and device is still /proc/bus/usb/002/005) and I get

# /etc/init.d/hotplug start
 * Starting input hotplugging...                                                                       [ ok ]
 * Starting pci hotplugging...                                                                         [ ok ]
 * Starting usb hotplugging...
chown: cannot access `/proc/bus/usb/002/003': No such file or directory
chmod: cannot access `/proc/bus/usb/002/003': No such file or directory
[ ok ]

The script has been called with the following vars:

 ACTION=add
 DEVICE=
 DEVPATH=bus/usb/devices/2-1

Why can't hotplug give us the right device?

/sys/$DEVPATH does not contain any devnum file

# ls -lR /sys/bus/usb/devices/2-1
lrwxrwxrwx  1 root root 49 Jun 17 14:50 /sys/bus/usb/devices/2-1 -> ../../../devices/pci0000:00/0000:00:0c.0/usb2/2-1

The file contents do not seem to point to /proc/bus...005 in any way:
Here is the list of files and their content:

# for ff in `find . -type f`; do echo $ff|paste $ff -;done
00      ./2-1:1.0/iInterface
ff      ./2-1:1.0/bInterfaceProtocol
ff      ./2-1:1.0/bInterfaceSubClass
ff      ./2-1:1.0/bInterfaceClass
02      ./2-1:1.0/bNumEndpoints
 0      ./2-1:1.0/bAlternateSetting
00      ./2-1:1.0/bInterfaceNumber
0       ./2-1:1.0/power/state
0       ./2-1:1.0/detach_state
Perfection1640  ./product
EPSON   ./manufacturer
12      ./speed
1       ./bNumConfigurations
ff      ./bDeviceProtocol
ff      ./bDeviceSubClass
ff      ./bDeviceClass
0104    ./bcdDevice
010a    ./idProduct
04b8    ./idVendor
  2mA   ./bMaxPower
40      ./bmAttributes
1       ./bConfigurationValue
 1      ./bNumInterfaces
0       ./power/state
0       ./detach_state


FYI,
# sane-find-scanner
found USB scanner (vendor=0x04b8 [EPSON], product=0x010a [Perfection1640]) at libusb:002:005

basil 2-1 # scanimage -L
device `epson:libusb:002:005' is a Epson Perfection1640 flatbed scanner
Comment 17 Patrick Kursawe (RETIRED) gentoo-dev 2004-06-17 07:40:32 UTC
Created attachment 33423 [details]
modified to check /sys when $DEVICE is not set

I'm afraid you mixed some things up. The device number from sys/$DEVPATH is
only relevant if DEVICE is empty.
So please try the attached file as your 
/etc/hotplug/usb/libusbscanner
Comment 18 Xavier Neys (RETIRED) gentoo-dev 2004-06-17 08:05:03 UTC
No mix up at all. Please read my previous comment again.

/sys/$DEVPATH/devnum does not exist.
Here is the list of files, again, see above for their content:
/sys/bus/usb/devices/2-1/:
total 0
drwxr-xr-x  3 root root    0 Jun 17 15:27 2-1:1.0
-r--r--r--  1 root root 4096 Jun 17 15:22 bcdDevice
-rw-r--r--  1 root root 4096 Jun 17 15:22 bConfigurationValue
-r--r--r--  1 root root 4096 Jun 17 15:22 bDeviceClass
-r--r--r--  1 root root 4096 Jun 17 15:22 bDeviceProtocol
-r--r--r--  1 root root 4096 Jun 17 15:22 bDeviceSubClass
-r--r--r--  1 root root 4096 Jun 17 15:22 bmAttributes
-r--r--r--  1 root root 4096 Jun 17 15:22 bMaxPower
-r--r--r--  1 root root 4096 Jun 17 15:22 bNumConfigurations
-r--r--r--  1 root root 4096 Jun 17 15:22 bNumInterfaces
-rw-r--r--  1 root root 4096 Jun 17 15:22 detach_state
-r--r--r--  1 root root 4096 Jun 17 15:22 idProduct
-r--r--r--  1 root root 4096 Jun 17 15:22 idVendor
-r--r--r--  1 root root 4096 Jun 17 15:22 manufacturer
drwxr-xr-x  2 root root    0 Jun 17 15:22 power
-r--r--r--  1 root root 4096 Jun 17 15:22 product
-r--r--r--  1 root root 4096 Jun 17 15:22 speed

/sys/bus/usb/devices/2-1/2-1:1.0:
total 0
-r--r--r--  1 root root 4096 Jun 17 15:27 bAlternateSetting
-r--r--r--  1 root root 4096 Jun 17 15:27 bInterfaceClass
-r--r--r--  1 root root 4096 Jun 17 15:27 bInterfaceNumber
-r--r--r--  1 root root 4096 Jun 17 15:27 bInterfaceProtocol
-r--r--r--  1 root root 4096 Jun 17 15:27 bInterfaceSubClass
-r--r--r--  1 root root 4096 Jun 17 15:27 bNumEndpoints
-rw-r--r--  1 root root 4096 Jun 17 15:27 detach_state
-r--r--r--  1 root root 4096 Jun 17 15:27 iInterface
drwxr-xr-x  2 root root    0 Jun 17 15:27 power

/sys/bus/usb/devices/2-1/2-1:1.0/power:
total 0
-rw-r--r--  1 root root 4096 Jun 17 15:27 state

/sys/bus/usb/devices/2-1/power:
total 0
-rw-r--r--  1 root root 4096 Jun 17 15:22 state
Comment 19 Xavier Neys (RETIRED) gentoo-dev 2004-06-17 08:06:31 UTC
Created attachment 33425 [details]
/etc/hotplug/usb/usbscanner

This the script I use to dump debug info into /tmp/toto
Crude hack, but well enough for the task.
Comment 20 Patrick Kursawe (RETIRED) gentoo-dev 2004-06-17 08:23:51 UTC
Xavier, the source of the irritation is maybe that the guy from bug #53950 and me have a "devnum" file in that directory and you haven't - which kernel version are you using? Mine is 2.6.6 (vanilla)
Comment 21 Xavier Neys (RETIRED) gentoo-dev 2004-06-17 08:28:14 UTC
# uname -a
Linux basil 2.6.3 #2 SMP Thu Feb 26 15:12:10 CET 2004 i686 AMD Athlon(tm) Processor AuthenticAMD GNU/Linux
Comment 22 Patrick Kursawe (RETIRED) gentoo-dev 2004-06-17 08:58:01 UTC
That's the problem. Google pointed me to the ChangeLog of 2.6.6-rc1:

<rml@ximian.com>
	[PATCH] USB: add missing usb entries to sysfs
	
	We have found in the course of hacking on HAL that some information that
	is in /proc/bus/usb/devices is not in sysfs.  It would be nice to rely
	only on sysfs, so the attached patch adds three files to usb devices in
	sysfs: devnum, maxChild, and version.

So it looks indeed like sysfs does _not_ give the necessary information in previous kernel versions. Would be really kind if hotplug provided this.

So I'd say I put the modified script into -r3 since I don't see an easy way to get this right for older 2.6 versions. With the old version it breaks for most people, witht the new version it works at least for those with a current kernel.
Comment 23 Xavier Neys (RETIRED) gentoo-dev 2004-06-17 09:36:54 UTC
I've just tried a with a vanilla 2.6.7 and devnum is there. The funny thing is the script is called 4 times when hotplug is started, twice with the right $DEVICE but before it is created and twice with an empty $DEVICE after the /proc/bus/usb/xxx/yyy entry has been created. The devnum file exists and can be used.

_But_ it will only work if the scanner is on when hotplug is started. If you switch the scanner on later or if you switch it off and then on only when you need it again, the script only gets called twice with the right value in $DEVICE but before it is created under /proc/bus/usb which makes it impossible to chown/chmod it:
+------------+
+In epson1640+
+------------+
ACTION=add
DEVICE=/proc/bus/usb/003/003
DEVPATH=/devices/pci0000:00/0000:00:10.2/usb3/3-1/3-1:1.0
TYPE=usb
/proc/bus/usb/003/:
total 0
-rw-r--r--  1 root root 43 Jun 17 18:20 001
+------------+
+In epson1640+
+------------+
ACTION=add
DEVICE=/proc/bus/usb/003/003
DEVPATH=/devices/pci0000:00/0000:00:10.2/usb3/3-1/3-1:1.0
TYPE=usb
/proc/bus/usb/003/:
total 0
-rw-r--r--  1 root root 43 Jun 17 18:20 001

which brings us to square one, scanning will only work for the root users.
Comment 24 Patrick Kursawe (RETIRED) gentoo-dev 2004-06-17 10:01:58 UTC
Am I the only one who considers this crazy?
Comment 25 Arthur Jackson 2004-06-17 16:08:41 UTC
I am still having the problem:

chown: cannot access `/proc/bus/usb/003/003': No such file or directory 
chmod: cannot access `/proc/bus/usb/003/003': No such file or directory

I am running Love Sources 2.6.7-rc3-love1 (the lastest bar one)

The scanner is always plugged in. 

I have tried a few suggested fixes (re permissions) but can still only access the scanner as root.

Have I missed something or am I hearing that there is no fix for this? I am confused...
Comment 26 Xavier Neys (RETIRED) gentoo-dev 2004-06-18 01:54:11 UTC
Isn't it crazy indeed?

Arthur: can you try the following script and look what params the script gets and what files exist? Rename it if you like. Tracing is appended to /tmp/toto

#!/bin/bash
#
# /etc/hotplug/usb/epson1640
#
                                                                                                                                                                                                
GROUP=users
                                                                                                                                                                                                
#!/bin/sh
echo "+------------+" >> /tmp/toto
echo "+In epson1640+" >> /tmp/toto
echo "+------------+" >> /tmp/toto
echo "ACTION=$ACTION" >> /tmp/toto
echo "DEVICE=$DEVICE" >> /tmp/toto
echo "DEVPATH=$DEVPATH" >> /tmp/toto
echo "TYPE=$TYPE" >> /tmp/toto
                                                                                                                                                                                                
ls -R /proc/bus/usb/ >> /tmp/toto
                                                                                                                                                                                                
if [ -z "$DEVICE" ] ; then
        echo "ls -R /sys/$DEVPATH/" >> /tmp/toto
        ls -lR /sys/$DEVPATH/ >> /tmp/toto
        cat /sys/$DEVPATH/devnum >> /tmp/toto
        IF=$(echo $DEVPATH | sed 's:\(bus/usb/devices/\)\(.*\)-\(.*\):\2:')
        DEV=$(cat /sys/$DEVPATH/devnum)
        DEVICE=$(printf '/proc/bus/usb/%.03d/%.03d' $IF $DEV)
        echo "new DEVICE=$DEVICE" >> /tmp/toto
fi
                                                                                                                                                                                                
if [ "$ACTION" = "add" -a "$TYPE" = "usb" ]; then
  chown root:"$GROUP" "$DEVICE"
  chmod 0660 "$DEVICE"
fi
Comment 27 Greg Kroah-Hartman (RETIRED) gentoo-dev 2004-09-20 15:58:39 UTC
Um, this shouldn't be assigned to me.

It's a sane issue, not a hotplug issue.

Who is the maintainer of the sane package?
Comment 28 Greg Kroah-Hartman (RETIRED) gentoo-dev 2004-11-14 19:04:41 UTC
*** Bug 71180 has been marked as a duplicate of this bug. ***
Comment 29 Greg Kroah-Hartman (RETIRED) gentoo-dev 2004-12-01 13:52:45 UTC
*** Bug 72676 has been marked as a duplicate of this bug. ***
Comment 30 Juan 2005-01-18 11:31:44 UTC
I am another user with the same issue. I have a USB Canon LIDE 30 flatbed that worked perfectly on a previous install but not this time around... even using the same configs from the previous install. My error is below:

root@epitaph usb # /etc/init.d/coldplug restart
 * Coldplugging input devices...                                                  [ ok ]
 * Coldplugging isapnp devices...                                                 [ ok ]
 * Coldplugging pci devices...                                                    [ ok ]
 * Coldplugging pnp devices...                                                    [ ok ]
 * Coldplugging usb devices...
chown: cannot access `/proc/bus/usb/001/003': No such file or directory
chmod: cannot access `/proc/bus/usb/001/003': No such file or directory
chown: cannot access `/proc/bus/usb/001/003': No such file or directory
chmod: cannot access `/proc/bus/usb/001/003': No such file or directory           [ ok ]
Comment 31 Juan 2005-01-18 11:35:15 UTC
I would also like to add that I can get rid of the error if I do the following:

Comment out Line #99 and add the following line below:

DEVICE="/proc/bus/usb/003/$devdev"

My scanner always seems to be on bus 003. So, it just seems coldplug isn't scanning the correct bus. I fail to see how this is a sane bug and not a hotplug/coldplug bug.
Comment 32 Juan 2005-01-18 11:36:13 UTC
My apologies... The file to modify (as described by me in post #31) is:

/etc/hotplug/usb.rc
Comment 33 Kelly Price 2005-01-18 21:47:01 UTC
Let's try to prove that SANE is not the problem, shall we?  I've done some debugging of the coldplug/hotplug scripts in bug 72676, but some folks aren't taking it.

Partial setup, USB stuff:
3 root USB hubs (1,2,3)
1 Sandisk 8-in-1 card reader
1 Sharp Zaurus 5500SL
1 Canon LiDE 30
1 Epson Stylus C82

The reader and the Zaurus are on hub #1, and read off as 1-2 and 1-3 respectively.
The scanner is on hub #2, and reads off as 2-2
The printer is on hub #3, and reads off as 3-2

The Zaurus, intresting enough, I can switch around to 2-3.  Let's make a new file called "usbnet" in /etc/hotplug/usb/ and put in this:

#!/bin/sh
logger -s $ACTION $DEVICE

Save that and chmod it 755 (I'm the only user, anyway).

Now let's reboot and see what it says:

logger: add /proc/bus/usb/001/003

Okay, now I'll switch the Zaurus to the second hub... errrr... nnnnnggghhhh.... damn why did I have to build it that way... Ahhhh.  There.  Switched, the system recognizes it.  Time to reboot.

System says the Zaurus is on 2-3, but usbnet reports:

logger: add /proc/bus/usb/001/003

That's a direct copy, folks!  If it was correct, it'll read /proc/bus/usb/002/003.

Sane is not at fault.  Back to my bug!
Comment 34 Patrick Kursawe (RETIRED) gentoo-dev 2005-01-18 22:55:42 UTC
Greg, would you please comment on comment #33? Looks rather convincing to me.
Comment 35 Adam Jakubek 2005-01-19 12:49:35 UTC
There were/are two similar but distinct bugs in scanner init scripts. The first one (described in the first post here) was caused by an off-by-one error in device enumeration code. This was sane-backends' issue. The second bug, described by Kelly and in #71180, is related to incorrect USB bus detection in coldplug. If scanner is detected as '/proc/bus/usb/XXX/YYY', and the 'XXX' part is wrong, then it's probably #71180.
Comment 36 Juan 2005-03-02 11:27:15 UTC
No fix yet?
Comment 37 Kelly Price 2005-03-02 17:26:20 UTC
Bug 83738 has a fix for hotplug/coldplug that makes things work.
Comment 38 Juan 2005-03-02 20:03:00 UTC
Thanks. Patch pretty much works with one exception. For some reason, when permissions on the scanner is set to 0660, no one in the users group can access it. My fix is setting permissions to 0770.

In the past, it has worked with a 0660 permission. I'm not sure why it doesn't now. I'm 100% sure that my user is in the users group.
Comment 39 Jakub Moc (RETIRED) gentoo-dev 2005-07-07 04:06:03 UTC
*** Bug 98206 has been marked as a duplicate of this bug. ***
Comment 40 Robin Smidsrød 2005-11-04 06:05:17 UTC
I've tried adding the patch from both Bug 83738 (usb.rc diff) and the provided
usbscanner script here, but it still doesn't work.

Running scanimage -L as the normal user shows no scanner after initial boot.

If I unplug and replug the scanner and re-run the command everything is fine.

This is with an Agfa SnapScan e50.

Coldboot is active and put in the boot runlevel. I noticed that the file
/tmp/toto wasn't created at all, which leads me to think that the file never got
executed in the coldboot process.

BTW: I renamed the file to /etc/hotplug/usb/libusbscanner, as this is the file
mentioned in the map file for this specific scanner.
Comment 41 Matteo Azzali (RETIRED) gentoo-dev 2006-05-09 03:47:44 UTC
Created attachment 86468 [details]
udev-usbgentoo.diff

This patch changes udev so usb devices in /dev/bus/usb are owned by root:usb
with permissions "664".
May be hackish, I don't know if it's safe, but it worked fine for me.
A temp fix with same method without involving patch is at: http://forums.gentoo.org/viewtopic-p-3305680.html#3305680
Comment 42 Jakub Moc (RETIRED) gentoo-dev 2006-05-09 11:34:08 UTC
*** Bug 132806 has been marked as a duplicate of this bug. ***
Comment 43 Matteo Azzali (RETIRED) gentoo-dev 2006-06-06 12:15:37 UTC
a better way to handle may be to add in 50-local.rules: 
BUS="usb",  SYSFS{product}=="*Scanner*", GROUP="scanner", MODE="664" 

just after usb_device rule, this may need to be repeated for "*scanner*" 
(without capital s). Changing permissions.d files didn't did nothing.
Comment 44 Matteo Azzali (RETIRED) gentoo-dev 2006-06-06 12:22:16 UTC
Just realized this is working for me but would NOT for CanoScan (see above).
What about using a script fix like the one I posted in 
http://forums.gentoo.org/viewtopic-p-3311185.html#3311185
and adding to udev or sane package? (I can refine it to be more useable and to 
work for more than 1 scanner at time).....
Comment 45 Marcus D. Hanwell (RETIRED) gentoo-dev 2006-06-06 12:37:26 UTC
I have also been hit by this bug, with the hackish solution of modifying the permissions of /dev/bus/usb/001/008 (my scanner). The permissions of /proc/bus/usb/ are set correctly but I cannot access the scanner as my user without modifying the permissions in /dev. Then all works as expected. I have been talking with Matteo on IRC and we have figured this much out although I don't usually mess with /dev and /proc unless I have to :) So I could well be missing something obvious you guys know about.
Comment 46 Matteo Azzali (RETIRED) gentoo-dev 2006-06-07 05:03:46 UTC
Created attachment 88593 [details]
newusbscanner

I tried modifying /etc/hotplug/usb/libusbscanner ,but without any result.
Also what's in /etc/hotplug/usb.agent line 448 (Action unsupported) made
me wonder if this method isn't useable anymore.

However, here's my newusbscanner script, perfected, that could be added
to sane-backends with :
einfo "usb scanners will need to run newusbscanner script as root"
einfo "just first time,to be used by users in scanner group".

The script handles udev rules to hook scanners, works for one or more
scanner/s at time, and if invoked with "newusbscanner auto" will do all 
automatically.
Comment 47 Barry Schwartz 2006-07-15 15:29:14 UTC
Matteo's script did me no good with an old Umax Astra 2200, though explicitly looking for that model of scanner worked:

BUS=="usb", SYSFS{idVendor}=="1606", SYSFS{idProduct}=="0230", GROUP="scanner", MODE="664"

Comment 48 Patrick Kursawe (RETIRED) gentoo-dev 2006-07-31 03:24:35 UTC
Please give sane-backends-1.0.18-r2 a try. I automatically generates udev rules for all supported scanners. 
Comment 49 Patrick Kursawe (RETIRED) gentoo-dev 2006-09-07 00:31:08 UTC
So, if nobody still has a problem with sane-backends-1.0.18-r2, let's close this bug.
Comment 50 Marcus D. Hanwell (RETIRED) gentoo-dev 2006-09-07 02:29:01 UTC
Didn't get chance to comment earlier but it is working great for me now. Why WONTFIX though? It seems fixed to me but may be I missed something. Thanks for sorting this out though as scanning was becomingly increasingly frustrating.
Comment 51 Patrick Kursawe (RETIRED) gentoo-dev 2006-09-07 02:58:58 UTC
WONTFIX or FIXED... I just wanted to state that there will be no change to this version of the package.