2018-07-29 15:40:00 -04:00
.. SPDX-License-Identifier: GPL-2.0
Block Group Descriptors
-----------------------
Each block group on the filesystem has one of these descriptors
associated with it. As noted in the Layout section above, the group
descriptors (if present) are the second item in the block group. The
standard configuration is for each block group to contain a full copy of
2022-05-20 10:22:55 +08:00
the block group descriptor table unless the sparse_super feature flag
2018-07-29 15:40:00 -04:00
is set.
Notice how the group descriptor records the location of both bitmaps and
the inode table (i.e. they can float). This means that within a block
group, the only data structures with fixed locations are the superblock
2022-05-20 10:22:55 +08:00
and the group descriptor table. The flex_bg mechanism uses this
2018-07-29 15:40:00 -04:00
property to group several block groups into a flex group and lay out all
of the groups' bitmaps and inode tables into one long run in the first
group of the flex group.
2022-05-20 10:22:55 +08:00
If the meta_bg feature flag is set, then several block groups are
grouped together into a meta group. Note that in the meta_bg case,
2018-07-29 15:40:00 -04:00
however, the first and last two block groups within the larger meta
group contain only group descriptors for the groups inside the meta
group.
2022-05-20 10:22:55 +08:00
flex_bg and meta_bg do not appear to be mutually exclusive features.
2018-07-29 15:40:00 -04:00
In ext2, ext3, and ext4 (when the 64bit feature is not enabled), the
block group descriptor was only 32 bytes long and therefore ends at
2022-05-20 10:22:55 +08:00
bg_checksum. On an ext4 filesystem with the 64bit feature enabled, the
2018-07-29 15:40:00 -04:00
block group descriptor expands to at least the 64 bytes described below;
the size is stored in the superblock.
2022-05-20 10:22:55 +08:00
If gdt_csum is set and metadata_csum is not set, the block group
2018-07-29 15:40:00 -04:00
checksum is the crc16 of the FS UUID, the group number, and the group
2022-05-20 10:22:55 +08:00
descriptor structure. If metadata_csum is set, then the block group
2018-07-29 15:40:00 -04:00
checksum is the lower 16 bits of the checksum of the FS UUID, the group
number, and the group descriptor structure. Both block and inode bitmap
checksums are calculated against the FS UUID, the group number, and the
entire bitmap.
The block group descriptor is laid out in `` struct ext4_group_desc `` .
.. list-table ::
2018-10-02 22:43:40 -04:00
:widths: 8 8 24 40
2018-07-29 15:40:00 -04:00
:header-rows: 1
* - Offset
- Size
- Name
- Description
* - 0x0
2022-05-20 10:22:55 +08:00
- __le32
- bg_block_bitmap_lo
2018-07-29 15:40:00 -04:00
- Lower 32-bits of location of block bitmap.
* - 0x4
2022-05-20 10:22:55 +08:00
- __le32
- bg_inode_bitmap_lo
2018-07-29 15:40:00 -04:00
- Lower 32-bits of location of inode bitmap.
* - 0x8
2022-05-20 10:22:55 +08:00
- __le32
- bg_inode_table_lo
2018-07-29 15:40:00 -04:00
- Lower 32-bits of location of inode table.
* - 0xC
2022-05-20 10:22:55 +08:00
- __le16
- bg_free_blocks_count_lo
2018-07-29 15:40:00 -04:00
- Lower 16-bits of free block count.
* - 0xE
2022-05-20 10:22:55 +08:00
- __le16
- bg_free_inodes_count_lo
2018-07-29 15:40:00 -04:00
- Lower 16-bits of free inode count.
* - 0x10
2022-05-20 10:22:55 +08:00
- __le16
- bg_used_dirs_count_lo
2018-07-29 15:40:00 -04:00
- Lower 16-bits of directory count.
* - 0x12
2022-05-20 10:22:55 +08:00
- __le16
- bg_flags
2018-07-29 15:40:00 -04:00
- Block group flags. See the bgflags_ table below.
* - 0x14
2022-05-20 10:22:55 +08:00
- __le32
- bg_exclude_bitmap_lo
2018-07-29 15:40:00 -04:00
- Lower 32-bits of location of snapshot exclusion bitmap.
* - 0x18
2022-05-20 10:22:55 +08:00
- __le16
- bg_block_bitmap_csum_lo
2018-07-29 15:40:00 -04:00
- Lower 16-bits of the block bitmap checksum.
* - 0x1A
2022-05-20 10:22:55 +08:00
- __le16
- bg_inode_bitmap_csum_lo
2018-07-29 15:40:00 -04:00
- Lower 16-bits of the inode bitmap checksum.
* - 0x1C
2022-05-20 10:22:55 +08:00
- __le16
- bg_itable_unused_lo
2018-07-29 15:40:00 -04:00
- Lower 16-bits of unused inode count. If set, we needn't scan past the
2022-05-20 10:22:55 +08:00
`` (sb.s_inodes_per_group - gdt.bg_itable_unused) `` th entry in the
2018-07-29 15:40:00 -04:00
inode table for this group.
* - 0x1E
2022-05-20 10:22:55 +08:00
- __le16
- bg_checksum
- Group descriptor checksum; crc16(sb_uuid+group_num+bg_desc) if the
RO_COMPAT_GDT_CSUM feature is set, or
crc32c(sb_uuid+group_num+bg_desc) & 0xFFFF if the
RO_COMPAT_METADATA_CSUM feature is set. The bg_checksum
field in bg_desc is skipped when calculating crc16 checksum,
2019-08-22 23:18:33 -04:00
and set to zero if crc32c checksum is used.
2018-07-29 15:40:00 -04:00
* -
-
-
- These fields only exist if the 64bit feature is enabled and s_desc_size
> 32.
* - 0x20
2022-05-20 10:22:55 +08:00
- __le32
- bg_block_bitmap_hi
2018-07-29 15:40:00 -04:00
- Upper 32-bits of location of block bitmap.
* - 0x24
2022-05-20 10:22:55 +08:00
- __le32
- bg_inode_bitmap_hi
2018-07-29 15:40:00 -04:00
- Upper 32-bits of location of inodes bitmap.
* - 0x28
2022-05-20 10:22:55 +08:00
- __le32
- bg_inode_table_hi
2018-07-29 15:40:00 -04:00
- Upper 32-bits of location of inodes table.
* - 0x2C
2022-05-20 10:22:55 +08:00
- __le16
- bg_free_blocks_count_hi
2018-07-29 15:40:00 -04:00
- Upper 16-bits of free block count.
* - 0x2E
2022-05-20 10:22:55 +08:00
- __le16
- bg_free_inodes_count_hi
2018-07-29 15:40:00 -04:00
- Upper 16-bits of free inode count.
* - 0x30
2022-05-20 10:22:55 +08:00
- __le16
- bg_used_dirs_count_hi
2018-07-29 15:40:00 -04:00
- Upper 16-bits of directory count.
* - 0x32
2022-05-20 10:22:55 +08:00
- __le16
- bg_itable_unused_hi
2018-07-29 15:40:00 -04:00
- Upper 16-bits of unused inode count.
* - 0x34
2022-05-20 10:22:55 +08:00
- __le32
- bg_exclude_bitmap_hi
2018-07-29 15:40:00 -04:00
- Upper 32-bits of location of snapshot exclusion bitmap.
* - 0x38
2022-05-20 10:22:55 +08:00
- __le16
- bg_block_bitmap_csum_hi
2018-07-29 15:40:00 -04:00
- Upper 16-bits of the block bitmap checksum.
* - 0x3A
2022-05-20 10:22:55 +08:00
- __le16
- bg_inode_bitmap_csum_hi
2018-07-29 15:40:00 -04:00
- Upper 16-bits of the inode bitmap checksum.
* - 0x3C
2022-05-20 10:22:55 +08:00
- __u32
- bg_reserved
2018-07-29 15:40:00 -04:00
- Padding to 64 bytes.
.. _bgflags:
Block group flags can be any combination of the following:
.. list-table ::
2018-10-02 22:43:40 -04:00
:widths: 16 64
2018-07-29 15:40:00 -04:00
:header-rows: 1
* - Value
- Description
* - 0x1
2022-05-20 10:22:55 +08:00
- inode table and bitmap are not initialized (EXT4_BG_INODE_UNINIT).
2018-07-29 15:40:00 -04:00
* - 0x2
2022-05-20 10:22:55 +08:00
- block bitmap is not initialized (EXT4_BG_BLOCK_UNINIT).
2018-07-29 15:40:00 -04:00
* - 0x4
2022-05-20 10:22:55 +08:00
- inode table is zeroed (EXT4_BG_INODE_ZEROED).