checksums.rst 2.9 KB

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