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 filesystem hierarchy 75(see also 76.Xr hier 7 ) . 77.Pp 78Until 79.Xr devfs 5 80is fully functional, each device node must be created statically and 81independently of the existence of the associated device driver, 82usually by running 83.Xr MAKEDEV 8 . 84.Pp 85Note that this could lead to an inconsistent state, where either there 86are device nodes that do not have a configured driver associated with 87them, or there may be drivers that have successfully probed for their 88devices, but cannot be accessed since the corresponding device node is 89still missing. In the first case, any attempt to reference the device 90through the device node will result in an error, returned by the upper 91layers of the kernel, usually 92.Er ENXIO . 93In the second case, the device node needs to be created before the 94driver and its device will be usable. 95.Pp 96Some devices come in two flavors: 97.Em block 98and 99.Em character 100devices, or to use better terms, buffered and unbuffered 101(raw) 102devices. The traditional names are reflected by the letters 103.Ql b 104and 105.Ql c 106as the file type identification in the output of 107.Ql ls -l . 108Buffered devices are being accessed through the buffer cache of the 109operating system, and they are solely intended to layer a filesystem 110on top of them. They are normally implemented for disks and disk-like 111devices only and, for historical reasons, for tape devices. 112.Pp 113Raw devices are available for all drivers, including those that also 114implement a buffered device. For the latter group of devices, the 115differentiation is conventionally done by prepending the letter 116.Ql r 117to the path name of the device node, for example 118.Pa /dev/rda0 119denotes the raw device for the first SCSI disk, while 120.Pa /dev/da0 121is the corresponding device node for the buffered device. 122.Pp 123Unbuffered devices should be used for all actions that are not related 124to filesystem operations, even if the device in question is a disk 125device. This includes making backups of entire disk partitions, or 126to 127.Em raw 128floppy disks 129(i.e. those used like tapes). 130.Pp 131Access restrictions to device nodes are usually subject to the regular 132file permissions of the device node entry, instead of being enforced 133directly by the drivers in the kernel. 134.Ss Drivers without device nodes 135Drivers for network devices do not use device nodes in order to be 136accessed. Their selection is based on other decisions inside the 137kernel, and instead of calling 138.Xr open 2 , 139use of a network device is generally introduced by using the system 140call 141.Xr socket 2 . 142.Ss Configuring a driver into the kernel 143For each kernel, there is a configuration file that is used as a base 144to select the facilities and drivers for that kernel, and to tune 145several options. See 146.Xr config 8 147for a detailed description of the files involved. The individual 148manual pages in this section provide a sample line for the 149configuration file in their synopsis portion. See also the sample 150config file 151.Pa /sys/i386/conf/LINT 152(for the 153.Em i386 154architecture). 155.Sh SEE ALSO 156.Xr close 2 , 157.Xr ioctl 2 , 158.Xr mmap 2 , 159.Xr open 2 , 160.Xr read 2 , 161.Xr select 2 , 162.Xr socket 2 , 163.Xr write 2 , 164.Xr devfs 5 , 165.Xr hier 7 , 166.Xr config 8 , 167.Xr MAKEDEV 8 168.Sh AUTHORS 169.An -nosplit 170This man page has been written by 171.An J\(:org Wunsch 172with initial input by 173.An David E. O'Brien . 174.Sh HISTORY 175.Nm Intro 176appeared in 177.Fx 2.1 . 178