# Scanning works only as root

## petrjanda

Ok, I got my usb scanner to work first time ever in Linux using sane-backends. I also installed xsane frontend, but i can only run it when su'd or logged in as root. How do I fixed that? I looked at man usb-sane, but it was of a little help for me.

Also now I get an error during boot up while theres "usb hotplugging" being done. (i use udev).

```

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

```

Thank you.

----------

## adaptr

What are the permissions along those paths ?

----------

## neysx

 *petrjanda wrote:*   

> Ok, I got my usb scanner to work first time ever in Linux using sane-backends. I also installed xsane frontend, but i can only run it when su'd or logged in as root. How do I fixed that? I looked at man usb-sane, but it was of a little help for me.
> 
> Also now I get an error during boot up while theres "usb hotplugging" being done. (i use udev).
> 
> ```
> ...

 

Maybe this thread can help you.

----------

## petrjanda

 *adaptr wrote:*   

> What are the permissions along those paths ?

 

The thing is, those paths don't even exist

Theres no such thing as /proc/bus/usb/002/004, the highest number is 002/003 which is the scanner.

----------

## neysx

How about the following /etc/hotplug/usb/libusbscanner that comes with the latest sane-backends (1.0.14-r3)

```
#!/bin/sh

# This file is part of sane-backends.

#

# This script changes the permissions and ownership of a USB device under

# /proc/bus/usb to grant access to this device to users in the scanner group.

#

# Ownership is set to root:scanner, permissions are set to 0660.

#

# Arguments :

# -----------

# ACTION=[add|remove]

# DEVICE=/proc/bus/usb/BBB/DDD

# TYPE=usb

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

if [ "$ACTION" = "add" -a "$TYPE" = "usb" ]; then

  chown root:scanner "$DEVICE"

  chmod 0660 "$DEVICE"

fi

# That's an insecure but simple alternative

# Everyone has access to the scanner

# if [ "$ACTION" = "add" -a "$TYPE" = "usb" ]; then

#  chmod 0666 "$DEVICE"

# fi
```

I am not using udev so I can't try with your setup. Sorry.

Hth.

----------

## petrjanda

Ive read the script, its same as the one you posted, but I can see a resolution in it. The question is, why is hotplug trying to access files 002/004 when they dont exist, clearly there is no device on it.  :Confused: 

----------

## neysx

The script above is indeed a verbatim copy of the one included in the latest sane-backends. I did not write it.

Could it be that

```
        DEV=$(expr $DEV + 1) 
```

 should have been

```
        DEV=$(expr $DEV - 1) 
```

 in your case, or in all cases? In your case at least, it looks very much like 004 should become 003, not 005. My guess is this check (-z) has been added for udev systems. All it does is increase the device number when /proc/bus/usb/BBB/DDD does not exist. Decreasing DDD should solve your problem. If it does, could you please file a bug on bugs.gentoo.org to let our devs know about this issue? Thanks.

Hth

----------

## petrjanda

 *neysx wrote:*   

> The script above is indeed a verbatim copy of the one included in the latest sane-backends. I did not write it.
> 
> Could it be that
> 
> ```
> ...

 

Well i temporarily solved it by commenting out everything but

```

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

```

and everything still works.

I'll try to do as you have told me to do now and come and post results.

----------

## petrjanda

Yes, changing the plus sign into minus solved it as well. Thanks a lot!  :Smile: 

Im gonna fill the bug report now.

----------

## neysx

Glad I could help.

Cheers.

----------

## Felix82

I also used the script above, but it still didn't work.

I can only acess the scanner as normal user after reboot. But when i switch it off and on again, it's not acessable.

----------

## neysx

Obviously the script doesn't do its work or can't be called.

Could you post

1) /etc/hotplug/usb.usermap

2) `ls -l /etc/hotplug/usb`

3) the script itself

4) `ls -lR /proc/bus/usb`

switch scanner off, on, wait ca. 30 seconds

5') `ls -lR /proc/bus/usb` again

I'll try to sort it out for you, if I can  :Wink: 

----------

## Felix82

Here are the files you wanted to see:

```

# /etc/hotplug/usb.usermap

# usb module         match_flags idVendor idProduct bcdDevice_lo bcdDevice_hi bDeviceClass bDeviceSubClass bDeviceProtocol bInterfaceClass bInterfaceSubClass bInterfaceProtocol driver_info

scanner 0x0003 0x04b8   0x0802   0x0000   0x0000   0x00   0x00   0x00   0x00   0x00   0x00   0x00000000

```

```

felix@primergy / $ ls -l /etc/hotplug/usb

total 4

-rwxr-xr-x    1 felix    users         913 May 13 17:35 scanner

```

