Home > Operation and Maintenance > Linux Operation and Maintenance > What are the reasons why file creation fails in Linux?

What are the reasons why file creation fails in Linux?

青灯夜游
Release: 2022-06-10 19:18:41
Original
6792 people have browsed it

Reasons for Linux file creation failure: 1. The disk space corresponding to the current directory is insufficient; when creating a file in a certain directory, it is actually operated on the disk corresponding to the directory. If the disk is full , the creation will naturally fail. 2. Insufficient inodes; since one file corresponds to one inode, when there are too many small files on the disk, there will be a lot of blocks, but the inodes have been allocated, that is, there is still a lot of space, but it cannot be created. That is because the file is created. When, the application for inode number failed.

What are the reasons why file creation fails in Linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Failed to create a file

Failure to create a file in a Linux system is relatively common. Of course, creating a file here does not only mean that the user manually creates a file. , more often than not, some network services, log systems, etc. need to continuously write files and create files. It is rare that a real user fails to create a file. Next we analyze some why the creation fails.

Cause for file creation failure:

1. The disk space corresponding to the current directory is insufficient

According to the above description, When creating a file in a certain directory, it is actually operated on the disk corresponding to the directory. If the disk is full, the creation will naturally fail. A more specific description is: when creating the file, the application for block fails. You can use the following command to check:

# 查看当前目录所在磁盘的空间使用情况
df -h ./
Copy after login

2. Insufficient inode

This is another reason why file creation fails. Since a file corresponds to an inode, when there are too many small files on the disk, there will be a lot of blocks, but the inode has been allocated, that is, there is still a lot of space, but it cannot be created. This is because when creating a file, an inode number is applied for. fail. You can use the following command to confirm whether the innode has been allocated

# 查看当前目录所在磁盘的inode的使用情况
df -i ./
Copy after login

Expand knowledge: several key nouns

  • superblock: use more popular words The explanation is: superblock manages a disk area, and all operations on files (creation, access, deletion) must go through superblock, which acts as a disk management housekeeper.

  • Inode: A small disk area pre-divided with disk formatting. Generally, each inode is 128 bytes. It is used to record file permissions, attributes, occupied blocks and other information. Each file corresponds to an inode. The application and return of inodes are managed by superblock. The number of inodes is limited.

  • block: where the file content is actually stored. The size of the block is also divided according to the disk format. Depending on the system, each block can be 1K, 2K, or 4K in size. The content of the file must occupy an integer number of blocks. If the remaining space is used up, it is wasted. For example: each block is 4K. If there is a file with a size of 1K, then a block needs to be allocated to it. The remaining 3K of this block cannot be used by other files. It's called disk fragmentation. Another situation is that a file is 10K, then it needs to occupy 3 blocks, the actual usage rate is 10/12, and the numbers of these three blocks are recorded in the inode corresponding to the file.

  • Mount point: In the Linux system, each physical disk is mounted in a certain directory. Creating a file in this directory is equivalent to placing it on this physical disk. Write something.

    In layman’s terms: a physical disk is first mounted on a directory in the file tree. The physical disk is divided into multiple areas. Each area has a superblock that manages the area. This area is installed along with the disk. Formatting is pre-divided into a certain number of numbered inodes and blocks. One inode corresponds to one file. When creating a new file, you need to go to the superblock to apply for an inode number first, and then apply for several blocks according to the file size, and record them in the inode. The file's attributes, permissions, occupied block number, and finally the real content of the file is written into the allocated block.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What are the reasons why file creation fails in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template