18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ciBlock Group Descriptors
48c2ecf20Sopenharmony_ci-----------------------
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciEach block group on the filesystem has one of these descriptors
78c2ecf20Sopenharmony_ciassociated with it. As noted in the Layout section above, the group
88c2ecf20Sopenharmony_cidescriptors (if present) are the second item in the block group. The
98c2ecf20Sopenharmony_cistandard configuration is for each block group to contain a full copy of
108c2ecf20Sopenharmony_cithe block group descriptor table unless the sparse\_super feature flag
118c2ecf20Sopenharmony_ciis set.
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciNotice how the group descriptor records the location of both bitmaps and
148c2ecf20Sopenharmony_cithe inode table (i.e. they can float). This means that within a block
158c2ecf20Sopenharmony_cigroup, the only data structures with fixed locations are the superblock
168c2ecf20Sopenharmony_ciand the group descriptor table. The flex\_bg mechanism uses this
178c2ecf20Sopenharmony_ciproperty to group several block groups into a flex group and lay out all
188c2ecf20Sopenharmony_ciof the groups' bitmaps and inode tables into one long run in the first
198c2ecf20Sopenharmony_cigroup of the flex group.
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciIf the meta\_bg feature flag is set, then several block groups are
228c2ecf20Sopenharmony_cigrouped together into a meta group. Note that in the meta\_bg case,
238c2ecf20Sopenharmony_cihowever, the first and last two block groups within the larger meta
248c2ecf20Sopenharmony_cigroup contain only group descriptors for the groups inside the meta
258c2ecf20Sopenharmony_cigroup.
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciflex\_bg and meta\_bg do not appear to be mutually exclusive features.
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciIn ext2, ext3, and ext4 (when the 64bit feature is not enabled), the
308c2ecf20Sopenharmony_ciblock group descriptor was only 32 bytes long and therefore ends at
318c2ecf20Sopenharmony_cibg\_checksum. On an ext4 filesystem with the 64bit feature enabled, the
328c2ecf20Sopenharmony_ciblock group descriptor expands to at least the 64 bytes described below;
338c2ecf20Sopenharmony_cithe size is stored in the superblock.
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciIf gdt\_csum is set and metadata\_csum is not set, the block group
368c2ecf20Sopenharmony_cichecksum is the crc16 of the FS UUID, the group number, and the group
378c2ecf20Sopenharmony_cidescriptor structure. If metadata\_csum is set, then the block group
388c2ecf20Sopenharmony_cichecksum is the lower 16 bits of the checksum of the FS UUID, the group
398c2ecf20Sopenharmony_cinumber, and the group descriptor structure. Both block and inode bitmap
408c2ecf20Sopenharmony_cichecksums are calculated against the FS UUID, the group number, and the
418c2ecf20Sopenharmony_cientire bitmap.
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciThe block group descriptor is laid out in ``struct ext4_group_desc``.
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci.. list-table::
468c2ecf20Sopenharmony_ci   :widths: 8 8 24 40
478c2ecf20Sopenharmony_ci   :header-rows: 1
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci   * - Offset
508c2ecf20Sopenharmony_ci     - Size
518c2ecf20Sopenharmony_ci     - Name
528c2ecf20Sopenharmony_ci     - Description
538c2ecf20Sopenharmony_ci   * - 0x0
548c2ecf20Sopenharmony_ci     - \_\_le32
558c2ecf20Sopenharmony_ci     - bg\_block\_bitmap\_lo
568c2ecf20Sopenharmony_ci     - Lower 32-bits of location of block bitmap.
578c2ecf20Sopenharmony_ci   * - 0x4
588c2ecf20Sopenharmony_ci     - \_\_le32
598c2ecf20Sopenharmony_ci     - bg\_inode\_bitmap\_lo
608c2ecf20Sopenharmony_ci     - Lower 32-bits of location of inode bitmap.
618c2ecf20Sopenharmony_ci   * - 0x8
628c2ecf20Sopenharmony_ci     - \_\_le32
638c2ecf20Sopenharmony_ci     - bg\_inode\_table\_lo
648c2ecf20Sopenharmony_ci     - Lower 32-bits of location of inode table.
658c2ecf20Sopenharmony_ci   * - 0xC
668c2ecf20Sopenharmony_ci     - \_\_le16
678c2ecf20Sopenharmony_ci     - bg\_free\_blocks\_count\_lo
688c2ecf20Sopenharmony_ci     - Lower 16-bits of free block count.
698c2ecf20Sopenharmony_ci   * - 0xE
708c2ecf20Sopenharmony_ci     - \_\_le16
718c2ecf20Sopenharmony_ci     - bg\_free\_inodes\_count\_lo
728c2ecf20Sopenharmony_ci     - Lower 16-bits of free inode count.
738c2ecf20Sopenharmony_ci   * - 0x10
748c2ecf20Sopenharmony_ci     - \_\_le16
758c2ecf20Sopenharmony_ci     - bg\_used\_dirs\_count\_lo
768c2ecf20Sopenharmony_ci     - Lower 16-bits of directory count.
778c2ecf20Sopenharmony_ci   * - 0x12
788c2ecf20Sopenharmony_ci     - \_\_le16
798c2ecf20Sopenharmony_ci     - bg\_flags
808c2ecf20Sopenharmony_ci     - Block group flags. See the bgflags_ table below.
818c2ecf20Sopenharmony_ci   * - 0x14
828c2ecf20Sopenharmony_ci     - \_\_le32
838c2ecf20Sopenharmony_ci     - bg\_exclude\_bitmap\_lo
848c2ecf20Sopenharmony_ci     - Lower 32-bits of location of snapshot exclusion bitmap.
858c2ecf20Sopenharmony_ci   * - 0x18
868c2ecf20Sopenharmony_ci     - \_\_le16
878c2ecf20Sopenharmony_ci     - bg\_block\_bitmap\_csum\_lo
888c2ecf20Sopenharmony_ci     - Lower 16-bits of the block bitmap checksum.
898c2ecf20Sopenharmony_ci   * - 0x1A
908c2ecf20Sopenharmony_ci     - \_\_le16
918c2ecf20Sopenharmony_ci     - bg\_inode\_bitmap\_csum\_lo
928c2ecf20Sopenharmony_ci     - Lower 16-bits of the inode bitmap checksum.
938c2ecf20Sopenharmony_ci   * - 0x1C
948c2ecf20Sopenharmony_ci     - \_\_le16
958c2ecf20Sopenharmony_ci     - bg\_itable\_unused\_lo
968c2ecf20Sopenharmony_ci     - Lower 16-bits of unused inode count. If set, we needn't scan past the
978c2ecf20Sopenharmony_ci       ``(sb.s_inodes_per_group - gdt.bg_itable_unused)``\ th entry in the
988c2ecf20Sopenharmony_ci       inode table for this group.
998c2ecf20Sopenharmony_ci   * - 0x1E
1008c2ecf20Sopenharmony_ci     - \_\_le16
1018c2ecf20Sopenharmony_ci     - bg\_checksum
1028c2ecf20Sopenharmony_ci     - Group descriptor checksum; crc16(sb\_uuid+group\_num+bg\_desc) if the
1038c2ecf20Sopenharmony_ci       RO\_COMPAT\_GDT\_CSUM feature is set, or
1048c2ecf20Sopenharmony_ci       crc32c(sb\_uuid+group\_num+bg\_desc) & 0xFFFF if the
1058c2ecf20Sopenharmony_ci       RO\_COMPAT\_METADATA\_CSUM feature is set.  The bg\_checksum
1068c2ecf20Sopenharmony_ci       field in bg\_desc is skipped when calculating crc16 checksum,
1078c2ecf20Sopenharmony_ci       and set to zero if crc32c checksum is used.
1088c2ecf20Sopenharmony_ci   * -
1098c2ecf20Sopenharmony_ci     -
1108c2ecf20Sopenharmony_ci     -
1118c2ecf20Sopenharmony_ci     - These fields only exist if the 64bit feature is enabled and s_desc_size
1128c2ecf20Sopenharmony_ci       > 32.
1138c2ecf20Sopenharmony_ci   * - 0x20
1148c2ecf20Sopenharmony_ci     - \_\_le32
1158c2ecf20Sopenharmony_ci     - bg\_block\_bitmap\_hi
1168c2ecf20Sopenharmony_ci     - Upper 32-bits of location of block bitmap.
1178c2ecf20Sopenharmony_ci   * - 0x24
1188c2ecf20Sopenharmony_ci     - \_\_le32
1198c2ecf20Sopenharmony_ci     - bg\_inode\_bitmap\_hi
1208c2ecf20Sopenharmony_ci     - Upper 32-bits of location of inodes bitmap.
1218c2ecf20Sopenharmony_ci   * - 0x28
1228c2ecf20Sopenharmony_ci     - \_\_le32
1238c2ecf20Sopenharmony_ci     - bg\_inode\_table\_hi
1248c2ecf20Sopenharmony_ci     - Upper 32-bits of location of inodes table.
1258c2ecf20Sopenharmony_ci   * - 0x2C
1268c2ecf20Sopenharmony_ci     - \_\_le16
1278c2ecf20Sopenharmony_ci     - bg\_free\_blocks\_count\_hi
1288c2ecf20Sopenharmony_ci     - Upper 16-bits of free block count.
1298c2ecf20Sopenharmony_ci   * - 0x2E
1308c2ecf20Sopenharmony_ci     - \_\_le16
1318c2ecf20Sopenharmony_ci     - bg\_free\_inodes\_count\_hi
1328c2ecf20Sopenharmony_ci     - Upper 16-bits of free inode count.
1338c2ecf20Sopenharmony_ci   * - 0x30
1348c2ecf20Sopenharmony_ci     - \_\_le16
1358c2ecf20Sopenharmony_ci     - bg\_used\_dirs\_count\_hi
1368c2ecf20Sopenharmony_ci     - Upper 16-bits of directory count.
1378c2ecf20Sopenharmony_ci   * - 0x32
1388c2ecf20Sopenharmony_ci     - \_\_le16
1398c2ecf20Sopenharmony_ci     - bg\_itable\_unused\_hi
1408c2ecf20Sopenharmony_ci     - Upper 16-bits of unused inode count.
1418c2ecf20Sopenharmony_ci   * - 0x34
1428c2ecf20Sopenharmony_ci     - \_\_le32
1438c2ecf20Sopenharmony_ci     - bg\_exclude\_bitmap\_hi
1448c2ecf20Sopenharmony_ci     - Upper 32-bits of location of snapshot exclusion bitmap.
1458c2ecf20Sopenharmony_ci   * - 0x38
1468c2ecf20Sopenharmony_ci     - \_\_le16
1478c2ecf20Sopenharmony_ci     - bg\_block\_bitmap\_csum\_hi
1488c2ecf20Sopenharmony_ci     - Upper 16-bits of the block bitmap checksum.
1498c2ecf20Sopenharmony_ci   * - 0x3A
1508c2ecf20Sopenharmony_ci     - \_\_le16
1518c2ecf20Sopenharmony_ci     - bg\_inode\_bitmap\_csum\_hi
1528c2ecf20Sopenharmony_ci     - Upper 16-bits of the inode bitmap checksum.
1538c2ecf20Sopenharmony_ci   * - 0x3C
1548c2ecf20Sopenharmony_ci     - \_\_u32
1558c2ecf20Sopenharmony_ci     - bg\_reserved
1568c2ecf20Sopenharmony_ci     - Padding to 64 bytes.
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci.. _bgflags:
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ciBlock group flags can be any combination of the following:
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci.. list-table::
1638c2ecf20Sopenharmony_ci   :widths: 16 64
1648c2ecf20Sopenharmony_ci   :header-rows: 1
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci   * - Value
1678c2ecf20Sopenharmony_ci     - Description
1688c2ecf20Sopenharmony_ci   * - 0x1
1698c2ecf20Sopenharmony_ci     - inode table and bitmap are not initialized (EXT4\_BG\_INODE\_UNINIT).
1708c2ecf20Sopenharmony_ci   * - 0x2
1718c2ecf20Sopenharmony_ci     - block bitmap is not initialized (EXT4\_BG\_BLOCK\_UNINIT).
1728c2ecf20Sopenharmony_ci   * - 0x4
1738c2ecf20Sopenharmony_ci     - inode table is zeroed (EXT4\_BG\_INODE\_ZEROED).
174