/[gentoo]/xml/htdocs/doc/en/devfs-guide.xml
Gentoo

Contents of /xml/htdocs/doc/en/devfs-guide.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download) (as text)
Wed Nov 19 05:40:27 2003 UTC (10 years, 9 months ago) by swift
Branch: MAIN
Changes since 1.3: +21 -22 lines
File MIME type: application/xml
Coding style

1 swift 1.1 <?xml version='1.0' encoding="UTF-8"?>
2 swift 1.4 <!-- $Header: /home/cvsroot/gentoo/xml/htdocs/doc/en/devfs-guide.xml,v 1.3 2003/11/15 00:35:18 neysx Exp $ -->
3 swift 1.1
4     <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
5    
6     <guide link="/doc/en/devfs-guide.xml">
7     <title>Device File System Guide</title>
8     <author title="Author">
9 swift 1.4 <mail link="swift@gentoo.org">Sven Vermeulen</mail>
10 swift 1.1 </author>
11     <author title="Reviewer">
12 swift 1.4 <mail link="seemant@gentoo.org">Seemant Kulleen</mail>
13 swift 1.1 </author>
14    
15     <abstract>
16     In this document you'll find information on what devfs is really about
17     and how to work with it.
18     </abstract>
19 swift 1.4
20 swift 1.1 <version>0.1</version>
21 swift 1.2 <date>September 11, 2003</date>
22 swift 1.4
23 swift 1.1 <license/>
24 swift 1.4
25 swift 1.1 <chapter>
26     <title>What is devfs?</title>
27     <section>
28     <title>The (good?) old days</title>
29     <body>
30    
31     <p>
32     Traditional Linux implementations provide their users with an
33     abstract device path, called <path>/dev</path>. Inside this path the
34     user finds <e>device nodes</e>, special files that represent devices
35     inside their system. For instance, <path>/dev/hda</path> represents the
36     first IDE device in their system. By providing device files to the
37     users, they can create programs that interact with hardware as if the
38     hardware was a regular file instead of using special APIs.
39     </p>
40    
41     <p>
42     The device files are split in two groups, called <e>character</e>
43     devices and <e>block</e> devices. The first group consists of hardware
44     of which read/writes are not buffered. The second group naturally
45     consists of hardware of which read/writes are buffered. Both devices can
46     be read one character at a time, or in blocks. Therefore, the naming
47     might sound confusing and in fact is wrong.
48     </p>
49    
50     <p>
51     If you take a look at a certain device file, you might find something
52     like this:
53     </p>
54    
55     <pre caption = "Checking the information of a device file">
56     # <i>ls -l /dev/hda</i>
57     brw-rw---- 1 root disk 3, 0 Jul 5 2000 /dev/hda
58     </pre>
59    
60     <p>
61     In the previous example we see that <path>/dev/hda</path> is a block
62     device. However, more importantly, it has two special numbers assigned
63     to it: <path>3, 0</path>. This pair is called the <e>major-minor</e>
64     pair. It is used by the kernel to map a device file to a real device.
65     The major corresponds with a certain device, the minor with a subdevice.
66     Seems confusing? It isn't.
67     </p>
68    
69     <p>
70     Two examples are <path>/dev/hda4</path> and <path>/dev/tty5</path>. The
71     first device file corresponds with the fourth partition on the first IDE
72     device. Its major-minor pair is <path>3, 4</path>. In other words, the
73     minor corresponds with the partition where the major corresponds with
74     the device. The second example has <path>4, 5</path> as major-minor
75     pair. In this case, the major corresponds with the terminal driver,
76     while the minor corresponds with the terminal number (in this case, the
77     fifth terminal).
78     </p>
79    
80     </body>
81     </section>
82     <section>
83     <title>The problems</title>
84     <body>
85    
86     <p>
87     If you do a quick check in such a <path>/dev</path>, you'll find out
88     that not only all your devices are listed, but <e>all</e> possible
89     devices that you can imagine. In other words, you have device files for
90     devices you don't have. Managing such a device group is cumbersome to
91     say the least. Imagine having to change the permissions of all device
92     files that have a corresponding device in your system, and leaving the
93     rest of the device files as they are.
94     </p>
95    
96     <p>
97     When you add new hardware to your system, and this hardware didn't have
98     a device file previously, you would have to create one. Advanced users know
99     that this task can be accomplished with <c>./MAKEDEV</c> inside the
100     <path>/dev</path> tree, but do you immediately know what device you have
101     to create?
102     </p>
103    
104     <p>
105     When you have programs interacting with hardware using the device files,
106     you can't have the root partition mounted read only, while there is no
107     further need to have it mounted read-write. And you can't have
108     <path>/dev</path> on a seperate partition, since <c>mount</c> needs
109     <path>/dev</path> to mount partitions.
110     </p>
111    
112     </body>
113     </section>
114     <section>
115     <title>The solutions</title>
116     <body>
117    
118     <p>
119     As you can imagine, the kernel hackers have found quite a number of
120     solutions to the aforementioned problems. However, many of them had
121     other flaws as described in
122     <uri>http://www.atnf.csiro.au/people/rgooch/linux/docs/devfs.html#faq-why</uri>.
123     We are not going to talk about these implementations, but focus on the
124     one implementation that did make it to the official kernel sources:
125     devfs.
126     </p>
127    
128     </body>
129     </section>
130     <section>
131     <title>devfs as all-round winner</title>
132     <body>
133    
134     <p>
135     devfs tackles all listed problems. It only provides the user with
136     existing devices, adds new nodes when new devices are found, and makes
137     it possible to mount the root filesystem read only. And it tackles more
138     problems we haven't discussed previously because they are less
139     interesting for users...
140     </p>
141    
142     <p>
143     For instance, with devfs, you don't have to worry about major/minor
144     pairs. It is still supported (for backwards compatibility), but isn't
145     needed. This makes it possible for Linux to support even more devices,
146     since there are no limits anymore (numbers always have boundaries :)
147     </p>
148    
149     </body>
150     </section>
151 swift 1.4 </chapter>
152 swift 1.1
153     <chapter>
154     <title>Navigating through the device tree</title>
155     <section>
156     <title>Directories</title>
157     <body>
158    
159     <p>
160     One of the first things you might notice is that devfs uses directories
161     to group devices together. This improves readability, as now all related
162     devices are inside a common directory.
163     </p>
164    
165     <p>
166     For instance, all IDE-related devices are inside the
167     <path>/dev/ide/</path> device directory, and SCSI-related devices are inside
168     <path>/dev/scsi/</path>. SCSI and IDE disks are seen in the same way,
169     meaning they both have the same subdirectory structure.
170     </p>
171    
172     <p>
173     IDE and SCSI disks are controlled by an adapter (on-board or a seperate
174     card), called the <e>host</e>. Every adapter can have several channels.
175     A channel is called a <e>bus</e>. On each channel, you can have several
176     IDs. Such an ID identifies a disk. This ID is called the <e>target</e>.
177     Some SCSI devices can have multiple luns (<e>Logical Unit Numbers</e>),
178     for instance devices that handle multiple media simultaneously (hi-end
179     tapedrives). You mostly have only a single lun, <path>lun0/</path>.
180     </p>
181    
182     <p>
183     So, whereas <path>/dev/hda4</path> was used previously, we now have
184     <path>/dev/ide/host0/bus0/target0/lun0/part4</path>. This is far more
185     easy... no, don't argue with me... it <e>is</e> easier... ah whatever!
186     :)
187     </p>
188    
189     <note>
190     You can also use more Unix-like device file naming for hard disks, such as
191     <path>c0b0t0u0p2</path>. They can be found in <path>/dev/ide/hd</path>,
192     <path>/dev/scsi/hd</path> etc.
193     </note>
194    
195     <p>
196     To give you an idea on the directories, this is a listing of the
197     directories which I have on my laptop:
198     </p>
199    
200     <pre caption = "Directories in /dev">
201     cdroms/ cpu/ discs/ floppy/
202     ide/ input/ loop/ misc/
203     netlink/ printers/ pts/ pty/
204     scsi/ sg/ shm/ sound/
205     sr/ usb/ vc/ vcc/
206     </pre>
207    
208     </body>
209     </section>
210     <section>
211     <title>Backwards compatibility using devfsd</title>
212     <body>
213    
214     <p>
215     Using this new scheme sounds fun, but several tools and programs make
216     use of the previous, old scheme. To make sure no system is broken,
217     <c>devfsd</c> is created. This daemon creates symlinks with the old
218     names, pointing to the new device files.
219     </p>
220    
221     <pre caption = "Created symlinks">
222     $ <i>ls -l /dev/hda4</i>
223     lr-xr-xr-x 1 root root 33 Aug 25 12:08 /dev/hda4 -> ide/host0/bus0/target0/lun0/part4
224     </pre>
225    
226     <p>
227     With <c>devfsd</c>, you can also set the permissions, create new device
228     files, define actions etc. All this is described in the next chapter.
229     </p>
230    
231     </body>
232     </section>
233     </chapter>
234 swift 1.4
235 swift 1.1 <chapter>
236     <title>Administrating the device tree</title>
237     <section>
238     <title>Restarting devfsd</title>
239     <body>
240    
241     <p>
242     When you alter the <path>/etc/devfsd.conf</path> file, and you want the
243     changes to be forced onto the system, you don't have to reboot.
244     Depending on what you want, you can use any of the two following
245     signals:
246     </p>
247    
248     <p>
249     <b>SIGHUP</b> will have <c>devfsd</c> reread the configuration file,
250     reload the shared objects and generate the REGISTER events for each leaf
251     node in the device tree.
252     </p>
253    
254     <p>
255     <b>SIGUSR1</b> will do the same, but won't generate REGISTER events.
256     </p>
257    
258     <p>
259     To send a signal, simply use <c>kill</c> or <c>killall</c>:
260     </p>
261    
262     <pre caption = "Sending the SIGHUP signal to devfsd">
263     # <i>kill -s SIGHUP `pidof devfsd`</i>
264     <comment>or</comment>
265     # <i>killall -s SIGHUP devfsd</i>
266     </pre>
267    
268     </body>
269     </section>
270     <section>
271     <title>Removing compatibility symlinks</title>
272     <body>
273    
274     <warn>
275     Currently, Gentoo cannot live without the compatibility symlinks.
276     </warn>
277    
278     <p>
279     If you want the compatibility symlinks that clutter up <path>/dev</path>
280     removed from your Gentoo system (Gentoo activates it per default), edit
281     <path>/etc/devfsd.conf</path> and remove the following two lines:
282     </p>
283    
284     <pre caption = "/etc/devfsd.conf for backwards compatibility">
285     <comment># Comment the following two lines out to remove the symlinks</comment>
286     REGISTER .* MKOLDCOMPAT
287     UNREGISTER .* RMOLDCOMPAT
288     </pre>
289    
290     <p>
291     You need to reboot your system for the changes to take affect.
292     </p>
293    
294     </body>
295     </section>
296     <section>
297     <title>Removing autoload functionality</title>
298     <body>
299    
300     <p>
301     When you load a module, devfs will automatically create the device
302     files. If you don't want this behaviour, remove the following line from
303     <path>/etc/devfsd.conf</path>:
304     </p>
305    
306     <pre caption = "/etc/devfsd.conf, autoload functionality">
307     LOOKUP .* MODLOAD
308     </pre>
309    
310     </body>
311     </section>
312 swift 1.4 </chapter>
313 swift 1.1
314     <chapter>
315     <title>Permission Related Items</title>
316     <section>
317     <title>Set/change permissions using PAM</title>
318     <body>
319    
320     <p>
321     Although you can set permissions in <path>/etc/devfsd.conf</path>, you
322     are advised to use PAM (<e>Pluggable Authentification Modules</e>). This
323     is because PAM has the final say on permissions, possibly ignoring the
324     changes you make in <path>/etc/devfsd.conf</path>.
325     </p>
326    
327     <p>
328     PAM uses the <path>/etc/security/console.perms</path> file for the
329     permissions. The file consists of two parts: the first one describes the
330     groups, and the second one the permissions.
331     </p>
332    
333     <p>
334     Let's first take a look at the groups part. As an example we view the
335     sound-group:
336     </p>
337    
338     <pre caption = "Sound group in /etc/security/console.perms">
339     &lt;sound&gt;=/dev/dsp* /dev/audio* /dev/midi* \
340     /dev/mixer* /dev/sequencer* \
341     /dev/sound/* /dev/snd/* /dev/beep \
342     /dev/admm* \
343     /dev/adsp* /dev/aload* /dev/amidi* /dev/dmfm* \
344     /dev/dmmidi* /dev/sndstat
345     </pre>
346    
347     <p>
348     The syntax is quite easy: you start with a group-name, and end with a
349     list of devices that belong to that group.
350     </p>
351    
352     <p>
353     Now, groups aren't very usefull if you can't do anything with them. So
354     the next part describes how permissions are handled.
355     </p>
356    
357     <pre caption = "Permissions for sound group in /etc/security/console.perms">
358     &lt;console&gt; 0600 &lt;sound&gt; 0600 root.audio
359     </pre>
360    
361     <p>
362     The first field is the terminal check. On most systems, this is the
363     console-group. PAM will check this field for every login. If the login
364     happens on a device contained in the console-group, PAM will check and
365     possibly change the permissions on some device files.
366     </p>
367    
368     <p>
369 swift 1.2 The second field contains the permissions to which a device file is set
370 swift 1.1 upon succesfull login. When a person logs into the system, and the device
371     files are owned by a default owner/group, PAM wil change the ownership
372     to the logged on user, and set the permissions to those in this second
373     field. In this case, 0600 is used (user has read/write access,
374     all others don't).
375     </p>
376    
377     <p>
378     The third field contains the device-group whose permissions will be
379     changed. In this case, the sound-group (all device files related to
380     sound) will be changed.
381     </p>
382    
383     <p>
384 swift 1.2 The fourth field defines the permissions to which the device file is set after
385 swift 1.1 returning to the default state. In other words, if the person who owns
386     all the device files logs out, PAM will set the permissions back to a
387     default state, described by this fourth field.
388     </p>
389    
390     <p>
391     The fifth field defines the ownership (with group if you want) to which
392     the device attributes are set after returning to the default state. In
393     other words, if the person who owns all the device files logs out, PAM
394     will set the ownership back to a default state, described by this fifth
395     field.
396     </p>
397    
398     </body>
399     </section>
400     <section>
401     <title>Set/change permissions with devfsd</title>
402     <body>
403    
404     <p>
405     If you really want to set permissions using
406     <path>/etc/devfsd.conf</path>, then use the syntax used in the following
407     example:
408     </p>
409    
410     <pre caption = "Permissions in /etc/devfsd.conf">
411     REGISTER ^cdroms/.* PERMISSIONS root.cdrom 0660
412     </pre>
413    
414     <p>
415     The second field is the device group, starting from <path>/dev</path>.
416     It is a regular expression, meaning you can select several device files
417     in one rule.
418     </p>
419    
420     <p>
421     The fourth field is the ownership of the device file. Unlike with PAM
422     this isn't changed (unless it is mentioned in <path>console.perms</path>
423     since PAM always wins).
424     </p>
425    
426     <p>
427     The fifth field contains the permissions of the device file.
428     </p>
429    
430     </body>
431     </section>
432     <section>
433     <title>Manually set permissions and have devfsd save it</title>
434     <body>
435    
436     <p>
437     This is the default behaviour for Gentoo: if you <c>chown</c> (CHange
438     OWNer) and <c>chmod</c> (CHange MODe) some device files, <c>devfsd</c>
439     will save the information when you are shutting down the system. This is
440     because the <path>/etc/devfsd.conf</path> file contains the following
441     lines:
442     </p>
443    
444     <pre caption = "/etc/devfsd.conf for saving permissions">
445     REGISTER ^pt[sy]/.* IGNORE
446     CHANGE ^pt[sy]/.* IGNORE
447     CREATE ^pt[sy]/.* IGNORE
448     DELETE ^pt[sy] IGNORE
449     REGISTER ^log IGNORE
450     CHANGE ^log IGNORE
451     CREATE ^log IGNORE
452     DELETE ^log IGNORE
453     REGISTER .* COPY /lib/dev-state/$devname $devpath
454     CHANGE .* COPY $devpath /lib/dev-state/$devname
455     CREATE .* COPY $devpath /lib/dev-state/$devname
456     DELETE .* CFUNCTION GLOBAL unlink
457     /lib/dev-state/$devname
458     RESTORE /lib/dev-state
459     </pre>
460    
461     <p>
462     In other words, changed device files are copied over to
463     <path>/lib/dev-state</path> when shutting down the system, and are
464     copied over to <path>/dev</path> when booting the system.
465     </p>
466    
467     <p>
468     Another possibility is to mount <path>/lib/dev-state</path> on
469     <path>/dev</path> at boot-time. To do this, you must make sure that
470     devfs is not mounted automatically (meaning you'll have to recompile
471     your kernel) and that <path>/dev/console</path> exists. Then, somewhere
472     at the beginning of the bootscripts of your system, you place:
473     </p>
474    
475     <pre caption = "Mounting /lib/dev-state on top of /dev">
476     mount --bind /dev /lib/dev-state
477     mount -t devfs none /dev
478     devfsd /dev
479     </pre>
480    
481     </body>
482     </section>
483     </chapter>
484    
485     <chapter>
486     <title>Resources</title>
487     <section>
488     <body>
489    
490     <p>
491     For more information on devfs, check out the following resources.
492     </p>
493    
494     <p>
495     The devfd.conf manpage explains the syntax of the
496     <path>/etc/devfsd.conf</path> file. To view it, type <c>man
497     devfsd.conf</c>.
498     </p>
499    
500     <p>
501     The <uri
502     link="http://www.atnf.csiro.au/people/rgooch/linux/docs/devfs.html">devfs
503     FAQ</uri> explains everything about devfs. It also contains information
504     about the internal devfs structure and how drivers can support devfs.
505     </p>
506    
507     <p>
508     On <uri link="http://www.linuxjournal.com">LinuxJournal</uri> there is
509     an interesting article on <uri
510     link="http://www.linuxjournal.com/article.php?sid=6035">devfs for
511     Management and Administration</uri>.
512     </p>
513    
514     <p>
515     Daniel Robbins has written a set of articles for IBM's DeveloperWorks
516     about Advanced filesystems. Three of them are about devfs:
517     </p>
518    
519     <ul>
520 swift 1.4 <li>
521     <uri link="http://www-106.ibm.com/developerworks/linux/library/l-fs4/">
522     Introduction to devfs</uri>
523     </li>
524     <li>
525     <uri link="http://www-106.ibm.com/developerworks/linux/library/l-fs5/">
526     Setting up devfs</uri>
527     </li>
528     <li>
529     <uri link="http://www-106.ibm.com/developerworks/linux/library/l-fs6/">
530     Implementing devfs</uri>
531     </li>
532 swift 1.1 </ul>
533    
534     </body>
535     </section>
536     </chapter>
537     </guide>

  ViewVC Help
Powered by ViewVC 1.1.20