Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 Checksums
0004 ---------
0005 
0006 Starting in early 2012, metadata checksums were added to all major ext4
0007 and jbd2 data structures. The associated feature flag is metadata_csum.
0008 The desired checksum algorithm is indicated in the superblock, though as
0009 of October 2012 the only supported algorithm is crc32c. Some data
0010 structures did not have space to fit a full 32-bit checksum, so only the
0011 lower 16 bits are stored. Enabling the 64bit feature increases the data
0012 structure size so that full 32-bit checksums can be stored for many data
0013 structures. However, existing 32-bit filesystems cannot be extended to
0014 enable 64bit mode, at least not without the experimental resize2fs
0015 patches to do so.
0016 
0017 Existing filesystems can have checksumming added by running
0018 ``tune2fs -O metadata_csum`` against the underlying device. If tune2fs
0019 encounters directory blocks that lack sufficient empty space to add a
0020 checksum, it will request that you run ``e2fsck -D`` to have the
0021 directories rebuilt with checksums. This has the added benefit of
0022 removing slack space from the directory files and rebalancing the htree
0023 indexes. If you _ignore_ this step, your directories will not be
0024 protected by a checksum!
0025 
0026 The following table describes the data elements that go into each type
0027 of checksum. The checksum function is whatever the superblock describes
0028 (crc32c as of October 2013) unless noted otherwise.
0029 
0030 .. list-table::
0031    :widths: 20 8 50
0032    :header-rows: 1
0033 
0034    * - Metadata
0035      - Length
0036      - Ingredients
0037    * - Superblock
0038      - __le32
0039      - The entire superblock up to the checksum field. The UUID lives inside
0040        the superblock.
0041    * - MMP
0042      - __le32
0043      - UUID + the entire MMP block up to the checksum field.
0044    * - Extended Attributes
0045      - __le32
0046      - UUID + the entire extended attribute block. The checksum field is set to
0047        zero.
0048    * - Directory Entries
0049      - __le32
0050      - UUID + inode number + inode generation + the directory block up to the
0051        fake entry enclosing the checksum field.
0052    * - HTREE Nodes
0053      - __le32
0054      - UUID + inode number + inode generation + all valid extents + HTREE tail.
0055        The checksum field is set to zero.
0056    * - Extents
0057      - __le32
0058      - UUID + inode number + inode generation + the entire extent block up to
0059        the checksum field.
0060    * - Bitmaps
0061      - __le32 or __le16
0062      - UUID + the entire bitmap. Checksums are stored in the group descriptor,
0063        and truncated if the group descriptor size is 32 bytes (i.e. ^64bit)
0064    * - Inodes
0065      - __le32
0066      - UUID + inode number + inode generation + the entire inode. The checksum
0067        field is set to zero. Each inode has its own checksum.
0068    * - Group Descriptors
0069      - __le16
0070      - If metadata_csum, then UUID + group number + the entire descriptor;
0071        else if gdt_csum, then crc16(UUID + group number + the entire
0072        descriptor). In all cases, only the lower 16 bits are stored.
0073