Operating System Chapter 4 _03 File Directory

Knowledge overview

insert image description here

file control block

insert image description here
insert image description here
What needs to be done with the directory?
Search: When a user wants to use a file, the system searches the directory according to the file name and finds the directory entry corresponding to the file
Create file: When creating a new file, you need to add a directory entry to the directory to which it belongs
Delete file: When deleting When there is a file, the corresponding directory entry needs to be deleted in the directory.
Display directory: the user can request to display the contents of the directory, such as displaying all files in the directory and their corresponding attributes
Modify the directory: some file attributes are stored in the directory, so these attributes Changes need to modify the corresponding directory items (such as: file renaming)

Single level directory structure

Early operating systems did not support multi-level directories. Only one directory table was established in the entire system, and each file accounted for one directory entry.
A single-level directory implements "access by name", but does not allow file names to be duplicated. When creating a file, it is necessary to first check whether there are files with the same name in the directory table, and only after confirming that there are no identical names can the file be created, and the directory entry corresponding to the new file is inserted into the directory table.
Obviously, a single-level directory structure is not suitable for a multi-user operating system.

insert image description here

Two-level directory structure

Early multi-user operating systems used a two-level directory structure. Divided into master file directory (MFD, Master File Directory) and user file directory.

insert image description here

multi-level directory

insert image description here
When a user (or user process) wants to access a file, the file is identified by the file path name, which is a string. The directories at all levels are separated by "/". A path from the root directory is called an absolute path.
For example: the absolute path of selfie.jpg is "/photos/2015-08/selfie.jpg" and the system finds the next directory layer by layer according to the absolute path. Just start reading the directory table of the root directory from the external storage; after finding the storage location of the "photos" directory, read the corresponding directory table from the external storage; then find the storage location of the "2015-08" directory, and then read from the external storage Enter the corresponding directory table; finally find the storage location of the file "selfie.jpg". The whole process requires 3 read disk I/O operations.
Many times, users will continuously access multiple files in the same directory (for example, viewing multiple photo files in the "2015-08" directory one after another),
obviously, it is very inefficient to search from the root directory every time. So a "current directory" can be set.

For example, the catalog file of "photos" has been opened at this time, that is to say, this catalog table has been transferred into the memory, so it can be set as the "current catalog". When a user wants to access a file, a "relative path" from the current directory can be used.
In Linux, "." means the current directory, so if "photos" is the current directory, the relative path of "selfie.jpg" is: "./2015-08/selfie.jpg". Starting from the current path, you only need to query the "photos" directory table in the memory to know the storage location of the "2015-08" directory table, and transfer the directory from the external memory to know the storage location of "selfie.jpg" .
It can be seen that after the introduction of "current directory" and "relative path", the number of disk I/Os is reduced. This improves the efficiency of accessing files.

Acyclic graph directory structure

insert image description here

You can point to the same file with different filenames, or even to the same directory (sharing everything under the same directory).
A shared counter needs to be set for each shared node to record how many places are sharing the node at this time. When a user requests to delete a node, it only deletes the user's FCB and decrements the shared counter by 1, and does not delete the shared node directly.
The node is deleted only when the shared counter is decremented to 0.
Note: Sharing a file is not the same as copying a file. In a shared file, since each user points to the same file, as long as one user modifies the file data, all users can see the change of the file data.

inode

insert image description here
insert image description here

Knowledge Review

insert image description here

Guess you like

Origin blog.csdn.net/qq_52077949/article/details/124353094