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

📄 lsg06.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 2 页
字号:
brw-rw---- 1 root disk 3, 1 Jul 17 1994 hda1







brw-rw---- 1 root disk 8, 1 Jul 17 1994 sda1







brw-rw---- 1 root disk 8, 10 Jul 17 1994 sda10







brw-rw---- 1 root disk 8, 11 Jul 17 1994 sda11







crw--w--w- 1 root root 4, 0 Jul 17 1994 tty0







crw--w--w- 1 root root 4, 1 Jul 7 18:16 tty1







crw--w--w- 1 root root 4, 2 Jul 7 17:58 tty2







crw-rw-rw- 1 root tty 4, 64 Jul 17 1994 ttyS0







crw-rw-rw- 1 root tty 4, 65 Jul 7 18:00 ttyS1</FONT></PRE>







<P>You may notice that this listing has two numbers where the file size usually belongs. These numbers are the major and minor device numbers. The next section explains these numbers.







<BR>







<P>Device drivers are usually named to indicate the type of device they are. Most terminals, for example, have a device driver name tty followed by two or more letters or numbers, such as tty1, tty1A, or tty04. The letters <I>tty</I> identify the file as a terminal (<I>tty</I> stands for teletype), and the numbers or letters identify the specific terminal. When coupled with the directory /dev, the full device driver name becomes /dev/tty01. Hard drives, as you saw in earlier chapters, have names like /dev/hda and /dev/sda (for IDE and SCSI drives respectively).







<BR>







<BR>







<A NAME="E69E69"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>Major and Minor Device Numbers</B></FONT></CENTER></H4>







<BR>







<P>A system may have more than one device of the same type. For example, your Linux system may have a multiport card (multiple serial ports) with ten Qume terminals hanging off it. Linux can use the same device driver for each one of the terminals, as they are all the same type of device. The same concept applies to multiple printers, so you can use the same device driver for two Hewlett Packard LaserJet printers attached to two parallel ports, for example.







<BR>







<P>The operating system must have a method of differentiating the ten terminals or two printers, however. Device numbers are that method. Each device is identified by a major number that identifies the device driver to be used and a minor number that identifies the device number. For example, the ten Qume terminals may all use a device driver with the same major number (which really points to the device driver file in the /dev directory), but each has a different minor number that uniquely identifies the Qume terminal to the operating system. In the following listing, you can see that all the device drivers for the ttyX device (which is the console and associated screens) have the same major device number of 4, but the minor device number changes from 0 to 9:







<BR>







<PRE>







<FONT COLOR="#000080">crw--w--w- 1 root tty 4, 0 Jul 17 1994 tty0







crw--w--w- 1 root root 4, 1 Oct 13 13:48 tty1







crw--w--w- 1 root root 4, 2 Oct 13 13:26 tty2







crw--w--w- 1 root root 4, 3 Oct 13 13:26 tty3







crw--w--w- 1 root root 4, 4 Oct 13 13:26 tty4







crw--w--w- 1 root root 4, 5 Oct 13 13:26 tty5







crw--w--w- 1 root root 4, 6 Oct 13 13:26 tty6







crw-rw-rw- 1 root tty 4, 7 Jul 17 1994 tty7







crw-rw-rw- 1 root tty 4, 8 Jul 17 1994 tty8







crw-rw-rw- 1 root tty 4, 9 Jul 18 1994 tty9</FONT></PRE>







<P>In directory listings, the major device number is always shown first, followed by the minor device number. 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. You can't create a device number within the device driver or by numbering the files. You create device numbers with the command mknod (make node) and remove them with the rm command. You must use mknod every time you want to configure a new device on your system.







<BR>







<BLOCKQUOTE>







<BLOCKQUOTE>







<HR ALIGN=CENTER>







<BR>







<NOTE>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 in order to adjust their output. These types of exceptions are rare, luckily, and don't occur on most Linux systems. You do not have to create these types of device numbers because an installation script usually handles the setup of the device drivers and their numbers.</NOTE>







<BR>







<HR ALIGN=CENTER>







</BLOCKQUOTE></BLOCKQUOTE>







<BR>







<A NAME="E69E70"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>The </B><B>mknod</B><B> Command</B></FONT></CENTER></H4>







<BR>







<P>The mknod (make node) command is used for several different purposes. Its most common usages are to create a FIFO (first in first out) device file, which is a form of queue for the device, or a character or block mode device file. The format of the mknod command is







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">mknod [options] device b|c|p|u major minor</FONT></PRE>







<P>You can use the following options with this command:







<BR>







<UL>







<LI>The --help option displays help information and exits.







<BR>







<BR>







<LI>The -m (or --mode) option sets the mode of the file to mode instead of the default 0666 (symbolic notation only).







<BR>







<BR>







<LI>The -p option lets you set file permissions.







<BR>







<BR>







<LI>The --version option displays version information, and then exits.







<BR>







<BR>







</UL>







<P>The argument after the device or path name specifies whether the file is a block mode device , character mode device , FIFO device (p), or unbuffered character mode device(u). One of these arguments must be present on the command line for the device number to be properly assigned.







<BR>







<P>Following the type of file argument are two numbers for the major and minor device numbers assigned to the new file. You must supply these numbers; mknod does not generate them for you. Every device on a UNIX system has a unique number that identifies the type of device (the major number) and the specific device itself (the minor number). You must specify both a major and minor number for any new block, character, or unbuffered mode devices. You don't need to specify device numbers for a type p device. You can pull the major and minor device numbers out of thin air as long as they don't conflict with any other device, but there is a general numbering convention for all devices. These numbering systems are discussed in more detail in the chapters on specific devices later in this part.







<BR>







<BR>







<A NAME="E68E37"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Device Permissions and Links</B></FONT></CENTER></H3>







<BR>







<P>When you create a new device with the mknod command, it is given the permissions associated with the symbolic value 666. You can override this value either on the mknod command line (with the -p option) or by using chmod afterwards to change the permissions.







<BR>







<P>Device file permissions are important as they can control access to the device. For example, a CD-ROM drive is a read-only device, and changing the permissions to prevent write access can help forestall many error messages when a user tries to write to the CD-ROM. Permissions are also useful for creating read-only partitions on a disk, such as a directory of databases or utilities that you don't want anyone modifying. <A HREF="lsg17.htm">Chapter 17</A>, &quot;System Names and Access Permissions,&quot; looks at the chmod command and file permissions in more detail.







<BR>







<P>As a general rule, the default permissions are valid for most devices unless you want to lock out access. When Linux installs the device files, it sets all the system devices (such as /dev/mem, the physical RAM) with the proper permissions and you shouldn't change them.







<BR>







<BR>







<A NAME="E68E38"></A>







<H3 ALIGN=CENTER>







<CENTER>







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







<BR>







<P>This chapter introduced device drivers and device numbers, both of which are important when you add new hardware to your system. The next few chapters look at the different hardware that you can add to expand your Linux system and how they are configured. This chapter's information will be important as you configure Linux to accept new devices.







<P ALIGN=LEFT>























































</td>
</tr>
</table>

<!-- begin footer information -->



</body></html>

⌨️ 快捷键说明

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