Super block, node I, a data block, directory blocks, indirect blocks,

First, the physical disk to the file system

File system used to store file content, file properties, and directories, and how these types of data stored on disk block it? Unix / linux using a simple method.

 

 

 He disk is divided into three parts:

  1. Super block, the first block of the file system is called a super block, the block storage file structure information he could bear itself. For example, the size of each super block recording area, the information stored also superblock disk blocks to be used.
  2. i_ node table. The next part is i- superblock node table, each file has an attribute, file size, file owner, creation time, and the like, these properties are called a record structure i- node. I- nodes all have the same size, and i- node table is a list of these structures, each file in the file system table has a i- node.
  3. Data area. The third part of the file system is a data area. Contents of the file saved in this area, the size of all the blocks on the disk are the same, if the file contains the contents of more than one block, the contents of the file will be stored in multiple disk block, a large files easily distributed thousands independent of disk blocks.

2. Create a file of procedure

We now know the contents and properties of files are stored separately, it is how they manage it? Now we have to create a file as an example to explain. At the command line, type the command:
$ the WHO> UserList
upon completion of this command. File system adds a new file to store the contents of the output of the command who, then this whole process in the end is how it happened?
Attributes and contents of the file: kernel file content stored in the data area, file attributes stored in the i- node, the file name stored in the directory. Figure 2 shows the example of creating a file, if the file to the new memory block 3 to store the contents.

 

 

 

It comprises the following four steps:

1) storage attributes, which is stored in the file properties, the kernel first find an empty i- node. 2 FIG. Kernel finds i- node number 47. The kernel information file recording them. The file size, file owner, creation time, etc., and
2) to store data, i.e., the file content is stored, since the file requires three pieces of data. Therefore, the kernel found three blocks from the free list of free blocks. FIG 2 respectively 627,200,992, a copy of data block 627 to the kernel buffer, the second and third, respectively 200 and copied to 992.
3) distribution record, save the data to three data blocks . It is necessary to record up later to find the right data. No. list of disk allocation recorded in the i- node's file. These three numbers are placed in three locations beginning.
4) add the file name to the name of the directory, the new file is userlist, the kernel will file entry (47, userlist) added to the catalog file. Correspondence between the file name and i- node number to the file name and content attributes of files and connect, locate the file name to find i- node number of the file, you can find properties and content files via i- node number.

It comprises the following four steps:

1) storage attributes, which is stored in the file properties, the kernel first find an empty i- node. 2 FIG. Kernel finds i- node number 47. The kernel information file recording them. The file size, file owner, creation time, etc., and
2) to store data, i.e., the file content is stored, since the file requires three pieces of data. Therefore, the kernel found three blocks from the free list of free blocks. FIG 2 respectively 627,200,992, a copy of data block 627 to the kernel buffer, the second and third, respectively 200 and copied to 992.
3) distribution record, save the data to three data blocks . It is necessary to record up later to find the right data. No. list of disk allocation recorded in the i- node's file. These three numbers are placed in three locations beginning.
4) add the file name to the name of the directory, the new file is userlist, the kernel will file entry (47, userlist) added to the catalog file. Correspondence between the file name and i- node number to the file name and content attributes of files and connect, locate the file name to find i- node number of the file, you can find properties and content files via i- node number.

Third, the process of creating a directory

I said earlier about the process of creating a file, create a directory Shiyou is how it happened?
We know that the file is actually a directory, but its contents are special: a file that contains a list of names, the list usually consists of two parts: i- node number and file name. So it's creation and file creation process the same, but different second step of writing content. Includes a directory to create at least two links: ".", ".."
We can see the contents of the directory through the system command: #ls -lia

 

 It is a graph of the results corresponding to the file name and node number i-, where "." Indicates the current directory, and ".." is the parent of the current directory. But there are special circumstances, we see the root of the situation:

  1. <span style="font-family:Microsoft YaHei;">[root@localhost ~]# ls -i1a /

  2. 2 .

  3. 2 ..

  4. 98305 .autofsck

  5. 1310721 backup</span>

We found "." And ".." are actually pointing to i- node 2. When you create a file system using mkfs, mkfs parent directory will point to the root directory of your own

Fourth, how to achieve if there is a large file

The distribution of the content of the document is to be recorded in the disk number of nodes in the i- list. But i- node contains only a distribution list contains up to 13 items, how to do if the data block allocation of more than 13 blocks?
Linux use an indirect block to solve this problem. For example, we want to record the number of 14 blocks, you can put in front of 10 recorded in the disk number of nodes in the list i-. 4 in a further number of data blocks. Storing pointer data recording block number, a pointer to find this number by the remaining four data blocks in item 11 i- node, the data is used to store the number called indirect block. The truth is, and certain goods on the shelves and in the rest of the warehouse, and make a note of the serial number label specific location in the warehouse of the same.
But when indirect block also is full we can re-open the second indirect block, even 3,4,5. . . More extra block. However, the kernel will not be recorded in the blocks 12 and 13 item i- node's file. But to open up a new list of blocks to store these indirect blocks, and the number of new store additional blocks in item 12 i- node. This kept the block numbers 2,3,4, and stores the number of the subsequent additional block, this block is called second indirect block.
Similarly when saturated indirect block can have two open third stage.

Guess you like

Origin www.cnblogs.com/ghl666/p/12033434.html