Life and times of the classic ext Linux filesystem
Superpowers
For an ext filesystem to be able to organize itself, it keeps a record of some important configuration parameters and current states. This information lives in the superblock, which always follows the first 1024 bytes of a storage medium (Figure 2).
This fixed position is important, for example, for the mount operation or for checking the filesystem. Among other things, the superblock contains the following:
- the exact block size
- the number of blocks and block groups
- the number of free and used inodes
- the date of the last successful mount
- the last change date
- the name of the operating system that created the filesystem
- the current state of the filesystem.
The superblock is more or less the heart of the ext filesystem. To avoid damage to the superblock that could destroy the filesystem, ext2 creates several copies of the superblock distributed across block groups. For repairs, tools rely on these backup copies.
Each block group has a group descriptor that holds some information about the block group. For security reasons, all block groups store all group descriptors of the ext filesystem.
Additionally, each block group contains inode and block bitmaps. These bitmaps act as registers that list all the inodes and blocks of each block group. A bit with a value of 0
marks an inode or block as free; a value of 1
indicates an occupied inode or block. A bitmap must always fit in one block, which also limits the size of a block group.
Storage in Action
If you create a new file or folder on ext2, the filesystem first makes a decision on the exact storage location. For an empty filesystem, the data could theoretically end up anywhere, but for performance reasons, it makes sense to store contiguous data as close together as possible. Ext2 thus tries to put subfolders and files in the block group in which the directory that holds them resides. The filesystem assumes that this data is related and the system will retrieve it, in quick succession if necessary. If the block group fills up, ext2 is forced to divert to another location. To determine which blocks and inodes are usable for storage, ext2 looks at the inode and block bitmaps.
Good References
Ext2 also introduced support for symbolic links, or symlinks for short. A symlink is a special type of file that only contains a reference to another file or directory instead of data. In contrast to hard links, Symlinks point to targets on all filesystems, not just their own.
Unlike hard links, you can recognize a symlink. Applications that access the files or folders hiding behind symlinks treat them as ordinary files. But when it matters, such as when creating backups, a program needs to handle a symlink separately.
Symlinks exist independently of the target. If you delete the file that is referenced by a symlink, the link will remain – after all, it is a separate file with its own inode. The potential downside: If you change the name or location of a file, you also need to modify the symlink accordingly.
The filesystem stores all symlinks fewer than 60 bytes in size directly in the associated inode. Storing the symlink in the inode avoids the association of a separate block in the ext2 filesystem. (Actually, this same procedure is also used for normal files: If the content of a file takes up fewer than 60 bytes, the filesystem writes the data directly to the associated inode as "inline data.")
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)