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