xref: /netbsd-src/share/man/man4/intro.4 (revision 76c7fc5f6b13ed0b1508e6b313e88e59977ed78e)
1.\" $NetBSD: intro.4,v 1.3 2017/12/20 09:58:36 wiz Exp $
2.\"
3.\" Copyright (c) 1996 David E. O'Brien, Joerg Wunsch
4.\"
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26.\"
27.\" $FreeBSD: head/share/man/man4/intro.4 131530 2004-07-03 18:29:24Z ru $
28.\"
29.Dd December 18, 2017
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
70.Ux Ns
71-like operating system are accessed
72through so-called
73.Em device nodes ,
74sometimes also called
75.Em special files .
76They are usually located under the directory
77.Pa /dev
78in the file system hierarchy
79(see also
80.Xr hier 7 ) .
81.Pp
82Note that this could lead to an inconsistent state, where either there
83are device nodes that do not have a configured driver associated with
84them, or there may be drivers that have successfully probed for their
85devices, but cannot be accessed since the corresponding device node is
86still missing.
87In the first case, any attempt to reference the device
88through the device node will result in an error, returned by the upper
89layers of the kernel, usually
90.Er ENXIO .
91In the second case, the device node needs to be created before the
92driver and its device will be usable.
93.Pp
94Some devices come in two flavors:
95.Em block
96and
97.Em character
98devices, or to use better terms, buffered and unbuffered
99(raw)
100devices.
101The traditional names are reflected by the letters
102.Ql b
103and
104.Ql c
105as the file type identification in the output of
106.Ql ls -l .
107Buffered devices are being accessed through the buffer cache of the
108operating system, and they are solely intended to layer a file system
109on top of them.
110They 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.
115For the latter group of devices, the
116differentiation is conventionally done by prepending the letter
117.Ql r
118to the path name of the device node, for example
119.Pa /dev/rsd0[cd]
120denotes the raw device for the first SCSI disk, while
121.Pa /dev/sd0[cd]
122is the corresponding device node for the buffered device.
123.Pp
124Unbuffered devices should be used for all actions that are not related
125to file system operations, even if the device in question is a disk
126device.
127This includes making backups of entire disk partitions, or
128to
129.Em raw
130floppy disks
131(i.e., those used like tapes).
132.Pp
133Access restrictions to device nodes are usually subject to the regular
134file permissions of the device node entry, instead of being enforced
135directly by the drivers in the kernel.
136.Ss Drivers without device nodes
137Drivers for network devices do not use device nodes in order to be
138accessed.
139Their selection is based on other decisions inside the
140kernel, and instead of calling
141.Xr open 2 ,
142use of a network device is generally introduced by using the system
143call
144.Xr socket 2 .
145.Ss Configuring a driver into the kernel
146For each kernel, there is a configuration file that is used as a base
147to select the facilities and drivers for that kernel, and to tune
148several options.
149See
150.Xr config 1
151for a detailed description of the files involved.
152The individual manual pages in this section provide a sample line for the
153configuration file in their synopsis portion.
154See also the sample config file
155.Pa /usr/src/sys/arch/i386/conf/GENERIC
156(for the
157.Em i386
158architecture).
159.Sh SEE ALSO
160.Xr config 1 ,
161.Xr close 2 ,
162.Xr ioctl 2 ,
163.Xr mmap 2 ,
164.Xr open 2 ,
165.Xr read 2 ,
166.Xr select 2 ,
167.Xr socket 2 ,
168.Xr write 2 ,
169.\" .Xr devfs 5 ,
170.Xr hier 7
171.Sh HISTORY
172This manual page first appeared in
173.Fx 2.1
174and
175.Nx 9 .
176.Sh AUTHORS
177.An -nosplit
178This man page has been written by
179.An J\(:org Wunsch
180with initial input by
181.An David E. O'Brien .
182