1.\" 2.\" Copyright (c) 1996 David E. O'Brien, Joerg Wunsch 3.\" 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25.\" 26.\" $FreeBSD$ 27.\" 28.Dd January 20, 1996 29.Dt INTRO 4 30.Os 31.Sh NAME 32.Nm intro 33.Nd introduction to devices and device drivers 34.Sh DESCRIPTION 35This section contains information related to devices, device drivers 36and miscellaneous hardware. 37.Ss The device abstraction 38Device is a term used mostly for hardware-related stuff that belongs 39to the system, like disks, printers, or a graphics display with its 40keyboard. There are also so-called 41.Em pseudo-devices 42where a device driver emulates the behaviour of a device in software 43without any particular underlying hardware. A typical example for 44the latter class is 45.Pa /dev/mem , 46a loophole where the physical memory can be accessed using the regular 47file access semantics. 48.Pp 49The device abstraction generally provides a common set of system calls 50layered on top of them, which are dispatched to the corresponding 51device driver by the upper layers of the kernel. The set of system 52calls available for devices is chosen from 53.Xr open 2 , 54.Xr close 2 , 55.Xr read 2 , 56.Xr write 2 , 57.Xr ioctl 2 , 58.Xr select 2 , 59and 60.Xr mmap 2 . 61Not all drivers implement all system calls, for example, calling 62.Xr mmap 2 63on terminal devices is likely to be not useful at all. 64.Ss Accessing Devices 65Most of the devices in a 66.Ux Ns 67-like operating system are accessed 68through so-called 69.Em device nodes , 70sometimes also called 71.Em special files . 72They are usually located under the directory 73.Pa /dev 74in the file system hierarchy 75(see also 76.Xr hier 7 ) . 77.Pp 78Note that this could lead to an inconsistent state, where either there 79are device nodes that do not have a configured driver associated with 80them, or there may be drivers that have successfully probed for their 81devices, but cannot be accessed since the corresponding device node is 82still missing. In the first case, any attempt to reference the device 83through the device node will result in an error, returned by the upper 84layers of the kernel, usually 85.Er ENXIO . 86In the second case, the device node needs to be created before the 87driver and its device will be usable. 88.Pp 89Some devices come in two flavors: 90.Em block 91and 92.Em character 93devices, or to use better terms, buffered and unbuffered 94(raw) 95devices. The traditional names are reflected by the letters 96.Ql b 97and 98.Ql c 99as the file type identification in the output of 100.Ql ls -l . 101Buffered devices are being accessed through the buffer cache of the 102operating system, and they are solely intended to layer a file system 103on top of them. They are normally implemented for disks and disk-like 104devices only and, for historical reasons, for tape devices. 105.Pp 106Raw devices are available for all drivers, including those that also 107implement a buffered device. For the latter group of devices, the 108differentiation is conventionally done by prepending the letter 109.Ql r 110to the path name of the device node, for example 111.Pa /dev/rda0 112denotes the raw device for the first SCSI disk, while 113.Pa /dev/da0 114is the corresponding device node for the buffered device. 115.Pp 116Unbuffered devices should be used for all actions that are not related 117to file system operations, even if the device in question is a disk 118device. This includes making backups of entire disk partitions, or 119to 120.Em raw 121floppy disks 122(i.e. those used like tapes). 123.Pp 124Access restrictions to device nodes are usually subject to the regular 125file permissions of the device node entry, instead of being enforced 126directly by the drivers in the kernel. 127.Ss Drivers without device nodes 128Drivers for network devices do not use device nodes in order to be 129accessed. Their selection is based on other decisions inside the 130kernel, and instead of calling 131.Xr open 2 , 132use of a network device is generally introduced by using the system 133call 134.Xr socket 2 . 135.Ss Configuring a driver into the kernel 136For each kernel, there is a configuration file that is used as a base 137to select the facilities and drivers for that kernel, and to tune 138several options. See 139.Xr config 8 140for a detailed description of the files involved. The individual 141manual pages in this section provide a sample line for the 142configuration file in their synopsis portion. See also the sample 143config file 144.Pa /sys/i386/conf/LINT 145(for the 146.Em i386 147architecture). 148.Sh SEE ALSO 149.Xr close 2 , 150.Xr ioctl 2 , 151.Xr mmap 2 , 152.Xr open 2 , 153.Xr read 2 , 154.Xr select 2 , 155.Xr socket 2 , 156.Xr write 2 , 157.Xr devfs 5 , 158.Xr hier 7 , 159.Xr config 8 160.Sh AUTHORS 161.An -nosplit 162This man page has been written by 163.An J\(:org Wunsch 164with initial input by 165.An David E. O'Brien . 166.Sh HISTORY 167.Nm Intro 168appeared in 169.Fx 2.1 . 170