1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<!--Converted with LaTeX2HTML 96.1-h (September 30, 1996) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds -->
<HTML>
<HEAD>
<TITLE>Two kinds of devices</TITLE>
<META NAME="description" CONTENT="Two kinds of devices">
<META NAME="keywords" CONTENT="sag">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<LINK REL=STYLESHEET HREF="sag.css">
</HEAD>
<BODY LANG="EN" >
<A NAME="tex2html680" HREF="node30.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="./next_motif.gif"></A> <A NAME="tex2html678" HREF="node28.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="./up_motif.gif"></A> <A NAME="tex2html672" HREF="node28.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="./previous_motif.gif"></A> <A NAME="tex2html682" HREF="node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="./contents_motif.gif"></A> <A NAME="tex2html683" HREF="node114.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="./index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME="tex2html681" HREF="node30.html">Hard disks</A>
<B>Up:</B> <A NAME="tex2html679" HREF="node28.html">Using Disks and Other </A>
<B> Previous:</B> <A NAME="tex2html673" HREF="node28.html">Using Disks and Other </A>
<BR> <P>
<H1><A NAME="SECTION00510000000000000000">Two kinds of devices</A></H1>
<P>
UNIX, and therefore Linux, recognizes two different
kinds of device: random-access block devices (such as disks),
and character devices (such as tapes and serial lines),
some of which may be serial, and some random-access. Each
supported device is represented in the filesystem as a
<b>device file</b>. When you read or write a device file, the
data comes from or goes to the device it represents. This way
no special programs (and no special application programming
methodology, such as catching interrupts or polling a serial
port) are necessary to access devices; for example, to send a
file to the printer, one could just say
<BLOCKQUOTE> <TT>
<code>$</code> <I>cat filename > /dev/lp1</I> <BR>
<code>$</code>
</TT></BLOCKQUOTE>
and the contents of the file are printed (the file must, of
course, be in a form that the printer understands). However,
since it is not a good idea to have several people cat their
files to the printer at the same time, one usually uses a special
program to send the files to be printed (usually <tt>lpr</tt><A NAME="1437"> </A>).
This program makes sure that only one file is being printed
at a time, and will automatically send files to the printer as
soon as it finishes with the previous file. Something similar
is needed for most devices. In fact, one seldom needs to worry
about device files at all.
<P>
Since devices show up as files in the filesystem (in the
<tt>/dev</tt><A NAME="1439"> </A> directory), it is easy
to see just what device files exist, using <tt>ls</tt><A NAME="1441"> </A> or
another suitable command. In the output of <tt>ls -l</tt><A NAME="1443"> </A>, the
first column contains the type of the file and its
permissions. For example, inspecting a serial device
gives on my system
<BLOCKQUOTE> <TT>
<code>$</code> <I>ls -l /dev/cua0</I> <BR>
<code>crw-rw-rw- 1 root uucp 5, 64 Nov 30 1993 /dev/cua0</code> <BR>
<code>$</code>
</TT></BLOCKQUOTE>
The first character in the first column, i.e., `<TT>c</TT>' in
<TT>crw-rw-rw-</TT> above, tells an informed user the type of the file,
in this case a character device. For
ordinary files, the first character is `<TT>-</TT>', for
directories it is `<TT>d</TT>', and for block devices `<TT>b</TT>';
see the <tt>ls</tt><A NAME="1445"> </A> man page for further information.
<P>
Note that usually all device files exist even though the
device itself might be not be installed. So just because you
have a file <tt>/dev/sda</tt><A NAME="1447"> </A>, it doesn't mean that you really do
have an SCSI hard disk.
Having all the device files makes the installation programs
simpler, and makes it easier to add new hardware (there is no
need to find out the correct parameters for and create the device
files for the new device).
<P>
<HR><A NAME="tex2html680" HREF="node30.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="./next_motif.gif"></A> <A NAME="tex2html678" HREF="node28.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="./up_motif.gif"></A> <A NAME="tex2html672" HREF="node28.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="./previous_motif.gif"></A> <A NAME="tex2html682" HREF="node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="./contents_motif.gif"></A> <A NAME="tex2html683" HREF="node114.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="./index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME="tex2html681" HREF="node30.html">Hard disks</A>
<B>Up:</B> <A NAME="tex2html679" HREF="node28.html">Using Disks and Other </A>
<B> Previous:</B> <A NAME="tex2html673" HREF="node28.html">Using Disks and Other </A>
<P><ADDRESS>
<I>Lars Wirzenius <BR>
Sat Nov 15 02:32:11 EET 1997</I>
</ADDRESS>
</BODY>
</HTML>
|