• 欢迎访问速搜资源吧,如果在网站上找不到你需要的资源,可以在留言板上留言,管理员会尽量满足你!

【速搜问答】UNIX文件系统是什么

问答 admin 2年前 (2020-08-18) 461次浏览 已收录 0个评论

汉英对照:
Chinese-English Translation:

Unix文件系统是对存储设备上的数据和元数据进行组织的机制。UNIX文件系统是UNIX系统的心脏部分,提供了层次结构的目录和文件。

UNIX file system is a mechanism to organize data and metadata on storage devices. UNIX file system is the heart part of UNIX system, which provides hierarchical directory and file.

Unix 文件系统是对存储设备上的数据和元数据进行组织的机制。UNIX 文件系统是 UNIX 系统的心脏部分,提供了层次结构的目录和文件。

UNIX file system is a mechanism to organize data and metadata on storage devices. UNIX file system is the heart part of UNIX system, which provides hierarchical directory and file.

软件介绍

Software introduction

Unix 系统的产生和流行推动了操作系统的革命,它的设计思想和在发展过程中积累的丰富经验及教训仍可为人们借鉴。文件系统负责系统内文件信息的管理,在整个系统中起着至关重要的作用,文件系统是 Unix 成功的关键。Unix 系统采用树形文件结构、内核与外核的结合、设备与文件一样的管理机制和使用方法等技术和措施,使得 Unix 文件系统成为当代非常优秀的系统。

The emergence and popularity of UNIX system promotes the revolution of operating system. Its design ideas and rich experience and lessons accumulated in the development process can still be used for reference. The file system is responsible for the management of the file information in the system and plays an important role in the whole system. The file system is the key to the success of UNIX. UNIX system adopts tree file structure, the combination of kernel and external core, the same management mechanism and use method of devices and files, which makes UNIX file system become a very excellent system in the contemporary era.

管理结构

Management structure

Unix 文件系统是通过“磁盘索引 i 节点”、“目录项”来进行管理的,在文件被打开或被引用后还需要“内存索引 i 节点”、“用户文件描述表”、“文件表”。文件系统磁盘结构如图

UNIX file system is managed by “disk index I node” and “directory entry”. After the file is opened or referenced, it also needs “memory index I node”, “user file description table” and “file table”. The file system disk structure is shown in the figure

。管理块主要管理磁盘结构中各部分区域的大小及资源(i 节点,磁盘块)的使用情况与管理方式。i 节点区用于存放该文件系统全部磁盘 i 节点结构,磁盘索引节点包含文件的重要信息如下:文件所有者标识符;文件类型;文件存取许可权;文件联结数目;文件存取时间;文件长度;文件地址索引表。

。 The management block mainly manages the size of each part of the disk structure and the usage and management mode of resources (I node, disk block). The I node area is used to store all the disk i-node structure of the file system. The disk index node contains the following important information: file owner identifier; file type; file access permission; number of file connections; file access time; file length; file address index table.

Unix 的每个目录项只存放文件名和 i 节点号,共 16 个字节,而文件中除名字以外的信息都存放到 i 节点中,优点是系统各级目录的规模大大减少。在 Unix 文件系统中,为了提高系统效率,减少内存空间的占用,当打开一个文件时,只是将与该文件相联系的目录项和磁盘 i 节点拷贝到主存中,为了对打开的文件进行管理,因此又设置了打开文件管理机构,它又由下列三部分组成:

Each directory entry of UNIX only stores the file name and node i number, a total of 16 bytes, while the information except the name in the file is stored in the I node. The advantage is that the size of the directory at all levels of the system is greatly reduced. In UNIX file system, in order to improve the system efficiency and reduce the occupation of memory space, when a file is opened, only the directory entry and disk I node associated with the file are copied to the main memory. In order to manage the open file, an open file management mechanism is set up, which is composed of the following three parts:

1、活动 i 节点(内存 i 节点)。作用是反映文件当前活动的情况,因此它添加了一些项目:内存索引节点状态、设备号、索引节点号、内存索引节点的访问计数。

1. Active I node (memory I node). It reflects the current activity of the file, so it adds some items: memory inode status, device number, inode number, and access count of memory inode.

2、打开文件表。i 节点中只包含有文件的静态信息,但当一个文件被同一进程或不同进程、用同一或不同路径名、相同的或互异操作同时打开时,仅靠 i 节点就不能满足要求,因此,打开文件表记录了打开文件所需的一些附加信息:读写状态、引用计数、指向内存索引点的指针、读/写位置指针。

2. Open the file table. The I node only contains the static information of files, but when a file is opened by the same process or different processes, with the same or different pathnames, or with the same or different operations, it only depends on I Therefore, the open file table records some additional information needed to open the file: read-write status, reference count, pointer to memory index point, and read / write location pointer.

