| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 | Purpose of rules file:This rules file provides nonvolatile, unique names (in the form of symlinks)for input devices that cooperate.Description of rules:This file starts off with a few rules that make Udev skip the entire file ifthe current uevent is not input related.  If ACTION is not "add", or SUBSYSTEMis not "input", or KERNEL (the device node) matches "input[0-9]*", then Udevwill GOTO the LABEL named "persistent_input_end", which is the last rule inthis file.  (input[0-9]* uevents are skipped because they do not create devicenodes.)This type of "skip this list of rules if X" operation is done in both thepersistent input and persistent storage rules files.  The reason is efficiency-- if Udev had to go run the usb_id and/or path_id programs for non-input andnon-storage rules, those rules would take much longer to process for no goodreason.First in this file is a set of rules for by-ID style symlinks.  These attemptto uniquely identify a device based on its serial number, but there are someissues with this.  Many USB manufacturers do not provide a unique serial numberfor each device -- for instance, my Microsoft Intellimouse Optical has a USBserial number of "Microsoft_Microsoft_IntelliMouse_Optical".  This kind ofnonsensical "serial number" means that if you plug in two Intellimouse Opticaldevices, they will both get the same by-id symlink, and the device that thesymlink points to will be random.  This defeats the purpose of by-ID symlinks.(However, I believe this behavior is technically valid according to the USBstandard.  I believe it is not recommended, though.)Anyway, first in the by-ID rules, we have a rule that runs for any (input)device hanging anywhere off a USB bus.  It uses the IMPORT{program} option torun the "/lib/udev/usb_id -x" program.  usb_id looks at the environment to findout which device to look at, generates a list of environment-variable VAR=valuepairs, and prints them.  Udev stores this output away while the process isrunning.  After the process exits, Udev modifies the current environment toinclude the VARs that usb_id printed.  (It assigns the "value"s that usb_idprinted to each of those VARs.)  Specifically, usb_id prints ID_VENDOR,ID_MODEL, ID_REVISION, ID_SERIAL, ID_TYPE, and ID_BUS (at least in the case ofthe aforementioned USB optical mouse).  These variable names will all be set inthe environment.Then, we have a set of rules to set ID_CLASS for various types of devices.  Therules first check for a "usb"-bus device that has a "bInterfaceClass" of 03 anda "bInterfaceProtocol" of 01.  If the interface class is 03, this is an HIDdevice.  If the protocol is 01, it's a keyboard device.  So we set ID_CLASS to"kbd".  The next rule checks whether the interface protocol is 02, and if so,sets ID_CLASS to "mouse" (HID devices with a protocol of 02 are mice).Any input device that the "pcspkr" driver claims must be a speaker.  Any inputdevice that the "atkbd" driver claims must be a keyboard.  Any input devicethat the "psmouse" driver claims must be a mouse.  If there's a sysfs attributenamed "name", whose contents contain "dvb", "DVB", or " IR ", then we setID_CLASS to "ir".Then, we have a rule to search the tree and find the first parent that has amodalias.  If that modalias matches the big long ugly string in the rules file,we assume this is a joystick device, and set ID_CLASS appropriately.  (Thisparent should be the kobject for the joystick device itself.  The reason wesearch the tree is that the current uevent is for a device node, not thephysical joystick device.)Once the ID_CLASS variable is set properly, we have one more modification toperform: if the ID_SERIAL variable was not set at all by the usb_id program, weset it to "noserial".Now that all the environment variables are set up properly, we start generatingthe by-ID symlinks in /dev/input/by-id/.  If the current device node's namestarts with "event", we add "event" into the symlink name.  Otherwise, we don'tadd anything for mice.  (Other device types don't get a persistent by-IDsymlink.)Next, we create by-path symlinks.  The /lib/udev/path_id program takes the pathof the device as an argument, and prints out "ID_PATH=string", where "string"is the "shortest physical path" to the device.  We import this value into theenvironment.If the path is non-empty, and the device node name starts with "mouse" or"event", we add a by-path symlink based on the path and the device class (andwe also add "event" if it's an event device).  This symlink should be stable aslong as the device never moves to a different port.
 |