Udev

From Organic Design wiki
Revision as of 00:03, 7 September 2005 by Rob (talk | contribs) (USB)

Hot plug is a complex collection of scripts to deal with hotplugging (and coldplugging) devices such as USB key drives, usb cameras and firewire drives. The standard debian hotplug package consists of a number of shell scripts.

Events

Hotplug includes a very useful feature that allows you to bind a program to a specific hotplug event. This means the OS can be notified when something happens (eg you plug in your USB memory stick). In our application this could simply be a perl script that sends a message through a loopback socket to peer.pl.

/etc/hotplug/usb.agent is a shell script that is executed when you plug or unplug a USB device. The Hotplug manager passes a number of enviroment variables to the script. The hotplug package supplies a script by default that loads kernel modules dynamically if they are needed to interface with the device.

USB

This document may be useful Mounting and unmounting removable devices in linux

USB devices live at /proc/bus/usb. When a device is plugged this file is updated. Here is an example of the file:

T:  Bus=01 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.8-2-386 uhci_hcd
S:  Product=Intel Corp. 82801AA USB
S:  SerialNumber=0000:00:1f.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=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  6 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=0d7d ProdID=1300 Rev= 0.50
S:  Product=USB2.0 FlashDisk
S:  SerialNumber=1D4402000054
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=200mA
I:  If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
E:  Ad=81(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms

This computer has only one external USB device plugged in (USB2.0 FlashDisk). The other entry is the host controler (Intel Corp. 82801AA USB).

Firewire and others

These should work in a similar way. The default scripts should detect and initialise the device, it is up to the user to mount the device on the file system. This is fine because it gives us control over how it is mounted and the path used.

Hotplugging and the Graphical User Interface

It is important to provide feedback to the user when they plug or unplug a device. It is suggested that both visual and audible feedback be provided where possible. The latency for plugging is about 1 second. For unplugging the response is almost immediate. The use of perl rather than shell scripts for the hotplug mechanisim would improve the performance further. The sounds used should be customisable and a small, well chosen selection will be provided by default.

Resources