summaryrefslogtreecommitdiffstats
path: root/fs/crypto/fscrypt_private.h
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2023-09-24 22:54:49 -0700
committerEric Biggers <ebiggers@google.com>2023-09-25 22:34:30 -0700
commitf0904e8bc3c513e9fd50bdca5365f998578177a0 (patch)
treea4283956108b4d0883cb5f8419b2fad1415b265c /fs/crypto/fscrypt_private.h
parent40e13e18168fd0f1a6ad10166f5042a21c47ab99 (diff)
downloadlinux-f0904e8bc3c513e9fd50bdca5365f998578177a0.tar.gz
linux-f0904e8bc3c513e9fd50bdca5365f998578177a0.tar.bz2
linux-f0904e8bc3c513e9fd50bdca5365f998578177a0.zip
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/fscrypt_private.h')
-rw-r--r--fs/crypto/fscrypt_private.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h
index 2d63da48635a..4b113214b53a 100644
--- a/fs/crypto/fscrypt_private.h
+++ b/fs/crypto/fscrypt_private.h
@@ -296,6 +296,16 @@ union fscrypt_iv {
void fscrypt_generate_iv(union fscrypt_iv *iv, u64 lblk_num,
const struct fscrypt_info *ci);
+/*
+ * Return the number of bits used by the maximum file logical block number that
+ * is possible on the given filesystem.
+ */
+static inline int
+fscrypt_max_file_lblk_bits(const struct super_block *sb)
+{
+ return fls64(sb->s_maxbytes - 1) - sb->s_blocksize_bits;
+}
+
/* fname.c */
bool __fscrypt_fname_encrypted_size(const union fscrypt_policy *policy,
u32 orig_len, u32 max_len,