<para>/dev contains the device files and is a very interesting directory that highlights one important aspect of the Linux filesystem - everything is a file or a directory. Look through this directory and you should hopefully see hda1, hda2 etc.... which represent the various partitions on the first master drive of the system. /dev/cdrom and /dev/fd0 represent your CD-ROM drive and your floppy drive. This may seem strange but it will make sense if you compare the characteristics of files to that of your hardware. Both can be read from and written to. Take /dev/dsp, for instance. This file represents your speaker device. Any data written to this file will be re-directed to your speaker. If you try 'cat /boot/vmlinuz > /dev/dsp' (on a properly configured system) you should hear some sound on the speaker. That's the sound of your kernel! A file sent to /dev/lp0 gets printed. Sending data to and reading from /dev/ttyS0 will allow you to communicate with a device attached there - for instance, your modem.</para>
<para>The majority of devices are either block or character devices; however other types of devices exist and can be created. In general, 'block devices' are devices that store or hold data, 'character devices' can be thought of as devices that transmit or transfer data. For example, diskette drives, hard drives and CD-ROM drives are all block devices while serial ports, mice and parallel printer ports are all character devices. There is a naming scheme of sorts but in the vast majority of cases these are completely illogical.</para>
The name DSP comes from the term digital signal processor, a specialized processor chip optimized for digital signal analysis. Sound cards may use a dedicated DSP chip, or may implement the functions with a number of discrete devices. Other terms that may be used for this device are digitized voice and PCM.</para></listitem></varlistentry>
This subdirectory contains most of the USB device nodes. Device name allocations are fairly simplistic so no elaboration is be necessary.</para></listitem></varlistentry>
First joystick device.</para></listitem></varlistentry>
</variablelist></para>
<para>Devices are defined by type, such as 'block' or 'character', and 'major' and 'minor' number. The major number is used to categorize a device and the minor number is used to identify a specific device type. For example, all IDE device connected to the primary controller have a major number of 3. Master and slave devices, as well as individual partitions are further defined by the use of minor numbers. These are the two numbers precede the date in the following display:</para>
<para># ls -l /dev/hd*</para>
<para>
<screen>
brw-rw---- 1 root disk 3, 0 Mar 15 2002 /dev/hda
brw-rw---- 1 root disk 3, 1 Mar 15 2002 /dev/hda1
brw-rw---- 1 root disk 3, 10 Mar 15 2002 /dev/hda10
brw-rw---- 1 root disk 3, 11 Mar 15 2002 /dev/hda11
brw-rw---- 1 root disk 3, 12 Mar 15 2002 /dev/hda12
brw-rw---- 1 root disk 3, 13 Mar 15 2002 /dev/hda13
brw-rw---- 1 root disk 3, 14 Mar 15 2002 /dev/hda14
brw-rw---- 1 root disk 3, 15 Mar 15 2002 /dev/hda15
brw-rw---- 1 root disk 3, 16 Mar 15 2002 /dev/hda16
brw-rw---- 1 root disk 3, 17 Mar 15 2002 /dev/hda17
brw-rw---- 1 root disk 3, 18 Mar 15 2002 /dev/hda18
brw-rw---- 1 root disk 3, 19 Mar 15 2002 /dev/hda19
brw-rw---- 1 root disk 3, 2 Mar 15 2002 /dev/hda2
brw-rw---- 1 root disk 3, 20 Mar 15 2002 /dev/hda20
brw-rw---- 1 root disk 3, 3 Mar 15 2002 /dev/hda3
brw-rw---- 1 root disk 3, 4 Mar 15 2002 /dev/hda4
brw-rw---- 1 root disk 3, 5 Mar 15 2002 /dev/hda5
brw-rw---- 1 root disk 3, 6 Mar 15 2002 /dev/hda6
brw-rw---- 1 root disk 3, 7 Mar 15 2002 /dev/hda7
brw-rw---- 1 root disk 3, 8 Mar 15 2002 /dev/hda8
brw-rw---- 1 root disk 3, 9 Mar 15 2002 /dev/hda9
brw-rw---- 1 root disk 3, 64 Mar 15 2002 /dev/hdb
brw-rw---- 1 root disk 3, 65 Mar 15 2002 /dev/hdb1
brw-rw---- 1 root disk 3, 74 Mar 15 2002 /dev/hdb10
brw-rw---- 1 root disk 3, 75 Mar 15 2002 /dev/hdb11
brw-rw---- 1 root disk 3, 76 Mar 15 2002 /dev/hdb12
brw-rw---- 1 root disk 3, 77 Mar 15 2002 /dev/hdb13
brw-rw---- 1 root disk 3, 78 Mar 15 2002 /dev/hdb14
brw-rw---- 1 root disk 3, 79 Mar 15 2002 /dev/hdb15
brw-rw---- 1 root disk 3, 80 Mar 15 2002 /dev/hdb16
brw-rw---- 1 root disk 3, 81 Mar 15 2002 /dev/hdb17
brw-rw---- 1 root disk 3, 82 Mar 15 2002 /dev/hdb18
brw-rw---- 1 root disk 3, 83 Mar 15 2002 /dev/hdb19
brw-rw---- 1 root disk 3, 66 Mar 15 2002 /dev/hdb2
brw-rw---- 1 root disk 3, 84 Mar 15 2002 /dev/hdb20
brw-rw---- 1 root disk 3, 67 Mar 15 2002 /dev/hdb3
brw-rw---- 1 root disk 3, 68 Mar 15 2002 /dev/hdb4
brw-rw---- 1 root disk 3, 69 Mar 15 2002 /dev/hdb5
brw-rw---- 1 root disk 3, 70 Mar 15 2002 /dev/hdb6
brw-rw---- 1 root disk 3, 71 Mar 15 2002 /dev/hdb7
brw-rw---- 1 root disk 3, 72 Mar 15 2002 /dev/hdb8
brw-rw---- 1 root disk 3, 73 Mar 15 2002 /dev/hdb9
brw-rw---- 1 root disk 22, 0 Mar 15 2002 /dev/hdc
brw-rw---- 1 root disk 22, 64 Mar 15 2002 /dev/hdd
</screen>
</para>
<para>The major number for both hda and hdb devices is 3. Of course, the minor number changes for each specific partition. The definition of each major number category can be examined by looking at the contents of the /usr/src/linux/include/linux/major.h file. The devices.txt also documents major and minor numbers. It is located in the /usr/src/linux/Documentation directory. This file defines the major numbers. Almost all files devices are created by default at the install time. However, you can always create a device using the mknod command or the MAKEDEV script which is located in the /dev directory itself. Devices can be created with this utility by supplying the device to be created, the device type (block or character) and the major and minor numbers. For example, let's say you have accidentally deleted /dev/ttyS0 (COM1 under Windows), it can be recreated using the following command</para>
<para># mknod ttyS0 c 4 64</para>
<para>For those of us who are rather lazy you can simply run the MAKEDEV script as such</para>
<para># MAKEDEV *</para>
<para>which will create all devices known.</para>
<para>For those of you who are wondering why Linux is using such a primitive system to reference devices it's simply because we haven't been able to devise a more sophisticated mechanism.</para>
<para>To date (as of kernel version 2.4), the best attempt has been made by Richard Gooch of the CSIRO. It's called devfsd and has been a part of the kernel for a number of years now. It has been sanctioned by the kernel developers and Linus himself and details of its implementation can be found at /usr/src/linux/Documentation/filesystems/devfs/README. Below is an excerpt from this document.</para>
<para>Devfs is an alternative to "real" character and block special devices on your root filesystem. Kernel device drivers can register devices by name rather than major and minor numbers. These devices will appear in devfs automatically, with whatever default ownership and protection the driver specified. A daemon (devfsd) can be used to override these defaults. Devfs has been in the kernel since 2.3.46.</para>
<para>NOTE that devfs is entirely optional. If you prefer the old disc-based device nodes, then simply leave CONFIG_DEVFS_FS=n (the default). In this case, nothing will change. ALSO NOTE that if you do enable devfs, the defaults are such that full compatibility is maintained with the old devices names.</para>
<para>There are two aspects to devfs: one is the underlying device namespace, which is a namespace just like any mounted filesystem. The other aspect is the filesystem code which provides a view of the device namespace. The reason I make a distinction is because devfs can be mounted many times, with each mount showing the same device namespace. Changes made are global to all mounted devfs filesystems. Also, because the devfs namespace exists without any devfs mounts, you can easily mount the root filesystem by referring to an entry in the devfs namespace.</para>
<para>The cost of devfs is a small increase in kernel code size and memory usage. About 7 pages of code (some of that in __init sections) and 72 bytes for each entry in the namespace. A modest system has only a couple of hundred device entries, so this costs a few more pages. Compare this with the suggestion to put /dev on a ramdisc.</para>
<para>On a typical machine, the cost is under 0.2 percent. On a modest system with 64 MBytes of RAM, the cost is under 0.1 percent. The accusations of "bloatware" levelled at devfs are not justified.</para>
<para>To alleviate problems of an ever burgeoning /dev directory creation of new device files was officially terminated on June 3, 2001 on Linus's series of kernels. Further development will proceed only on the -ac series (see /usr/src/linux/Documentation/devices.txt for further details).</para>