2 * fscrypt_common.h: common declarations for per-file encryption
4 * Copyright (C) 2015, Google, Inc.
6 * Written by Michael Halcrow, 2015.
7 * Modified by Jaegeuk Kim, 2015.
10 #ifndef _LINUX_FSCRYPT_COMMON_H
11 #define _LINUX_FSCRYPT_COMMON_H
13 #include <linux/key.h>
16 #include <linux/bio.h>
17 #include <linux/dcache.h>
18 #include <crypto/skcipher.h>
19 #include <uapi/linux/fs.h>
21 #define FS_CRYPTO_BLOCK_SIZE 16
28 struct page
*bounce_page
; /* Ciphertext page */
29 struct page
*control_page
; /* Original page */
33 struct work_struct work
;
35 struct list_head free_list
; /* Free list */
41 * For encrypted symlinks, the ciphertext length is stored at the beginning
42 * of the string in little-endian format.
44 struct fscrypt_symlink_data
{
46 char encrypted_path
[1];
55 const struct qstr
*usr_fname
;
56 struct fscrypt_str disk_name
;
59 struct fscrypt_str crypto_buf
;
62 #define FSTR_INIT(n, l) { .name = n, .len = l }
63 #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len)
64 #define fname_name(p) ((p)->disk_name.name)
65 #define fname_len(p) ((p)->disk_name.len)
68 * fscrypt superblock flags
70 #define FS_CFLG_OWN_PAGES (1U << 1)
73 * crypto opertions for filesystems
75 struct fscrypt_operations
{
77 const char *key_prefix
;
78 int (*get_context
)(struct inode
*, void *, size_t);
79 int (*set_context
)(struct inode
*, const void *, size_t, void *);
80 bool (*dummy_context
)(struct inode
*);
81 bool (*is_encrypted
)(struct inode
*);
82 bool (*empty_dir
)(struct inode
*);
83 unsigned (*max_namelen
)(struct inode
*);
86 /* Maximum value for the third parameter of fscrypt_operations.set_context(). */
87 #define FSCRYPT_SET_CONTEXT_MAX_SIZE 28
89 static inline bool fscrypt_dummy_context_enabled(struct inode
*inode
)
91 if (inode
->i_sb
->s_cop
->dummy_context
&&
92 inode
->i_sb
->s_cop
->dummy_context(inode
))
97 static inline bool fscrypt_valid_enc_modes(u32 contents_mode
,
100 if (contents_mode
== FS_ENCRYPTION_MODE_AES_128_CBC
&&
101 filenames_mode
== FS_ENCRYPTION_MODE_AES_128_CTS
)
104 if (contents_mode
== FS_ENCRYPTION_MODE_AES_256_XTS
&&
105 filenames_mode
== FS_ENCRYPTION_MODE_AES_256_CTS
)
111 static inline bool fscrypt_is_dot_dotdot(const struct qstr
*str
)
113 if (str
->len
== 1 && str
->name
[0] == '.')
116 if (str
->len
== 2 && str
->name
[0] == '.' && str
->name
[1] == '.')
122 static inline struct page
*fscrypt_control_page(struct page
*page
)
124 #if IS_ENABLED(CONFIG_FS_ENCRYPTION)
125 return ((struct fscrypt_ctx
*)page_private(page
))->w
.control_page
;
128 return ERR_PTR(-EINVAL
);
132 static inline int fscrypt_has_encryption_key(const struct inode
*inode
)
134 #if IS_ENABLED(CONFIG_FS_ENCRYPTION)
135 return (inode
->i_crypt_info
!= NULL
);
141 #endif /* _LINUX_FSCRYPT_COMMON_H */