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

📄 0195-0197.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:


<HTML>

<HEAD>

<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:Filesystems, Disks, and Other Devices</TITLE>

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

 -->




<!-- ISBN=0672311739 //-->

<!-- TITLE=RED HAT LINUX 2ND EDITION //-->

<!-- AUTHOR=DAVID PITTS ET AL //-->

<!-- PUBLISHER=MACMILLAN //-->

<!-- IMPRINT=SAMS PUBLISHING //-->

<!-- PUBLICATION DATE=1998 //-->

<!-- CHAPTER=11 //-->

<!-- PAGES=0195-0228 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="../ch10/0189-0194.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0198-0200.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-195"><P>Page 195</P></A>









<H3><A NAME="ch11_ 1">

CHAPTER 11

</A></H3>











<H2>



Filesystems, Disks,<BR>

and Other Devices



</H2>









<B>by James Youngman</B>









<H3><A NAME="ch11_ 2">

IN THIS CHAPTER

</A></H3>









<UL>

<LI>     Block Devices



<LI>     Filesystems



<LI>     The mount Command



<LI>     Setting Up Filesystems



<LI>     Creating New Filesystems



<LI>     Repairing Filesystems



<LI>     Hardware



<LI>     Character Devices

</UL>



<A NAME="PAGENUM-196"><P>Page 196</P></A>













<P>One of the simplest and most elegant aspects of UNIX (and Linux) design is the way that

everything is represented as a file. Even the devices on which files are stored are represented

as files.

</P>









<P>Hardware devices are associated with drivers that provide a file interface; the special files

representing hardware devices (or just devices) are kept in the directory

/dev. Devices are either block devices or character devices.

</P>









<P>A character device is one from which you can read a sequence of characters&#151;for example,

the sequence of keys typed at a keyboard or the sequence of bytes sent over a serial line. A

block device is one that stores data and offers access to all parts of it equally; floppy and hard disks

are block devices. Block devices are sometimes

called random access devices, just as character devices are sometimes called

sequentially accessed devices. With the latter, you can get data

from any random part of a hard disk, but you have to retrieve the data from a serial line in the

order it was sent.

</P>









<P>When you perform some operation on a file, the kernel can tell that the file involved is a

device by looking at its file mode (not its location). The device nodes are distinguished by having

different major and minor device numbers. The major device number

indicates to the kernel which of its drivers the device node represents. (For example, a block device with major number 3

is an IDE disk drive, and one with the major device number 8 is a SCSI disk.) Each driver

is responsible for several instances of the hardware it drives, and these are indicated by the

value of the minor device number. For example, the SCSI disk with the minor number 0

represents the whole &quot;first&quot; SCSI disk, and the minor numbers 1 to 15 represent fifteen possible

partitions on it. The ls command prints the major and minor device numbers for you:

</P>





<!-- CODE //-->

<PRE>

$ ls -l --sort=none /dev/sda{,?,??} /dev/sdb

brw-rw----   1 root     disk       8,   0 Sep 12  1994 /dev/sda

brw-rw----   1 root     disk       8,   1 Sep 12  1994 /dev/sda1

brw-rw----   1 root     disk       8,   2 Sep 12  1994 /dev/sda2

brw-rw----   1 root     disk       8,   3 Sep 12  1994 /dev/sda3

brw-rw----   1 root     disk       8,   4 Sep 12  1994 /dev/sda4

brw-rw----   1 root     disk       8,   5 Sep 12  1994 /dev/sda5

brw-rw----   1 root     disk       8,   6 Sep 12  1994 /dev/sda6

brw-rw----   1 root     disk       8,   7 Sep 12  1994 /dev/sda7

brw-rw----   1 root     disk       8,   8 Sep 12  1994 /dev/sda8

brw-rw----   1 root     disk       8,   9 Sep 12  1994 /dev/sda9

brw-rw----   1 root     disk       8,  10 Sep 12  1994 /dev/sda10

brw-rw----   1 root     disk       8,  11 Sep 12  1994 /dev/sda11

brw-rw----   1 root     disk       8,  12 Sep 12  1994 /dev/sda12

brw-rw----   1 root     disk       8,  13 Sep 12  1994 /dev/sda13

brw-rw----   1 root     disk       8,  14 Sep 12  1994 /dev/sda14

brw-rw----   1 root     disk       8,  15 Sep 12  1994 /dev/sda15

brw-rw----   1 root     disk       8,  16 Sep 12  1994 /dev/sdb

</PRE>

<!-- END CODE //-->











<P>The obscure options to this ls command ensure that the devices are presented in this order.

If just ls -l had been used, the entries would have been sorted alphabetically, and

/dev/sda10 would have come before /dev/sda2.

</P>



<A NAME="PAGENUM-197"><P>Page 197</P></A>













<P>The b at the far left indicates that all of these are block devices. (Character devices are

indicated by a c.) The major and minor device numbers appear just before the time field, separated

by commas. (This is the position normally occupied in

ls -l output by the file's size.)

</P>









<H3><A NAME="ch11_ 3">

Block Devices

</A></H3>









<P>If you had just one file of data to store, you could put it directly on a block device and read

it back. Block devices have some fixed capacity, though, and you would need some method

of marking the end of your data. Block devices behave in most respects just like ordinary

files, except that although an ordinary file has a length determined by how much data is in it,

the &quot;length&quot; of a block device is just its total capacity. If you wrote a megabyte to a 100MB

block device and read back its contents, you would get the 1MB of data followed by 99MB of

its previous contents. Bearing in mind this restriction, there are still several UNIX utilities

that encode the amount of data available in the file's data rather than the file's total length,

and hence are suitable for storing data directly on block devices&#151;for example,

tar and cpio, which are suitable for everybody; and

dump, which is suitable only for the system administrator

(because it requires read access to the block device underlying the data to be backed up). To

back up the entire contents of your home directory to floppy disk, you would type the following:

</P>





<!-- CODE SNIP //-->

<PRE>

$ tar cf /dev/fd0 $HOME

</PRE>

<!-- END CODE SNIP //-->











<P>

or

</P>





<!-- CODE SNIP //-->

<PRE>

$ find $HOME -print0 | cpio --create -0 --format=crc &gt;/dev/fd0

</PRE>

<!-- END CODE SNIP //-->











<P>The -print0 and -0 options for find and cpio ensure that the names of the files to be

backed up that find sends to cpio are separated by ASCII NULs, rather than newlines. This

ensures that any filenames containing a newline are correctly backed up.

</P>

<P>

<P>



<CENTER>

<TABLE BGCOLOR="#FFFF99">

<TR><TD><B>

NOTE

</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

The only characters that are illegal in UNIX filenames are the slash and the ASCII NUL.

</BLOCKQUOTE></TD></TR>

</TABLE></CENTER>

</P>

<P>These backup utilities are written specifically to write their backups to any kind of file; in

fact, they were designed for sequentially accessed character devices&#151;for example, tape

drives.

</P>









<H3><A NAME="ch11_ 4">

Filesystems

</A></H3>









<P>When you have more than one item of data, it is necessary to have some method of

organizing files on the device. These methods are called

filesystems. Linux enables you to choose any organizational method to marshal your files on their storage device. For example, you can use

the MS-DOS filesystem on a floppy, or the faster

ext2 filesystem on your hard disk.

</P>



<P><CENTER>

<a href="../ch10/0189-0194.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0198-0200.html">Next</A>

</CENTER></P>









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

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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