This chapter starts with the Unix file system.
How does a file system manage files? Let's start with the file's storage media--disk
A disk is a hardware device for a computer system in order to manage the disk. It is three layers of abstraction (this article all refers to the Unix file system, the Windows file system interested in the students to study their own!)! ~
The first layer of abstraction: partitioning a whole block of disks
Second layer of abstraction: cutting disk to block
The third layer of abstraction: logically dividing blocks into four regions
And the third level is the part we're going to look at.
The partitions of the UNIX system are as follows:
| Boot block |
Super Block |
I node table |
File Storage Area |
(1) Guide BLOCK: Block No. No. 0. Is the first block of each file system that stores the kernel program that is used to boot the operating system when the system boots, when the entire file system is composed of multiple file systems. Only the boot block of the root file system is valid.
(2) Super Block: Block 1th, usually also become a management block. is the second block of the file system and the head of the file system. Store all management information for installing and managing file systems. Contains the file system size, the device area where the file system resides, the I node table size, the spare space size, and the spare list first.
(3) I node table: A piece of disk area composed of several blocks, I node table in the Super block indicated, an I node number corresponding to a file, I node related content such as the following:
Mode
|
Type
|
Uid
|
Gid
|
Link.no
|
Size
|
addr.pt
|
Time
|
Occupancy flags. 0: Empty, 1: Occupied
|
File type
|
Owner
|
Genus Group
|
Number of links
|
Size
|
Pointer to the actual data block of the file
|
Recent interview/Change date time
|
The properties of each file system, such as size, all files, recent changes, etc., are recorded in the I-node structure. All I-nodes have the same size
(4) file storage: Except for the first three parts. The rest of the space is the file store, which accounts for the vast majority of the storage space.
Life is short, let's see it through examples
First, create the file: How the file system allocates the three regions
Perform a cat spwd.c > Test
So what does this process file system do? (As for the inside of the pipeline, there is time will have a special article to analyze)
The steps you create, such as
There are four main operations to create a file
1. Find an empty I-node store file properties
2. The kernel finds several blocks that can store the file size from the free data block. The storage data graph is to find a,b,c three blocks
3. Record the A,b,cblock to the 40th Block I node (i-node, can store 13 blocks altogether. Only 10 data blocks can be stored. After 3 space in the presence of large file use, 11 block called two-level indirect block, 12 block called three-level indirect block, 13? That means the file is too large, you need to define the size of the block again, Block big, natural I-node can be put down)
4. Add I-node to the target. The mapping relationship is 40:test, and the folder below discusses
Ii. What is a folder
A folder is a special file that includes a list of file name words, different systems are implemented differently, but the abstract model is basically consistent-------I-node and file name lists.
Knowing this is almost the same.
Third, how is the document read out?
Can be seen as a reverse operation to create a file.
1, go to folder to find the same as the test file name I-node number
2, go to the order of the 40i-node to find the record blocka,b,c
3. Read A,b,c
4. Copy to User space
It is important to note that the all-in-one process is in kernel space. The 4th step is to the user stack space, where the kernel state and user state are involved. There is still no discussion here, too much content.
The above, but a rough introduction, the file system involves a lot of content, such as large file storage. Integration of multiple file systems, virtual file systems, etc.
Before you finish this article. Another sentence, a block is 5 1 2 bytes, we often use the size option in the Find command is BLCOK for calculation. Use of the Find command please consult the man find manual for yourself
As for whether it is 5 1 2 bytes, let's practice it. Spwd is 9,368 bytes
Execute the Find. -type f-size +19
Find files with a file type that is larger than 19 blocks in the current folder under Type.
Not found, then we execute find. -type f-size +18 (18*512=9126)
OK, I found it.
We'll be here today. File properties and folders are discussed next
JAVA File class Analysis (ii)