1 | Purpose of rules file:
|
---|
2 |
|
---|
3 | This is the core rules file for Udev on LFS. If these rules were not included,
|
---|
4 | most devices would either only work for root, or would not work at all.
|
---|
5 |
|
---|
6 |
|
---|
7 | Description of rules:
|
---|
8 |
|
---|
9 | By default, Udev creates device nodes with UID 0, GID 0, and permissions 0660,
|
---|
10 | and in one flat directory structure with all nodes in /dev. This does not
|
---|
11 | always work well.
|
---|
12 |
|
---|
13 | KERNEL=="ptmx"
|
---|
14 |
|
---|
15 | Any uevent generated by the kernel with a name matching "ptmx" will match this
|
---|
16 | rule. Note that the matching done by Udev is shell-style; these are not regex
|
---|
17 | matches. For the ptmx device, we first change the permisions, by assigning to
|
---|
18 | the MODE value:
|
---|
19 |
|
---|
20 | KERNEL=="ptmx", MODE="0666"
|
---|
21 |
|
---|
22 | We also assign a different GID to /dev/ptmx (also all other TTY devices), by
|
---|
23 | assigning to the GROUP value:
|
---|
24 |
|
---|
25 | KERNEL=="ptmx", MODE="0666", "GROUP="tty"
|
---|
26 |
|
---|
27 |
|
---|
28 | There are also devices that should not be in /dev, because historically they
|
---|
29 | have been created in subdirectories instead. For instance, all Alsa devices
|
---|
30 | have traditionally been put into the /dev/snd subdirectory:
|
---|
31 |
|
---|
32 | KERNEL=="controlC[0-9]*", <...>, NAME="snd/%k"
|
---|
33 |
|
---|
34 | "%k" expands into "the original value of KERNEL" (note: not the pattern that was
|
---|
35 | matched against). This type of rule puts any matching device into the snd/
|
---|
36 | subdirectory.
|
---|
37 |
|
---|
38 | Sometimes we need to move devices based on more than just their name. For
|
---|
39 | example, USB printer devices need to be moved to /dev/usb/lpX, but we can't
|
---|
40 | match only "lp[0-9]*", because that would also match parallel port printers.
|
---|
41 | So we match both KERNEL and SUBSYSTEMS in this case, to move USB printers only.
|
---|
42 |
|
---|
43 |
|
---|
44 | Some devices also commonly have symlinks pointing to them -- for example,
|
---|
45 | /dev/mouse is usually a symlink to /dev/input/mice. We acheive this by
|
---|
46 | assigning to the SYMLINK value. But note that SYMLINK can store multiple values
|
---|
47 | (because each device node could have multiple symlinks pointing to it), so we
|
---|
48 | need to add to the list of symlinks, not overwrite the whole list:
|
---|
49 |
|
---|
50 | KERNEL=="mice", <...>, SYMLINK+="mouse"
|
---|
51 |
|
---|
52 | If we needed to add multiple symlinks, they would be space-separated inside the
|
---|
53 | double quotes.
|
---|
54 |
|
---|
55 | Of course, symlinks, permissions, and device names can all be combined in a
|
---|
56 | rule if needed. But note that if you combine permissions and symlinks, or if
|
---|
57 | you combine GROUP and symlinks, the permissions of the symlink will not be
|
---|
58 | modified, only those of the target device. (This is because the kernel does
|
---|
59 | not pay any attention to the permissions on symlinks, only the permissions on
|
---|
60 | their targets, and there's no reason to change something that won't be used.)
|
---|
61 |
|
---|
62 |
|
---|
63 | Finally, we have this rule:
|
---|
64 |
|
---|
65 | SUBSYSTEM=="usb_device", PROGRAM="/bin/sh -c 'X=%k; X=$${X#usbdev}; B=$${X%%%%.*} D=$${X#*.}; echo bus/usb/$$B/$$D'", NAME="%c"
|
---|
66 |
|
---|
67 | This rule matches any device under the SUBSYSTEM of usb_device. (All devices
|
---|
68 | that were traditionally created under /proc/bus/usb/ use this subsystem.) We
|
---|
69 | tell Udev to run the specified PROGRAM; Udev will save the output of this
|
---|
70 | program (it will be available under %c later).
|
---|
71 |
|
---|
72 | The program itself is a shell that starts by setting the variable X to the
|
---|
73 | original kernel name (which is "usbdevB.D" for these devices, where B and D are
|
---|
74 | the bus and device numbers of the USB device). Then, the rule re-sets X to the
|
---|
75 | value of X with the string "usbdev" removed from the start. So now, X has the
|
---|
76 | value "B.D". Then, the rule sets B to the value of X after a period, and all
|
---|
77 | characters following it, have been removed from the end; this sets B to just
|
---|
78 | the string "B" (just the bus number of the USB device). Then, the rule sets D
|
---|
79 | to the value of X after a period, and all characters before it, have been
|
---|
80 | removed from the beginning; this sets D to just the string "D" (just the device
|
---|
81 | number).
|
---|
82 |
|
---|
83 | Then, the rule echoes "bus/usb/$B/$D" (bus/usb/bus-number/device-number), so
|
---|
84 | Udev will capture that value. The rule sets NAME="%c" to put the device node
|
---|
85 | at /dev/bus/usb/bus-number/device-number. (This is the same layout that the
|
---|
86 | /proc/bus/usb/ devices used.)
|
---|
87 |
|
---|
88 | Most of the doubled characters in this rule are doubled so that Udev does not
|
---|
89 | interpret them. The rule looks all the more confusing because of this method
|
---|
90 | of escaping special characters.
|
---|
91 |
|
---|
92 |
|
---|
93 | A final word of caution: Any particular rule must be written on one line, and a
|
---|
94 | comma must separate each part of the rule.
|
---|