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