132190f0aSLinus Torvalds /* SPDX-License-Identifier: GPL-2.0 */
2734f0d24SDave Chinner /*
3734f0d24SDave Chinner * fscrypt.h: declarations for per-file encryption
4734f0d24SDave Chinner *
5643fa961SChandan Rajendra * Filesystems that implement per-file encryption must include this header
6643fa961SChandan Rajendra * file.
7734f0d24SDave Chinner *
8734f0d24SDave Chinner * Copyright (C) 2015, Google, Inc.
9734f0d24SDave Chinner *
10734f0d24SDave Chinner * Written by Michael Halcrow, 2015.
11734f0d24SDave Chinner * Modified by Jaegeuk Kim, 2015.
12734f0d24SDave Chinner */
13734f0d24SDave Chinner #ifndef _LINUX_FSCRYPT_H
14734f0d24SDave Chinner #define _LINUX_FSCRYPT_H
15734f0d24SDave Chinner
16734f0d24SDave Chinner #include <linux/fs.h>
17643fa961SChandan Rajendra #include <linux/mm.h>
18643fa961SChandan Rajendra #include <linux/slab.h>
197af0ab0dSEric Biggers #include <uapi/linux/fscrypt.h>
20734f0d24SDave Chinner
2163cec138SEric Biggers /*
2263cec138SEric Biggers * The lengths of all file contents blocks must be divisible by this value.
2363cec138SEric Biggers * This is needed to ensure that all contents encryption modes will work, as
2463cec138SEric Biggers * some of the supported modes don't support arbitrarily byte-aligned messages.
2563cec138SEric Biggers *
2663cec138SEric Biggers * Since the needed alignment is 16 bytes, most filesystems will meet this
2763cec138SEric Biggers * requirement naturally, as typical block sizes are powers of 2. However, if a
2863cec138SEric Biggers * filesystem can generate arbitrarily byte-aligned block lengths (e.g., via
2963cec138SEric Biggers * compression), then it will need to pad to this alignment before encryption.
3063cec138SEric Biggers */
3163cec138SEric Biggers #define FSCRYPT_CONTENTS_ALIGNMENT 16
32734f0d24SDave Chinner
33ac4acb1fSEric Biggers union fscrypt_policy;
34734f0d24SDave Chinner struct fscrypt_info;
35218d921bSEric Biggers struct fs_parameter;
36ed318a6cSEric Biggers struct seq_file;
37734f0d24SDave Chinner
38734f0d24SDave Chinner struct fscrypt_str {
39734f0d24SDave Chinner unsigned char *name;
40734f0d24SDave Chinner u32 len;
41734f0d24SDave Chinner };
42734f0d24SDave Chinner
43734f0d24SDave Chinner struct fscrypt_name {
44734f0d24SDave Chinner const struct qstr *usr_fname;
45734f0d24SDave Chinner struct fscrypt_str disk_name;
46734f0d24SDave Chinner u32 hash;
47734f0d24SDave Chinner u32 minor_hash;
48734f0d24SDave Chinner struct fscrypt_str crypto_buf;
4970fb2612SEric Biggers bool is_nokey_name;
50734f0d24SDave Chinner };
51734f0d24SDave Chinner
52734f0d24SDave Chinner #define FSTR_INIT(n, l) { .name = n, .len = l }
53734f0d24SDave Chinner #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len)
54734f0d24SDave Chinner #define fname_name(p) ((p)->disk_name.name)
55734f0d24SDave Chinner #define fname_len(p) ((p)->disk_name.len)
56734f0d24SDave Chinner
57734f0d24SDave Chinner /* Maximum value for the third parameter of fscrypt_operations.set_context(). */
585dae460cSEric Biggers #define FSCRYPT_SET_CONTEXT_MAX_SIZE 40
59734f0d24SDave Chinner
60643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION
6138ef66b0SEric Biggers
62643fa961SChandan Rajendra /*
6338ef66b0SEric Biggers * If set, the fscrypt bounce page pool won't be allocated (unless another
6438ef66b0SEric Biggers * filesystem needs it). Set this if the filesystem always uses its own bounce
6538ef66b0SEric Biggers * pages for writes and therefore won't need the fscrypt bounce page pool.
66643fa961SChandan Rajendra */
67643fa961SChandan Rajendra #define FS_CFLG_OWN_PAGES (1U << 1)
68643fa961SChandan Rajendra
6938ef66b0SEric Biggers /* Crypto operations for filesystems */
70643fa961SChandan Rajendra struct fscrypt_operations {
7138ef66b0SEric Biggers
7238ef66b0SEric Biggers /* Set of optional flags; see above for allowed flags */
73643fa961SChandan Rajendra unsigned int flags;
7438ef66b0SEric Biggers
7538ef66b0SEric Biggers /*
7638ef66b0SEric Biggers * If set, this is a filesystem-specific key description prefix that
7738ef66b0SEric Biggers * will be accepted for "logon" keys for v1 fscrypt policies, in
7838ef66b0SEric Biggers * addition to the generic prefix "fscrypt:". This functionality is
7938ef66b0SEric Biggers * deprecated, so new filesystems shouldn't set this field.
8038ef66b0SEric Biggers */
81643fa961SChandan Rajendra const char *key_prefix;
8238ef66b0SEric Biggers
8338ef66b0SEric Biggers /*
8438ef66b0SEric Biggers * Get the fscrypt context of the given inode.
8538ef66b0SEric Biggers *
8638ef66b0SEric Biggers * @inode: the inode whose context to get
8738ef66b0SEric Biggers * @ctx: the buffer into which to get the context
8838ef66b0SEric Biggers * @len: length of the @ctx buffer in bytes
8938ef66b0SEric Biggers *
9038ef66b0SEric Biggers * Return: On success, returns the length of the context in bytes; this
9138ef66b0SEric Biggers * may be less than @len. On failure, returns -ENODATA if the
9238ef66b0SEric Biggers * inode doesn't have a context, -ERANGE if the context is
9338ef66b0SEric Biggers * longer than @len, or another -errno code.
9438ef66b0SEric Biggers */
95fe015a78SEric Biggers int (*get_context)(struct inode *inode, void *ctx, size_t len);
9638ef66b0SEric Biggers
9738ef66b0SEric Biggers /*
9838ef66b0SEric Biggers * Set an fscrypt context on the given inode.
9938ef66b0SEric Biggers *
10038ef66b0SEric Biggers * @inode: the inode whose context to set. The inode won't already have
10138ef66b0SEric Biggers * an fscrypt context.
10238ef66b0SEric Biggers * @ctx: the context to set
10338ef66b0SEric Biggers * @len: length of @ctx in bytes (at most FSCRYPT_SET_CONTEXT_MAX_SIZE)
10438ef66b0SEric Biggers * @fs_data: If called from fscrypt_set_context(), this will be the
10538ef66b0SEric Biggers * value the filesystem passed to fscrypt_set_context().
10638ef66b0SEric Biggers * Otherwise (i.e. when called from
10738ef66b0SEric Biggers * FS_IOC_SET_ENCRYPTION_POLICY) this will be NULL.
10838ef66b0SEric Biggers *
10938ef66b0SEric Biggers * i_rwsem will be held for write.
11038ef66b0SEric Biggers *
11138ef66b0SEric Biggers * Return: 0 on success, -errno on failure.
11238ef66b0SEric Biggers */
113fe015a78SEric Biggers int (*set_context)(struct inode *inode, const void *ctx, size_t len,
114fe015a78SEric Biggers void *fs_data);
11538ef66b0SEric Biggers
11638ef66b0SEric Biggers /*
11738ef66b0SEric Biggers * Get the dummy fscrypt policy in use on the filesystem (if any).
11838ef66b0SEric Biggers *
11938ef66b0SEric Biggers * Filesystems only need to implement this function if they support the
12038ef66b0SEric Biggers * test_dummy_encryption mount option.
12138ef66b0SEric Biggers *
12238ef66b0SEric Biggers * Return: A pointer to the dummy fscrypt policy, if the filesystem is
12338ef66b0SEric Biggers * mounted with test_dummy_encryption; otherwise NULL.
12438ef66b0SEric Biggers */
125ac4acb1fSEric Biggers const union fscrypt_policy *(*get_dummy_policy)(struct super_block *sb);
12638ef66b0SEric Biggers
12738ef66b0SEric Biggers /*
12838ef66b0SEric Biggers * Check whether a directory is empty. i_rwsem will be held for write.
12938ef66b0SEric Biggers */
130fe015a78SEric Biggers bool (*empty_dir)(struct inode *inode);
13138ef66b0SEric Biggers
13238ef66b0SEric Biggers /*
13338ef66b0SEric Biggers * Check whether the filesystem's inode numbers and UUID are stable,
13438ef66b0SEric Biggers * meaning that they will never be changed even by offline operations
13538ef66b0SEric Biggers * such as filesystem shrinking and therefore can be used in the
13638ef66b0SEric Biggers * encryption without the possibility of files becoming unreadable.
13738ef66b0SEric Biggers *
13838ef66b0SEric Biggers * Filesystems only need to implement this function if they want to
13938ef66b0SEric Biggers * support the FSCRYPT_POLICY_FLAG_IV_INO_LBLK_{32,64} flags. These
14038ef66b0SEric Biggers * flags are designed to work around the limitations of UFS and eMMC
14138ef66b0SEric Biggers * inline crypto hardware, and they shouldn't be used in scenarios where
14238ef66b0SEric Biggers * such hardware isn't being used.
14338ef66b0SEric Biggers *
14438ef66b0SEric Biggers * Leaving this NULL is equivalent to always returning false.
14538ef66b0SEric Biggers */
146b103fb76SEric Biggers bool (*has_stable_inodes)(struct super_block *sb);
14738ef66b0SEric Biggers
14838ef66b0SEric Biggers /*
14938ef66b0SEric Biggers * Get the number of bits that the filesystem uses to represent inode
15038ef66b0SEric Biggers * numbers and file logical block numbers.
15138ef66b0SEric Biggers *
15238ef66b0SEric Biggers * By default, both of these are assumed to be 64-bit. This function
15338ef66b0SEric Biggers * can be implemented to declare that either or both of these numbers is
15438ef66b0SEric Biggers * shorter, which may allow the use of the
15538ef66b0SEric Biggers * FSCRYPT_POLICY_FLAG_IV_INO_LBLK_{32,64} flags and/or the use of
15638ef66b0SEric Biggers * inline crypto hardware whose maximum DUN length is less than 64 bits
15738ef66b0SEric Biggers * (e.g., eMMC v5.2 spec compliant hardware). This function only needs
15838ef66b0SEric Biggers * to be implemented if support for one of these features is needed.
15938ef66b0SEric Biggers */
160b103fb76SEric Biggers void (*get_ino_and_lblk_bits)(struct super_block *sb,
161b103fb76SEric Biggers int *ino_bits_ret, int *lblk_bits_ret);
16238ef66b0SEric Biggers
16338ef66b0SEric Biggers /*
1640e91fc1eSChristoph Hellwig * Return an array of pointers to the block devices to which the
1650e91fc1eSChristoph Hellwig * filesystem may write encrypted file contents, NULL if the filesystem
1660e91fc1eSChristoph Hellwig * only has a single such block device, or an ERR_PTR() on error.
1670e91fc1eSChristoph Hellwig *
1680e91fc1eSChristoph Hellwig * On successful non-NULL return, *num_devs is set to the number of
1690e91fc1eSChristoph Hellwig * devices in the returned array. The caller must free the returned
1700e91fc1eSChristoph Hellwig * array using kfree().
17138ef66b0SEric Biggers *
17238ef66b0SEric Biggers * If the filesystem can use multiple block devices (other than block
17338ef66b0SEric Biggers * devices that aren't used for encrypted file contents, such as
17438ef66b0SEric Biggers * external journal devices), and wants to support inline encryption,
17538ef66b0SEric Biggers * then it must implement this function. Otherwise it's not needed.
17638ef66b0SEric Biggers */
1770e91fc1eSChristoph Hellwig struct block_device **(*get_devices)(struct super_block *sb,
1780e91fc1eSChristoph Hellwig unsigned int *num_devs);
179643fa961SChandan Rajendra };
180643fa961SChandan Rajendra
fscrypt_get_info(const struct inode * inode)181ab673b98SEric Biggers static inline struct fscrypt_info *fscrypt_get_info(const struct inode *inode)
182643fa961SChandan Rajendra {
183ab673b98SEric Biggers /*
1845b421f08SEric Biggers * Pairs with the cmpxchg_release() in fscrypt_setup_encryption_info().
185ab673b98SEric Biggers * I.e., another task may publish ->i_crypt_info concurrently, executing
186ab673b98SEric Biggers * a RELEASE barrier. We need to use smp_load_acquire() here to safely
187ab673b98SEric Biggers * ACQUIRE the memory the other task published.
188ab673b98SEric Biggers */
189ab673b98SEric Biggers return smp_load_acquire(&inode->i_crypt_info);
190643fa961SChandan Rajendra }
191643fa961SChandan Rajendra
19256dce717SEric Biggers /**
19356dce717SEric Biggers * fscrypt_needs_contents_encryption() - check whether an inode needs
19456dce717SEric Biggers * contents encryption
195d2fe9754SEric Biggers * @inode: the inode to check
19656dce717SEric Biggers *
19756dce717SEric Biggers * Return: %true iff the inode is an encrypted regular file and the kernel was
19856dce717SEric Biggers * built with fscrypt support.
19956dce717SEric Biggers *
20056dce717SEric Biggers * If you need to know whether the encrypt bit is set even when the kernel was
20156dce717SEric Biggers * built without fscrypt support, you must use IS_ENCRYPTED() directly instead.
20256dce717SEric Biggers */
fscrypt_needs_contents_encryption(const struct inode * inode)20356dce717SEric Biggers static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
20456dce717SEric Biggers {
20556dce717SEric Biggers return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode);
20656dce717SEric Biggers }
20756dce717SEric Biggers
2080bf3d5c1SEric Biggers /*
209501e43fbSEric Biggers * When d_splice_alias() moves a directory's no-key alias to its plaintext alias
210501e43fbSEric Biggers * as a result of the encryption key being added, DCACHE_NOKEY_NAME must be
211501e43fbSEric Biggers * cleared. Note that we don't have to support arbitrary moves of this flag
212501e43fbSEric Biggers * because fscrypt doesn't allow no-key names to be the source or target of a
213501e43fbSEric Biggers * rename().
2140bf3d5c1SEric Biggers */
fscrypt_handle_d_move(struct dentry * dentry)2150bf3d5c1SEric Biggers static inline void fscrypt_handle_d_move(struct dentry *dentry)
2160bf3d5c1SEric Biggers {
217501e43fbSEric Biggers dentry->d_flags &= ~DCACHE_NOKEY_NAME;
2180bf3d5c1SEric Biggers }
2190bf3d5c1SEric Biggers
220159e1de2SEric Biggers /**
221159e1de2SEric Biggers * fscrypt_is_nokey_name() - test whether a dentry is a no-key name
222159e1de2SEric Biggers * @dentry: the dentry to check
223159e1de2SEric Biggers *
224159e1de2SEric Biggers * This returns true if the dentry is a no-key dentry. A no-key dentry is a
225159e1de2SEric Biggers * dentry that was created in an encrypted directory that hasn't had its
226159e1de2SEric Biggers * encryption key added yet. Such dentries may be either positive or negative.
227159e1de2SEric Biggers *
228159e1de2SEric Biggers * When a filesystem is asked to create a new filename in an encrypted directory
229159e1de2SEric Biggers * and the new filename's dentry is a no-key dentry, it must fail the operation
230159e1de2SEric Biggers * with ENOKEY. This includes ->create(), ->mkdir(), ->mknod(), ->symlink(),
231159e1de2SEric Biggers * ->rename(), and ->link(). (However, ->rename() and ->link() are already
232159e1de2SEric Biggers * handled by fscrypt_prepare_rename() and fscrypt_prepare_link().)
233159e1de2SEric Biggers *
234159e1de2SEric Biggers * This is necessary because creating a filename requires the directory's
235159e1de2SEric Biggers * encryption key, but just checking for the key on the directory inode during
236159e1de2SEric Biggers * the final filesystem operation doesn't guarantee that the key was available
237159e1de2SEric Biggers * during the preceding dentry lookup. And the key must have already been
238159e1de2SEric Biggers * available during the dentry lookup in order for it to have been checked
239159e1de2SEric Biggers * whether the filename already exists in the directory and for the new file's
240159e1de2SEric Biggers * dentry not to be invalidated due to it incorrectly having the no-key flag.
241159e1de2SEric Biggers *
242159e1de2SEric Biggers * Return: %true if the dentry is a no-key name
243159e1de2SEric Biggers */
fscrypt_is_nokey_name(const struct dentry * dentry)244159e1de2SEric Biggers static inline bool fscrypt_is_nokey_name(const struct dentry *dentry)
245159e1de2SEric Biggers {
246159e1de2SEric Biggers return dentry->d_flags & DCACHE_NOKEY_NAME;
247159e1de2SEric Biggers }
248159e1de2SEric Biggers
249643fa961SChandan Rajendra /* crypto.c */
25060700902SEric Biggers void fscrypt_enqueue_decrypt_work(struct work_struct *);
25153bc1d85SEric Biggers
25260700902SEric Biggers struct page *fscrypt_encrypt_pagecache_blocks(struct page *page,
25353bc1d85SEric Biggers unsigned int len,
25453bc1d85SEric Biggers unsigned int offs,
25553bc1d85SEric Biggers gfp_t gfp_flags);
25660700902SEric Biggers int fscrypt_encrypt_block_inplace(const struct inode *inode, struct page *page,
25760700902SEric Biggers unsigned int len, unsigned int offs,
25860700902SEric Biggers u64 lblk_num, gfp_t gfp_flags);
259aa8bc1acSEric Biggers
26051e4e315SEric Biggers int fscrypt_decrypt_pagecache_blocks(struct folio *folio, size_t len,
26151e4e315SEric Biggers size_t offs);
26260700902SEric Biggers int fscrypt_decrypt_block_inplace(const struct inode *inode, struct page *page,
26360700902SEric Biggers unsigned int len, unsigned int offs,
26460700902SEric Biggers u64 lblk_num);
265643fa961SChandan Rajendra
fscrypt_is_bounce_page(struct page * page)266d2d0727bSEric Biggers static inline bool fscrypt_is_bounce_page(struct page *page)
267643fa961SChandan Rajendra {
268d2d0727bSEric Biggers return page->mapping == NULL;
269643fa961SChandan Rajendra }
270643fa961SChandan Rajendra
fscrypt_pagecache_page(struct page * bounce_page)271d2d0727bSEric Biggers static inline struct page *fscrypt_pagecache_page(struct page *bounce_page)
272d2d0727bSEric Biggers {
273d2d0727bSEric Biggers return (struct page *)page_private(bounce_page);
274d2d0727bSEric Biggers }
275d2d0727bSEric Biggers
fscrypt_is_bounce_folio(struct folio * folio)276*c76e14dcSMatthew Wilcox static inline bool fscrypt_is_bounce_folio(struct folio *folio)
277*c76e14dcSMatthew Wilcox {
278*c76e14dcSMatthew Wilcox return folio->mapping == NULL;
279*c76e14dcSMatthew Wilcox }
280*c76e14dcSMatthew Wilcox
fscrypt_pagecache_folio(struct folio * bounce_folio)281*c76e14dcSMatthew Wilcox static inline struct folio *fscrypt_pagecache_folio(struct folio *bounce_folio)
282*c76e14dcSMatthew Wilcox {
283*c76e14dcSMatthew Wilcox return bounce_folio->private;
284*c76e14dcSMatthew Wilcox }
285*c76e14dcSMatthew Wilcox
28660700902SEric Biggers void fscrypt_free_bounce_page(struct page *bounce_page);
287643fa961SChandan Rajendra
288643fa961SChandan Rajendra /* policy.c */
28960700902SEric Biggers int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg);
29060700902SEric Biggers int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg);
29160700902SEric Biggers int fscrypt_ioctl_get_policy_ex(struct file *filp, void __user *arg);
29260700902SEric Biggers int fscrypt_ioctl_get_nonce(struct file *filp, void __user *arg);
29360700902SEric Biggers int fscrypt_has_permitted_context(struct inode *parent, struct inode *child);
294637fa738SJeff Layton int fscrypt_context_for_new_inode(void *ctx, struct inode *inode);
295a992b20cSEric Biggers int fscrypt_set_context(struct inode *inode, void *fs_data);
296fe015a78SEric Biggers
297ac4acb1fSEric Biggers struct fscrypt_dummy_policy {
298ac4acb1fSEric Biggers const union fscrypt_policy *policy;
299ed318a6cSEric Biggers };
300ed318a6cSEric Biggers
301218d921bSEric Biggers int fscrypt_parse_test_dummy_encryption(const struct fs_parameter *param,
302218d921bSEric Biggers struct fscrypt_dummy_policy *dummy_policy);
303218d921bSEric Biggers bool fscrypt_dummy_policies_equal(const struct fscrypt_dummy_policy *p1,
304218d921bSEric Biggers const struct fscrypt_dummy_policy *p2);
305ed318a6cSEric Biggers void fscrypt_show_test_dummy_encryption(struct seq_file *seq, char sep,
306ed318a6cSEric Biggers struct super_block *sb);
307218d921bSEric Biggers static inline bool
fscrypt_is_dummy_policy_set(const struct fscrypt_dummy_policy * dummy_policy)308218d921bSEric Biggers fscrypt_is_dummy_policy_set(const struct fscrypt_dummy_policy *dummy_policy)
309218d921bSEric Biggers {
310218d921bSEric Biggers return dummy_policy->policy != NULL;
311218d921bSEric Biggers }
312ed318a6cSEric Biggers static inline void
fscrypt_free_dummy_policy(struct fscrypt_dummy_policy * dummy_policy)313ac4acb1fSEric Biggers fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *dummy_policy)
314ed318a6cSEric Biggers {
315ac4acb1fSEric Biggers kfree(dummy_policy->policy);
316ac4acb1fSEric Biggers dummy_policy->policy = NULL;
317ed318a6cSEric Biggers }
318ed318a6cSEric Biggers
31922d94f49SEric Biggers /* keyring.c */
320ccd30a47SEric Biggers void fscrypt_destroy_keyring(struct super_block *sb);
32160700902SEric Biggers int fscrypt_ioctl_add_key(struct file *filp, void __user *arg);
32260700902SEric Biggers int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg);
32360700902SEric Biggers int fscrypt_ioctl_remove_key_all_users(struct file *filp, void __user *arg);
32460700902SEric Biggers int fscrypt_ioctl_get_key_status(struct file *filp, void __user *arg);
32522d94f49SEric Biggers
326feed8258SEric Biggers /* keysetup.c */
327a992b20cSEric Biggers int fscrypt_prepare_new_inode(struct inode *dir, struct inode *inode,
328a992b20cSEric Biggers bool *encrypt_ret);
32960700902SEric Biggers void fscrypt_put_encryption_info(struct inode *inode);
33060700902SEric Biggers void fscrypt_free_inode(struct inode *inode);
33160700902SEric Biggers int fscrypt_drop_inode(struct inode *inode);
332643fa961SChandan Rajendra
333643fa961SChandan Rajendra /* fname.c */
334d3e94fdcSJeff Layton int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname,
335d3e94fdcSJeff Layton u8 *out, unsigned int olen);
336d3e94fdcSJeff Layton bool fscrypt_fname_encrypted_size(const struct inode *inode, u32 orig_len,
337d3e94fdcSJeff Layton u32 max_len, u32 *encrypted_len_ret);
33860700902SEric Biggers int fscrypt_setup_filename(struct inode *inode, const struct qstr *iname,
339fe015a78SEric Biggers int lookup, struct fscrypt_name *fname);
340643fa961SChandan Rajendra
fscrypt_free_filename(struct fscrypt_name * fname)341643fa961SChandan Rajendra static inline void fscrypt_free_filename(struct fscrypt_name *fname)
342643fa961SChandan Rajendra {
343643fa961SChandan Rajendra kfree(fname->crypto_buf.name);
344643fa961SChandan Rajendra }
345643fa961SChandan Rajendra
3468b10fe68SJeff Layton int fscrypt_fname_alloc_buffer(u32 max_encrypted_len,
347fe015a78SEric Biggers struct fscrypt_str *crypto_str);
34860700902SEric Biggers void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str);
34960700902SEric Biggers int fscrypt_fname_disk_to_usr(const struct inode *inode,
3508a4ab0b8SEric Biggers u32 hash, u32 minor_hash,
3518a4ab0b8SEric Biggers const struct fscrypt_str *iname,
3528a4ab0b8SEric Biggers struct fscrypt_str *oname);
35360700902SEric Biggers bool fscrypt_match_name(const struct fscrypt_name *fname,
354edc440e3SDaniel Rosenberg const u8 *de_name, u32 de_name_len);
35560700902SEric Biggers u64 fscrypt_fname_siphash(const struct inode *dir, const struct qstr *name);
3565b2a828bSEric Biggers int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags);
357aa408f83SDaniel Rosenberg
358643fa961SChandan Rajendra /* bio.c */
35914db0b3cSEric Biggers bool fscrypt_decrypt_bio(struct bio *bio);
36060700902SEric Biggers int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
361fe015a78SEric Biggers sector_t pblk, unsigned int len);
362643fa961SChandan Rajendra
363643fa961SChandan Rajendra /* hooks.c */
36460700902SEric Biggers int fscrypt_file_open(struct inode *inode, struct file *filp);
36560700902SEric Biggers int __fscrypt_prepare_link(struct inode *inode, struct inode *dir,
366968dd6d0SEric Biggers struct dentry *dentry);
36760700902SEric Biggers int __fscrypt_prepare_rename(struct inode *old_dir, struct dentry *old_dentry,
36860700902SEric Biggers struct inode *new_dir, struct dentry *new_dentry,
369643fa961SChandan Rajendra unsigned int flags);
37060700902SEric Biggers int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry,
371b01531dbSEric Biggers struct fscrypt_name *fname);
372ec0caa97SEric Biggers int fscrypt_prepare_lookup_partial(struct inode *dir, struct dentry *dentry);
3737622350eSEric Biggers int __fscrypt_prepare_readdir(struct inode *dir);
37460700902SEric Biggers int __fscrypt_prepare_setattr(struct dentry *dentry, struct iattr *attr);
3756e1918cfSDaniel Rosenberg int fscrypt_prepare_setflags(struct inode *inode,
37631114726SEric Biggers unsigned int oldflags, unsigned int flags);
37731114726SEric Biggers int fscrypt_prepare_symlink(struct inode *dir, const char *target,
378643fa961SChandan Rajendra unsigned int len, unsigned int max_len,
37960700902SEric Biggers struct fscrypt_str *disk_link);
38060700902SEric Biggers int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
38160700902SEric Biggers unsigned int len, struct fscrypt_str *disk_link);
382643fa961SChandan Rajendra const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
383643fa961SChandan Rajendra unsigned int max_size,
384d1876056SEric Biggers struct delayed_call *done);
385eea2c05dSSascha Hauer int fscrypt_symlink_getattr(const struct path *path, struct kstat *stat);
fscrypt_set_ops(struct super_block * sb,const struct fscrypt_operations * s_cop)386eea2c05dSSascha Hauer static inline void fscrypt_set_ops(struct super_block *sb,
387eea2c05dSSascha Hauer const struct fscrypt_operations *s_cop)
388eea2c05dSSascha Hauer {
389eea2c05dSSascha Hauer sb->s_cop = s_cop;
390643fa961SChandan Rajendra }
391643fa961SChandan Rajendra #else /* !CONFIG_FS_ENCRYPTION */
392ab673b98SEric Biggers
fscrypt_get_info(const struct inode * inode)393643fa961SChandan Rajendra static inline struct fscrypt_info *fscrypt_get_info(const struct inode *inode)
394ab673b98SEric Biggers {
395643fa961SChandan Rajendra return NULL;
396643fa961SChandan Rajendra }
39756dce717SEric Biggers
fscrypt_needs_contents_encryption(const struct inode * inode)39856dce717SEric Biggers static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
39956dce717SEric Biggers {
40056dce717SEric Biggers return false;
40156dce717SEric Biggers }
4020bf3d5c1SEric Biggers
fscrypt_handle_d_move(struct dentry * dentry)4030bf3d5c1SEric Biggers static inline void fscrypt_handle_d_move(struct dentry *dentry)
4040bf3d5c1SEric Biggers {
4050bf3d5c1SEric Biggers }
406159e1de2SEric Biggers
fscrypt_is_nokey_name(const struct dentry * dentry)407159e1de2SEric Biggers static inline bool fscrypt_is_nokey_name(const struct dentry *dentry)
408159e1de2SEric Biggers {
409159e1de2SEric Biggers return false;
410159e1de2SEric Biggers }
411643fa961SChandan Rajendra
412643fa961SChandan Rajendra /* crypto.c */
fscrypt_enqueue_decrypt_work(struct work_struct * work)413643fa961SChandan Rajendra static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
414643fa961SChandan Rajendra {
415643fa961SChandan Rajendra }
41653bc1d85SEric Biggers
fscrypt_encrypt_pagecache_blocks(struct page * page,unsigned int len,unsigned int offs,gfp_t gfp_flags)417643fa961SChandan Rajendra static inline struct page *fscrypt_encrypt_pagecache_blocks(struct page *page,
418643fa961SChandan Rajendra unsigned int len,
41953bc1d85SEric Biggers unsigned int offs,
420643fa961SChandan Rajendra gfp_t gfp_flags)
421643fa961SChandan Rajendra {
422643fa961SChandan Rajendra return ERR_PTR(-EOPNOTSUPP);
423643fa961SChandan Rajendra }
42403569f2fSEric Biggers
fscrypt_encrypt_block_inplace(const struct inode * inode,struct page * page,unsigned int len,unsigned int offs,u64 lblk_num,gfp_t gfp_flags)42503569f2fSEric Biggers static inline int fscrypt_encrypt_block_inplace(const struct inode *inode,
42603569f2fSEric Biggers struct page *page,
42703569f2fSEric Biggers unsigned int len,
42803569f2fSEric Biggers unsigned int offs, u64 lblk_num,
42903569f2fSEric Biggers gfp_t gfp_flags)
43003569f2fSEric Biggers {
43103569f2fSEric Biggers return -EOPNOTSUPP;
43203569f2fSEric Biggers }
43351e4e315SEric Biggers
fscrypt_decrypt_pagecache_blocks(struct folio * folio,size_t len,size_t offs)43451e4e315SEric Biggers static inline int fscrypt_decrypt_pagecache_blocks(struct folio *folio,
435643fa961SChandan Rajendra size_t len, size_t offs)
436643fa961SChandan Rajendra {
437643fa961SChandan Rajendra return -EOPNOTSUPP;
438643fa961SChandan Rajendra }
43941adbcb7SEric Biggers
fscrypt_decrypt_block_inplace(const struct inode * inode,struct page * page,unsigned int len,unsigned int offs,u64 lblk_num)44041adbcb7SEric Biggers static inline int fscrypt_decrypt_block_inplace(const struct inode *inode,
44141adbcb7SEric Biggers struct page *page,
44241adbcb7SEric Biggers unsigned int len,
44341adbcb7SEric Biggers unsigned int offs, u64 lblk_num)
44441adbcb7SEric Biggers {
44541adbcb7SEric Biggers return -EOPNOTSUPP;
44641adbcb7SEric Biggers }
447d2d0727bSEric Biggers
fscrypt_is_bounce_page(struct page * page)448d2d0727bSEric Biggers static inline bool fscrypt_is_bounce_page(struct page *page)
449d2d0727bSEric Biggers {
450d2d0727bSEric Biggers return false;
451d2d0727bSEric Biggers }
452d2d0727bSEric Biggers
fscrypt_pagecache_page(struct page * bounce_page)453643fa961SChandan Rajendra static inline struct page *fscrypt_pagecache_page(struct page *bounce_page)
454643fa961SChandan Rajendra {
455643fa961SChandan Rajendra WARN_ON_ONCE(1);
456643fa961SChandan Rajendra return ERR_PTR(-EINVAL);
457643fa961SChandan Rajendra }
458*c76e14dcSMatthew Wilcox
fscrypt_is_bounce_folio(struct folio * folio)459*c76e14dcSMatthew Wilcox static inline bool fscrypt_is_bounce_folio(struct folio *folio)
460*c76e14dcSMatthew Wilcox {
461*c76e14dcSMatthew Wilcox return false;
462*c76e14dcSMatthew Wilcox }
463*c76e14dcSMatthew Wilcox
fscrypt_pagecache_folio(struct folio * bounce_folio)464*c76e14dcSMatthew Wilcox static inline struct folio *fscrypt_pagecache_folio(struct folio *bounce_folio)
465*c76e14dcSMatthew Wilcox {
466*c76e14dcSMatthew Wilcox WARN_ON_ONCE(1);
467*c76e14dcSMatthew Wilcox return ERR_PTR(-EINVAL);
468*c76e14dcSMatthew Wilcox }
469d2d0727bSEric Biggers
fscrypt_free_bounce_page(struct page * bounce_page)470643fa961SChandan Rajendra static inline void fscrypt_free_bounce_page(struct page *bounce_page)
471643fa961SChandan Rajendra {
472643fa961SChandan Rajendra }
473643fa961SChandan Rajendra
474643fa961SChandan Rajendra /* policy.c */
fscrypt_ioctl_set_policy(struct file * filp,const void __user * arg)475643fa961SChandan Rajendra static inline int fscrypt_ioctl_set_policy(struct file *filp,
476643fa961SChandan Rajendra const void __user *arg)
477643fa961SChandan Rajendra {
478643fa961SChandan Rajendra return -EOPNOTSUPP;
479643fa961SChandan Rajendra }
480643fa961SChandan Rajendra
fscrypt_ioctl_get_policy(struct file * filp,void __user * arg)481643fa961SChandan Rajendra static inline int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
482643fa961SChandan Rajendra {
483643fa961SChandan Rajendra return -EOPNOTSUPP;
484643fa961SChandan Rajendra }
4855dae460cSEric Biggers
fscrypt_ioctl_get_policy_ex(struct file * filp,void __user * arg)4865dae460cSEric Biggers static inline int fscrypt_ioctl_get_policy_ex(struct file *filp,
4875dae460cSEric Biggers void __user *arg)
4885dae460cSEric Biggers {
4895dae460cSEric Biggers return -EOPNOTSUPP;
4905dae460cSEric Biggers }
491e98ad464SEric Biggers
fscrypt_ioctl_get_nonce(struct file * filp,void __user * arg)492e98ad464SEric Biggers static inline int fscrypt_ioctl_get_nonce(struct file *filp, void __user *arg)
493e98ad464SEric Biggers {
494e98ad464SEric Biggers return -EOPNOTSUPP;
495e98ad464SEric Biggers }
496643fa961SChandan Rajendra
fscrypt_has_permitted_context(struct inode * parent,struct inode * child)497643fa961SChandan Rajendra static inline int fscrypt_has_permitted_context(struct inode *parent,
498643fa961SChandan Rajendra struct inode *child)
499643fa961SChandan Rajendra {
500643fa961SChandan Rajendra return 0;
501643fa961SChandan Rajendra }
502a992b20cSEric Biggers
fscrypt_set_context(struct inode * inode,void * fs_data)503a992b20cSEric Biggers static inline int fscrypt_set_context(struct inode *inode, void *fs_data)
504a992b20cSEric Biggers {
505a992b20cSEric Biggers return -EOPNOTSUPP;
506a992b20cSEric Biggers }
507ac4acb1fSEric Biggers
508ed318a6cSEric Biggers struct fscrypt_dummy_policy {
509ed318a6cSEric Biggers };
510218d921bSEric Biggers
511218d921bSEric Biggers static inline int
fscrypt_parse_test_dummy_encryption(const struct fs_parameter * param,struct fscrypt_dummy_policy * dummy_policy)512218d921bSEric Biggers fscrypt_parse_test_dummy_encryption(const struct fs_parameter *param,
513218d921bSEric Biggers struct fscrypt_dummy_policy *dummy_policy)
514218d921bSEric Biggers {
515218d921bSEric Biggers return -EINVAL;
516218d921bSEric Biggers }
517218d921bSEric Biggers
518218d921bSEric Biggers static inline bool
fscrypt_dummy_policies_equal(const struct fscrypt_dummy_policy * p1,const struct fscrypt_dummy_policy * p2)519218d921bSEric Biggers fscrypt_dummy_policies_equal(const struct fscrypt_dummy_policy *p1,
520218d921bSEric Biggers const struct fscrypt_dummy_policy *p2)
521218d921bSEric Biggers {
522218d921bSEric Biggers return true;
523218d921bSEric Biggers }
524ed318a6cSEric Biggers
fscrypt_show_test_dummy_encryption(struct seq_file * seq,char sep,struct super_block * sb)525ed318a6cSEric Biggers static inline void fscrypt_show_test_dummy_encryption(struct seq_file *seq,
526ed318a6cSEric Biggers char sep,
527ed318a6cSEric Biggers struct super_block *sb)
528ed318a6cSEric Biggers {
529ed318a6cSEric Biggers }
530218d921bSEric Biggers
531218d921bSEric Biggers static inline bool
fscrypt_is_dummy_policy_set(const struct fscrypt_dummy_policy * dummy_policy)532218d921bSEric Biggers fscrypt_is_dummy_policy_set(const struct fscrypt_dummy_policy *dummy_policy)
533218d921bSEric Biggers {
534218d921bSEric Biggers return false;
535218d921bSEric Biggers }
536ed318a6cSEric Biggers
537ac4acb1fSEric Biggers static inline void
fscrypt_free_dummy_policy(struct fscrypt_dummy_policy * dummy_policy)538ed318a6cSEric Biggers fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *dummy_policy)
539ed318a6cSEric Biggers {
540ed318a6cSEric Biggers }
54122d94f49SEric Biggers
542ccd30a47SEric Biggers /* keyring.c */
fscrypt_destroy_keyring(struct super_block * sb)54322d94f49SEric Biggers static inline void fscrypt_destroy_keyring(struct super_block *sb)
54422d94f49SEric Biggers {
54522d94f49SEric Biggers }
54622d94f49SEric Biggers
fscrypt_ioctl_add_key(struct file * filp,void __user * arg)54722d94f49SEric Biggers static inline int fscrypt_ioctl_add_key(struct file *filp, void __user *arg)
54822d94f49SEric Biggers {
54922d94f49SEric Biggers return -EOPNOTSUPP;
55022d94f49SEric Biggers }
551b1c0ec35SEric Biggers
fscrypt_ioctl_remove_key(struct file * filp,void __user * arg)552b1c0ec35SEric Biggers static inline int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg)
553b1c0ec35SEric Biggers {
554b1c0ec35SEric Biggers return -EOPNOTSUPP;
555b1c0ec35SEric Biggers }
55678a1b96bSEric Biggers
fscrypt_ioctl_remove_key_all_users(struct file * filp,void __user * arg)55778a1b96bSEric Biggers static inline int fscrypt_ioctl_remove_key_all_users(struct file *filp,
55878a1b96bSEric Biggers void __user *arg)
55978a1b96bSEric Biggers {
56078a1b96bSEric Biggers return -EOPNOTSUPP;
56178a1b96bSEric Biggers }
5625a7e2992SEric Biggers
fscrypt_ioctl_get_key_status(struct file * filp,void __user * arg)5635a7e2992SEric Biggers static inline int fscrypt_ioctl_get_key_status(struct file *filp,
5645a7e2992SEric Biggers void __user *arg)
5655a7e2992SEric Biggers {
5665a7e2992SEric Biggers return -EOPNOTSUPP;
5675a7e2992SEric Biggers }
568feed8258SEric Biggers
569643fa961SChandan Rajendra /* keysetup.c */
570a992b20cSEric Biggers
fscrypt_prepare_new_inode(struct inode * dir,struct inode * inode,bool * encrypt_ret)571a992b20cSEric Biggers static inline int fscrypt_prepare_new_inode(struct inode *dir,
572a992b20cSEric Biggers struct inode *inode,
573a992b20cSEric Biggers bool *encrypt_ret)
574a992b20cSEric Biggers {
575a992b20cSEric Biggers if (IS_ENCRYPTED(dir))
576a992b20cSEric Biggers return -EOPNOTSUPP;
577a992b20cSEric Biggers return 0;
578a992b20cSEric Biggers }
579643fa961SChandan Rajendra
fscrypt_put_encryption_info(struct inode * inode)580643fa961SChandan Rajendra static inline void fscrypt_put_encryption_info(struct inode *inode)
581643fa961SChandan Rajendra {
582643fa961SChandan Rajendra return;
583643fa961SChandan Rajendra }
5842c58d548SEric Biggers
fscrypt_free_inode(struct inode * inode)5852c58d548SEric Biggers static inline void fscrypt_free_inode(struct inode *inode)
5862c58d548SEric Biggers {
5872c58d548SEric Biggers }
588b1c0ec35SEric Biggers
fscrypt_drop_inode(struct inode * inode)589b1c0ec35SEric Biggers static inline int fscrypt_drop_inode(struct inode *inode)
590b1c0ec35SEric Biggers {
591b1c0ec35SEric Biggers return 0;
592b1c0ec35SEric Biggers }
593643fa961SChandan Rajendra
594643fa961SChandan Rajendra /* fname.c */
fscrypt_setup_filename(struct inode * dir,const struct qstr * iname,int lookup,struct fscrypt_name * fname)595643fa961SChandan Rajendra static inline int fscrypt_setup_filename(struct inode *dir,
596643fa961SChandan Rajendra const struct qstr *iname,
597643fa961SChandan Rajendra int lookup, struct fscrypt_name *fname)
598643fa961SChandan Rajendra {
599643fa961SChandan Rajendra if (IS_ENCRYPTED(dir))
600643fa961SChandan Rajendra return -EOPNOTSUPP;
601b01531dbSEric Biggers
602643fa961SChandan Rajendra memset(fname, 0, sizeof(*fname));
603643fa961SChandan Rajendra fname->usr_fname = iname;
604643fa961SChandan Rajendra fname->disk_name.name = (unsigned char *)iname->name;
605643fa961SChandan Rajendra fname->disk_name.len = iname->len;
606643fa961SChandan Rajendra return 0;
607643fa961SChandan Rajendra }
608643fa961SChandan Rajendra
fscrypt_free_filename(struct fscrypt_name * fname)609643fa961SChandan Rajendra static inline void fscrypt_free_filename(struct fscrypt_name *fname)
610643fa961SChandan Rajendra {
611643fa961SChandan Rajendra return;
612643fa961SChandan Rajendra }
6138b10fe68SJeff Layton
fscrypt_fname_alloc_buffer(u32 max_encrypted_len,struct fscrypt_str * crypto_str)614643fa961SChandan Rajendra static inline int fscrypt_fname_alloc_buffer(u32 max_encrypted_len,
615643fa961SChandan Rajendra struct fscrypt_str *crypto_str)
616643fa961SChandan Rajendra {
617643fa961SChandan Rajendra return -EOPNOTSUPP;
618643fa961SChandan Rajendra }
619643fa961SChandan Rajendra
fscrypt_fname_free_buffer(struct fscrypt_str * crypto_str)620643fa961SChandan Rajendra static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
621643fa961SChandan Rajendra {
622643fa961SChandan Rajendra return;
623643fa961SChandan Rajendra }
6248a4ab0b8SEric Biggers
fscrypt_fname_disk_to_usr(const struct inode * inode,u32 hash,u32 minor_hash,const struct fscrypt_str * iname,struct fscrypt_str * oname)625643fa961SChandan Rajendra static inline int fscrypt_fname_disk_to_usr(const struct inode *inode,
626643fa961SChandan Rajendra u32 hash, u32 minor_hash,
627643fa961SChandan Rajendra const struct fscrypt_str *iname,
628643fa961SChandan Rajendra struct fscrypt_str *oname)
629643fa961SChandan Rajendra {
630643fa961SChandan Rajendra return -EOPNOTSUPP;
631643fa961SChandan Rajendra }
632643fa961SChandan Rajendra
fscrypt_match_name(const struct fscrypt_name * fname,const u8 * de_name,u32 de_name_len)633643fa961SChandan Rajendra static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
634643fa961SChandan Rajendra const u8 *de_name, u32 de_name_len)
635643fa961SChandan Rajendra {
636643fa961SChandan Rajendra /* Encryption support disabled; use standard comparison */
637643fa961SChandan Rajendra if (de_name_len != fname->disk_name.len)
638643fa961SChandan Rajendra return false;
639643fa961SChandan Rajendra return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
640643fa961SChandan Rajendra }
641aa408f83SDaniel Rosenberg
fscrypt_fname_siphash(const struct inode * dir,const struct qstr * name)642aa408f83SDaniel Rosenberg static inline u64 fscrypt_fname_siphash(const struct inode *dir,
643aa408f83SDaniel Rosenberg const struct qstr *name)
644aa408f83SDaniel Rosenberg {
645aa408f83SDaniel Rosenberg WARN_ON_ONCE(1);
646aa408f83SDaniel Rosenberg return 0;
647aa408f83SDaniel Rosenberg }
6485b2a828bSEric Biggers
fscrypt_d_revalidate(struct dentry * dentry,unsigned int flags)6495b2a828bSEric Biggers static inline int fscrypt_d_revalidate(struct dentry *dentry,
6505b2a828bSEric Biggers unsigned int flags)
6515b2a828bSEric Biggers {
6525b2a828bSEric Biggers return 1;
6535b2a828bSEric Biggers }
654643fa961SChandan Rajendra
65514db0b3cSEric Biggers /* bio.c */
fscrypt_decrypt_bio(struct bio * bio)656643fa961SChandan Rajendra static inline bool fscrypt_decrypt_bio(struct bio *bio)
65714db0b3cSEric Biggers {
658643fa961SChandan Rajendra return true;
659643fa961SChandan Rajendra }
660643fa961SChandan Rajendra
fscrypt_zeroout_range(const struct inode * inode,pgoff_t lblk,sector_t pblk,unsigned int len)661643fa961SChandan Rajendra static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
662643fa961SChandan Rajendra sector_t pblk, unsigned int len)
663643fa961SChandan Rajendra {
664643fa961SChandan Rajendra return -EOPNOTSUPP;
665643fa961SChandan Rajendra }
666643fa961SChandan Rajendra
667643fa961SChandan Rajendra /* hooks.c */
668643fa961SChandan Rajendra
fscrypt_file_open(struct inode * inode,struct file * filp)669643fa961SChandan Rajendra static inline int fscrypt_file_open(struct inode *inode, struct file *filp)
670643fa961SChandan Rajendra {
671643fa961SChandan Rajendra if (IS_ENCRYPTED(inode))
672643fa961SChandan Rajendra return -EOPNOTSUPP;
673643fa961SChandan Rajendra return 0;
674643fa961SChandan Rajendra }
675968dd6d0SEric Biggers
__fscrypt_prepare_link(struct inode * inode,struct inode * dir,struct dentry * dentry)676968dd6d0SEric Biggers static inline int __fscrypt_prepare_link(struct inode *inode, struct inode *dir,
677643fa961SChandan Rajendra struct dentry *dentry)
678643fa961SChandan Rajendra {
679643fa961SChandan Rajendra return -EOPNOTSUPP;
680643fa961SChandan Rajendra }
681643fa961SChandan Rajendra
__fscrypt_prepare_rename(struct inode * old_dir,struct dentry * old_dentry,struct inode * new_dir,struct dentry * new_dentry,unsigned int flags)682643fa961SChandan Rajendra static inline int __fscrypt_prepare_rename(struct inode *old_dir,
683643fa961SChandan Rajendra struct dentry *old_dentry,
684643fa961SChandan Rajendra struct inode *new_dir,
685643fa961SChandan Rajendra struct dentry *new_dentry,
686643fa961SChandan Rajendra unsigned int flags)
687643fa961SChandan Rajendra {
688643fa961SChandan Rajendra return -EOPNOTSUPP;
689643fa961SChandan Rajendra }
690643fa961SChandan Rajendra
__fscrypt_prepare_lookup(struct inode * dir,struct dentry * dentry,struct fscrypt_name * fname)691b01531dbSEric Biggers static inline int __fscrypt_prepare_lookup(struct inode *dir,
692b01531dbSEric Biggers struct dentry *dentry,
693643fa961SChandan Rajendra struct fscrypt_name *fname)
694643fa961SChandan Rajendra {
695643fa961SChandan Rajendra return -EOPNOTSUPP;
696643fa961SChandan Rajendra }
697ec0caa97SEric Biggers
fscrypt_prepare_lookup_partial(struct inode * dir,struct dentry * dentry)698ec0caa97SEric Biggers static inline int fscrypt_prepare_lookup_partial(struct inode *dir,
699ec0caa97SEric Biggers struct dentry *dentry)
700ec0caa97SEric Biggers {
701ec0caa97SEric Biggers return -EOPNOTSUPP;
7027622350eSEric Biggers }
7037622350eSEric Biggers
__fscrypt_prepare_readdir(struct inode * dir)7047622350eSEric Biggers static inline int __fscrypt_prepare_readdir(struct inode *dir)
7057622350eSEric Biggers {
7067622350eSEric Biggers return -EOPNOTSUPP;
7077622350eSEric Biggers }
7086e1918cfSDaniel Rosenberg
__fscrypt_prepare_setattr(struct dentry * dentry,struct iattr * attr)7096e1918cfSDaniel Rosenberg static inline int __fscrypt_prepare_setattr(struct dentry *dentry,
7106e1918cfSDaniel Rosenberg struct iattr *attr)
7116e1918cfSDaniel Rosenberg {
7126e1918cfSDaniel Rosenberg return -EOPNOTSUPP;
7136e1918cfSDaniel Rosenberg }
7146e1918cfSDaniel Rosenberg
fscrypt_prepare_setflags(struct inode * inode,unsigned int oldflags,unsigned int flags)71531114726SEric Biggers static inline int fscrypt_prepare_setflags(struct inode *inode,
71631114726SEric Biggers unsigned int oldflags,
717643fa961SChandan Rajendra unsigned int flags)
718643fa961SChandan Rajendra {
719643fa961SChandan Rajendra return 0;
720643fa961SChandan Rajendra }
72131114726SEric Biggers
fscrypt_prepare_symlink(struct inode * dir,const char * target,unsigned int len,unsigned int max_len,struct fscrypt_str * disk_link)722643fa961SChandan Rajendra static inline int fscrypt_prepare_symlink(struct inode *dir,
72331114726SEric Biggers const char *target,
72431114726SEric Biggers unsigned int len,
72531114726SEric Biggers unsigned int max_len,
72631114726SEric Biggers struct fscrypt_str *disk_link)
72731114726SEric Biggers {
728643fa961SChandan Rajendra if (IS_ENCRYPTED(dir))
729643fa961SChandan Rajendra return -EOPNOTSUPP;
730643fa961SChandan Rajendra disk_link->name = (unsigned char *)target;
731643fa961SChandan Rajendra disk_link->len = len + 1;
732643fa961SChandan Rajendra if (disk_link->len > max_len)
733643fa961SChandan Rajendra return -ENAMETOOLONG;
734643fa961SChandan Rajendra return 0;
735643fa961SChandan Rajendra }
736643fa961SChandan Rajendra
__fscrypt_encrypt_symlink(struct inode * inode,const char * target,unsigned int len,struct fscrypt_str * disk_link)737643fa961SChandan Rajendra static inline int __fscrypt_encrypt_symlink(struct inode *inode,
738643fa961SChandan Rajendra const char *target,
739643fa961SChandan Rajendra unsigned int len,
740643fa961SChandan Rajendra struct fscrypt_str *disk_link)
741643fa961SChandan Rajendra {
742643fa961SChandan Rajendra return -EOPNOTSUPP;
743643fa961SChandan Rajendra }
744643fa961SChandan Rajendra
fscrypt_get_symlink(struct inode * inode,const void * caddr,unsigned int max_size,struct delayed_call * done)745eea2c05dSSascha Hauer static inline const char *fscrypt_get_symlink(struct inode *inode,
746d1876056SEric Biggers const void *caddr,
747d1876056SEric Biggers unsigned int max_size,
748d1876056SEric Biggers struct delayed_call *done)
749d1876056SEric Biggers {
750d1876056SEric Biggers return ERR_PTR(-EOPNOTSUPP);
751d1876056SEric Biggers }
752eea2c05dSSascha Hauer
fscrypt_symlink_getattr(const struct path * path,struct kstat * stat)753eea2c05dSSascha Hauer static inline int fscrypt_symlink_getattr(const struct path *path,
754eea2c05dSSascha Hauer struct kstat *stat)
755eea2c05dSSascha Hauer {
756eea2c05dSSascha Hauer return -EOPNOTSUPP;
757643fa961SChandan Rajendra }
758734f0d24SDave Chinner
fscrypt_set_ops(struct super_block * sb,const struct fscrypt_operations * s_cop)7595fee3609SSatya Tangirala static inline void fscrypt_set_ops(struct super_block *sb,
7605fee3609SSatya Tangirala const struct fscrypt_operations *s_cop)
7615fee3609SSatya Tangirala {
7625fee3609SSatya Tangirala }
7635fee3609SSatya Tangirala
7645fee3609SSatya Tangirala #endif /* !CONFIG_FS_ENCRYPTION */
7655fee3609SSatya Tangirala
7665fee3609SSatya Tangirala /* inline_crypt.c */
7675fee3609SSatya Tangirala #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
7685fee3609SSatya Tangirala
7695fee3609SSatya Tangirala bool __fscrypt_inode_uses_inline_crypto(const struct inode *inode);
7705fee3609SSatya Tangirala
7715fee3609SSatya Tangirala void fscrypt_set_bio_crypt_ctx(struct bio *bio,
7725fee3609SSatya Tangirala const struct inode *inode, u64 first_lblk,
7735fee3609SSatya Tangirala gfp_t gfp_mask);
7745fee3609SSatya Tangirala
7755fee3609SSatya Tangirala void fscrypt_set_bio_crypt_ctx_bh(struct bio *bio,
7765fee3609SSatya Tangirala const struct buffer_head *first_bh,
7775fee3609SSatya Tangirala gfp_t gfp_mask);
77853dd3f80SEric Biggers
779c6c89783SEric Biggers bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,
780c6c89783SEric Biggers u64 next_lblk);
781c6c89783SEric Biggers
7825fee3609SSatya Tangirala bool fscrypt_mergeable_bio_bh(struct bio *bio,
7835fee3609SSatya Tangirala const struct buffer_head *next_bh);
7845fee3609SSatya Tangirala
7855fee3609SSatya Tangirala bool fscrypt_dio_supported(struct inode *inode);
7865fee3609SSatya Tangirala
7875fee3609SSatya Tangirala u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk, u64 nr_blocks);
7885fee3609SSatya Tangirala
7895fee3609SSatya Tangirala #else /* CONFIG_FS_ENCRYPTION_INLINE_CRYPT */
7905fee3609SSatya Tangirala
__fscrypt_inode_uses_inline_crypto(const struct inode * inode)7915fee3609SSatya Tangirala static inline bool __fscrypt_inode_uses_inline_crypto(const struct inode *inode)
7925fee3609SSatya Tangirala {
7935fee3609SSatya Tangirala return false;
7945fee3609SSatya Tangirala }
7955fee3609SSatya Tangirala
fscrypt_set_bio_crypt_ctx(struct bio * bio,const struct inode * inode,u64 first_lblk,gfp_t gfp_mask)7965fee3609SSatya Tangirala static inline void fscrypt_set_bio_crypt_ctx(struct bio *bio,
7975fee3609SSatya Tangirala const struct inode *inode,
7985fee3609SSatya Tangirala u64 first_lblk, gfp_t gfp_mask) { }
7995fee3609SSatya Tangirala
fscrypt_set_bio_crypt_ctx_bh(struct bio * bio,const struct buffer_head * first_bh,gfp_t gfp_mask)8005fee3609SSatya Tangirala static inline void fscrypt_set_bio_crypt_ctx_bh(
8015fee3609SSatya Tangirala struct bio *bio,
8025fee3609SSatya Tangirala const struct buffer_head *first_bh,
8035fee3609SSatya Tangirala gfp_t gfp_mask) { }
8045fee3609SSatya Tangirala
fscrypt_mergeable_bio(struct bio * bio,const struct inode * inode,u64 next_lblk)8055fee3609SSatya Tangirala static inline bool fscrypt_mergeable_bio(struct bio *bio,
8065fee3609SSatya Tangirala const struct inode *inode,
8075fee3609SSatya Tangirala u64 next_lblk)
8085fee3609SSatya Tangirala {
8095fee3609SSatya Tangirala return true;
810c6c89783SEric Biggers }
81153dd3f80SEric Biggers
fscrypt_mergeable_bio_bh(struct bio * bio,const struct buffer_head * next_bh)812c6c89783SEric Biggers static inline bool fscrypt_mergeable_bio_bh(struct bio *bio,
813c6c89783SEric Biggers const struct buffer_head *next_bh)
814c6c89783SEric Biggers {
815c6c89783SEric Biggers return true;
816c6c89783SEric Biggers }
817c6c89783SEric Biggers
fscrypt_dio_supported(struct inode * inode)818c6c89783SEric Biggers static inline bool fscrypt_dio_supported(struct inode *inode)
819c6c89783SEric Biggers {
820c6c89783SEric Biggers return !fscrypt_needs_contents_encryption(inode);
8215fee3609SSatya Tangirala }
8225fee3609SSatya Tangirala
fscrypt_limit_io_blocks(const struct inode * inode,u64 lblk,u64 nr_blocks)8235fee3609SSatya Tangirala static inline u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk,
8245fee3609SSatya Tangirala u64 nr_blocks)
8255fee3609SSatya Tangirala {
8265fee3609SSatya Tangirala return nr_blocks;
8275fee3609SSatya Tangirala }
8285fee3609SSatya Tangirala #endif /* !CONFIG_FS_ENCRYPTION_INLINE_CRYPT */
8295fee3609SSatya Tangirala
8305fee3609SSatya Tangirala /**
8315fee3609SSatya Tangirala * fscrypt_inode_uses_inline_crypto() - test whether an inode uses inline
8325fee3609SSatya Tangirala * encryption
8335fee3609SSatya Tangirala * @inode: an inode. If encrypted, its key must be set up.
8345fee3609SSatya Tangirala *
8355fee3609SSatya Tangirala * Return: true if the inode requires file contents encryption and if the
8365fee3609SSatya Tangirala * encryption should be done in the block layer via blk-crypto rather
8375fee3609SSatya Tangirala * than in the filesystem layer.
8385fee3609SSatya Tangirala */
fscrypt_inode_uses_inline_crypto(const struct inode * inode)8395fee3609SSatya Tangirala static inline bool fscrypt_inode_uses_inline_crypto(const struct inode *inode)
8405fee3609SSatya Tangirala {
8415fee3609SSatya Tangirala return fscrypt_needs_contents_encryption(inode) &&
8425fee3609SSatya Tangirala __fscrypt_inode_uses_inline_crypto(inode);
8435fee3609SSatya Tangirala }
8445fee3609SSatya Tangirala
8455fee3609SSatya Tangirala /**
8465fee3609SSatya Tangirala * fscrypt_inode_uses_fs_layer_crypto() - test whether an inode uses fs-layer
8475fee3609SSatya Tangirala * encryption
8485fee3609SSatya Tangirala * @inode: an inode. If encrypted, its key must be set up.
8495fee3609SSatya Tangirala *
8505fee3609SSatya Tangirala * Return: true if the inode requires file contents encryption and if the
8515fee3609SSatya Tangirala * encryption should be done in the filesystem layer rather than in the
8525fee3609SSatya Tangirala * block layer via blk-crypto.
853d293c3e4SEric Biggers */
fscrypt_inode_uses_fs_layer_crypto(const struct inode * inode)854ab673b98SEric Biggers static inline bool fscrypt_inode_uses_fs_layer_crypto(const struct inode *inode)
855ab673b98SEric Biggers {
856ab673b98SEric Biggers return fscrypt_needs_contents_encryption(inode) &&
857ab673b98SEric Biggers !__fscrypt_inode_uses_inline_crypto(inode);
858ab673b98SEric Biggers }
859ab673b98SEric Biggers
860ab673b98SEric Biggers /**
861ab673b98SEric Biggers * fscrypt_has_encryption_key() - check whether an inode has had its key set up
862ab673b98SEric Biggers * @inode: the inode to check
863ab673b98SEric Biggers *
864ab673b98SEric Biggers * Return: %true if the inode has had its encryption key set up, else %false.
865ab673b98SEric Biggers *
866ab673b98SEric Biggers * Usually this should be preceded by fscrypt_get_encryption_info() to try to
867ab673b98SEric Biggers * set up the key first.
868d2fe9754SEric Biggers */
fscrypt_has_encryption_key(const struct inode * inode)869d2fe9754SEric Biggers static inline bool fscrypt_has_encryption_key(const struct inode *inode)
8700ea87a96SEric Biggers {
8710ea87a96SEric Biggers return fscrypt_get_info(inode) != NULL;
8720ea87a96SEric Biggers }
8730ea87a96SEric Biggers
8740ea87a96SEric Biggers /**
8750ea87a96SEric Biggers * fscrypt_prepare_link() - prepare to link an inode into a possibly-encrypted
876234f1b7fSEric Biggers * directory
8770ea87a96SEric Biggers * @old_dentry: an existing dentry for the inode being linked
8780ea87a96SEric Biggers * @dir: the target directory
8790ea87a96SEric Biggers * @dentry: negative dentry for the target filename
8800ea87a96SEric Biggers *
8810ea87a96SEric Biggers * A new link can only be added to an encrypted directory if the directory's
882f5e55e77SEric Biggers * encryption key is available --- since otherwise we'd have no way to encrypt
8830ea87a96SEric Biggers * the filename.
8840ea87a96SEric Biggers *
8850ea87a96SEric Biggers * We also verify that the link will not violate the constraint that all files
8860ea87a96SEric Biggers * in an encrypted directory tree use the same encryption policy.
8870ea87a96SEric Biggers *
8880ea87a96SEric Biggers * Return: 0 on success, -ENOKEY if the directory's encryption key is missing,
8890ea87a96SEric Biggers * -EXDEV if the link would result in an inconsistent encryption policy, or
890968dd6d0SEric Biggers * another -errno code.
8910ea87a96SEric Biggers */
fscrypt_prepare_link(struct dentry * old_dentry,struct inode * dir,struct dentry * dentry)8920ea87a96SEric Biggers static inline int fscrypt_prepare_link(struct dentry *old_dentry,
8930ea87a96SEric Biggers struct inode *dir,
89494b26f36SEric Biggers struct dentry *dentry)
895d2fe9754SEric Biggers {
896d2fe9754SEric Biggers if (IS_ENCRYPTED(dir))
89794b26f36SEric Biggers return __fscrypt_prepare_link(d_inode(old_dentry), dir, dentry);
89894b26f36SEric Biggers return 0;
89994b26f36SEric Biggers }
90094b26f36SEric Biggers
90194b26f36SEric Biggers /**
90294b26f36SEric Biggers * fscrypt_prepare_rename() - prepare for a rename between possibly-encrypted
90394b26f36SEric Biggers * directories
90494b26f36SEric Biggers * @old_dir: source directory
90594b26f36SEric Biggers * @old_dentry: dentry for source file
90694b26f36SEric Biggers * @new_dir: target directory
90794b26f36SEric Biggers * @new_dentry: dentry for target location (may be negative unless exchanging)
90894b26f36SEric Biggers * @flags: rename flags (we care at least about %RENAME_EXCHANGE)
90994b26f36SEric Biggers *
91094b26f36SEric Biggers * Prepare for ->rename() where the source and/or target directories may be
91194b26f36SEric Biggers * encrypted. A new link can only be added to an encrypted directory if the
91294b26f36SEric Biggers * directory's encryption key is available --- since otherwise we'd have no way
913f5e55e77SEric Biggers * to encrypt the filename. A rename to an existing name, on the other hand,
91494b26f36SEric Biggers * *is* cryptographically possible without the key. However, we take the more
91594b26f36SEric Biggers * conservative approach and just forbid all no-key renames.
91694b26f36SEric Biggers *
91794b26f36SEric Biggers * We also verify that the rename will not violate the constraint that all files
91894b26f36SEric Biggers * in an encrypted directory tree use the same encryption policy.
91994b26f36SEric Biggers *
92094b26f36SEric Biggers * Return: 0 on success, -ENOKEY if an encryption key is missing, -EXDEV if the
92194b26f36SEric Biggers * rename would cause inconsistent encryption policies, or another -errno code.
92294b26f36SEric Biggers */
fscrypt_prepare_rename(struct inode * old_dir,struct dentry * old_dentry,struct inode * new_dir,struct dentry * new_dentry,unsigned int flags)92394b26f36SEric Biggers static inline int fscrypt_prepare_rename(struct inode *old_dir,
92494b26f36SEric Biggers struct dentry *old_dentry,
92594b26f36SEric Biggers struct inode *new_dir,
92694b26f36SEric Biggers struct dentry *new_dentry,
92794b26f36SEric Biggers unsigned int flags)
92832c3cf02SEric Biggers {
929d2fe9754SEric Biggers if (IS_ENCRYPTED(old_dir) || IS_ENCRYPTED(new_dir))
930d2fe9754SEric Biggers return __fscrypt_prepare_rename(old_dir, old_dentry,
93132c3cf02SEric Biggers new_dir, new_dentry, flags);
93232c3cf02SEric Biggers return 0;
933b01531dbSEric Biggers }
93432c3cf02SEric Biggers
935b01531dbSEric Biggers /**
93670fb2612SEric Biggers * fscrypt_prepare_lookup() - prepare to lookup a name in a possibly-encrypted
937a14d0b67SEric Biggers * directory
938a14d0b67SEric Biggers * @dir: directory being searched
939a14d0b67SEric Biggers * @dentry: filename being looked up
94032c3cf02SEric Biggers * @fname: (output) the name to use to search the on-disk directory
941bb9cd910SDaniel Rosenberg *
942bb9cd910SDaniel Rosenberg * Prepare for ->lookup() in a directory which may be encrypted by determining
943bb9cd910SDaniel Rosenberg * the name that will actually be used to search the directory on-disk. If the
944bb9cd910SDaniel Rosenberg * directory's encryption policy is supported by this kernel and its encryption
945bb9cd910SDaniel Rosenberg * key is available, then the lookup is assumed to be by plaintext name;
94632c3cf02SEric Biggers * otherwise, it is assumed to be by no-key name.
94770fb2612SEric Biggers *
94870fb2612SEric Biggers * This will set DCACHE_NOKEY_NAME on the dentry if the lookup is by no-key
94970fb2612SEric Biggers * name. In this case the filesystem must assign the dentry a dentry_operations
95032c3cf02SEric Biggers * which contains fscrypt_d_revalidate (or contains a d_revalidate method that
95132c3cf02SEric Biggers * calls fscrypt_d_revalidate), so that the dentry will be invalidated if the
95232c3cf02SEric Biggers * directory's encryption key is later added.
953b01531dbSEric Biggers *
95432c3cf02SEric Biggers * Return: 0 on success; -ENOENT if the directory's key is unavailable but the
95532c3cf02SEric Biggers * filename isn't a valid no-key name, so a negative dentry should be created;
956b01531dbSEric Biggers * or another -errno code.
957b01531dbSEric Biggers */
fscrypt_prepare_lookup(struct inode * dir,struct dentry * dentry,struct fscrypt_name * fname)958b01531dbSEric Biggers static inline int fscrypt_prepare_lookup(struct inode *dir,
959b01531dbSEric Biggers struct dentry *dentry,
960b01531dbSEric Biggers struct fscrypt_name *fname)
961b01531dbSEric Biggers {
96232c3cf02SEric Biggers if (IS_ENCRYPTED(dir))
96332c3cf02SEric Biggers return __fscrypt_prepare_lookup(dir, dentry, fname);
96432c3cf02SEric Biggers
965815dac33SEric Biggers memset(fname, 0, sizeof(*fname));
966ec0caa97SEric Biggers fname->usr_fname = &dentry->d_name;
967ec0caa97SEric Biggers fname->disk_name.name = (unsigned char *)dentry->d_name.name;
968ec0caa97SEric Biggers fname->disk_name.len = dentry->d_name.len;
969ec0caa97SEric Biggers return 0;
970ec0caa97SEric Biggers }
971ec0caa97SEric Biggers
972ec0caa97SEric Biggers /**
973ec0caa97SEric Biggers * fscrypt_prepare_readdir() - prepare to read a possibly-encrypted directory
974a14d0b67SEric Biggers * @dir: the directory inode
975a14d0b67SEric Biggers *
976a14d0b67SEric Biggers * If the directory is encrypted and it doesn't already have its encryption key
977ec0caa97SEric Biggers * set up, try to set it up so that the filenames will be listed in plaintext
978ec0caa97SEric Biggers * form rather than in no-key form.
979ec0caa97SEric Biggers *
980ec0caa97SEric Biggers * Return: 0 on success; -errno on error. Note that the encryption key being
981ec0caa97SEric Biggers * unavailable is not considered an error. It is also not an error if
982ec0caa97SEric Biggers * the encryption policy is unsupported by this kernel; that is treated
983ec0caa97SEric Biggers * like the key being unavailable, so that files can still be deleted.
984ec0caa97SEric Biggers */
fscrypt_prepare_readdir(struct inode * dir)985ec0caa97SEric Biggers static inline int fscrypt_prepare_readdir(struct inode *dir)
986d2fe9754SEric Biggers {
987d2fe9754SEric Biggers if (IS_ENCRYPTED(dir))
988815dac33SEric Biggers return __fscrypt_prepare_readdir(dir);
989815dac33SEric Biggers return 0;
990815dac33SEric Biggers }
991815dac33SEric Biggers
992815dac33SEric Biggers /**
993815dac33SEric Biggers * fscrypt_prepare_setattr() - prepare to change a possibly-encrypted inode's
994815dac33SEric Biggers * attributes
995815dac33SEric Biggers * @dentry: dentry through which the inode is being changed
996815dac33SEric Biggers * @attr: attributes to change
997815dac33SEric Biggers *
998815dac33SEric Biggers * Prepare for ->setattr() on a possibly-encrypted inode. On an encrypted file,
999815dac33SEric Biggers * most attribute changes are allowed even without the encryption key. However,
1000815dac33SEric Biggers * without the encryption key we do have to forbid truncates. This is needed
1001815dac33SEric Biggers * because the size being truncated to may not be a multiple of the filesystem
1002815dac33SEric Biggers * block size, and in that case we'd have to decrypt the final block, zero the
1003815dac33SEric Biggers * portion past i_size, and re-encrypt it. (We *could* allow truncating to a
1004815dac33SEric Biggers * filesystem block boundary, but it's simpler to just forbid all truncates ---
1005815dac33SEric Biggers * and we already forbid all other contents modifications without the key.)
10067622350eSEric Biggers *
10077622350eSEric Biggers * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code
1008815dac33SEric Biggers * if a problem occurred while setting up the encryption key.
1009815dac33SEric Biggers */
fscrypt_prepare_setattr(struct dentry * dentry,struct iattr * attr)1010815dac33SEric Biggers static inline int fscrypt_prepare_setattr(struct dentry *dentry,
101176e81d6dSEric Biggers struct iattr *attr)
1012d2fe9754SEric Biggers {
101376e81d6dSEric Biggers if (IS_ENCRYPTED(d_inode(dentry)))
101476e81d6dSEric Biggers return __fscrypt_prepare_setattr(dentry, attr);
101576e81d6dSEric Biggers return 0;
101676e81d6dSEric Biggers }
101776e81d6dSEric Biggers
101876e81d6dSEric Biggers /**
101976e81d6dSEric Biggers * fscrypt_encrypt_symlink() - encrypt the symlink target if needed
102076e81d6dSEric Biggers * @inode: symlink inode
102176e81d6dSEric Biggers * @target: plaintext symlink target
102276e81d6dSEric Biggers * @len: length of @target excluding null terminator
102376e81d6dSEric Biggers * @disk_link: (in/out) the on-disk symlink target being prepared
102476e81d6dSEric Biggers *
102576e81d6dSEric Biggers * If the symlink target needs to be encrypted, then this function encrypts it
102676e81d6dSEric Biggers * into @disk_link->name. fscrypt_prepare_symlink() must have been called
102776e81d6dSEric Biggers * previously to compute @disk_link->len. If the filesystem did not allocate a
102876e81d6dSEric Biggers * buffer for @disk_link->name after calling fscrypt_prepare_link(), then one
102976e81d6dSEric Biggers * will be kmalloc()'ed and the filesystem will be responsible for freeing it.
103076e81d6dSEric Biggers *
103176e81d6dSEric Biggers * Return: 0 on success, -errno on failure
103276e81d6dSEric Biggers */
fscrypt_encrypt_symlink(struct inode * inode,const char * target,unsigned int len,struct fscrypt_str * disk_link)103376e81d6dSEric Biggers static inline int fscrypt_encrypt_symlink(struct inode *inode,
103476e81d6dSEric Biggers const char *target,
103576e81d6dSEric Biggers unsigned int len,
1036d2d0727bSEric Biggers struct fscrypt_str *disk_link)
1037d2d0727bSEric Biggers {
1038d2d0727bSEric Biggers if (IS_ENCRYPTED(inode))
1039d2d0727bSEric Biggers return __fscrypt_encrypt_symlink(inode, target, len, disk_link);
1040d2d0727bSEric Biggers return 0;
1041d2d0727bSEric Biggers }
1042d2d0727bSEric Biggers
1043d2d0727bSEric Biggers /* If *pagep is a bounce page, free it and set *pagep to the pagecache page */
fscrypt_finalize_bounce_page(struct page ** pagep)1044d2d0727bSEric Biggers static inline void fscrypt_finalize_bounce_page(struct page **pagep)
1045d2d0727bSEric Biggers {
1046d2d0727bSEric Biggers struct page *page = *pagep;
1047734f0d24SDave Chinner
1048 if (fscrypt_is_bounce_page(page)) {
1049 *pagep = fscrypt_pagecache_page(page);
1050 fscrypt_free_bounce_page(page);
1051 }
1052 }
1053
1054 #endif /* _LINUX_FSCRYPT_H */
1055