chiark / gitweb /
collect: fix size_t printf
[elogind.git] / udev.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <article>
6   <section>
7     <title>udev</title>
8     <refentry>
9       <refentryinfo>
10         <title>udev</title>
11         <date>August 2005</date>
12         <productname>udev</productname>
13       </refentryinfo>
14
15       <refmeta>
16         <refentrytitle>udev</refentrytitle>
17         <manvolnum>7</manvolnum>
18         <refmiscinfo class="version"></refmiscinfo>
19       </refmeta>
20
21       <refnamediv>
22         <refname>udev</refname>
23         <refpurpose>dynamic device management</refpurpose>
24       </refnamediv>
25
26       <refsect1><title>DESCRIPTION</title>
27         <para>udev provides a dynamic device directory containing only the files for
28         actually present devices. It creates or removes device node files in the
29         <filename>/dev</filename> directory, or it renames network interfaces.</para>
30
31         <para>Usually udev runs as <citerefentry><refentrytitle>udevd</refentrytitle>
32         <manvolnum>8</manvolnum></citerefentry> and receives uevents directly from the
33         kernel if a device is added or removed from the system.</para>
34
35         <para>If udev receives a device event, it matches its configured rules
36         against the available device attributes provided in sysfs to identify the device.
37         Rules that match may provide additional device information or specify a device
38         node name and multiple symlink names and instruct udev to run additional programs
39         as part of the device event handling.</para>
40       </refsect1>
41
42       <refsect1><title>CONFIGURATION</title>
43         <para>All udev configuration files are placed in <filename>/etc/udev/*</filename>.
44         Every file consists of a set of lines of text. All empty lines or lines beginning
45         with '#' will be ignored.</para>
46
47         <refsect2><title>Configuration file</title>
48           <para>udev expects its main configuration file at <filename>/etc/udev/udev.conf</filename>.
49           It consists of a set of variables allowing the user to override default udev values.
50           The following variables can be set:</para>
51           <variablelist>
52             <varlistentry>
53               <term><option>udev_root</option></term>
54               <listitem>
55                 <para>Specifies where to place the device nodes in the filesystem.
56                 The default value is <filename>/dev</filename>.</para>
57               </listitem>
58             </varlistentry>
59
60             <varlistentry>
61               <term><option>udev_rules</option></term>
62               <listitem>
63                 <para>The name of the udev rules file or directory to look for files
64                 with the suffix <filename>.rules</filename>. Multiple rule files are
65                 read in lexical order. The default value is
66                 <filename>/etc/udev/rules.d</filename>.</para>
67               </listitem>
68             </varlistentry>
69
70             <varlistentry>
71               <term><option>udev_log</option></term>
72               <listitem>
73                 <para>The logging priority. Valid values are the numerical syslog priorities
74                 or their textual representations: <option>err</option>, <option>info</option>
75                 and <option>debug</option>.</para>
76               </listitem>
77             </varlistentry>
78           </variablelist>
79         </refsect2>
80
81         <refsect2><title>Rules files</title>
82           <para>The udev rules are read from the files located in the
83           <filename>/etc/udev/rules.d</filename> directory or at the location specified
84           value in the configuration file. Every line in the rules file contains at least
85           one key value pair. There are two kind of keys, match and assignment keys.
86           If all match keys are matching against its value, the rule gets applied and the
87           assign keys get the specified value assigned.</para>
88
89           <para>A matching rule may specify the name of the device node, add a symlink
90           pointing to the node, or run a specified program as part of the event handling.
91           If no matching rule is found, the default device node name is used.</para>
92
93           <para>A rule may consist of a list of one or more key value pairs separated by
94           a comma. Each key has a distinct operation, depending on the used operator. Valid
95           operators are:</para>
96           <variablelist>
97             <varlistentry>
98               <term><option>==</option></term>
99               <listitem>
100                 <para>Compare for equality.</para>
101               </listitem>
102             </varlistentry>
103
104             <varlistentry>
105               <term><option>!=</option></term>
106               <listitem>
107                 <para>Compare for non-equality.</para>
108               </listitem>
109             </varlistentry>
110
111             <varlistentry>
112               <term><option>=</option></term>
113               <listitem>
114                 <para>Assign a value to a key. Keys that represent a list, are reset
115                 and only this single value is assigned.</para>
116               </listitem>
117             </varlistentry>
118
119             <varlistentry>
120               <term><option>+=</option></term>
121               <listitem>
122                 <para>Add the value to a key that holds a list of entries.</para>
123               </listitem>
124             </varlistentry>
125
126             <varlistentry>
127               <term><option>:=</option></term>
128               <listitem>
129                 <para>Assign  a  value  to  a key finally; disallow any later changes,
130                 which may be used to prevent changes by any later rules.</para>
131               </listitem>
132             </varlistentry>
133           </variablelist>
134
135           <para>The following key names can be used to match against device properties.
136           Some of the keys also match against properties of the parent devices in sysfs,
137           not only the device that has generated the event. If multiple keys that match
138           a parent device are specified in a single rule, all these keys must match at
139           one and the same parent device.</para>
140           <variablelist>
141             <varlistentry>
142               <term><option>ACTION</option></term>
143               <listitem>
144                 <para>Match the name of the event action.</para>
145               </listitem>
146             </varlistentry>
147
148             <varlistentry>
149               <term><option>DEVPATH</option></term>
150               <listitem>
151                 <para>Match the devpath of the event device.</para>
152               </listitem>
153             </varlistentry>
154
155             <varlistentry>
156               <term><option>KERNEL</option></term>
157               <listitem>
158                 <para>Match the name of the event device.</para>
159               </listitem>
160             </varlistentry>
161
162             <varlistentry>
163               <term><option>NAME</option></term>
164               <listitem>
165                 <para>Match the name of the node or network interface. It can
166                 be used once the NAME key has been set in one of the preceding
167                 rules.</para>
168               </listitem>
169             </varlistentry>
170
171             <varlistentry>
172               <term><option>SUBSYSTEM</option></term>
173               <listitem>
174                 <para>Match the subsystem of the event device.</para>
175               </listitem>
176             </varlistentry>
177             <varlistentry>
178               <term><option>DRIVER</option></term>
179               <listitem>
180                 <para>Match the driver name of the event device. Only set for devices
181                 which are bound to a driver at the time the event is generated.</para>
182               </listitem>
183             </varlistentry>
184             <varlistentry>
185               <term><option>ATTR{<replaceable>filename</replaceable>}</option></term>
186               <listitem>
187                 <para>Match sysfs attribute values of the event device. Up to five
188                 <option>ATTR</option> keys can be specified per rule. Trailing
189                 whitespace in the attribute values is ignored, if the specified match
190                 value does not contain trailing whitespace itself. Depending on the type
191                 of operator, this key is also used to set the value of a sysfs attribute.
192                 </para>
193               </listitem>
194             </varlistentry>
195
196             <varlistentry>
197               <term><option>KERNELS</option></term>
198               <listitem>
199                 <para>Search the devpath upwards for a matching device name.</para>
200               </listitem>
201             </varlistentry>
202
203             <varlistentry>
204               <term><option>SUBSYSTEMS</option></term>
205               <listitem>
206                 <para>Search the devpath upwards for a matching device subsystem name.</para>
207               </listitem>
208             </varlistentry>
209
210             <varlistentry>
211               <term><option>DRIVERS</option></term>
212               <listitem>
213                 <para>Search the devpath upwards for a matching device driver name.</para>
214               </listitem>
215             </varlistentry>
216
217             <varlistentry>
218               <term><option>ATTRS{<replaceable>filename</replaceable>}</option></term>
219               <listitem>
220                 <para>Search the devpath upwards for a device with matching sysfs attribute values.
221                 Up to five <option>ATTRS</option> keys can be specified per rule, but all of them
222                 must match on the same device. Trailing whitespace in the attribute values is ignored,
223                 if the specified match value does not contain trailing whitespace itself.</para>
224               </listitem>
225             </varlistentry>
226
227             <varlistentry>
228               <term><option>ENV{<replaceable>key</replaceable>}</option></term>
229               <listitem>
230                 <para>Match against the value of an environment variable. Up to five <option>ENV</option>
231                 keys can be specified per rule. Depending on the type of operator, this key is also used
232                 to export a variable to the environment.</para>
233               </listitem>
234             </varlistentry>
235
236             <varlistentry>
237               <term><option>TEST{<replaceable>octal mode mask</replaceable>}</option></term>
238               <listitem>
239                 <para>Test the existence of a file. An octal mode mask can be specified
240                 if needed.</para>
241               </listitem>
242             </varlistentry>
243
244             <varlistentry>
245               <term><option>PROGRAM</option></term>
246               <listitem>
247                 <para>Execute external program. The key is true, if the program returns
248                 with exit code zero. The whole event environment is available to the
249                 executed program. The program's output printed to stdout, is available in
250                 the RESULT key.</para>
251               </listitem>
252             </varlistentry>
253
254             <varlistentry>
255               <term><option>RESULT</option></term>
256               <listitem>
257                 <para>Match the returned string of the last PROGRAM call. This key can
258                 be used in the same or in any later rule after a PROGRAM call.</para>
259               </listitem>
260             </varlistentry>
261           </variablelist>
262
263           <para>Most of the fields support a shell style pattern matching. The following
264           pattern characters are supported:</para>
265           <variablelist>
266             <varlistentry>
267               <term><option>*</option></term>
268               <listitem>
269                 <para>Matches zero, or any number of characters.</para>
270               </listitem>
271             </varlistentry>
272             <varlistentry>
273               <term><option>?</option></term>
274               <listitem>
275                 <para>Matches any single character.</para>
276               </listitem>
277             </varlistentry>
278             <varlistentry>
279               <term><option>[]</option></term>
280               <listitem>
281                 <para>Matches any single character specified within the brackets. For
282                 example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
283                 Ranges are also supported within this match with the '-' character.
284                 For example, to match on the range of all digits, the pattern [0-9] would
285                 be used. If the first character following the '[' is a '!', any characters
286                 not enclosed are matched.</para>
287               </listitem>
288             </varlistentry>
289           </variablelist>
290
291           <para>The following keys can get values assigned:</para>
292           <variablelist>
293             <varlistentry>
294               <term><option>NAME</option></term>
295               <listitem>
296                 <para>The name of the node to be created, or the name the network interface
297                 should be renamed to. Only one rule can set the node name, all later rules with
298                 a NAME key will be ignored.</para>
299               </listitem>
300             </varlistentry>
301
302             <varlistentry>
303               <term><option>SYMLINK</option></term>
304               <listitem>
305                 <para>The name of a symlink targeting the node. Every matching rule can add
306                 this value to the list of symlinks to be created along with the device  node.
307                 Multiple symlinks may be specified by separating the names by the space
308                 character.</para>
309               </listitem>
310             </varlistentry>
311
312             <varlistentry>
313               <term><option>OWNER, GROUP, MODE</option></term>
314               <listitem>
315                 <para>The permissions for the device node. Every specified value overwrites
316                 the compiled-in default value.</para>
317               </listitem>
318             </varlistentry>
319
320             <varlistentry>
321               <term><option>ATTR{<replaceable>key</replaceable>}</option></term>
322               <listitem>
323                 <para>The value that should be written to a sysfs attribute of the
324                 event device. Depending on the type of operator, this key is also
325                 used to match against the value of a sysfs attribute.</para>
326               </listitem>
327             </varlistentry>
328
329             <varlistentry>
330               <term><option>ENV{<replaceable>key</replaceable>}</option></term>
331               <listitem>
332                 <para>Export a variable to the environment. Depending on the type of operator,
333                 this key is also to match against an environment variable.</para>
334               </listitem>
335             </varlistentry>
336
337             <varlistentry>
338               <term><option>RUN</option></term>
339               <listitem>
340                 <para>Add a program to the list of programs to be executed for a specific
341                 device. This can only be used for very short running tasks. Running an
342                 event process for a long period of time may block all further events for
343                 this or a dependent device. Long running tasks need to be immediately
344                 detached from the event process itself.</para>
345                 <para>If the specifiefd string starts with
346                 <option>socket:<replaceable>path</replaceable></option>, all current event
347                 values will be passed to the specified socket, as a message in the same
348                 format the kernel sends an uevent. If the first character of the specified path
349                 is an @ character, an abstract namespace socket is used, instead of an existing
350                 socket file.</para>
351               </listitem>
352             </varlistentry>
353
354             <varlistentry>
355               <term><option>LABEL</option></term>
356               <listitem>
357                 <para>Named label where a GOTO can jump to.</para>
358               </listitem>
359             </varlistentry>
360
361             <varlistentry>
362               <term><option>GOTO</option></term>
363               <listitem>
364                 <para>Jumps to the next LABEL with a matching name</para>
365               </listitem>
366             </varlistentry>
367
368             <varlistentry>
369               <term><option>IMPORT{<replaceable>type</replaceable>}</option></term>
370               <listitem>
371                 <para>Import a set of variables into the event environment,
372                 depending on <replaceable>type</replaceable>:</para>
373                 <variablelist>
374                   <varlistentry>
375                     <term><option>program</option></term>
376                     <listitem>
377                       <para>Execute an external program specified as the assigned value and
378                       import its output, which must be in environment key format.</para>
379                     </listitem>
380                   </varlistentry>
381                   <varlistentry>
382                     <term><option>file</option></term>
383                     <listitem>
384                       <para>Import a text file specified as the assigned value, which must be in
385                       environment key format.</para>
386                     </listitem>
387                   </varlistentry>
388                   <varlistentry>
389                     <term><option>parent</option></term>
390                     <listitem>
391                       <para>Import the stored keys from the parent device by reading
392                       the database entry of the parent device. The value assigned to
393                       <option>IMPORT{parent}</option> is used as a filter of key names
394                       to import (with the same shell-style pattern matching used for
395                       comparisons).</para>
396                     </listitem>
397                   </varlistentry>
398                 </variablelist>
399                 <para>If no option is given, udev will choose between <option>program</option>
400                 and <option>file</option> based on the executable bit of the file
401                 permissions.</para>
402               </listitem>
403             </varlistentry>
404
405             <varlistentry>
406               <term><option>WAIT_FOR</option></term>
407               <listitem>
408                 <para>Wait for a file to become available.</para>
409               </listitem>
410             </varlistentry>
411
412             <varlistentry>
413               <term><option>OPTIONS</option></term>
414               <listitem>
415                 <para>Rule and device options:</para>
416                 <variablelist>
417                   <varlistentry>
418                     <term><option>last_rule</option></term>
419                     <listitem>
420                       <para>Stops further rules application. No later rules will have
421                       any effect.</para>
422                     </listitem>
423                   </varlistentry>
424                   <varlistentry>
425                     <term><option>ignore_device</option></term>
426                     <listitem>
427                       <para>Ignore this event completely.</para>
428                     </listitem>
429                   </varlistentry>
430                   <varlistentry>
431                     <term><option>ignore_remove</option></term>
432                     <listitem>
433                       <para>Do not remove the device node when the device goes away. This may be
434                       useful as a workaround for broken device drivers.</para>
435                     </listitem>
436                   </varlistentry>
437                   <varlistentry>
438                     <term><option>link_priority=<replaceable>value</replaceable></option></term>
439                     <listitem>
440                       <para>Specify the priority of the created symlinks. Devices with higher
441                       priorities overwrite existing symlinks of other devices.</para>
442                     </listitem>
443                   </varlistentry>
444                   <varlistentry>
445                     <term><option>all_partitions</option></term>
446                     <listitem>
447                       <para>Create the device nodes for all available partitions of a block device.
448                       This may be useful for removable media devices where media changes are not
449                       detected.</para>
450                     </listitem>
451                   </varlistentry>
452                   <varlistentry>
453                     <term><option>event_timeout=</option></term>
454                     <listitem>
455                       <para>Number of seconds an event will wait for operations to finish, before it
456                       will terminate itself.</para>
457                     </listitem>
458                   </varlistentry>
459                   <varlistentry>
460                     <term><option>string_escape=<replaceable>none|replace</replaceable></option></term>
461                     <listitem>
462                       <para>Usually control and other possibly unsafe characters are replaced
463                       in strings used for device naming. The mode of replacement can be specified
464                       with this option.</para>
465                     </listitem>
466                   </varlistentry>
467                 </variablelist>
468               </listitem>
469             </varlistentry>
470           </variablelist>
471
472           <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
473           <option>OWNER</option>, <option>GROUP</option>, <option>MODE</option>  and  <option>RUN</option>
474           fields support simple printf-like string substitutions. The <option>RUN</option>
475           format chars gets applied after all rules have been processed, right before the program
476           is executed. It allows the use of the complete environment set by earlier matching
477           rules. For all other fields, substitutions are applied while the individual rule is
478           being processed. The available substitutions are:</para>
479           <variablelist>
480             <varlistentry>
481               <term><option>$kernel</option>, <option>%k</option></term>
482               <listitem>
483                 <para>The kernel name for this device.</para>
484               </listitem>
485             </varlistentry>
486
487             <varlistentry>
488               <term><option>$number</option>, <option>%n</option></term>
489               <listitem>
490                 <para>The kernel number for this device. For example, 'sda3' has
491                 kernel number of '3'</para>
492               </listitem>
493             </varlistentry>
494
495             <varlistentry>
496               <term><option>$devpath</option>, <option>%p</option></term>
497               <listitem>
498                 <para>The devpath of the device.</para>
499               </listitem>
500             </varlistentry>
501
502             <varlistentry>
503               <term><option>$id</option>, <option>%b</option></term>
504               <listitem>
505                 <para>The name of the device matched while searching the devpath upwards for
506                   <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
507                 </para>
508               </listitem>
509             </varlistentry>
510
511             <varlistentry>
512               <term><option>$driver</option></term>
513               <listitem>
514                 <para>The driver name of the device matched while searching the devpath upwards for
515                   <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
516                 </para>
517               </listitem>
518             </varlistentry>
519
520             <varlistentry>
521               <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
522               <listitem>
523                 <para>The value of a sysfs attribute found at the device, where
524                 all keys of the rule have matched. If the matching device does not have
525                 such an attribute, all devices along the chain of parents are searched
526                 for a matching attribute.
527                 If the attribute is a symlink, the last element of the symlink target is
528                 returned as the value.</para>
529               </listitem>
530             </varlistentry>
531
532             <varlistentry>
533               <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
534               <listitem>
535                 <para>The value of an environment variable.</para>
536               </listitem>
537             </varlistentry>
538
539             <varlistentry>
540               <term><option>$major</option>, <option>%M</option></term>
541               <listitem>
542                 <para>The kernel major number for the device.</para>
543               </listitem>
544             </varlistentry>
545
546             <varlistentry>
547               <term><option>$minor</option>, <option>%m</option></term>
548               <listitem>
549                 <para>The kernel minor number for the device.</para>
550               </listitem>
551             </varlistentry>
552
553             <varlistentry>
554               <term><option>$result</option>, <option>%c</option></term>
555               <listitem>
556                 <para>The string returned by the external program requested with PROGRAM.
557                 A single part of the string, separated by a space character may be selected
558                 by specifying the part number as an attribute: <option>%c{N}</option>.
559                 If the number is followed by the '+' char this part plus all remaining parts
560                 of the result string are substituted: <option>%c{N+}</option></para>
561               </listitem>
562             </varlistentry>
563
564             <varlistentry>
565               <term><option>$parent</option>, <option>%P</option></term>
566               <listitem>
567                 <para>The node name of the parent device.</para>
568               </listitem>
569             </varlistentry>
570
571             <varlistentry>
572               <term><option>$name</option></term>
573               <listitem>
574                 <para>The current name of the device node. If not changed by a rule, it is the
575                 name of the kernel device.</para>
576               </listitem>
577             </varlistentry>
578
579             <varlistentry>
580               <term><option>$links</option></term>
581               <listitem>
582                 <para>The current list of symlinks, separated by a space character. The value is
583                 only set if an earlier rule assigned a value, or during a remove events.</para>
584               </listitem>
585             </varlistentry>
586
587             <varlistentry>
588               <term><option>$root</option>, <option>%r</option></term>
589               <listitem>
590                 <para>The udev_root value.</para>
591               </listitem>
592             </varlistentry>
593
594             <varlistentry>
595               <term><option>$sys</option>, <option>%S</option></term>
596               <listitem>
597                 <para>The sysfs mount point.</para>
598               </listitem>
599             </varlistentry>
600
601             <varlistentry>
602               <term><option>$tempnode</option>, <option>%N</option></term>
603               <listitem>
604                 <para>The name of a created temporary device node to provide access to
605                 the device from a external program before the real node is created.</para>
606               </listitem>
607             </varlistentry>
608
609             <varlistentry>
610               <term><option>%%</option></term>
611               <listitem>
612               <para>The '%' character itself.</para>
613               </listitem>
614             </varlistentry>
615
616             <varlistentry>
617               <term><option>$$</option></term>
618               <listitem>
619               <para>The '$' character itself.</para>
620               </listitem>
621             </varlistentry>
622           </variablelist>
623           <para>The count of characters to be substituted may be limited by specifying
624           the format length value. For example, '%3s{file}' will only
625           insert the first three characters of the sysfs attribute</para>
626         </refsect2>
627       </refsect1>
628
629       <refsect1><title>AUTHOR</title>
630         <para>Written by Greg Kroah-Hartman <email>greg@kroah.com</email> and
631         Kay Sievers <email>kay.sievers@vrfy.org</email>. With much help from
632         Dan Stekloff and many others.</para>
633       </refsect1>
634
635       <refsect1>
636         <title>SEE ALSO</title>
637         <para><citerefentry>
638             <refentrytitle>udevd</refentrytitle><manvolnum>8</manvolnum>
639           </citerefentry>, 
640           <citerefentry>
641             <refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum>
642         </citerefentry></para>
643       </refsect1>
644     </refentry>
645   </section>
646 </article>