OSDN Git Service

Correctly calculate tot_used_blocks on ext4 with uninit_bg
authorEric Biggers <ebiggers@google.com>
Tue, 3 Nov 2020 22:11:01 +0000 (14:11 -0800)
committerEric Biggers <ebiggers@google.com>
Tue, 3 Nov 2020 22:11:01 +0000 (14:11 -0800)
commit7e70d6939d848e6c9000444d162ff6e907ae4534
tree2d8d11bc1fa20a06776d7e6d98680f3edb91f282
parentb3ba087d9ca9b00267586d37939b7c4f61c2e6fe
Correctly calculate tot_used_blocks on ext4 with uninit_bg

The calculated number of blocks to encrypt is too high on ext4
filesystems that have the uninit_bg feature.  This is because the
calculation assumes that all blocks not counted in bg_free_blocks_count
need to encrypted.  But actually, uninitialized block groups have inode
blocks which vold doesn't encrypt since they are uninitialized, but they
are "allocated" and thus reduce bg_free_blocks_count.

Therefore, add a helper function num_base_meta_blocks_in_group() which
returns the number of blocks to encrypt in an uninitialized block group.
Use it both for the encryption and for calculating 'tot_used_blocks'.

Also compute 'tot_used_blocks' additively rather than subtractively, as
this is easier to understand.

Test: see I08fc8465f7962abd698904b5466f3ed080d53953
Change-Id: I4d2cb40291da67dd1bafd61289ccb9e6343bfda3
EncryptInplace.cpp