| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | Purpose of rules file:This is the core rules file for Udev on LFS.  If these rules were not included,most devices would either only work for root, or would not work at all.Description of rules:By default, Udev creates device nodes with UID 0, GID 0, and permissions 0660,and in one flat directory structure with all nodes in /dev.  This does notalways work well.KERNEL=="ptmx"Any uevent generated by the kernel with a name matching "ptmx" will match thisrule.  Note that the matching done by Udev is shell-style; these are not regexmatches.  For the ptmx device, we first change the permisions, by assigning tothe MODE value:KERNEL=="ptmx", MODE="0666"We also assign a different GID to /dev/ptmx (also all other TTY devices), byassigning to the GROUP value:KERNEL=="ptmx", MODE="0666", "GROUP="tty"There are also devices that should not be in /dev, because historically theyhave been created in subdirectories instead.  For instance, all Alsa deviceshave traditionally been put into the /dev/snd subdirectory:KERNEL=="controlC[0-9]*", <...>, NAME="snd/%k""%k" expands into "the original value of KERNEL" (note: not the pattern that wasmatched against).  This type of rule puts any matching device into the snd/subdirectory.Sometimes we need to move devices based on more than just their name.  Forexample, USB printer devices need to be moved to /dev/usb/lpX, but we can'tmatch only "lp[0-9]*", because that would also match parallel port printers.So we match both KERNEL and SUBSYSTEMS in this case, to move USB printers only.Some devices also commonly have symlinks pointing to them -- for example,/dev/mouse is usually a symlink to /dev/input/mice.  We acheive this byassigning to the SYMLINK value.  But note that SYMLINK can store multiple values(because each device node could have multiple symlinks pointing to it), so weneed to add to the list of symlinks, not overwrite the whole list:KERNEL=="mice", <...>, SYMLINK+="mouse"If we needed to add multiple symlinks, they would be space-separated inside thedouble quotes.Of course, symlinks, permissions, and device names can all be combined in arule if needed.  But note that if you combine permissions and symlinks, or ifyou combine GROUP and symlinks, the permissions of the symlink will not bemodified, only those of the target device.  (This is because the kernel doesnot pay any attention to the permissions on symlinks, only the permissions ontheir targets, and there's no reason to change something that won't be used.)Finally, we have this rule:SUBSYSTEM=="usb_device", PROGRAM="/bin/sh -c 'X=%k; X=$${X#usbdev}; B=$${X%%%%.*} D=$${X#*.}; echo bus/usb/$$B/$$D'", NAME="%c"This rule matches any device under the SUBSYSTEM of usb_device.  (All devicesthat were traditionally created under /proc/bus/usb/ use this subsystem.)  Wetell Udev to run the specified PROGRAM; Udev will save the output of thisprogram (it will be available under %c later).The program itself is a shell that starts by setting the variable X to theoriginal kernel name (which is "usbdevB.D" for these devices, where B and D arethe bus and device numbers of the USB device).  Then, the rule re-sets X to thevalue of X with the string "usbdev" removed from the start.  So now, X has thevalue "B.D".  Then, the rule sets B to the value of X after a period, and allcharacters following it, have been removed from the end; this sets B to justthe string "B" (just the bus number of the USB device).  Then, the rule sets Dto the value of X after a period, and all characters before it, have beenremoved from the beginning; this sets D to just the string "D" (just the devicenumber).Then, the rule echoes "bus/usb/$B/$D" (bus/usb/bus-number/device-number), soUdev will capture that value.  The rule sets NAME="%c" to put the device nodeat /dev/bus/usb/bus-number/device-number.  (This is the same layout that the/proc/bus/usb/ devices used.)Most of the doubled characters in this rule are doubled so that Udev does notinterpret them.  The rule looks all the more confusing because of this methodof escaping special characters.A final word of caution: Any particular rule must be written on one line, and acomma must separate each part of the rule.
 |