```

felix@primergy / $ cat /etc/hotplug/usb/scanner

#!/bin/sh

# This file is part of sane-backends.

#

# This script changes the permissions and ownership of a USB device under

# /proc/bus/usb to grant access to this device to users in the scanner group.

#

# Ownership is set to root:scanner, permissions are set to 0660.

#

# Arguments :

# -----------

# ACTION=[add|remove]

# DEVICE=/proc/bus/usb/BBB/DDD

# TYPE=usb

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

if [ "$ACTION" = "add" -a "$TYPE" = "usb" ]; then

  chown root:scanner "$DEVICE"

  chmod 0660 "$DEVICE"

fi

# That's an insecure but simple alternative

# Everyone has access to the scanner

# if [ "$ACTION" = "add" -a "$TYPE" = "usb" ]; then

#  chmod 0666 "$DEVICE"

# fi

```

```

felix@primergy / $ ls -lR /proc/bus/usb

/proc/bus/usb:

total 0

dr-xr-xr-x    2 root     root            0 May 13 17:45 001

dr-xr-xr-x    2 root     root            0 May 13 17:45 002

dr-xr-xr-x    2 root     root            0 May 13 17:45 003

-r--r--r--    1 root     root            0 May 13 18:14 devices

/proc/bus/usb/001:

total 0

-rw-r--r--    1 root     root           43 May 13 17:45 001

/proc/bus/usb/002:

total 0

-rw-r--r--    1 root     root           43 May 13 17:45 001

-rw-r--r--    1 root     root           73 May 13 18:14 005

/proc/bus/usb/003:

total 0

-rw-r--r--    1 root     root           43 May 13 17:45 001

-rw-r--r--    1 root     root           43 May 13 17:45 002

```

After about 1 min:

```

felix@primergy / $ ls -lR /proc/bus/usb

/proc/bus/usb:

total 0

dr-xr-xr-x    2 root     root            0 May 13 17:45 001

dr-xr-xr-x    2 root     root            0 May 13 17:45 002

dr-xr-xr-x    2 root     root            0 May 13 17:45 003

-r--r--r--    1 root     root            0 May 13 18:19 devices

/proc/bus/usb/001:

total 0

-rw-r--r--    1 root     root           43 May 13 17:45 001

/proc/bus/usb/002:

total 0

-rw-r--r--    1 root     root           43 May 13 17:45 001

-rw-r--r--    1 root     root           73 May 13 18:19 006

/proc/bus/usb/003:

total 0

-rw-r--r--    1 root     root           43 May 13 17:45 001

-rw-r--r--    1 root     root           43 May 13 17:45 002

```

----------

## neysx

In petrjanda's case it turned out the device number had to be decreased and not increased. It has to do with udev and I have no idea whether it is generic or specific to his setup.

I added some tracing to find out if the script is actually called and what input it receives and what is does.

I just found out that the script does not receive the same input when hotplug is restarted and when the scanner is switched back on.

When I do /etc/init.d/hotplug restart, the script is called three times and does not work. I get 

```
In usbscanner

ACTION=add

DEVICE=/proc/bus/usb/002/002

DEVPATH=/devices/pci0000:00/0000:00:0c.0/usb2/2-1/2-1:1.0

In usbscanner

ACTION=add

DEVICE=/proc/bus/usb/002/003

DEVPATH=/devices/pci0000:00/0000:00:0c.0/usb2/2-1/2-1:1.0

/proc/bus/usb/002:

total 0

-rw-r--r--  1 root root 43 May 13 19:36 001

/proc/bus/usb/002:

total 0

-rw-r--r--  1 root root 43 May 13 19:36 001

In usbscanner

ACTION=add

DEVICE=

DEVPATH=bus/usb/devices/2-1

/proc/bus/usb/002:

total 0

-rw-r--r--  1 root root 43 May 13 19:36 001

-rw-r--r--  1 root root 50 May 13 19:36 003

new DEVICE=/proc/bus/usb/002/002

/proc/bus/usb/002:

total 0

-rw-r--r--  1 root root 43 May 13 19:36 001

-rw-r--r--  1 root root 50 May 13 19:36 003

```

I have no idea what DEVPATH=bus/usb/devices/2-1 means. I guess 2 is the bus and 1 the device. Or is it 1 for first device. I have to do +2 because my scanner starts as /proc/bus/usb/002/003. Or maybe 2-1 is the other way around and should become /proc/bus/usb/{1++}/{2++} ?

But when I switched my scanner on, script is called once and works. I get 

```
In usbscanner

ACTION=add

DEVICE=/proc/bus/usb/002/004

DEVPATH=/devices/pci0000:00/0000:00:0c.0/usb2/2-1/2-1:1.0

/proc/bus/usb/002:

total 0

-rw-r--r--  1 root root 43 May 13 19:36 001

-rw-r--r--  1 root root 50 May 13 19:38 004

/proc/bus/usb/002:

total 0

-rw-r--r--  1 root root  43 May 13 19:36 001

-rw-rw----  1 root users 50 May 13 19:38 004
```

Could you add some tracing in the script to find out what's happening on your system?

Here is my /etc/hotplug/usb/usbscanner

```
#!/bin/bash

#

# /etc/hotplug/usb/usbscanner

#

GROUP=users

#!/bin/sh

echo "In usbscanner" >> /tmp/toto

echo "ACTION=$ACTION" >> /tmp/toto

echo "DEVICE=$DEVICE" >> /tmp/toto

echo "DEVPATH=$DEVPATH" >> /tmp/toto

ls -lR /proc/bus/usb/ >> /tmp/toto

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 + 2)

        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

ls -lR /proc/bus/usb/ >> /tmp/toto

```

