1 .. SPDX-License-Identifier: GPL-2.0 1 .. SPDX-License-Identifier: GPL-2.0 2 2 3 Checksums 3 Checksums 4 --------- 4 --------- 5 5 6 Starting in early 2012, metadata checksums wer 6 Starting in early 2012, metadata checksums were added to all major ext4 7 and jbd2 data structures. The associated featu !! 7 and jbd2 data structures. The associated feature flag is metadata\_csum. 8 The desired checksum algorithm is indicated in 8 The desired checksum algorithm is indicated in the superblock, though as 9 of October 2012 the only supported algorithm i 9 of October 2012 the only supported algorithm is crc32c. Some data 10 structures did not have space to fit a full 32 10 structures did not have space to fit a full 32-bit checksum, so only the 11 lower 16 bits are stored. Enabling the 64bit f 11 lower 16 bits are stored. Enabling the 64bit feature increases the data 12 structure size so that full 32-bit checksums c 12 structure size so that full 32-bit checksums can be stored for many data 13 structures. However, existing 32-bit filesyste 13 structures. However, existing 32-bit filesystems cannot be extended to 14 enable 64bit mode, at least not without the ex 14 enable 64bit mode, at least not without the experimental resize2fs 15 patches to do so. 15 patches to do so. 16 16 17 Existing filesystems can have checksumming add 17 Existing filesystems can have checksumming added by running 18 ``tune2fs -O metadata_csum`` against the under 18 ``tune2fs -O metadata_csum`` against the underlying device. If tune2fs 19 encounters directory blocks that lack sufficie 19 encounters directory blocks that lack sufficient empty space to add a 20 checksum, it will request that you run ``e2fsc 20 checksum, it will request that you run ``e2fsck -D`` to have the 21 directories rebuilt with checksums. This has t 21 directories rebuilt with checksums. This has the added benefit of 22 removing slack space from the directory files 22 removing slack space from the directory files and rebalancing the htree 23 indexes. If you _ignore_ this step, your direc !! 23 indexes. If you \_ignore\_ this step, your directories will not be 24 protected by a checksum! 24 protected by a checksum! 25 25 26 The following table describes the data element 26 The following table describes the data elements that go into each type 27 of checksum. The checksum function is whatever 27 of checksum. The checksum function is whatever the superblock describes 28 (crc32c as of October 2013) unless noted other 28 (crc32c as of October 2013) unless noted otherwise. 29 29 30 .. list-table:: 30 .. list-table:: 31 :widths: 20 8 50 31 :widths: 20 8 50 32 :header-rows: 1 32 :header-rows: 1 33 33 34 * - Metadata 34 * - Metadata 35 - Length 35 - Length 36 - Ingredients 36 - Ingredients 37 * - Superblock 37 * - Superblock 38 - __le32 !! 38 - \_\_le32 39 - The entire superblock up to the checksu 39 - The entire superblock up to the checksum field. The UUID lives inside 40 the superblock. 40 the superblock. 41 * - MMP 41 * - MMP 42 - __le32 !! 42 - \_\_le32 43 - UUID + the entire MMP block up to the c 43 - UUID + the entire MMP block up to the checksum field. 44 * - Extended Attributes 44 * - Extended Attributes 45 - __le32 !! 45 - \_\_le32 46 - UUID + the entire extended attribute bl 46 - UUID + the entire extended attribute block. The checksum field is set to 47 zero. 47 zero. 48 * - Directory Entries 48 * - Directory Entries 49 - __le32 !! 49 - \_\_le32 50 - UUID + inode number + inode generation 50 - UUID + inode number + inode generation + the directory block up to the 51 fake entry enclosing the checksum field 51 fake entry enclosing the checksum field. 52 * - HTREE Nodes 52 * - HTREE Nodes 53 - __le32 !! 53 - \_\_le32 54 - UUID + inode number + inode generation 54 - UUID + inode number + inode generation + all valid extents + HTREE tail. 55 The checksum field is set to zero. 55 The checksum field is set to zero. 56 * - Extents 56 * - Extents 57 - __le32 !! 57 - \_\_le32 58 - UUID + inode number + inode generation 58 - UUID + inode number + inode generation + the entire extent block up to 59 the checksum field. 59 the checksum field. 60 * - Bitmaps 60 * - Bitmaps 61 - __le32 or __le16 !! 61 - \_\_le32 or \_\_le16 62 - UUID + the entire bitmap. Checksums are 62 - UUID + the entire bitmap. Checksums are stored in the group descriptor, 63 and truncated if the group descriptor s 63 and truncated if the group descriptor size is 32 bytes (i.e. ^64bit) 64 * - Inodes 64 * - Inodes 65 - __le32 !! 65 - \_\_le32 66 - UUID + inode number + inode generation 66 - UUID + inode number + inode generation + the entire inode. The checksum 67 field is set to zero. Each inode has it 67 field is set to zero. Each inode has its own checksum. 68 * - Group Descriptors 68 * - Group Descriptors 69 - __le16 !! 69 - \_\_le16 70 - If metadata_csum, then UUID + group num !! 70 - If metadata\_csum, then UUID + group number + the entire descriptor; 71 else if gdt_csum, then crc16(UUID + gro !! 71 else if gdt\_csum, then crc16(UUID + group number + the entire 72 descriptor). In all cases, only the low 72 descriptor). In all cases, only the lower 16 bits are stored. 73 73
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.