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: src/share/man/man4/intro.4,v 1.13.2.6 2002/01/09 15:36:51 ru Exp $ 27.\" $DragonFly: src/share/man/man4/intro.4,v 1.4 2006/10/24 17:09:45 swildner Exp $ 28.\" 29.Dd January 20, 1996 30.Dt INTRO 4 31.Os 32.Sh NAME 33.Nm intro 34.Nd introduction to devices and device drivers 35.Sh DESCRIPTION 36This section contains information related to devices, device drivers 37and miscellaneous hardware. 38.Ss The device abstraction 39Device is a term used mostly for hardware-related stuff that belongs 40to the system, like disks, printers, or a graphics display with its 41keyboard. 42There are also so-called 43.Em pseudo-devices 44where a device driver emulates the behaviour of a device in software 45without any particular underlying hardware. 46A typical example for 47the latter class is 48.Pa /dev/mem , 49a loophole where the physical memory can be accessed using the regular 50file access semantics. 51.Pp 52The device abstraction generally provides a common set of system calls 53layered on top of them, which are dispatched to the corresponding 54device driver by the upper layers of the kernel. 55The set of system 56calls available for devices is chosen from 57.Xr open 2 , 58.Xr close 2 , 59.Xr read 2 , 60.Xr write 2 , 61.Xr ioctl 2 , 62.Xr select 2 , 63and 64.Xr mmap 2 . 65Not all drivers implement all system calls, for example, calling 66.Xr mmap 2 67on terminal devices is likely to be not useful at all. 68.Ss Accessing Devices 69Most of the devices in a unix-like operating system are accessed 70through so-called 71.Em device nodes , 72sometimes also called 73.Em special files . 74They are usually located under the directory 75.Pa /dev 76in the file system hierarchy 77(see also 78.Xr hier 7 ) . 79.Pp 80Each 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. 90In the first case, any attempt to reference the device 91through the device node will result in an error, returned by the upper 92layers of the kernel, usually 93.Er ENXIO . 94In the second case, the device node needs to be created before the 95driver and its device will be usable. 96.Pp 97Some devices come in two flavors: 98.Em block 99and 100.Em character 101devices, or to use better terms, buffered and unbuffered 102(raw) 103devices. 104The traditional names are reflected by the letters 105.Ql b 106and 107.Ql c 108as the file type identification in the output of 109.Ql ls -l . 110Buffered devices are being accessed through the buffer cache of the 111operating system, and they are solely intended to layer a file system 112on top of them. 113They are normally implemented for disks and disk-like 114devices only and, for historical reasons, for tape devices. 115.Pp 116Raw devices are available for all drivers, including those that also 117implement a buffered device. 118For the latter group of devices, the 119differentiation is conventionally done by prepending the letter 120.Ql r 121to the path name of the device node, for example 122.Pa /dev/rda0 123denotes the raw device for the first SCSI disk, while 124.Pa /dev/da0 125is the corresponding device node for the buffered device. 126.Pp 127Unbuffered devices should be used for all actions that are not related 128to file system operations, even if the device in question is a disk 129device. 130This includes making backups of entire disk partitions, or 131to 132.Em raw 133floppy disks 134(i.e. those used like tapes). 135.Pp 136Access restrictions to device nodes are usually subject to the regular 137file permissions of the device node entry, instead of being enforced 138directly by the drivers in the kernel. 139.Ss Drivers without device nodes 140Drivers for network devices do not use device nodes in order to be 141accessed. 142Their selection is based on other decisions inside the 143kernel, and instead of calling 144.Xr open 2 , 145use of a network device is generally introduced by using the system 146call 147.Xr socket 2 . 148.Ss Configuring a driver into the kernel 149For each kernel, there is a configuration file that is used as a base 150to select the facilities and drivers for that kernel, and to tune 151several options. 152See 153.Xr config 8 154for a detailed description of the files involved. 155The individual manual pages in this section provide a sample line for the 156configuration file in their synopsis portion. See also the sample 157config file 158.Pa /sys/config/LINT 159(for the 160.Em i386 161architecture). 162.Sh SEE ALSO 163.Xr close 2 , 164.Xr ioctl 2 , 165.Xr mmap 2 , 166.Xr open 2 , 167.Xr read 2 , 168.Xr select 2 , 169.Xr socket 2 , 170.Xr write 2 , 171.Xr hier 7 , 172.Xr config 8 , 173.Xr MAKEDEV 8 174.Sh HISTORY 175The 176.Nm 177manual page first appeared in 178.Fx 2.1 . 179.Sh AUTHORS 180.An -nosplit 181This man page was written by 182.An J\(:org Wunsch 183with initial input by 184.An David E. O'Brien . 185