The previous discussion of the Virtual File System VFS has come to an end. VFS mainly provides a system call interface, and then concatenates Related File System Objects with specific file systems. Starting from this blog, We will select a specific file system for research. This file system is the second extended File System (ext2 ). Why study this thing? Because ext2 is inherent in Linux and is actually used in every Linux system, we naturally need to discuss ext2. In addition, ext2 also shows many good practices in terms of high performance support for modern file systems. Of course, other file systems supported by Linux have many interesting features, but the extended file system is the top node in Linux, so we will not discuss it one by one with other file systems.
Unix-like operating systems use multiple file systems. Although all these file systems have a few common attribute subsets required by POSIX APIs (such as State (), the implementation of each file system is different.
The first version of Linux is based on the minix file system. When Linux is mature, extended filesystem (ext fs) is introduced, which contains several important extensions but provides unsatisfactory performance. In 1994, the second extended File System (ext2) was introduced. In addition to several new features, it also features high performance and stability, ext2 and its next generation File System ext3 and e3fs have become widely used Linux file systems.
Ext2 file system has the following general features:
1. When creating an ext2 file system, the system administrator can select the optimal Block Size (from 1024b--4096b) based on the average length of the expected file ). For example, when the average length of a file is less than several thousand characters, the block size of B is the best, this results in a small amount of internal fragments-that is, the file length does not match the disk partition of the storage block. On the other hand, large blocks are usually suitable for files larger than several thousands of bytes, because such disks transmit less, thus reducing the system overhead.
2. When creating an ext2 file system, the system administrator can select the number of index nodes allocated to the partition based on the expected number of files stored in the given partition size. This effectively exploits the disk space.
3. The file system divides disk blocks into groups. Each group contains data blocks and index nodes stored on adjacent channels. This structure enables parallel access to files stored in a separate block group with less average disk seek time.
4. Before the disk data blocks are actually used, the file system pre-allocates these blocks to common files. Therefore, when the file size increases, several adjacent physical blocks are retained, which reduces the file fragmentation.
5. Quick symbolic links are supported. If a symbolic link represents a short path name (less than or equal to 60 characters), it is stored in the index node instead of being converted by a data block.
In addition, ext2 includes some features that make it robust and flexible:
1. careful implementation of file update policies minimizes the impact of system crashes. Here is only one example to demonstrate this advantage: for example, when creating a hard link for a file, first add the hard link counter in the disk index node, then add the new name to the appropriate directory. In this way, if a hardware fault occurs before the directory is changed after the index node is updated, the directories are consistent even if the counters on the index node are incorrect. Therefore, although the data block of the file cannot be automatically recovered when the file is deleted, it does not have disastrous consequences. If the processing order is the opposite (change the directory before updating the index node), the same hardware failure will lead to dangerous inconsistency, deleting the original hard link will delete its data blocks from the disk, but the new directory item will point to a non-existent index node. If the index node number is used by another file, the write operation to the old directory will destroy the new file.
2. automatic consistency check on the file system status is supported at startup. This check is done by the external program e2fsck, which can be activated not only after the system crashes, it can also be activated after a predefined number of file system installations (add 1 to the counter after each installation operation, or, it is activated after the predefined time that has elapsed since the recent check.
3. Support immutable files (which cannot be modified, deleted, or renamed) and append-only files (only data can be appended to the end of the file ).
4. compatible with UNIX System V Release 4 (svr4) and the BSD semantics of the user group ID of the new file. In svr4, the new file uses the user group ID of the process that created it. In BSD, the new file inherits the user group ID that contains its directory. Ext2 contains an installation option that specifies the semantics used.
Even if the ext2 file system is such a mature and stable program, consider introducing several other negative features. Currently, some negative features have been avoided by new file systems or external patches. Others are still in the planning stage, but in some cases, new fields have been introduced for these features in the ext2 index node. The most important features are as follows:
Block fragmentation)
The system administrator usually chooses a large block for access to the disk because computer applications often process large files. Therefore, storing small files in large blocks will waste a lot of disk space. This problem can be solved by storing several files in different parts of the same block.
Transparent processing of compressed and encrypted files
These new options (which must be specified when a file is created) allow users to transparently store compressed and/or encrypted file versions on the disk.
Logical Deletion
An undelete option will allow users to easily restore previously deleted file content when necessary.
Logs
Logs prevent the file system from automatically performing time-consuming checks when it is suddenly uninstalled (for example, as a consequence of system crash.
In fact, none of these features are officially included in the ext2 file system. Some may say that ext2 is the victim of such success; until a few years ago, it was still the preferred file system adopted by most Linux publishing companies, and thousands of users were using it every day, these users will question any attempt to replace ext2 with another file system.
The most prominent feature missing in ext2 is log, which is a required feature for high-availability servers. For smooth transition, logs are not introduced to the ext2 file system. However, we will discuss in the "ext3 File System" blog that a new file system fully compatible with ext2 has been created, this file system provides logs. Users who do not really need logs can continue to use the good and old-fashioned ext2 file system, while other users may adopt this new file system. Most of the systems currently released use ext3 as the standard file system.