Super block
The superblock contains all the information about the configuration of the filesystem. The information in the superblock contains fields such as the total number of inodes and blocks in the filesystem and how many are free, how many inodes and blocks are in each block group, when the filesystem was mounted (and if it was cleanly unmounted), when it was modified, what version of the filesystem it is and which OS created it.
The primary copy of the superblock is stored at an offset of 1024 bytes from the start of the file, block device or partition formatted with Ext2 and later variants (Ext3, Ext4). Its structure is mostly constant from Ext2 to Ext3 and Ext4 with only some minor changes. It is essential to mounting the filesystem. Since it is so important, backup copies of the superblock are stored in block groups throughout the filesystem.
The first version of ext-2 (revision 0) stores a copy at the start of every block group, along with backups of the group descriptor block(s). Because this can consume a considerable amount of space for large filesystems, later revisions can optionally reduce the number of backup copies by only putting backups in specific groups (this is the sparse superblock feature). The groups chosen are 0, 1 and powers of 3, 5 and 7
Revision 1 and higher of the filesystem also store extra fields, such as a volume name, a unique identification number, the inode size, and space for optional filesystem features to store configuration info.
All fields in the superblock (as in all other ext-2 structures) are stored on the disc in little endian format, so a filesystem is portable between machines without having to know what machine it was created on.
Offset (bytes) | Size (bytes) | Description |
---|---|---|
0 | 4 | s_inodes_count |
4 | 4 | s_blocks_count |
8 | 4 | s_r_blocks_count |
12 | 4 | s_free_blocks_count |
16 | 4 | s_free_inodes_count |
20 | 4 | s_first_data_block |
24 | 4 | s_log_block_size |
28 | 4 | s_log_frag_size |
32 | 4 | s_blocks_per_group |
36 | 4 | s_frags_per_group |
40 | 4 | s_inodes_per_group |
44 | 4 | s_mtime |
48 | 4 | s_wtime |
52 | 2 | s_mnt_count |
54 | 2 | s_max_mnt_count |
56 | 2 | s_magic |
58 | 2 | s_state |
60 | 2 | s_errors |
62 | 2 | s_minor_rev_level |
64 | 4 | s_lastcheck |
68 | 4 | s_checkinterval |
72 | 4 | s_creator_os |
76 | 4 | s_rev_level |
80 | 2 | s_def_resuid |
82 | 2 | s_def_resgid |
s_inodes_count
32bit value indicating the total number of inodes, both used and free, in the file system. This value must be lower or equal to (s_inodes_per_group * number of block groups). It must be equal to the sum of the inodes defined in each block group.
Offset (bytes) | Size (bytes) | Description |
---|---|---|
84 | 4 | s_first_ino |
88 | 2 | s_inode_size |
90 | 2 | s_block_group_nr |
92 | 4 | s_feature_compat |
96 | 4 | s_feature_incompat |
100 | 4 | s_feature_ro_compat |
104 | 16 | s_uuid |
120 | 16 | s_volume_name |
136 | 64 | s_last_mounted |
200 | 4 | s_algo_bitmap |
s_first_ino
32bit value used as index to the first inode useable for standard files. In revision 0, the first non-reserved inode is fixed to 11 (EXT2_GOOD_OLD_FIRST_INO). In revision 1 and later this value may be set to any value.