Besides, I have noticed that both libusbscanner and my own usbscanner are run. Probably because of the libsane.usermap file. I removed it and libusbscanner to make sure there was no interference.

----------

## douglas_slac

I had some craziness like that when I upgraded to sane-backends 1.0.14, lots of errors in the start of hotplug, and usb hotplugging would just fail.  I had to remove the "scanner" script I had included when I upgraded to the 2.6.5 kernel, it was getting the way of the libusbscanner which came with sane-backends 1.0.14.

But I still could see the scanner, and my usb card reader wouldn't work either.  It turns out the libusbscanner script was setting up the card reader as scanner, because of the line:

```

       DEV=$(expr $DEV + 1) 

```

I commented this line out of the script, and now the scanner and the card reader work again.  It is good that sane-backends took care the usb usermap and the libusbscanner script, but why is there this $DEV + 1 part of the script?  And why  do some people need to to be +1, some -1 and some +2?

Getting this scanner to work with kernel 2.6.5 has been a surreal experience.

----------

## Ateo

I had an interesting time getting xsane to open and access my scanner (canon lide 50) as a user (I was alway able to access the scanner as root). As everything in this thread, and numerous others, failed me, I tried something I didn't recall noticing. I created a group called scanner and added myself to it. After doing so, I installed 

```
emerge libusb hotplug xsane sane-frontends sane-backends
```

.....After installing I started hotplug, exited my su environment, opened xsane and it gave me the choice of device (I also have a 3com usb webcam).

Since I had modified files and wanted a fresh start, before installing the above packages, I made sure they were all uninstalled and I removed 2 directories. In addition, I stopped hotplug and deleted it from startup. I probably over did it, but whatever.

```
/etc/init.d/hotplug stop

rc-update del hotplug

emerge -C libusb hotplug xsane sane-frontends sane-backends

rm -fr /etc/hotplug/ /etc/sane.d/
```

I laughed at myself at how simple it was in the end. Granted this might not be everyone's solution, but it IS practical. xsane wants to access the scanner using group root or scanner scanner by default.

----------

## phosphan

If you have this trouble with the device number and want to help, please check https://bugs.gentoo.org/show_bug.cgi?id=50934

----------

## 2sheds

 *phosphan wrote:*   

> If you have this trouble with the device number and want to help, please check https://bugs.gentoo.org/show_bug.cgi?id=50934

 

i have this problem, i gather the bug still hasnt got a fix? iwas going to add my 

name to the bug but couldnt work out how.

```
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
```

----------

## phosphan

- go to https://bugs.gentoo.org/

- Open a new Bugzilla account

- Log in using this account

- go to the bug

- type your email address in the "Add CC" input field

- press the "commit" button

----------

## 2sheds

thanks phospan - i'll do that right now

----------

## Schnacki

One moment... this line just about made me drop out of my chair:

 *Ateo wrote:*   

> I had an interesting time getting xsane to open and access my scanner (canon lide 50) as a user

 

Are you really impying here, that you have the "Canon LiDE 50" working with sane? If so, what did you do? I'm just now doing research on wich scanner to buy. And apart from the fact that (until just now) everybody says that this scanner just "won't work", it has exactly the features, I want to have. So, could you clarify that for me, please?  :Smile: 

Ciao, Jan

----------

## Joseph_sys

I have the same problem every time I reboot I get this error:

 *Quote:*   

> * Starting usb hotplugging...
> 
> chown: cannot access `/proc/bus/usb/001/005': No such file or directory
> 
> chmod: cannot access `/proc/bus/usb/001/005': No such file or directory

 

Though only when the scanner is plugged IN; if I unplug the scanner and restart hotplug then plug the scanner again there is no error when I restart hotplug. 

Changing DEV=$(expr $DEV + 1) from +1 to -1 or +2 does not help

----------

## Vermyndax

FYI, I had to change the line:

DEV=$(expr $DEV + 1) 

... to:

DEV=$(expr $DEV)

...otherwise the script would execute on the wrong device!

----------

## kamagurka

For me (as a udev user) it was pretty simple. I looked at my scanner with udevinfo

```
udevinfo -q all -n /dev/bus/usb/001/008
```

and used the P: output for a walk along the device chain

```
udevinfo -a -p /class/usb_device/usbdev1.8
```

In that output I looked for my scanner and made a rule to have my scanner always owned by group scanner:

```
vim /etc/udev/rules.d/10-local.rules

SYSFS{manufacturer}=="EPSON", SYSFS{idProduct}=="0110", SYSFS{idVendor}=="04b8", SYSFS{product}=="EPSON Scanner", GROUP="scanner"
```

Booya.

----------

## pjp

Moved from Other Things Gentoo

----------

## Matteo Azzali

TEMPORARY FIX:

https://forums.gentoo.org/viewtopic-p-3305680.html#3305680

----------

