Linux File System (inode and block)

Source: Internet
Author: User

Linux File System (inode and block)

Formatting: The file attributes/permissions set by each operating system are different. to store the data required for these files, you need to format the partitions, to become a file system format available to the operating system. In linux, the file format is Ext2/Ext3. Now it seems that Ext4.windows is vfat or NTFS.

Linux File System:

In addition to the actual file content, file data in the operating system also has many attributes, such as file permission (rwx) and file attributes (owner, group, and time parameter ).

The file system usually stores these two parts of data in different blocks. Put the permission attribute in inode, and put the actual data in the data block.

Another super block records the overall information of the file system, including the number and usage of inode and block.

Inode: records file attributes. A file occupies one inode and records the block number of the data in this file;

Block: the content of the file is recorded. If the file is too large, multiple blocks are occupied;

Super block: records the overall information of the file system, including the total inode/block quantity, usage, remaining amount, and the format and related information of the file system.

Each inode and block is numbered, and each file system occupies one inode. inode contains the block number for storing file data. We can find the inode of the file, find the block number of the data stored in the file, and then read the data. This data access method becomes an indexed file system. This type of file system generally does not require frequent disk fragmentation.

The U disk is in the FAT file format, and each block number is recorded in the previous block number. Therefore, the Data Reading performance is poor and it takes a long time to fragment.

In linux, The Ext2 file system has planned inode and block at the beginning. Unless it is re-formatted (or the file system size is changed using commands such as resize2fs), inode and block will not change after they are fixed.

If the file system is too large, it is difficult to manage all inode and blocks together. Therefore, the Ext2 file system is divided into multiple block groups during formatting ), each block group has an independent inode/block/super block system.

Data block)

The Ext2 file system supports three types of blocks: 1 K, 2 K, and 4 K. The block is fixed during formatting, and each block has a number. Note that the maximum disk capacity supported by the file system is different from that supported by a single file.

If the block used is too small, two more blocks are used for a file, and inode records are increased to reduce read/write performance.

If the block is too large and the file size is small, the remaining space will be unavailable and resources will be wasted.

Inodetable (inode table)

The file data recorded by inode. inode must include at least the following:

Access Mode of the file;

The owner of the file and all groups;

The size of the file;

The time when the file is created or the status changes (ctime );

The last read time (atime );

Last modification time (mtime );

The true content of the file.

Inode also has the following features:

The size of each inode is fixed to 128 bytes;

Each file occupies one inode;

When the system reads a file, it must first find the inode and analyze whether the permissions recorded by the inode match the user. If yes, the system can read the block content.

However, there is a problem: there are many file attributes to be recorded, and a file may have many blocks, while inode is too small (4 bytes is required to record a block). What should I do? In linux, the solution is to define the inode record block number as 12 direct, indirect, dual indirect, and triindirect record areas. The total number of blocks that can be recorded is 12 + 256 + 256*256 + 256*256*256 (K) = 16G, which only meets the condition where the block size is 1 K.

Superblock)

This record the overall situation of the file system. For example, the Mount time of the file system, the time when data was last written, and the time when the last disk (fsck) was verified. There is also a validbit value. If the file system has been mounted, the validbit value is 0. If not, the validbit value is 1.

After learning about the concept of a file system, check the file system and run the following command:

# Dumpe2fs [-bh] Device File Name

-B: list the parts that are retained as bad channels.

-H: only lists superblock data and does not list other sections.

For example:

# Dumpe2fs/dev/hdc2

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.