📄 ch39.htm
字号:
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<UL>
<LI><A HREF="#Heading1">- 39 -</A>
<UL>
<LI><A HREF="#Heading2">Devices</A>
<UL>
<LI><A HREF="#Heading3">Character and Block Mode Devices</A>
<LI><A HREF="#Heading4">NOTE</A>
<UL>
<LI><A HREF="#Heading5">Major and Minor Device Numbers</A>
<LI><A HREF="#Heading6">The mknod Command</A>
</UL>
<LI><A HREF="#Heading7">Printer Administration</A>
<UL>
<LI><A HREF="#Heading8">The lpd Printing Daemon</A>
<LI><A HREF="#Heading9">Following a Print Request</A>
</UL>
<LI><A HREF="#Heading10">NOTE</A>
<UL>
<LI><A HREF="#Heading11">The /etc/printcap File and Spooling Directories</A>
</UL>
<LI><A HREF="#Heading12">NOTE</A>
<UL>
<LI><A HREF="#Heading13">Adding Printer Devices with mknod</A>
</UL>
<LI><A HREF="#Heading14">NOTE</A>
<LI><A HREF="#Heading15">NOTE</A>
<UL>
<LI><A HREF="#Heading16">Managing Printers with lpc</A>
</UL>
<LI><A HREF="#Heading17">WARNING</A>
<UL>
<LI><A HREF="#Heading18">Managing the Printer Queue with lpq and lprm</A>
</UL>
<LI><A HREF="#Heading19">NOTE</A>
<LI><A HREF="#Heading20">WARNING</A>
<LI><A HREF="#Heading21">NOTE</A>
<LI><A HREF="#Heading22">Terminals</A>
<UL>
<LI><A HREF="#Heading23">Using Multiport Cards</A>
<LI><A HREF="#Heading24">Adding Serial Port Terminals</A>
</UL>
<LI><A HREF="#Heading25">NOTE</A>
<UL>
<LI><A HREF="#Heading26">The Login Process</A>
<LI><A HREF="#Heading27">What Are /sbin/getty and /etc/gettydefs?</A>
</UL>
<LI><A HREF="#Heading28">NOTE</A>
<UL>
<LI><A HREF="#Heading29">Terminal Files: /etc/ttys and /etc/inittab</A>
</UL>
<LI><A HREF="#Heading30">WARNING</A>
<UL>
<LI><A HREF="#Heading31">Terminal Definitions: The /etc/termcap File</A>
</UL>
<LI><A HREF="#Heading32">NOTE</A>
<UL>
<LI><A HREF="#Heading33">Adding a Terminal</A>
</UL>
<LI><A HREF="#Heading34">NOTE</A>
<UL>
<LI><A HREF="#Heading35">Using stty and tset</A>
<LI><A HREF="#Heading36">Resetting a Screwy Terminal</A>
</UL>
<LI><A HREF="#Heading37">Adding a Modem</A>
<LI><A HREF="#Heading38">Summary</A>
</UL>
</UL>
</UL>
<P>
<HR SIZE="4">
<H2 ALIGN="CENTER"><A NAME="Heading1<FONT COLOR="#000077">- 39 -</FONT></H2>
<H2 ALIGN="CENTER"><A NAME="Heading2<FONT COLOR="#000077">Devices</FONT></H2>
<P><I>by Tim Parker</I></P>
<P>IN THIS CHAPTER</P>
<UL>
<LI>Character and Block Mode Devices
<P>
<LI>Printer Administration
<P>
<LI>Terminals
<P>
<LI>Adding a Modem
</UL>
<P><BR>
This chapter is devoted to devices that might be attached to your Linux system, such
as terminals, modems, and printers. It shows you how to add and manage the different
devices, and it also looks at many of the Linux commands you will need to properly
administer your system.</P>
<P>In this chapter, you will learn about the following topics:
<UL>
<LI>What a device driver is
<P>
<LI>The difference between block mode and character mode devices
<P>
<LI>Major and minor device numbers
<P>
<LI>The <TT>mknod</TT> command
<P>
<LI> How to manage printers and the print spooler
<P>
<LI>How to add a printer
<P>
<LI>How to add a terminal and modem
<P>
<LI>The configuration files used by terminals
<P>
<LI>The startup sequence used to permit logins
</UL>
<P>All of this information is necessary if you are to have a smoothly running system.
Even if you don't intend to add terminals or modems, you should know about the startup
process and how the configuration files are handled.
<H3 ALIGN="CENTER"><A NAME="Heading3<FONT COLOR="#000077">Character and Block
Mode Devices</FONT></H3>
<P>Everything attached to the computer you are using to run Linux is treated as a
device by the operating system. It doesn't matter whether the device is a terminal,
a hard disk, a printer, a CD-ROM drive, or a modem. Everything that accepts or sends
data to the operating system is a device.</P>
<P>The concept of treating everything on the system as a device is one of the benefits
of the UNIX architecture. Each device has a special section in the kernel, called
a device driver, which includes all the instructions necessary for Linux to communicate
with the device. When a new device is developed, it can be used with Linux by writing
a device driver, which is usually a set of instructions that explains how to send
and receive data.</P>
<P>Device drivers allow the Linux kernel to include only the operating system and
support software. By having the instructions for talking to devices within a set
of files, they can be loaded as needed (in the case of rarely used devices), or kept
in memory all the time when the operating system boots. As refinements are made to
a peripheral, small changes to the device driver file can be linked into the kernel
to keep the operating system informed of the new features and capabilities.</P>
<P>When an application instructs a device to perform an action, the Linux kernel
doesn't have to worry about the mechanism. It simply passes the request to the device
driver and lets it handle the communications. Similarly, when you're typing at the
keyboard, your terminal's device driver accepts the keystrokes and passes them to
the shell or application, filtering out any special codes that the kernel doesn't
know how to handle by translating them into something the kernel can perform.</P>
<P>Linux keeps device files in the <TT>/dev</TT> directory by default and convention.
It is permissible to keep device files anywhere on the file system, but keeping them
all in <TT>/dev</TT> makes it obvious that they are device files.</P>
<P>Every type of device on the Linux system communicates in one of two ways: character
by character or as a set of data in a predefined chunk or block. Terminals, printers,
and asynchronous modems are character devices, using characters sent one at a time
and echoed by the other end. Hard drives and most tape drives, on the other hand,
use blocks of data, because this is the fastest way to send large chunks of information.
These peripherals are called either character mode or block mode devices, based on
the way they communicate.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading4<FONT COLOR="#000077"><B>NOTE:</B> </FONT>Another way to differentiate
between character and block mode devices is by how the buffering to the device is
handled. Character mode devices want to do their own buffering. Block mode devices,
which usually communicate in chunks of 512 or 1,024 bytes, have the kernel perform
the buffering. Some devices can be both character and block mode devices. Some tape
drives, for example, can handle both character and block modes, and therefore have
two different device drivers. The device driver that is used depends on how the user
wants to write data to the device.
<HR>
</DL>
<P>The device file has all the details about whether the device is a character mode
or block mode device. There is an easy way to tell which type of device a peripheral
is: Look at the output of the listing command that shows file permissions (such as
<TT>ls -l</TT>). If the first character is a <TT>b</TT>, the device is a block mode
device; a <TT>c</TT> indicates a character mode device.</P>
<P>Device files are usually named to indicate the type of device they are. Most terminals,
for example, have a device driver with the name <TT>tty</TT> followed by two or more
letters or numbers, such as <TT>tty1</TT>, <TT>tty1A</TT>, or <TT>tty04</TT>. The
letters <TT>tty</TT> identify the file as a terminal (<TT>tty</TT> stands for teletype),
and the numbers or letters identify the specific terminal referred to. When coupled
with the directory name <TT>/dev</TT>, the full device driver name becomes <TT>/dev/tty01</TT>.
<H4 ALIGN="CENTER"><A NAME="Heading5<FONT COLOR="#000077">Major and Minor Device
Numbers</FONT></H4>
<P>There might be more than one device of the same type on a system. For example,
your Linux system might have a multiport card (multiple serial ports) with 10 Wyse
60 terminals hanging off it. Linux can use the same device driver for each of the
terminals because they are all the same type of device.</P>
<P>However, there must be a method for the operating system to differentiate which
one of the 10 terminals you want to address. That's where device numbers are used.
Each device is identified by two device numbers: The major number identifies the
device driver to be used, and the minor number identifies the device number. For
example, the 10 Wyse 60 terminals on the multiport card can all use a device file
with the same major number, but each will have a different minor number, thereby
uniquely identifying it to the operating system.</P>
<P>Every device on the system has both major and minor device numbers assigned in
such a way as to ensure that they are unique. If two devices are assigned the same
number, Linux can't properly communicate with them.</P>
<P>Some devices use the major and minor device numbers in a strange way. Some tape
drives, for example, use the minor number to identify the density of the tape and
adjust its output in that manner.</P>
<P>Device files are created with the command <TT>mknod</TT> (make node) and removed
with the standard <TT>rm</TT> command.
<H4 ALIGN="CENTER"><A NAME="Heading6<FONT COLOR="#000077">The mknod Command</FONT></H4>
<P>The <TT>mknod</TT> (make node) command is used for several different purposes
in Linux. It can create a FIFO (first in first out) pipe or a character or block
mode device file. The format of this com-mand is<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">mknod [options] device b|c|p|u major minor
</FONT></PRE>
<P>The options can be one of the following:
<TABLE BORDER="0">
<TR ALIGN="LEFT" rowspan="1">
<TD ALIGN="LEFT" VALIGN="TOP"><TT>--help</TT> </TD>
<TD ALIGN="LEFT" VALIGN="TOP">Displays help information and then exits. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD ALIGN="LEFT" VALIGN="TOP"><TT>-m [</TT>mode<TT>]</TT> </TD>
<TD ALIGN="LEFT" VALIGN="TOP">Sets the mode of the file to mode instead of the default <TT>0666</TT> (only symbolic
notation is allowed). </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD ALIGN="LEFT" VALIGN="TOP"><TT>--version<BR>
</TT></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Displays version information, then exits.<BR>
</TD>
</TR>
</TABLE>
The argument after the device or pathname specifies whether the file is a block mode
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -