libfscrypt: add support for specifying 4K data units

Add a new flag "dusize_4k" that can be specified in the fileencryption
option in the fstab and in the ro.crypto.volume.options system property.
This flag causes the data unit size of the fscrypt policy to be set to
4K if that's not already the filesystem's default.  This takes advantage
of the ability to specify a sub-block data unit size that was recently
added to the kernel.

The use case for this is to allow inline encryption hardware that only
supports a data unit size of 4K to be used when the userdata filesystem
uses a 16K filesystem block size.  A 16K filesystem block size is needed
on f2fs when the system page size is 16K.  Note that currently there is
no known use case for data unit sizes other than 4K or the filesystem
block size, so for now we keep things simple and just handle "dusize_4k"
specifically.  We could allow other dusize_* values in the future.

This new flag will be added to the documentation at
https://source.android.com/docs/security/features/encryption/file-based#enabling-fbe-on-internal-storage

Bug: 299136786
Test: atest libfscrypt_unit_test
Change-Id: I0a6c889e05b9ded39cfe726e6dea6285ee85f129
3 files changed