⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lsg06.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 2 页
字号:


<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>

 -->


























<LINK REL="ToC" HREF="index.htm">







<LINK REL="Index" HREF="htindex.htm">







<LINK REL="Next" HREF="lsg07.htm">



















<A NAME="I0"></A>







<H2>Linux System Administrator's Survival Guide lsg06.htm</H2>







<P ALIGN=LEFT>







































<HR ALIGN=CENTER>







<P>







<UL>







<UL>







<UL>







<LI>







<A HREF="#E68E35" >Device Drivers</A>







<LI>







<A HREF="#E68E36" >Character and Block Mode Devices</A>







<UL>







<LI>







<A HREF="#E69E69" >Major and Minor Device Numbers</A>







<LI>







<A HREF="#E69E70" >The mknod Command</A></UL>







<LI>







<A HREF="#E68E37" >Device Permissions and Links</A>







<LI>







<A HREF="#E68E38" >Summary</A></UL></UL></UL>







<HR ALIGN=CENTER>







<A NAME="E66E8"></A>







<H1 ALIGN=CENTER>







<CENTER>







<FONT SIZE=6 COLOR="#FF0000"><B>Chapter 6</B></FONT></CENTER></H1>







<BR>







<A NAME="E67E11"></A>







<H2 ALIGN=CENTER>







<CENTER>







<FONT SIZE=6 COLOR="#FF0000"><B>Devices and Device Drivers</B></FONT></CENTER></H2>







<BR>







<P>One of the primary concepts of Linux that you must understand to administer a Linux system properly is that of devices. Without a basic knowledge of devices and device drivers, you can't add new hardware, manage existing hardware, or change your Linux hardware configuration. Luckily, devices and device drivers are very easy to understand.







<BR>







<P>This short chapter is devoted to devices and device drivers. In this chapter, you learn what a device driver is, how to handle the two different types of devices (character and block mode), what the major and minor device numbers are, and how to use the mknod command. Once you understand these concepts, you can change, add to, and manage your Linux hardware easily. Devices are referred to throughout this section of the book, so you should understand these concepts before going on.







<BR>







<BR>







<A NAME="E68E35"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Device Drivers</B></FONT></CENTER></H3>







<BR>







<P>The Linux operating system has no built-in instructions for handling hard drives, floppy disk drives, keyboards, monitors, or any other peripheral or piece of hardware attached to the system. All the instructions for communicating with the peripheral are contained in a file called a device driver. Device drivers are usually a small piece of assembler or C code that have a set of instructions for sending and receiving data with the device.







<BR>







<P>You make the device driver a part of the Linux kernel by linking it. Linking means that the code becomes part of the operating system kernel and is loaded automatically when Linux boots, which allows Linux to communicate with the device much faster than if it had to read the instructions from the device driver every time a request to communicate with the device was issued. Linux can have many different device drivers linked to it; the number is limited only by the amount of RAM in your system. Practically, though, the number of device drivers is kept to a few dozen because most systems don't have too many devices attached.







<BR>







<P>When an application instructs a device to perform some action, the Linux kernel doesn't have to worry about the mechanism to perform the act. It simply passes the request to the device driver and lets it handle the communications. Similarly, when you are typing at the keyboard, your terminal's device driver accepts the keystrokes and passes them to the shell, filtering out any special codes that the kernel doesn't know how to handle by translating them into something the kernel can perform.







<BR>







<P>You can use a single device driver to instruct Linux about communicating with many different devices, as long as they use the same basic instructions. For example, if you have four terminals attached to your Linux system but they all use the same serial communications method, a single device driver linked into the kernel can handle all four terminals. Linking new device drivers into the kernel is dealt with later in this book in <A HREF="lsg25.htm">Chapter 25</A>, &quot;Modifying the Kernel.&quot;







<BR>







<P>The use of device drivers is one of the real strengths of the UNIX operating system (and therefore Linux too) because it provides a continual method for expanding the system using the same kernel and adapting existing systems to new devices as they are developed. When a new hardware device is developed, it can be used with Linux by programming a device driver, which is usually not a difficult task for an experienced programmer.







<BR>







<P>Linux keeps all device drivers in the /dev directory by default and convention. Figure 6.1 shows part of a typical Linux /dev directory listing. You can't see all the device drivers on a single screen because there are so many of them. Over 500 device drivers are included with the Slackware Linux system on the CD-ROM supplied with this book. Many are simply duplicates of a basic device driver with a different device number, but each file has to be separate.







<BR>







<P><B> <A HREF="06LSG01.gif">Figure 6.1.</B>







<BR><B>A partial listing of the /dev directory.</A></B>







<BR>







<P>You can keep device drivers anywhere on the Linux filesystem, but keeping them all in /dev makes it obvious that they are device drivers. If you check the /dev directory, you see that many of the files are actually links to other files. These links enable you to name devices more clearly. You can access the CD-ROM drive as /dev/cdrom instead of /dev/sbpcd2, for example. Likewise, the mouse device can be linked to /dev/mouse. These links are a convenience for the user and are not necessarily important for Linux. Figure 6.2. shows a long listing of some of the device drivers. You can see that the file cdrom is linked to the file /dev/scd0. <A HREF="lsg18.htm">Chapter 18</A>, &quot;Filesystems and Disks,&quot; discusses links and what they mean.







<BR>







<P><B> <A HREF="06LSG02.gif">Figure 6.2.</B>







<BR><B>A long directory listing of the /dev directory shows that some of the </B><B>files are links to other files, as both cdrom and core are here.</A></B>







<BR>







<BR>







<A NAME="E68E36"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Character and Block Mode Devices</B></FONT></CENTER></H3>







<BR>







<P>Everything attached to the computer that Linux communicates with is treated as a device. Terminals, printers, and asynchronous modems are character mode devices; they communicate by using characters sent one at a time and echoed back by the other end. Hard drives and most tape drives, on the other hand, use blocks of data, which is the fastest way to send large chunks of information. They are called block mode devices.







<BR>







<P>Some devices can be both character and block mode devices, although not at the same time. Some tape drives, for example, can handle both character and block modes, which means that such drives will have two different device drivers. The device driver that is used depends on how the user wants to read or write data with the device. For the fastest throughput, a block mode device is used. For retrieval of a single file or backing up just a single directory, for example, a character mode device driver is preferable.







<BR>







<BLOCKQUOTE>







<BLOCKQUOTE>







<HR ALIGN=CENTER>







<BR>







<NOTE><A NAME="I2"></A>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 1024 bytes, have the kernel perform the buffering. This buffering is usually transparent to users.</NOTE>







<BR>







<HR ALIGN=CENTER>







</BLOCKQUOTE></BLOCKQUOTE>







<P>The device driver file has all the details about whether the device is a character mode or block mode device. To figure out which type of device a peripheral is, look at the permission block of the device driver file. If the first character of the permission block is a b, the device is a block mode device. A c as the first character in the permission block indicates a character mode device. In the following extract from a /dev directory listing, you can see the device's type from the first character in the permission blocks:







<BR>







<PRE>







<FONT COLOR="#000080">crw-rw---- 1 root uucp 5, 74 Jul 17 1994 cua10







crw-rw---- 1 root uucp 5, 75 Jul 17 1994 cua11







brw-rw---- 1 root floppy 2, 0 Jul 17 1994 fd0







brw-rw---- 1 root floppy 2, 1 Jul 17 1994 fd1







brw-rw---- 1 root disk 3, 0 Jul 17 1994 hda







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -