diff options
author | Eric Biggers <ebiggers@google.com> | 2019-12-09 23:50:21 +0300 |
---|---|---|
committer | Eric Biggers <ebiggers@google.com> | 2019-12-31 19:33:50 +0300 |
commit | 56dce717950925f9d734b9e5621cbd41cbeb3e33 (patch) | |
tree | 7e75057b5c802c825b9b9759f334418f5c322041 /include/linux | |
parent | 2ebdef6d8c766ab7da532002091ad486f9db88ed (diff) | |
download | linux-56dce717950925f9d734b9e5621cbd41cbeb3e33.tar.xz |
fscrypt: introduce fscrypt_needs_contents_encryption()
Add a function fscrypt_needs_contents_encryption() which takes an inode
and returns true if it's an encrypted regular file and the kernel was
built with fscrypt support.
This will allow replacing duplicated checks of IS_ENCRYPTED() &&
S_ISREG() on the I/O paths in ext4 and f2fs, while also optimizing out
unneeded code when !CONFIG_FS_ENCRYPTION.
Link: https://lore.kernel.org/r/20191209205021.231767-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/fscrypt.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index 6eaa729544a3..6fe8d0f96a4a 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -72,6 +72,21 @@ static inline bool fscrypt_has_encryption_key(const struct inode *inode) return READ_ONCE(inode->i_crypt_info) != NULL; } +/** + * fscrypt_needs_contents_encryption() - check whether an inode needs + * contents encryption + * + * Return: %true iff the inode is an encrypted regular file and the kernel was + * built with fscrypt support. + * + * If you need to know whether the encrypt bit is set even when the kernel was + * built without fscrypt support, you must use IS_ENCRYPTED() directly instead. + */ +static inline bool fscrypt_needs_contents_encryption(const struct inode *inode) +{ + return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); +} + static inline bool fscrypt_dummy_context_enabled(struct inode *inode) { return inode->i_sb->s_cop->dummy_context && @@ -269,6 +284,11 @@ static inline bool fscrypt_has_encryption_key(const struct inode *inode) return false; } +static inline bool fscrypt_needs_contents_encryption(const struct inode *inode) +{ + return false; +} + static inline bool fscrypt_dummy_context_enabled(struct inode *inode) { return false; |