The underlying principle of linux file system

The file in the Linux file system is a collection of data. The file system not only contains the data in the file but also the structure of the file system. All files, directories, soft links and file protection information seen by Linux users and programs are stored in the file system. in.

Bottom Schematic:

Before explaining each block, first introduce the inode

Introduction to inodes

To understand inodes, you must first understand how files are stored. We all know that files are stored on the hard disk. The smallest unit of a hard disk is a sector, and each sector is 512 bytes in size.
If the system reads the hard disk data one by one, the efficiency is too low. Instead, multiple sectors are read continuously at one time, so the designer integrates multiple sectors into one block. (block), so a block is the smallest unit of file access. A block is 4k in size.
We now have the concept of blocks, and file data is stored in blocks. But data alone is not enough? In order to manage files conveniently, we also need the meta information of the file, such as file attributes, creation time, permissions, block size, number and so on. This information is inode information. Therefore, the hard disk will be divided into two areas when partitioning, one area stores data, and the other area stores inode information.
Each file has a corresponding inode.

inode information

Use the stat command to view the inode information of the corresponding file:

The specific content is as follows:
file name
inode number
file owner uid
file belonging user group gid
file readable, writable, executable permissions: Access: (0755/drwxr-xr-x)
Timestamp of the file:

  • access time : the last time the file was opened
  • modify time: the time when the file content was last modified
  • change time : The time when the inode information of the file was last changed

The number of hard links: the blocks occupied by the links
file data: the number of bytes occupied by the blocks
file, size
, etc.
Everything under Linux is a file, and each file has corresponding inode information.

Regarding the inode number, I will say the following here. Each file corresponds to an inode number. The operating system uses the inode number to identify the file. For the system, the file name is an alias or nickname that is easy to identify with the inode number.
On the surface, opening a file is based on the file name. In fact, the following three steps are performed:
1. Find the inode number of the file
2. Find the inode information according to the inode number
3. Find the file according to the inode information. read and write.

inode size

The size of an inode node is generally 128 bytes or 256 bytes. The number of inode nodes is given when the hard disk is formatted. Therefore, when too many files are created on Linux, the problem of running out of inodes and unable to create new files may occur .

View inode information command

View the inode number of each file in each directory
ls -i

View the inode information of the corresponding file
stat [file]

View the total number of inodes on the hard drive and where applicable
df -i

View the total number and usage of blocks (1k-blocks) on the hard disk
df -k

 

super block: responsible for controlling the overall situation, that is, managing all inode numbers

inode block: responsible for storing meta information of files

directory block: responsible for storing the file information in the directory, that is, one record, including the file name and inode number

data block (ie the remaining block): responsible for storing the data of the file

View the file diagram:

Schematic diagram of deleting files:

----- The file is not really deleted, only by overwriting it is possible to actually delete it (that is, the newly created file just uses this block to store data, that is, the original data is overwritten)

-----Format: Rebuild these blocks

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325374467&siteId=291194637