blob: 12a0072bddd394690835d30469a406b048c8fdca [file] [log] [blame]
Richard Weinbergerd475a502016-10-20 16:47:56 +02001#include "ubifs.h"
2
3static int ubifs_crypt_get_context(struct inode *inode, void *ctx, size_t len)
4{
5 return ubifs_xattr_get(inode, UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT,
6 ctx, len);
7}
8
9static int ubifs_crypt_set_context(struct inode *inode, const void *ctx,
10 size_t len, void *fs_data)
11{
12 return ubifs_xattr_set(inode, UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT,
13 ctx, len, 0);
14}
15
16static bool ubifs_crypt_empty_dir(struct inode *inode)
17{
18 return ubifs_check_dir_empty(inode) == 0;
19}
20
21static unsigned int ubifs_crypt_max_namelen(struct inode *inode)
22{
23 if (S_ISLNK(inode->i_mode))
24 return UBIFS_MAX_INO_DATA;
25 else
26 return UBIFS_MAX_NLEN;
27}
28
29static int ubifs_key_prefix(struct inode *inode, u8 **key)
30{
31 static char prefix[] = "ubifs:";
32
33 *key = prefix;
34
35 return sizeof(prefix) - 1;
36}
37
38struct fscrypt_operations ubifs_crypt_operations = {
39 .flags = FS_CFLG_INPLACE_ENCRYPTION,
40 .get_context = ubifs_crypt_get_context,
41 .set_context = ubifs_crypt_set_context,
42 .is_encrypted = ubifs_crypt_is_encrypted,
43 .empty_dir = ubifs_crypt_empty_dir,
44 .max_namelen = ubifs_crypt_max_namelen,
45 .key_prefix = ubifs_key_prefix,
46};