3、用户文件描述符表。每个用户进程有一个用户文件描述符表,每一个表项就是一个指针,并指向打开文件表的一个表项,这个表的作用就是保证每个进程能够打开多个文件,或者对同一个文件以不同形式操作打开。假定一个进程执行下列代码:

3. User file descriptor table. Each user process has a user file descriptor table. Each table entry is a pointer and points to a table entry of the open file table. The function of this table is to ensure that each process can open multiple files or open the same file in different forms. Suppose a process executes the following code:

fd1= open(”/etc/pad”,O- RDONLY);

fd1= open(”/etc/pad”,O- RDONLY);

fd1= open(”/etc/pad”,O- RDWD);

fd1= open(”/etc/pad”,O- RDWD);

则这三个表的作用和关系如图所示

The functions and relationships of the three tables are shown in the figure

物理结构

Physical structure

Unix 文件系统采用的是索引文件结构,在索引节点中建立有 13 个地址项,如图

UNIX file system adopts index file structure. There are 13 address entries in the index node, as shown in the figure

对于长度不超过 10 个物理块的小型文件,可直接找到该文件所在的盘块号;对于中、大型文件采用一次或两次间接寻址;对超大型文件采用三次间接寻址。索引节点的优点是:索引节点占用的空间小,对小文件的索引速度快,同时又允许组织大型和超大型文件。文件最多可占用的物理块数可达到 10+ 256+256^2+ 256^3 个。

For small files with no more than 10 physical blocks, the disk block number of the file can be found directly; for medium and large files, indirect addressing is used once or twice; for super large files, indirect addressing is used for three times. The advantages of inodes are: the space occupied by the inodes is small, the indexing speed of small files is fast, and large and super large files can be organized at the same time. The maximum number of physical blocks that a file can occupy can reach 10 + 256 + 256 ^ 2 + 256 ^ 3.

Unix 的统计数据表明,80%为小文件,20%为大文件(其中 1%为超大文件),这组数据就更加说明了 Unix 文件系统设计的精妙和科学。为了提高磁盘空间的利用率,允许文件在磁盘上不连续存放,且其寻址方式最多可达到三次。它的缺点是造成访问文件的寻道时间延长和多次访问磁盘。在非实时场合是可行的,但在实时场合,它的这一缺点就很突出。例如:假设磁盘的平均寻道时间为 15ms,每个磁盘块的大小为 512 字节,某文件大小为 3kB,如果连续存放,寻道时间只需 15ms;如果不连续存放,它要占用 6 个分散的磁盘块,可能位于不同的磁道,因此寻道时间需 90ms,比连续存放多浪费 75ms。

According to the statistical data of UNIX, 80% are small files, 20% are large files (1% of them are super large files). This group of data shows the exquisite and scientific design of UNIX file system. In order to improve the utilization of disk space, files are allowed to be stored on the disk discontinuously, and the addressing mode can be up to three times. The disadvantage of this method is to prolong the seek time of accessing files and visit the disk many times. It is feasible in the non real-time situation, but in the real-time situation, this shortcoming is very prominent. For example, suppose that the average seek time of the disk is 15ms, the size of each disk block is 512 bytes, and the size of a file is 3KB. If the disk is continuously stored, the seek time only needs 15ms; if it is not stored continuously, it will occupy 6 scattered disk blocks, which may be located in different tracks. Because of this, the seek time takes 90 ms, which is 75 ms more than that of continuous storage.

空闲磁盘块

Free disk block

Unix 文件系统通过管理块来实现空闲块管理。管理块的数据结构如下:struct filsys{int s- isize; /*i 节点区总块数*/int s- fsize; /*文件卷总块数*/int s- nfree; /*直接管理的空闲块数*/int s- free[100] ; /*空闲块号栈*/int s- ninode; /*直接管理的空闲 i 节点数*/int s- inode[100] ;/*空闲 i 节点号栈*/… …}

UNIX file system realizes free block management by managing blocks. The data structure of the management block is as follows: struct Filsys {int s – isize; / * total number of blocks in node area * / int s – fsize; / * total block number of file volume * / int s – nfree; / * number of free blocks managed directly * / int s – free [100]; / * number of free I nodes managed directly * / int s – inode [100]; / * number of free I nodes managed directly * / int s – inode [100]; / * number of idle I nodes * /… ”  … }

