Senior
How is the Ext4 file system organized?
sobes.tech AI
Answer from AI
Ext4 is a journaling file system that uses an inode- and block-based structure.
Key concepts:
- Superblock: Stores metadata about the file system (size, number of blocks, inodes, etc.). Located at the beginning of the file system and has backup copies.
- Block groups: The file system is divided into block groups to improve data locality and reduce fragmentation. Each group has its own descriptor.
- Block group descriptor: Contains information about a specific group: address of the inode table, block bitmap, inode bitmap.
- Block bitmap: A map of block usage within the group.
- Inode bitmap: A map of inode usage within the group.
- Inode table: An array of inode structures.
- Inode: A structure describing a file or directory. Stores metadata: file type, permissions, owner, group, size, timestamps, data block pointers.
- Data blocks: Contain the actual content of files. Block size is configured at filesystem creation (usually 4KB).
- Directory: A file containing a list of entries. Each entry links a filename or directory name to its inode number.
Pointers to data blocks in inode:
- Direct pointers: Point directly to data blocks. Usually several (e.g., 12), allowing quick access to small files.
- Indirect pointers: Point to blocks containing pointers to data blocks. Single, double, triple indirect. Used for large files.
- Extents: Ext4 introduced extents to improve performance and handle large files. An extent is a range of contiguous blocks, reducing the number of pointers in the inode.
Journaling: Ext4 has a journal that records changes before applying them to the main file system. This allows quick recovery after a crash.
Features of Ext4:
- Support for very large files (up to 16 TiB).
- Support for very large file systems (up to 1 EB).
- Increased performance through extents.
- Delayed block allocation.
- Checksums for metadata integrity.
- Fast fstrim/discard for SSDs.