0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef _LINUX_FSCRYPT_H
0014 #define _LINUX_FSCRYPT_H
0015
0016 #include <linux/fs.h>
0017 #include <linux/mm.h>
0018 #include <linux/slab.h>
0019 #include <uapi/linux/fscrypt.h>
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #define FSCRYPT_CONTENTS_ALIGNMENT 16
0032
0033 union fscrypt_policy;
0034 struct fscrypt_info;
0035 struct fs_parameter;
0036 struct seq_file;
0037
0038 struct fscrypt_str {
0039 unsigned char *name;
0040 u32 len;
0041 };
0042
0043 struct fscrypt_name {
0044 const struct qstr *usr_fname;
0045 struct fscrypt_str disk_name;
0046 u32 hash;
0047 u32 minor_hash;
0048 struct fscrypt_str crypto_buf;
0049 bool is_nokey_name;
0050 };
0051
0052 #define FSTR_INIT(n, l) { .name = n, .len = l }
0053 #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len)
0054 #define fname_name(p) ((p)->disk_name.name)
0055 #define fname_len(p) ((p)->disk_name.len)
0056
0057
0058 #define FSCRYPT_SET_CONTEXT_MAX_SIZE 40
0059
0060 #ifdef CONFIG_FS_ENCRYPTION
0061
0062
0063
0064
0065
0066
0067 #define FS_CFLG_OWN_PAGES (1U << 1)
0068
0069
0070 struct fscrypt_operations {
0071
0072
0073 unsigned int flags;
0074
0075
0076
0077
0078
0079
0080
0081 const char *key_prefix;
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 int (*get_context)(struct inode *inode, void *ctx, size_t len);
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113 int (*set_context)(struct inode *inode, const void *ctx, size_t len,
0114 void *fs_data);
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 const union fscrypt_policy *(*get_dummy_policy)(struct super_block *sb);
0126
0127
0128
0129
0130 bool (*empty_dir)(struct inode *inode);
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 bool (*has_stable_inodes)(struct super_block *sb);
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160 void (*get_ino_and_lblk_bits)(struct super_block *sb,
0161 int *ino_bits_ret, int *lblk_bits_ret);
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172 int (*get_num_devices)(struct super_block *sb);
0173
0174
0175
0176
0177
0178
0179
0180 void (*get_devices)(struct super_block *sb,
0181 struct request_queue **devs);
0182 };
0183
0184 static inline struct fscrypt_info *fscrypt_get_info(const struct inode *inode)
0185 {
0186
0187
0188
0189
0190
0191
0192 return smp_load_acquire(&inode->i_crypt_info);
0193 }
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206 static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
0207 {
0208 return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode);
0209 }
0210
0211
0212
0213
0214
0215
0216
0217
0218 static inline void fscrypt_handle_d_move(struct dentry *dentry)
0219 {
0220 dentry->d_flags &= ~DCACHE_NOKEY_NAME;
0221 }
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247 static inline bool fscrypt_is_nokey_name(const struct dentry *dentry)
0248 {
0249 return dentry->d_flags & DCACHE_NOKEY_NAME;
0250 }
0251
0252
0253 void fscrypt_enqueue_decrypt_work(struct work_struct *);
0254
0255 struct page *fscrypt_encrypt_pagecache_blocks(struct page *page,
0256 unsigned int len,
0257 unsigned int offs,
0258 gfp_t gfp_flags);
0259 int fscrypt_encrypt_block_inplace(const struct inode *inode, struct page *page,
0260 unsigned int len, unsigned int offs,
0261 u64 lblk_num, gfp_t gfp_flags);
0262
0263 int fscrypt_decrypt_pagecache_blocks(struct page *page, unsigned int len,
0264 unsigned int offs);
0265 int fscrypt_decrypt_block_inplace(const struct inode *inode, struct page *page,
0266 unsigned int len, unsigned int offs,
0267 u64 lblk_num);
0268
0269 static inline bool fscrypt_is_bounce_page(struct page *page)
0270 {
0271 return page->mapping == NULL;
0272 }
0273
0274 static inline struct page *fscrypt_pagecache_page(struct page *bounce_page)
0275 {
0276 return (struct page *)page_private(bounce_page);
0277 }
0278
0279 void fscrypt_free_bounce_page(struct page *bounce_page);
0280
0281
0282 int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg);
0283 int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg);
0284 int fscrypt_ioctl_get_policy_ex(struct file *filp, void __user *arg);
0285 int fscrypt_ioctl_get_nonce(struct file *filp, void __user *arg);
0286 int fscrypt_has_permitted_context(struct inode *parent, struct inode *child);
0287 int fscrypt_context_for_new_inode(void *ctx, struct inode *inode);
0288 int fscrypt_set_context(struct inode *inode, void *fs_data);
0289
0290 struct fscrypt_dummy_policy {
0291 const union fscrypt_policy *policy;
0292 };
0293
0294 int fscrypt_parse_test_dummy_encryption(const struct fs_parameter *param,
0295 struct fscrypt_dummy_policy *dummy_policy);
0296 bool fscrypt_dummy_policies_equal(const struct fscrypt_dummy_policy *p1,
0297 const struct fscrypt_dummy_policy *p2);
0298 int fscrypt_set_test_dummy_encryption(struct super_block *sb, const char *arg,
0299 struct fscrypt_dummy_policy *dummy_policy);
0300 void fscrypt_show_test_dummy_encryption(struct seq_file *seq, char sep,
0301 struct super_block *sb);
0302 static inline bool
0303 fscrypt_is_dummy_policy_set(const struct fscrypt_dummy_policy *dummy_policy)
0304 {
0305 return dummy_policy->policy != NULL;
0306 }
0307 static inline void
0308 fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *dummy_policy)
0309 {
0310 kfree(dummy_policy->policy);
0311 dummy_policy->policy = NULL;
0312 }
0313
0314
0315 void fscrypt_sb_free(struct super_block *sb);
0316 int fscrypt_ioctl_add_key(struct file *filp, void __user *arg);
0317 int fscrypt_add_test_dummy_key(struct super_block *sb,
0318 const struct fscrypt_dummy_policy *dummy_policy);
0319 int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg);
0320 int fscrypt_ioctl_remove_key_all_users(struct file *filp, void __user *arg);
0321 int fscrypt_ioctl_get_key_status(struct file *filp, void __user *arg);
0322
0323
0324 int fscrypt_prepare_new_inode(struct inode *dir, struct inode *inode,
0325 bool *encrypt_ret);
0326 void fscrypt_put_encryption_info(struct inode *inode);
0327 void fscrypt_free_inode(struct inode *inode);
0328 int fscrypt_drop_inode(struct inode *inode);
0329
0330
0331 int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname,
0332 u8 *out, unsigned int olen);
0333 bool fscrypt_fname_encrypted_size(const struct inode *inode, u32 orig_len,
0334 u32 max_len, u32 *encrypted_len_ret);
0335 int fscrypt_setup_filename(struct inode *inode, const struct qstr *iname,
0336 int lookup, struct fscrypt_name *fname);
0337
0338 static inline void fscrypt_free_filename(struct fscrypt_name *fname)
0339 {
0340 kfree(fname->crypto_buf.name);
0341 }
0342
0343 int fscrypt_fname_alloc_buffer(u32 max_encrypted_len,
0344 struct fscrypt_str *crypto_str);
0345 void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str);
0346 int fscrypt_fname_disk_to_usr(const struct inode *inode,
0347 u32 hash, u32 minor_hash,
0348 const struct fscrypt_str *iname,
0349 struct fscrypt_str *oname);
0350 bool fscrypt_match_name(const struct fscrypt_name *fname,
0351 const u8 *de_name, u32 de_name_len);
0352 u64 fscrypt_fname_siphash(const struct inode *dir, const struct qstr *name);
0353 int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags);
0354
0355
0356 void fscrypt_decrypt_bio(struct bio *bio);
0357 int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
0358 sector_t pblk, unsigned int len);
0359
0360
0361 int fscrypt_file_open(struct inode *inode, struct file *filp);
0362 int __fscrypt_prepare_link(struct inode *inode, struct inode *dir,
0363 struct dentry *dentry);
0364 int __fscrypt_prepare_rename(struct inode *old_dir, struct dentry *old_dentry,
0365 struct inode *new_dir, struct dentry *new_dentry,
0366 unsigned int flags);
0367 int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry,
0368 struct fscrypt_name *fname);
0369 int __fscrypt_prepare_readdir(struct inode *dir);
0370 int __fscrypt_prepare_setattr(struct dentry *dentry, struct iattr *attr);
0371 int fscrypt_prepare_setflags(struct inode *inode,
0372 unsigned int oldflags, unsigned int flags);
0373 int fscrypt_prepare_symlink(struct inode *dir, const char *target,
0374 unsigned int len, unsigned int max_len,
0375 struct fscrypt_str *disk_link);
0376 int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
0377 unsigned int len, struct fscrypt_str *disk_link);
0378 const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
0379 unsigned int max_size,
0380 struct delayed_call *done);
0381 int fscrypt_symlink_getattr(const struct path *path, struct kstat *stat);
0382 static inline void fscrypt_set_ops(struct super_block *sb,
0383 const struct fscrypt_operations *s_cop)
0384 {
0385 sb->s_cop = s_cop;
0386 }
0387 #else
0388
0389 static inline struct fscrypt_info *fscrypt_get_info(const struct inode *inode)
0390 {
0391 return NULL;
0392 }
0393
0394 static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
0395 {
0396 return false;
0397 }
0398
0399 static inline void fscrypt_handle_d_move(struct dentry *dentry)
0400 {
0401 }
0402
0403 static inline bool fscrypt_is_nokey_name(const struct dentry *dentry)
0404 {
0405 return false;
0406 }
0407
0408
0409 static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
0410 {
0411 }
0412
0413 static inline struct page *fscrypt_encrypt_pagecache_blocks(struct page *page,
0414 unsigned int len,
0415 unsigned int offs,
0416 gfp_t gfp_flags)
0417 {
0418 return ERR_PTR(-EOPNOTSUPP);
0419 }
0420
0421 static inline int fscrypt_encrypt_block_inplace(const struct inode *inode,
0422 struct page *page,
0423 unsigned int len,
0424 unsigned int offs, u64 lblk_num,
0425 gfp_t gfp_flags)
0426 {
0427 return -EOPNOTSUPP;
0428 }
0429
0430 static inline int fscrypt_decrypt_pagecache_blocks(struct page *page,
0431 unsigned int len,
0432 unsigned int offs)
0433 {
0434 return -EOPNOTSUPP;
0435 }
0436
0437 static inline int fscrypt_decrypt_block_inplace(const struct inode *inode,
0438 struct page *page,
0439 unsigned int len,
0440 unsigned int offs, u64 lblk_num)
0441 {
0442 return -EOPNOTSUPP;
0443 }
0444
0445 static inline bool fscrypt_is_bounce_page(struct page *page)
0446 {
0447 return false;
0448 }
0449
0450 static inline struct page *fscrypt_pagecache_page(struct page *bounce_page)
0451 {
0452 WARN_ON_ONCE(1);
0453 return ERR_PTR(-EINVAL);
0454 }
0455
0456 static inline void fscrypt_free_bounce_page(struct page *bounce_page)
0457 {
0458 }
0459
0460
0461 static inline int fscrypt_ioctl_set_policy(struct file *filp,
0462 const void __user *arg)
0463 {
0464 return -EOPNOTSUPP;
0465 }
0466
0467 static inline int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
0468 {
0469 return -EOPNOTSUPP;
0470 }
0471
0472 static inline int fscrypt_ioctl_get_policy_ex(struct file *filp,
0473 void __user *arg)
0474 {
0475 return -EOPNOTSUPP;
0476 }
0477
0478 static inline int fscrypt_ioctl_get_nonce(struct file *filp, void __user *arg)
0479 {
0480 return -EOPNOTSUPP;
0481 }
0482
0483 static inline int fscrypt_has_permitted_context(struct inode *parent,
0484 struct inode *child)
0485 {
0486 return 0;
0487 }
0488
0489 static inline int fscrypt_set_context(struct inode *inode, void *fs_data)
0490 {
0491 return -EOPNOTSUPP;
0492 }
0493
0494 struct fscrypt_dummy_policy {
0495 };
0496
0497 static inline int
0498 fscrypt_parse_test_dummy_encryption(const struct fs_parameter *param,
0499 struct fscrypt_dummy_policy *dummy_policy)
0500 {
0501 return -EINVAL;
0502 }
0503
0504 static inline bool
0505 fscrypt_dummy_policies_equal(const struct fscrypt_dummy_policy *p1,
0506 const struct fscrypt_dummy_policy *p2)
0507 {
0508 return true;
0509 }
0510
0511 static inline void fscrypt_show_test_dummy_encryption(struct seq_file *seq,
0512 char sep,
0513 struct super_block *sb)
0514 {
0515 }
0516
0517 static inline bool
0518 fscrypt_is_dummy_policy_set(const struct fscrypt_dummy_policy *dummy_policy)
0519 {
0520 return false;
0521 }
0522
0523 static inline void
0524 fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *dummy_policy)
0525 {
0526 }
0527
0528
0529 static inline void fscrypt_sb_free(struct super_block *sb)
0530 {
0531 }
0532
0533 static inline int fscrypt_ioctl_add_key(struct file *filp, void __user *arg)
0534 {
0535 return -EOPNOTSUPP;
0536 }
0537
0538 static inline int
0539 fscrypt_add_test_dummy_key(struct super_block *sb,
0540 const struct fscrypt_dummy_policy *dummy_policy)
0541 {
0542 return 0;
0543 }
0544
0545 static inline int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg)
0546 {
0547 return -EOPNOTSUPP;
0548 }
0549
0550 static inline int fscrypt_ioctl_remove_key_all_users(struct file *filp,
0551 void __user *arg)
0552 {
0553 return -EOPNOTSUPP;
0554 }
0555
0556 static inline int fscrypt_ioctl_get_key_status(struct file *filp,
0557 void __user *arg)
0558 {
0559 return -EOPNOTSUPP;
0560 }
0561
0562
0563
0564 static inline int fscrypt_prepare_new_inode(struct inode *dir,
0565 struct inode *inode,
0566 bool *encrypt_ret)
0567 {
0568 if (IS_ENCRYPTED(dir))
0569 return -EOPNOTSUPP;
0570 return 0;
0571 }
0572
0573 static inline void fscrypt_put_encryption_info(struct inode *inode)
0574 {
0575 return;
0576 }
0577
0578 static inline void fscrypt_free_inode(struct inode *inode)
0579 {
0580 }
0581
0582 static inline int fscrypt_drop_inode(struct inode *inode)
0583 {
0584 return 0;
0585 }
0586
0587
0588 static inline int fscrypt_setup_filename(struct inode *dir,
0589 const struct qstr *iname,
0590 int lookup, struct fscrypt_name *fname)
0591 {
0592 if (IS_ENCRYPTED(dir))
0593 return -EOPNOTSUPP;
0594
0595 memset(fname, 0, sizeof(*fname));
0596 fname->usr_fname = iname;
0597 fname->disk_name.name = (unsigned char *)iname->name;
0598 fname->disk_name.len = iname->len;
0599 return 0;
0600 }
0601
0602 static inline void fscrypt_free_filename(struct fscrypt_name *fname)
0603 {
0604 return;
0605 }
0606
0607 static inline int fscrypt_fname_alloc_buffer(u32 max_encrypted_len,
0608 struct fscrypt_str *crypto_str)
0609 {
0610 return -EOPNOTSUPP;
0611 }
0612
0613 static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
0614 {
0615 return;
0616 }
0617
0618 static inline int fscrypt_fname_disk_to_usr(const struct inode *inode,
0619 u32 hash, u32 minor_hash,
0620 const struct fscrypt_str *iname,
0621 struct fscrypt_str *oname)
0622 {
0623 return -EOPNOTSUPP;
0624 }
0625
0626 static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
0627 const u8 *de_name, u32 de_name_len)
0628 {
0629
0630 if (de_name_len != fname->disk_name.len)
0631 return false;
0632 return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
0633 }
0634
0635 static inline u64 fscrypt_fname_siphash(const struct inode *dir,
0636 const struct qstr *name)
0637 {
0638 WARN_ON_ONCE(1);
0639 return 0;
0640 }
0641
0642 static inline int fscrypt_d_revalidate(struct dentry *dentry,
0643 unsigned int flags)
0644 {
0645 return 1;
0646 }
0647
0648
0649 static inline void fscrypt_decrypt_bio(struct bio *bio)
0650 {
0651 }
0652
0653 static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
0654 sector_t pblk, unsigned int len)
0655 {
0656 return -EOPNOTSUPP;
0657 }
0658
0659
0660
0661 static inline int fscrypt_file_open(struct inode *inode, struct file *filp)
0662 {
0663 if (IS_ENCRYPTED(inode))
0664 return -EOPNOTSUPP;
0665 return 0;
0666 }
0667
0668 static inline int __fscrypt_prepare_link(struct inode *inode, struct inode *dir,
0669 struct dentry *dentry)
0670 {
0671 return -EOPNOTSUPP;
0672 }
0673
0674 static inline int __fscrypt_prepare_rename(struct inode *old_dir,
0675 struct dentry *old_dentry,
0676 struct inode *new_dir,
0677 struct dentry *new_dentry,
0678 unsigned int flags)
0679 {
0680 return -EOPNOTSUPP;
0681 }
0682
0683 static inline int __fscrypt_prepare_lookup(struct inode *dir,
0684 struct dentry *dentry,
0685 struct fscrypt_name *fname)
0686 {
0687 return -EOPNOTSUPP;
0688 }
0689
0690 static inline int __fscrypt_prepare_readdir(struct inode *dir)
0691 {
0692 return -EOPNOTSUPP;
0693 }
0694
0695 static inline int __fscrypt_prepare_setattr(struct dentry *dentry,
0696 struct iattr *attr)
0697 {
0698 return -EOPNOTSUPP;
0699 }
0700
0701 static inline int fscrypt_prepare_setflags(struct inode *inode,
0702 unsigned int oldflags,
0703 unsigned int flags)
0704 {
0705 return 0;
0706 }
0707
0708 static inline int fscrypt_prepare_symlink(struct inode *dir,
0709 const char *target,
0710 unsigned int len,
0711 unsigned int max_len,
0712 struct fscrypt_str *disk_link)
0713 {
0714 if (IS_ENCRYPTED(dir))
0715 return -EOPNOTSUPP;
0716 disk_link->name = (unsigned char *)target;
0717 disk_link->len = len + 1;
0718 if (disk_link->len > max_len)
0719 return -ENAMETOOLONG;
0720 return 0;
0721 }
0722
0723 static inline int __fscrypt_encrypt_symlink(struct inode *inode,
0724 const char *target,
0725 unsigned int len,
0726 struct fscrypt_str *disk_link)
0727 {
0728 return -EOPNOTSUPP;
0729 }
0730
0731 static inline const char *fscrypt_get_symlink(struct inode *inode,
0732 const void *caddr,
0733 unsigned int max_size,
0734 struct delayed_call *done)
0735 {
0736 return ERR_PTR(-EOPNOTSUPP);
0737 }
0738
0739 static inline int fscrypt_symlink_getattr(const struct path *path,
0740 struct kstat *stat)
0741 {
0742 return -EOPNOTSUPP;
0743 }
0744
0745 static inline void fscrypt_set_ops(struct super_block *sb,
0746 const struct fscrypt_operations *s_cop)
0747 {
0748 }
0749
0750 #endif
0751
0752
0753 #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
0754
0755 bool __fscrypt_inode_uses_inline_crypto(const struct inode *inode);
0756
0757 void fscrypt_set_bio_crypt_ctx(struct bio *bio,
0758 const struct inode *inode, u64 first_lblk,
0759 gfp_t gfp_mask);
0760
0761 void fscrypt_set_bio_crypt_ctx_bh(struct bio *bio,
0762 const struct buffer_head *first_bh,
0763 gfp_t gfp_mask);
0764
0765 bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,
0766 u64 next_lblk);
0767
0768 bool fscrypt_mergeable_bio_bh(struct bio *bio,
0769 const struct buffer_head *next_bh);
0770
0771 bool fscrypt_dio_supported(struct kiocb *iocb, struct iov_iter *iter);
0772
0773 u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk, u64 nr_blocks);
0774
0775 #else
0776
0777 static inline bool __fscrypt_inode_uses_inline_crypto(const struct inode *inode)
0778 {
0779 return false;
0780 }
0781
0782 static inline void fscrypt_set_bio_crypt_ctx(struct bio *bio,
0783 const struct inode *inode,
0784 u64 first_lblk, gfp_t gfp_mask) { }
0785
0786 static inline void fscrypt_set_bio_crypt_ctx_bh(
0787 struct bio *bio,
0788 const struct buffer_head *first_bh,
0789 gfp_t gfp_mask) { }
0790
0791 static inline bool fscrypt_mergeable_bio(struct bio *bio,
0792 const struct inode *inode,
0793 u64 next_lblk)
0794 {
0795 return true;
0796 }
0797
0798 static inline bool fscrypt_mergeable_bio_bh(struct bio *bio,
0799 const struct buffer_head *next_bh)
0800 {
0801 return true;
0802 }
0803
0804 static inline bool fscrypt_dio_supported(struct kiocb *iocb,
0805 struct iov_iter *iter)
0806 {
0807 const struct inode *inode = file_inode(iocb->ki_filp);
0808
0809 return !fscrypt_needs_contents_encryption(inode);
0810 }
0811
0812 static inline u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk,
0813 u64 nr_blocks)
0814 {
0815 return nr_blocks;
0816 }
0817 #endif
0818
0819
0820
0821
0822
0823
0824
0825
0826
0827
0828 static inline bool fscrypt_inode_uses_inline_crypto(const struct inode *inode)
0829 {
0830 return fscrypt_needs_contents_encryption(inode) &&
0831 __fscrypt_inode_uses_inline_crypto(inode);
0832 }
0833
0834
0835
0836
0837
0838
0839
0840
0841
0842
0843 static inline bool fscrypt_inode_uses_fs_layer_crypto(const struct inode *inode)
0844 {
0845 return fscrypt_needs_contents_encryption(inode) &&
0846 !__fscrypt_inode_uses_inline_crypto(inode);
0847 }
0848
0849
0850
0851
0852
0853
0854
0855
0856
0857
0858 static inline bool fscrypt_has_encryption_key(const struct inode *inode)
0859 {
0860 return fscrypt_get_info(inode) != NULL;
0861 }
0862
0863
0864
0865
0866
0867
0868
0869
0870
0871
0872
0873
0874
0875
0876
0877
0878
0879
0880
0881 static inline int fscrypt_prepare_link(struct dentry *old_dentry,
0882 struct inode *dir,
0883 struct dentry *dentry)
0884 {
0885 if (IS_ENCRYPTED(dir))
0886 return __fscrypt_prepare_link(d_inode(old_dentry), dir, dentry);
0887 return 0;
0888 }
0889
0890
0891
0892
0893
0894
0895
0896
0897
0898
0899
0900
0901
0902
0903
0904
0905
0906
0907
0908
0909
0910
0911
0912 static inline int fscrypt_prepare_rename(struct inode *old_dir,
0913 struct dentry *old_dentry,
0914 struct inode *new_dir,
0915 struct dentry *new_dentry,
0916 unsigned int flags)
0917 {
0918 if (IS_ENCRYPTED(old_dir) || IS_ENCRYPTED(new_dir))
0919 return __fscrypt_prepare_rename(old_dir, old_dentry,
0920 new_dir, new_dentry, flags);
0921 return 0;
0922 }
0923
0924
0925
0926
0927
0928
0929
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939
0940
0941
0942
0943
0944
0945
0946
0947 static inline int fscrypt_prepare_lookup(struct inode *dir,
0948 struct dentry *dentry,
0949 struct fscrypt_name *fname)
0950 {
0951 if (IS_ENCRYPTED(dir))
0952 return __fscrypt_prepare_lookup(dir, dentry, fname);
0953
0954 memset(fname, 0, sizeof(*fname));
0955 fname->usr_fname = &dentry->d_name;
0956 fname->disk_name.name = (unsigned char *)dentry->d_name.name;
0957 fname->disk_name.len = dentry->d_name.len;
0958 return 0;
0959 }
0960
0961
0962
0963
0964
0965
0966
0967
0968
0969
0970
0971
0972
0973
0974 static inline int fscrypt_prepare_readdir(struct inode *dir)
0975 {
0976 if (IS_ENCRYPTED(dir))
0977 return __fscrypt_prepare_readdir(dir);
0978 return 0;
0979 }
0980
0981
0982
0983
0984
0985
0986
0987
0988
0989
0990
0991
0992
0993
0994
0995
0996
0997
0998
0999 static inline int fscrypt_prepare_setattr(struct dentry *dentry,
1000 struct iattr *attr)
1001 {
1002 if (IS_ENCRYPTED(d_inode(dentry)))
1003 return __fscrypt_prepare_setattr(dentry, attr);
1004 return 0;
1005 }
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022 static inline int fscrypt_encrypt_symlink(struct inode *inode,
1023 const char *target,
1024 unsigned int len,
1025 struct fscrypt_str *disk_link)
1026 {
1027 if (IS_ENCRYPTED(inode))
1028 return __fscrypt_encrypt_symlink(inode, target, len, disk_link);
1029 return 0;
1030 }
1031
1032
1033 static inline void fscrypt_finalize_bounce_page(struct page **pagep)
1034 {
1035 struct page *page = *pagep;
1036
1037 if (fscrypt_is_bounce_page(page)) {
1038 *pagep = fscrypt_pagecache_page(page);
1039 fscrypt_free_bounce_page(page);
1040 }
1041 }
1042
1043 #endif