-The ID and PLACE keys do have their uses, but they are not commonly used in rules. This document focuses on using BUS and KERNEL keys, as well as SYSFS{...} keys (detailed in the next section). I will show how to use these keys by example.<br /><br />
-
-<font size="2">For extra flexibility, udev also provides keys to call external scripts and examine their result. This is out of scope of this document. Look at the udev man page for more details.</font>
-
-<a name="identify-sysfs"></a>
-<h2>Identifying devices through SYSFS files</h2>
-
-<font size="2">Background information: SYSFS stores many small files under a tree of directories which provide information about your hardware. One file typically contains just one "data item" - e.g. device name, manufacturer, or product ID.<br /><br />
-Note that SYSFS{...} keys can be combined with the basic keys described in the previous section.</font><br /><br />
-
-You can use keys in the format SYSFS{<i>filename</i>} to match specific info from SYSFS, where <i>filename</i> corresponds to a file in your SYSFS tree. For example, when my camera is connected, there is a file located at <i>/sys/block/sda/device/model</i> which contains "USB 2.0M DSC". To match this, I could use the following key: SYSFS{model} = "USB 2.0M DSC"<br /><br />
-
-<b>Note that <u>any</u> file in sysfs can be matched in this manner, but if you match more than one file (through multiple keys), then you must only match files that exist in the same directory.</b> Typically, there will be several directories giving information about one device. You cannot mix and match (as shown by example below).<br /><br />
-
-Luckily, the process of rule writing does not entail hunting through millions of files in SYSFS, the <i>udevinfo</i> utility does the hard work. This program is included in the udev distribution.</b><br /><br />
-
-The first thing you need to do is find a directory somewhere in /sys that corresponds to your hardware, and includes a file named "<i>dev</i>", as udevinfo can only work on directories of this type. These directories are all found under either <i>/sys/block</i> or <i>/sys/class</i> - there is no point looking anywhere else! However, udevinfo will follow links through this directory and read info found from other sections of sysfs.<br /><br />
-
-Once you have found a directory of this type, you can use the following command to assist you in the creation of writing keys for udev rules:
-<blockquote><pre># udevinfo -a -p /sys/path/to/hardware/info</pre></blockquote>
-
-Some snipped output of the results of my "udevinfo -a -p /sys/block/sda" command is shown below, with colour added.<br />
-
-<pre><font color="#003300">
-follow the class device's "device"
- looking at the device chain at '/sys/devices/pci0000:00/0000:00:02.1/usb3/3-3/3-3:1.0/host0/0:0:0:0':
- BUS="scsi"
- ID="0:0:0:0"
- SYSFS{detach_state}="0"
- SYSFS{type}="0"
- SYSFS{max_sectors}="240"
- SYSFS{device_blocked}="0"
- SYSFS{queue_depth}="1"
- SYSFS{scsi_level}="3"
- SYSFS{vendor}=" "
- SYSFS{model}="USB 2.0M DSC "
- SYSFS{rev}="1.00"
- SYSFS{online}="1"</font>
-<font color="#0000FF">
- looking at the device chain at '/sys/devices/pci0000:00/0000:00:02.1/usb3/3-3':
- BUS="usb"
- ID="3-3"
- SYSFS{detach_state}="0"
- SYSFS{bNumInterfaces}=" 1"
- SYSFS{bConfigurationValue}="1"
- SYSFS{bmAttributes}="c0"
- SYSFS{bMaxPower}=" 0mA"
- SYSFS{idVendor}="052b"
- SYSFS{idProduct}="1514"
- SYSFS{bcdDevice}="0100"
- SYSFS{bDeviceClass}="00"
- SYSFS{bDeviceSubClass}="00"
- SYSFS{bDeviceProtocol}="00"
- SYSFS{bNumConfigurations}="1"
- SYSFS{speed}="12"
- SYSFS{manufacturer}="Tekom Technologies, Inc"
- SYSFS{product}="USB 2.0M DSC"</font>
-</pre>
-
-The <i>udevinfo</i> tool provides a lot of information which you can simply copy-paste as udev rules. The reason that I have colour coded the above output is to point out that <b>you generally cannot mix and match information from different parts of the udevinfo output</b>. In the above output, I could not combine information from the different coloured sections - this is because each section of output refers to a different directory in SYSFS. For example, the following rule would not work:
-<blockquote><pre><font color="#003300">BUS="scsi"</font>, <font color="#0000FF">SYSFS{manufacturer}="Tekom Technologies, Inc"</font>, NAME="%k"</pre></blockquote>
-This rule would not work because I am combining information found in the section beginning with BUS="scsi" (green) with information only found in the blue section. The rule would work if I used BUS="usb", sticking only to information found in the blue section above.<br /><br />
-
-You will notice that a lot of information is not relevant for writing basic rules (there is so much of it!), you should generally be looking for information that you recognise and know will not change (e.g. model name).<br /><br />
-
-<b>Note that if you write your own rule to identify a device, the default devfs-style rules will not take effect!</b> It is usually sensible to use NAME="%k" and specify your own extra names in the SYMLINK parameter so that you do not lose the default sensible names.<br /><br />
-
-I will show three examples of this <i>rule writing based on udevinfo output</i> process below. I will then attempt to list some device-dependant tips and tricks for locating the correct info.<br /><br />
-
-<font size=2>A reader wrote to me and informed me that he found KDE's control centre useful for writing rules. Apparently, information about USB devices (and others) can be found in the "Info Centre" section of the KDE Control Centre. This interface shows information such as serial number, vendor ID, etc. If you prefer a GUI-like approach, you might want to investigate this.</font>