^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) Block Group Descriptors
^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) Each block group on the filesystem has one of these descriptors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) associated with it. As noted in the Layout section above, the group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) descriptors (if present) are the second item in the block group. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) standard configuration is for each block group to contain a full copy of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) the block group descriptor table unless the sparse\_super feature flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) Notice how the group descriptor records the location of both bitmaps and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) the inode table (i.e. they can float). This means that within a block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) group, the only data structures with fixed locations are the superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) and the group descriptor table. The flex\_bg mechanism uses this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) property to group several block groups into a flex group and lay out all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) of the groups' bitmaps and inode tables into one long run in the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) group of the flex group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) If the meta\_bg feature flag is set, then several block groups are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) grouped together into a meta group. Note that in the meta\_bg case,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) however, the first and last two block groups within the larger meta
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) group contain only group descriptors for the groups inside the meta
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) flex\_bg and meta\_bg do not appear to be mutually exclusive features.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) In ext2, ext3, and ext4 (when the 64bit feature is not enabled), the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) block group descriptor was only 32 bytes long and therefore ends at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) bg\_checksum. On an ext4 filesystem with the 64bit feature enabled, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) block group descriptor expands to at least the 64 bytes described below;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) the size is stored in the superblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) If gdt\_csum is set and metadata\_csum is not set, the block group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) checksum is the crc16 of the FS UUID, the group number, and the group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) descriptor structure. If metadata\_csum is set, then the block group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) checksum is the lower 16 bits of the checksum of the FS UUID, the group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) number, and the group descriptor structure. Both block and inode bitmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) checksums are calculated against the FS UUID, the group number, and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) entire bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) The block group descriptor is laid out in ``struct ext4_group_desc``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .. list-table::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) :widths: 8 8 24 40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) :header-rows: 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * - Offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) - Size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) - Name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) - Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * - 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) - bg\_block\_bitmap\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) - Lower 32-bits of location of block bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * - 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) - bg\_inode\_bitmap\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) - Lower 32-bits of location of inode bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * - 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) - bg\_inode\_table\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) - Lower 32-bits of location of inode table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * - 0xC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) - bg\_free\_blocks\_count\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) - Lower 16-bits of free block count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * - 0xE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) - bg\_free\_inodes\_count\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) - Lower 16-bits of free inode count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * - 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) - bg\_used\_dirs\_count\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) - Lower 16-bits of directory count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * - 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) - bg\_flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) - Block group flags. See the bgflags_ table below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * - 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) - bg\_exclude\_bitmap\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) - Lower 32-bits of location of snapshot exclusion bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * - 0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) - bg\_block\_bitmap\_csum\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) - Lower 16-bits of the block bitmap checksum.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * - 0x1A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) - bg\_inode\_bitmap\_csum\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) - Lower 16-bits of the inode bitmap checksum.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * - 0x1C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) - bg\_itable\_unused\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) - Lower 16-bits of unused inode count. If set, we needn't scan past the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ``(sb.s_inodes_per_group - gdt.bg_itable_unused)``\ th entry in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) inode table for this group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * - 0x1E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) - bg\_checksum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) - Group descriptor checksum; crc16(sb\_uuid+group\_num+bg\_desc) if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) RO\_COMPAT\_GDT\_CSUM feature is set, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) crc32c(sb\_uuid+group\_num+bg\_desc) & 0xFFFF if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) RO\_COMPAT\_METADATA\_CSUM feature is set. The bg\_checksum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) field in bg\_desc is skipped when calculating crc16 checksum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) and set to zero if crc32c checksum is used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) - These fields only exist if the 64bit feature is enabled and s_desc_size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) > 32.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * - 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) - bg\_block\_bitmap\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) - Upper 32-bits of location of block bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * - 0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) - bg\_inode\_bitmap\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) - Upper 32-bits of location of inodes bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * - 0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) - bg\_inode\_table\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) - Upper 32-bits of location of inodes table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * - 0x2C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) - bg\_free\_blocks\_count\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) - Upper 16-bits of free block count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * - 0x2E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) - bg\_free\_inodes\_count\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) - Upper 16-bits of free inode count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * - 0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) - bg\_used\_dirs\_count\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) - Upper 16-bits of directory count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * - 0x32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) - bg\_itable\_unused\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) - Upper 16-bits of unused inode count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * - 0x34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) - bg\_exclude\_bitmap\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) - Upper 32-bits of location of snapshot exclusion bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * - 0x38
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) - bg\_block\_bitmap\_csum\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) - Upper 16-bits of the block bitmap checksum.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * - 0x3A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) - bg\_inode\_bitmap\_csum\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) - Upper 16-bits of the inode bitmap checksum.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * - 0x3C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) - \_\_u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) - bg\_reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) - Padding to 64 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .. _bgflags:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) Block group flags can be any combination of the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .. list-table::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) :widths: 16 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) :header-rows: 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * - Value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) - Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * - 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) - inode table and bitmap are not initialized (EXT4\_BG\_INODE\_UNINIT).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * - 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) - block bitmap is not initialized (EXT4\_BG\_BLOCK\_UNINIT).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * - 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) - inode table is zeroed (EXT4\_BG\_INODE\_ZEROED).