diff options
author | Eric Biggers <ebiggers@google.com> | 2023-09-25 08:54:49 +0300 |
---|---|---|
committer | Eric Biggers <ebiggers@google.com> | 2023-09-26 08:34:30 +0300 |
commit | f0904e8bc3c513e9fd50bdca5365f998578177a0 (patch) | |
tree | a4283956108b4d0883cb5f8419b2fad1415b265c /fs/crypto/inline_crypt.c | |
parent | 40e13e18168fd0f1a6ad10166f5042a21c47ab99 (diff) | |
download | linux-f0904e8bc3c513e9fd50bdca5365f998578177a0.tar.xz |
fscrypt: compute max_lblk_bits from s_maxbytes and block size
For a given filesystem, the number of bits used by the maximum file
logical block number is computable from the maximum file size and the
block size. These values are always present in struct super_block.
Therefore, compute it this way instead of using the value from
fscrypt_operations::get_ino_and_lblk_bits. Since filesystems always
have to set the super_block fields anyway, this avoids having to provide
this information redundantly via fscrypt_operations.
This change is in preparation for adding support for sub-block data
units. For that, the value that is needed will become "the maximum file
data unit index". A hardcoded value won't suffice for that; it will
need to be computed anyway.
Link: https://lore.kernel.org/r/20230925055451.59499-4-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Diffstat (limited to 'fs/crypto/inline_crypt.c')
-rw-r--r-- | fs/crypto/inline_crypt.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/fs/crypto/inline_crypt.c b/fs/crypto/inline_crypt.c index 8bfb3ce86476..7d9f6c167de5 100644 --- a/fs/crypto/inline_crypt.c +++ b/fs/crypto/inline_crypt.c @@ -41,9 +41,8 @@ static struct block_device **fscrypt_get_devices(struct super_block *sb, static unsigned int fscrypt_get_dun_bytes(const struct fscrypt_info *ci) { - struct super_block *sb = ci->ci_inode->i_sb; + const struct super_block *sb = ci->ci_inode->i_sb; unsigned int flags = fscrypt_policy_flags(&ci->ci_policy); - int ino_bits = 64, lblk_bits = 64; if (flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) return offsetofend(union fscrypt_iv, nonce); @@ -55,9 +54,7 @@ static unsigned int fscrypt_get_dun_bytes(const struct fscrypt_info *ci) return sizeof(__le32); /* Default case: IVs are just the file logical block number */ - if (sb->s_cop->get_ino_and_lblk_bits) - sb->s_cop->get_ino_and_lblk_bits(sb, &ino_bits, &lblk_bits); - return DIV_ROUND_UP(lblk_bits, 8); + return DIV_ROUND_UP(fscrypt_max_file_lblk_bits(sb), 8); } /* |