空闲块的管理方法是:将空闲块从后向前,若干个空闲块(如 100 个)分为一组(最后一组为 99 块),每组最后一块作为索引表,用来登记下一组 100 的物理块号和块数,最前的一组物理块号和块数存放在管理块的 s_free[100]和 s_nfree 中。这种对空闲块先分组,再把组与组进行链接的管理方法称为组链接法。对空闲块的分配和释放类似于栈,使用后进先出算法。但其管理机构分为两级,一级常驻内存(管理块的 s-nfree 和 s-free[]),另一级则驻在各组的第一个盘块上。其优点是常驻内存的只有一个组,而不是将所有组的空闲表都调入内存,这样就大大的节省了内存空间,同时软件开销也小。缺点是可能导致物理块的利用率不均匀。例如:假设当前的 s-nfree= 80,此时某进程释放一个文件块,其占用的物理块号为 300,系统回收它后,s-nfree= 81,s-free= 300。接着某用户又申请物理空间,文件系统总是从索引表中取最后一项的值,即 s-free 出栈,将 300 号物理块又立即分配使用。可以想象,300 号块还会面临再释放,再分配的可能。300 号块多次被使用,而其它空闲块却未被分配使用,即有些物理块可能长期被使用,而有些物理块可能长期得不到使用,因此对外存储器的使用寿命不利。

The management method of free blocks is: from back to front, several free blocks (such as 100) are divided into a group (the last group is 99 blocks). The last block in each group is used as an index table to register the physical block number and block number of the next group of 100. The first group of physical block numbers and block numbers are stored in s of the management block_ Free [100] and S_ Nfree. This kind of management method is called group linking method, in which the idle blocks are grouped first and then linked with groups. The allocation and release of free blocks is similar to stack, using the last in first out algorithm. However, the management mechanism is divided into two levels, one is memory resident (s-nfree and s-free [] of management block), and the other is located on the first disk of each group. The advantage of this method is that there is only one group resident in the memory, instead of transferring all the free tables of the groups into the memory, so the memory space is greatly saved, and the software cost is also small. The disadvantage is that it may lead to uneven utilization of physical blocks. For example: suppose the current s-nfree = 80, a process releases a file block, and the physical block number occupied by it is 300. After the system recycles it, s-nfree = 81, s-free = 300. Then a user applies for physical space. The file system always takes the value of the last item from the index table, that is, s-free, and allocates physical block No. 300 to use immediately. It can be imagined that block 300 will face the possibility of re release and redistribution. Block 300 is used many times, while other free blocks are not allocated for use, that is, some physical blocks may be used for a long time, while some physical blocks may not be used for a long time, so the service life of external memory is unfavorable.

结构和共享

Structure and sharing

Unix 的文件系统采用多级树型目录结构,其优点是有效的解决了文件重名问题,又可以很方便地实现文件共享。基本文件系统和子文件系统是可安装和可拆卸的,但在多用户环境下,多用户间共享数据同样感到不方便,绝对路径名是文件的唯一符号名,用户难以用另外符号名使用共享文件,因此 Uinx 文件又提供了如下两种链接机制。

The file system of UNIX adopts multi-level tree structure, which can effectively solve the problem of file name duplication and realize file sharing conveniently. The basic file system and sub file system are installable and detachable. However, in the multi-user environment, it is also inconvenient for users to share data. Absolute path name is the only symbolic name of a file, which makes it difficult for users to use other symbolic names to share files. Therefore, UINX file provides the following two link mechanisms.

1、硬链接技术。如果想为文件 1.c 建立一个硬链接 2.c,则只需将 2.c 的目录项指针指到文件 1.c 的 i 节点,同时将 i 节点链接数加 1 即可。这样用户似乎是增加了一个物理拷贝,可实际却只有一个文件实体,当删除链接时,只要删除一个目录项和将链接数减 1。

1. Hard link technology. If you want to establish a hard link 2. C for file 1. C, just point the directory entry pointer of 2. C to the I node of file 1. C, and add the number of I node links by 1. In this way, the user seems to have added a physical copy, but actually there is only one file entity. When deleting a link, he only needs to delete a directory entry and reduce the number of links by 1.

2、符号链接技术。如果想为 usr/sxk/1.c 建立一个符合链接 2.c,则 Unix 通过 read link 读出文件内容,即找到原文件路径名,再通过原文件路径名去打开文件。符号链接相当于给文件增加了一个别名。也可为目录建立符号链接,并且可以跨文件系统。Unix 文件链接的优点是用很小的开销为多用户共享文件提供了有效方式,且能快速定位文件和目录;缺点是对多用户使用文件不能加以并发控制,易造成数据的不一致性。硬链接只适用于普通文件,而不适用于目录文件和不同文件系统。

2. Symbolic link technology. If you want to create a compliant link 2. C for usr / SXK / 1. C, UNIX reads the file content through read link, that is, finds the original file path name, and then opens the file through the original file path name. Symbolic links add an alias to the file. You can also establish symbolic links for directories and cross file systems. The advantage of UNIX file link is that it provides an effective way for multi-user to share files with a small cost, and it can quickly locate files and directories; the disadvantage is that multi-user files can not be controlled concurrency, which easily leads to data inconsistency. Hard links only apply to ordinary files, not to catalog files and different file systems.


速搜资源网 , 版权所有丨如未注明 , 均为原创丨转载请注明原文链接:【速搜问答】UNIX文件系统是什么
喜欢 (0)
[361009623@qq.com]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址