crypto.h (14e034a61c908d4479be1a7ee9fe5b8d3d1f09b8) crypto.h (77cdb7e17e39ebb986f60bbd3c2b3507687bf475)
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Ceph fscrypt functionality
4 */
5
6#ifndef _CEPH_CRYPTO_H
7#define _CEPH_CRYPTO_H
8

--- 91 unchanged lines hidden (view full) ---

100 if (IS_ENCRYPTED(parent))
101 fscrypt_fname_free_buffer(fname);
102}
103
104int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname,
105 struct fscrypt_str *oname, bool *is_nokey);
106int ceph_fscrypt_prepare_readdir(struct inode *dir);
107
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Ceph fscrypt functionality
4 */
5
6#ifndef _CEPH_CRYPTO_H
7#define _CEPH_CRYPTO_H
8

--- 91 unchanged lines hidden (view full) ---

100 if (IS_ENCRYPTED(parent))
101 fscrypt_fname_free_buffer(fname);
102}
103
104int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname,
105 struct fscrypt_str *oname, bool *is_nokey);
106int ceph_fscrypt_prepare_readdir(struct inode *dir);
107
108static inline unsigned int ceph_fscrypt_blocks(u64 off, u64 len)
109{
110 /* crypto blocks cannot span more than one page */
111 BUILD_BUG_ON(CEPH_FSCRYPT_BLOCK_SHIFT > PAGE_SHIFT);
112
113 return ((off+len+CEPH_FSCRYPT_BLOCK_SIZE-1) >> CEPH_FSCRYPT_BLOCK_SHIFT) -
114 (off >> CEPH_FSCRYPT_BLOCK_SHIFT);
115}
116
117/*
118 * If we have an encrypted inode then we must adjust the offset and
119 * range of the on-the-wire read to cover an entire encryption block.
120 * The copy will be done using the original offset and length, after
121 * we've decrypted the result.
122 */
123static inline void ceph_fscrypt_adjust_off_and_len(struct inode *inode,
124 u64 *off, u64 *len)
125{
126 if (IS_ENCRYPTED(inode)) {
127 *len = ceph_fscrypt_blocks(*off, *len) * CEPH_FSCRYPT_BLOCK_SIZE;
128 *off &= CEPH_FSCRYPT_BLOCK_MASK;
129 }
130}
131
132int ceph_fscrypt_decrypt_block_inplace(const struct inode *inode,
133 struct page *page, unsigned int len,
134 unsigned int offs, u64 lblk_num);
135int ceph_fscrypt_encrypt_block_inplace(const struct inode *inode,
136 struct page *page, unsigned int len,
137 unsigned int offs, u64 lblk_num,
138 gfp_t gfp_flags);
139int ceph_fscrypt_decrypt_pages(struct inode *inode, struct page **page,
140 u64 off, int len);
141int ceph_fscrypt_decrypt_extents(struct inode *inode, struct page **page,
142 u64 off, struct ceph_sparse_extent *map,
143 u32 ext_cnt);
144int ceph_fscrypt_encrypt_pages(struct inode *inode, struct page **page, u64 off,
145 int len, gfp_t gfp);
108#else /* CONFIG_FS_ENCRYPTION */
109
110static inline void ceph_fscrypt_set_ops(struct super_block *sb)
111{
112}
113
114static inline void ceph_fscrypt_free_dummy_policy(struct ceph_fs_client *fsc)
115{

--- 45 unchanged lines hidden (view full) ---

161 oname->len = fname->name_len;
162 return 0;
163}
164
165static inline int ceph_fscrypt_prepare_readdir(struct inode *dir)
166{
167 return 0;
168}
146#else /* CONFIG_FS_ENCRYPTION */
147
148static inline void ceph_fscrypt_set_ops(struct super_block *sb)
149{
150}
151
152static inline void ceph_fscrypt_free_dummy_policy(struct ceph_fs_client *fsc)
153{

--- 45 unchanged lines hidden (view full) ---

199 oname->len = fname->name_len;
200 return 0;
201}
202
203static inline int ceph_fscrypt_prepare_readdir(struct inode *dir)
204{
205 return 0;
206}
207
208static inline void ceph_fscrypt_adjust_off_and_len(struct inode *inode,
209 u64 *off, u64 *len)
210{
211}
212
213static inline int ceph_fscrypt_decrypt_block_inplace(const struct inode *inode,
214 struct page *page, unsigned int len,
215 unsigned int offs, u64 lblk_num)
216{
217 return 0;
218}
219
220static inline int ceph_fscrypt_encrypt_block_inplace(const struct inode *inode,
221 struct page *page, unsigned int len,
222 unsigned int offs, u64 lblk_num,
223 gfp_t gfp_flags)
224{
225 return 0;
226}
227
228static inline int ceph_fscrypt_decrypt_pages(struct inode *inode,
229 struct page **page, u64 off,
230 int len)
231{
232 return 0;
233}
234
235static inline int ceph_fscrypt_decrypt_extents(struct inode *inode,
236 struct page **page, u64 off,
237 struct ceph_sparse_extent *map,
238 u32 ext_cnt)
239{
240 return 0;
241}
242
243static inline int ceph_fscrypt_encrypt_pages(struct inode *inode,
244 struct page **page, u64 off,
245 int len, gfp_t gfp)
246{
247 return 0;
248}
169#endif /* CONFIG_FS_ENCRYPTION */
170
171#endif
249#endif /* CONFIG_FS_ENCRYPTION */
250
251#endif