udev

UDEV and USB


Newer instructions
for more modern udev implementations are here.
Peter Kropf's
notes below are still a good general explanation of udev.

Peter Kropf has written these instructions on using udev for USB access for non-root users 

Overview
========

There are times when access to the 1-Wire USB controller has to be
modified to allow a user other than root to have write access. This
article presents a simple way to use the Linux udev subsystem to
change the file ownership and permissions on the file associated with
a 1-Wire controller.


Udev Subsystem
--------------

The notes presented here are specific to the Linux udev subsystem and
it must be installed for it to work. Several leading-edge Linux
distributions have udev installed as part of the base system including
FedoraCore 6 and Suse 10.

If it's not installed on your system, see the documentation for that
version Linux for more details on how to install the udev subsystem.


USB Vendor and Product IDs
--------------------------

The USB vendor and product ids can be used by the udev subsystem to
identify which program is to be run when the device is plugged in.

If you don't know the vendor and product ids for the 1-Wire USB
controller you'll be using, you can use the lsusb program to find
them. If lsusb isn't installed (typically in /usr/sbin or /sbin)
you'll need to install the appropiate package for your Linux
distribution.

Once installed, run lsusb with the 1-Wire USB controlled plugged in:

$ /sbin/lsusb
Bus 001 Device 005: ID 04fa:2490 Dallas Semiconductor DS1490F 2-in-1 Fob, 1-Wire adapter
Bus 001 Device 001: ID 0000:0000
$

The 04fa is the vendor id and 2490 is the product id.

Unplug the 1-Wire USB controller.


Customize udev
--------------

With the vendor and product ids in hand, the udev subsystem can be
modified to change the file permissions and file ownership.

Create a new file called /etc/udev/rules.d/46_ds2490.rules. This will
contain the mapping of vendor / product id and the program to run. The
file should contain the following:


BUS=="usb", SYSFS=="04fa", SYSFS=="2490", \
GROUP="users", MODE="0774", \
PROGRAM="/bin/sh -c 'K=%k; K=$$; printf bus/usb/%%03i/%%03i $$ $$'", \
NAME="%c", RUN="/etc/udev/ds2490 '%c'"


Change the 0x04fa to the vendor id and 0x2490 to the product id for
your 1-Wire USB controller.

Create a new shell program called /etc/udev/ds2490. This will be the
program that is run. Here's a simple example of changing the file
group to ow and giving the group read and write access.


#! /bin/sh -x

MATCH="no"
if [ "$1" != "" ]; then
if [ -f /proc/$1 ]; then
chgrp ow /proc/$1 && \
chmod g+rw /proc/$1 && \
logger ow udev: group set to ow and permission g+rw on /proc/$1
MATCH="yes"
fi

if [ -e /dev/$1 ]; then
chgrp ow /dev/$1 && \
chmod g+rw /dev/$1 && \
logger ow udev: group set to ow and permission g+rw on /dev/$1
MATCH="yes"
fi
fi

if [ "$MATCH" = "no" ]; then
echo ow udev: no device file found for "$1"
logger ow udev: no device file found for "$1"
fi


The file has to be made executable via

chmod +x /etc/udev/ds2490

otherwise it will not be excuted by the udev subsystem.

Don't forget to add a group called ow and add users to the group.

Once this is setup, you can plug the 1-Wire USB controller into the
computer. After a bit, you should see a messages in the system log file
that looks like:

Nov 30 14:29:52 localhost logger: ow udev: group set to ow and permission g+rw on /proc/bus/usb/001/006
Nov 30 14:29:52 localhost logger: ow udev: group set to ow and permission g+rw on /dev/bus/usb/001/006

and that can be verified by

$ ls -l /proc/bus/usb/001/006 /dev/bus/usb/001/006
crw-rw---- 1 root ow 189, 12 Nov 30 14:29 /dev/bus/usb/001/006
-rw-rw-r-- 1 root ow 147 Nov 30 14:29 /proc/bus/usb/001/006

 Note that these steps (as well as symbolic links of the programs to /usr/bin) is done automatically by a script:

src/scripts/usb/suse_setup.sh

Which has been tested on Suse 10.1

 


Previous page: OWFS install step
Next page: UDEV and USB