18a98ec7cSDarrick J. Wong.. SPDX-License-Identifier: GPL-2.0 28a98ec7cSDarrick J. Wong 38a98ec7cSDarrick J. WongChecksums 48a98ec7cSDarrick J. Wong--------- 58a98ec7cSDarrick J. Wong 68a98ec7cSDarrick J. WongStarting in early 2012, metadata checksums were added to all major ext4 7*3103084aSWang Jianjianand jbd2 data structures. The associated feature flag is metadata_csum. 88a98ec7cSDarrick J. WongThe desired checksum algorithm is indicated in the superblock, though as 98a98ec7cSDarrick J. Wongof October 2012 the only supported algorithm is crc32c. Some data 108a98ec7cSDarrick J. Wongstructures did not have space to fit a full 32-bit checksum, so only the 118a98ec7cSDarrick J. Wonglower 16 bits are stored. Enabling the 64bit feature increases the data 128a98ec7cSDarrick J. Wongstructure size so that full 32-bit checksums can be stored for many data 138a98ec7cSDarrick J. Wongstructures. However, existing 32-bit filesystems cannot be extended to 148a98ec7cSDarrick J. Wongenable 64bit mode, at least not without the experimental resize2fs 158a98ec7cSDarrick J. Wongpatches to do so. 168a98ec7cSDarrick J. Wong 178a98ec7cSDarrick J. WongExisting filesystems can have checksumming added by running 188a98ec7cSDarrick J. Wong``tune2fs -O metadata_csum`` against the underlying device. If tune2fs 198a98ec7cSDarrick J. Wongencounters directory blocks that lack sufficient empty space to add a 208a98ec7cSDarrick J. Wongchecksum, it will request that you run ``e2fsck -D`` to have the 218a98ec7cSDarrick J. Wongdirectories rebuilt with checksums. This has the added benefit of 228a98ec7cSDarrick J. Wongremoving slack space from the directory files and rebalancing the htree 23*3103084aSWang Jianjianindexes. If you _ignore_ this step, your directories will not be 248a98ec7cSDarrick J. Wongprotected by a checksum! 258a98ec7cSDarrick J. Wong 268a98ec7cSDarrick J. WongThe following table describes the data elements that go into each type 278a98ec7cSDarrick J. Wongof checksum. The checksum function is whatever the superblock describes 288a98ec7cSDarrick J. Wong(crc32c as of October 2013) unless noted otherwise. 298a98ec7cSDarrick J. Wong 308a98ec7cSDarrick J. Wong.. list-table:: 318a98ec7cSDarrick J. Wong :widths: 20 8 50 328a98ec7cSDarrick J. Wong :header-rows: 1 338a98ec7cSDarrick J. Wong 348a98ec7cSDarrick J. Wong * - Metadata 358a98ec7cSDarrick J. Wong - Length 368a98ec7cSDarrick J. Wong - Ingredients 378a98ec7cSDarrick J. Wong * - Superblock 38*3103084aSWang Jianjian - __le32 398a98ec7cSDarrick J. Wong - The entire superblock up to the checksum field. The UUID lives inside 408a98ec7cSDarrick J. Wong the superblock. 418a98ec7cSDarrick J. Wong * - MMP 42*3103084aSWang Jianjian - __le32 438a98ec7cSDarrick J. Wong - UUID + the entire MMP block up to the checksum field. 448a98ec7cSDarrick J. Wong * - Extended Attributes 45*3103084aSWang Jianjian - __le32 468a98ec7cSDarrick J. Wong - UUID + the entire extended attribute block. The checksum field is set to 478a98ec7cSDarrick J. Wong zero. 488a98ec7cSDarrick J. Wong * - Directory Entries 49*3103084aSWang Jianjian - __le32 508a98ec7cSDarrick J. Wong - UUID + inode number + inode generation + the directory block up to the 518a98ec7cSDarrick J. Wong fake entry enclosing the checksum field. 528a98ec7cSDarrick J. Wong * - HTREE Nodes 53*3103084aSWang Jianjian - __le32 548a98ec7cSDarrick J. Wong - UUID + inode number + inode generation + all valid extents + HTREE tail. 558a98ec7cSDarrick J. Wong The checksum field is set to zero. 568a98ec7cSDarrick J. Wong * - Extents 57*3103084aSWang Jianjian - __le32 588a98ec7cSDarrick J. Wong - UUID + inode number + inode generation + the entire extent block up to 598a98ec7cSDarrick J. Wong the checksum field. 608a98ec7cSDarrick J. Wong * - Bitmaps 61*3103084aSWang Jianjian - __le32 or __le16 628a98ec7cSDarrick J. Wong - UUID + the entire bitmap. Checksums are stored in the group descriptor, 638a98ec7cSDarrick J. Wong and truncated if the group descriptor size is 32 bytes (i.e. ^64bit) 648a98ec7cSDarrick J. Wong * - Inodes 65*3103084aSWang Jianjian - __le32 668a98ec7cSDarrick J. Wong - UUID + inode number + inode generation + the entire inode. The checksum 678a98ec7cSDarrick J. Wong field is set to zero. Each inode has its own checksum. 688a98ec7cSDarrick J. Wong * - Group Descriptors 69*3103084aSWang Jianjian - __le16 70*3103084aSWang Jianjian - If metadata_csum, then UUID + group number + the entire descriptor; 71*3103084aSWang Jianjian else if gdt_csum, then crc16(UUID + group number + the entire 728a98ec7cSDarrick J. Wong descriptor). In all cases, only the lower 16 bits are stored. 738a98ec7cSDarrick J. Wong 74