xref: /freebsd/share/man/man4/intro.4 (revision 380a989b3223d455375b4fae70fd0b9bdd43bafb)
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.\" $Id: intro.4,v 1.10 1998/03/12 07:30:17 charnier Exp $
27.\"
28.Dd January 20, 1996
29.Dt INTRO 4
30.Os FreeBSD 2.1
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 driver
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 a terminal devices is likely to be not useful at all.
64.Ss Accessing Devices
65Most of the devices in a unix-like operating system are accessed
66through so-called
67.Em device nodes ,
68sometimes also called
69.Em special files .
70They are usually located under the directory
71.Pa /dev
72in the file system hierarchy
73.Pq see also Xr hier 7 .
74.Pp
75Until
76.Xr devfs 5
77is fully functional, each device node must be created statically and
78independently of the existence of the associated device driver,
79usually by running
80.Xr MAKEDEV 8 .
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.  In the first case, any attempt to reference the device
87through the device node will result in an error, returned by the upper
88layers of the kernel, usually
89.Ql ENXIO .
90In the second case, the device node needs to be created before the
91driver and its device will be usable.
92.Pp
93Some devices come in two flavors:
94.Em block
95and
96.Em character
97devices, or by a better name, buffered and unbuffered
98.Pq raw
99devices.  The traditional names are reflected by the letters
100.Ql b
101and
102.Ql c
103as the file type identification in the output of
104.Ql ls -l .
105Buffered devices are being accessed through the buffer cache of the
106operating system, and they are solely intended to layer a file system
107on top of them.  They are normally implemented for disks and disk-like
108devices only, for historical reasons also for tape devices.
109.Pp
110Raw devices are available for all drivers, including those that also
111implement a buffered device.  For the latter group of devices, the
112differentiation is conventionally done by prepending the latter
113.Ql r
114to the path name of the device node, for example
115.Pa /dev/rda0
116denotes the raw device for the first SCSI disk, while
117.Pa /dev/da0
118is the corresponding device node for the buffered device.
119.Pp
120Unbuffered devices should be used for all actions that are not related
121to file system operations, even if the device in question is a disk
122device.  This includes making backups of entire disk partitions, or
123to
124.Em raw
125floppy disks
126.Pq i.e. those used like tapes .
127.Pp
128Access restrictions to device nodes are usually subject of the regular
129file permissions of the device node entry, instead of being implied
130directly by the drivers in the kernel.
131.Ss Drivers without device nodes
132Drivers for network devices do not use device nodes in order to be
133accessed.  Their selection is based on other decisions inside the
134kernel, and instead of calling
135.Xr open 2 ,
136use of a network device is generally introduced by using the system
137call
138.Xr socket 2 .
139.Ss Configuring a driver into the kernel
140For each kernel, there is a configuration file that is used as a base
141to select the facilities and drivers for that kernel, and to tune
142several options.  See
143.Xr config 8
144for a detailed description of the files involved.  The individual
145manual pages in this section provide a sample line for the
146configuration file in their synopsis portion.  See also the sample
147config file
148.Pa /sys/i386/conf/LINT
149.Po
150for the
151.Em i386
152architecture
153.Pc .
154.Sh SEE ALSO
155.Xr close 2 ,
156.Xr ioctl 2 ,
157.Xr mmap 2 ,
158.Xr open 2 ,
159.Xr read 2 ,
160.Xr select 2 ,
161.Xr socket 2 ,
162.Xr write 2 ,
163.Xr devfs 5 ,
164.Xr hier 7 ,
165.Xr config 8 ,
166.Xr MAKEDEV 8
167.Sh AUTHORS
168This man page has been written by
169.if t J\(:org Wunsch
170.if n Joerg Wunsch
171with initial input by
172.An David E. O'Brien .
173.Sh HISTORY
174.Nm Intro
175appeared in
176.Fx 2.1 .
177