Difference between revisions of "Udev"

From Organic Design wiki
(Resources)
(USB)
Line 1: Line 1:
Thanks to HotPlug and /proc it has never been easier for software to determine the state of devices plugged into the system.
+
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]].
 +
 
 +
<code>/etc/hotplug/usb.agent</code> 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 ==
 
== 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:
 
USB devices live at /proc/bus/usb. When a device is plugged this file is updated. Here is an example of the file:
 
<pre>
 
<pre>
Line 28: Line 35:
  
 
== Firewire and others ==
 
== Firewire and others ==
These all work in a similar way. It is a simple matter to parse the /proc files to extract whatever relevant data is needed to feed into the UI.
+
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 ==
== Events ==
+
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.
Hotpug also 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).
+
The sounds used should be customisable and a small, well chosen selection will be provided by default.
  
In the directory /etc/hotplug.d is a buch of directories that represent all the kinds of devices that may be hotplugged.
 
<pre>
 
drwxr-xr-x  2 root root 4096 2004-09-04 06:15 chandev
 
drwxr-xr-x  2 root root 4096 2005-05-11 04:39 default
 
drwxr-xr-x  2 root root 4096 2004-09-04 06:15 dock
 
drwxr-xr-x  2 root root 4096 2004-09-04 06:15 ieee1394
 
drwxr-xr-x  2 root root 4096 2004-09-04 06:15 input
 
drwxr-xr-x  2 root root 4096 2004-09-04 06:15 net
 
drwxr-xr-x  2 root root 4096 2004-09-04 06:15 pci
 
drwxr-xr-x  2 root root 4096 2004-09-04 06:15 scsi
 
drwxr-xr-x  2 root root 4096 2005-05-27 05:59 usb
 
</pre>
 
'''Example:'''
 
I want to run a script when the USB device is plugged in. So I put some kind of executable in the usb directory and suffix it with '''.hotplug'''.
 
 
== Resources ==
 
== Resources ==
  
[http://linux-hotplug.sourceforge.net/ Linux Hotplugging]
+
*[http://linux-hotplug.sourceforge.net/ Linux Hotplug project]
[http://www.bangmoney.org/presentations/hotplug/ Useful tutorial on hotplugging]
+
*[http://opensource.idealcorp.com/hotplug-perl/ Hotplug in Perl]
 +
*[http://lkml.org/lkml/2005/2/10/179 Best of all: Hotplug in C]
 +
*[http://www.buberel.org/linux/usb-automounter.php Scripts to auto-mount usb devices]
 +
*[http://www.bangmoney.org/presentations/hotplug/ Useful tutorial on hotplugging]

Revision as of 00:03, 7 September 2005

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