Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
fscrypt: introduce fscrypt_needs_contents_encryption()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ebiggers authored and Jaegeuk Kim committed Feb 13, 2020
1 parent 3871977 commit bfa4ca6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions include/linux/fscrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -264,6 +279,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;
Expand Down

0 comments on commit bfa4ca6

Please sign in to comment.