4.2 Implementation of the file system

Insert picture description here

4.2.1 File system hierarchy

1. User call interface
Insert picture description here
Insert picture description here

4.2.2 Directory implementation

1、线性列表

Organize the file names into a linear table, and compare each entry in the linear table in turn when searching.

2、哈希表

The file name obtains a pointer to the file through the hash function. This method is very fast, but you must pay attention to avoid conflicts.

4.2.3 File realization

1. File distribution method

1)连续分配方式
Insert picture description here
Each file is stored on the disk as a series of consecutive data blocks. Therefore, on a disk with a block size of 1KB, 50 consecutive blocks are allocated for a 50KB file. For a disk with a block size of 2KB, 25 consecutive blocks are allocated.

优点:Simple implementation, fast access speed is
缺点:not conducive to additions and deletions, repeated additions and deletions will produce外部碎片

2)链接分配

Connection allocation Discrete distributionWay, there 隐式链接and 显式链接in two ways.

(1) Implicit link

advantage: 消除了外部碎片,显著提高了磁盘利用率,对增删改也非常方便

Disadvantages: 无法直接访问盘块,只能通过指针顺序访问文件

Insert picture description here
(2) Explicit link

Explicit linking is to extract the pointers of implicitly linked physical blocks from the end of each physical block.Explicitly stored in a linked list in memoryThe table 文件分配表(FAT)entries correspond to the disk blockThere is only one table for the entire disk

Insert picture description here

-1 Means The last piece of the file
-2 Means Disk block free

FAT table at system startup 就被装入内存

优点:Not only records the sequential connection between the blocks of the file, but also records the free disk blocks, there will be no fragmentation, and random access is supported

3)索引分配

In order to solve链接分配不能支持直接访问(FAT除外) Index allocation solves this problem.

把所有文件的磁盘块号集中存放在一起 Compose index table


Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


2. File storage space management

Insert picture description here


1、空闲表法 (Continuous allocation)

  • 把所有空闲块组织成表
    Insert picture description here

2、空闲链表法

There are two main forms:空闲盘块链 空闲盘区链

空闲盘块链(Suitable for discrete)

空闲盘区链(Applicable to both discrete and continuous)

Insert picture description here

  • The free extent chain will be all on the disk Free panel Pull into a chain (每个空闲盘区可包含若干盘块)

3、位示图法

一个字长为16bit,每个bit代表一个盘块

0 Means 空闲
1 Means 已分配
Insert picture description here


4、成组链接法

空闲链表法And 空闲表法do not apply toLarge file system
UINIX system uses Group Link Method

Guess you like

Origin blog.csdn.net/weixin_38220799/article/details/109263374