文件系统概括
文件系统是存储在 Disk 上的,因为我们需要永久的保存文件,而不是在关机以后就把数据丢掉!除非特殊说明,我下面提到的所有东西都是存储在 Disk 上的。假设我们有一个1T的硬盘,我们可以把它划分成一个或多个分区,每个分区都可以有各自的文件系统。接下来,我们把这个硬盘分成一个带有 Unix File System(UFS) 的分区,那么这个分区大致包含以下4个结构:
- Boot Control Block:information needed by the system to boot from that volume
- Superblock:volume or partition details, such as the number of blocks in the partition, size of the blocks, freeblock count and free-block pointers, and free FCB count and FCB pointers
- Directory structure:in UFS, this includes file names and associated inode numbers
- File Control Block:contains file details including permissions, ownership, size, and location of the data blocks. In UFS, this is called the inode
下面我总结一些常见的误区和容易混淆的概念!
1、一个 Unix 文件包括两部分:the data blocks(文件的实际内容) and the inodes(文件的元数据,比如文件大小,创建日期,指向 data blocks 的指针等)。
2、目录并不包含文件,它本身实际上就是一个文件!因此像所有文件一样,目录的元数据存储在 inodes 中,inodes 中有指向实际内容(data blocks)的 pointers. 那么一个目录的 data blocks 包含什么呢?答案是:目录中文件的名字和与之相对应的 inode number(它们2个结合在一起成为一个 Directory Entry). The file’s actual attributes and pointers to disk blocks are kept elsewhere, in the inode for the file. Therefore, Directories(or Directory Structure) can be thought of as “files containing lists of names and inode numbers”. Files have data blocks containing file data; directories also have data blocks; but, the blocks contain lists of names and inode numbers. If a directory is damaged in Unix, only the names are lost, not any of the file data blocks or the file attributes. 因此,当我们给定一个文件名字的时候,可以通过搜索相应目录结构得到一个 Directory Entry,然后得到相应的 inode number,再通过 inode number 得到对应的 inode.
文件的逻辑结构
The file system consists of two distinct parts: a collection of files, each storing related data, and a directory structure, which organizes and provides information a