1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * fscrypt_notsupp.h
4  *
5  * This stubs out the fscrypt functions for filesystems configured without
6  * encryption support.
7  *
8  * Do not include this file directly. Use fscrypt.h instead!
9  */
10 #ifndef _LINUX_FSCRYPT_H
11 #error "Incorrect include of linux/fscrypt_notsupp.h!"
12 #endif
13 
14 #ifndef _LINUX_FSCRYPT_NOTSUPP_H
15 #define _LINUX_FSCRYPT_NOTSUPP_H
16 
fscrypt_has_encryption_key(const struct inode * inode)17 static inline bool fscrypt_has_encryption_key(const struct inode *inode)
18 {
19 	return false;
20 }
21 
fscrypt_dummy_context_enabled(struct inode * inode)22 static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
23 {
24 	return false;
25 }
26 
fscrypt_is_nokey_name(const struct dentry * dentry)27 static inline bool fscrypt_is_nokey_name(const struct dentry *dentry)
28 {
29 	return false;
30 }
31 
32 /* crypto.c */
fscrypt_enqueue_decrypt_work(struct work_struct * work)33 static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
34 {
35 }
36 
fscrypt_get_ctx(const struct inode * inode,gfp_t gfp_flags)37 static inline struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode,
38 						  gfp_t gfp_flags)
39 {
40 	return ERR_PTR(-EOPNOTSUPP);
41 }
42 
fscrypt_release_ctx(struct fscrypt_ctx * ctx)43 static inline void fscrypt_release_ctx(struct fscrypt_ctx *ctx)
44 {
45 	return;
46 }
47 
fscrypt_encrypt_page(const struct inode * inode,struct page * page,unsigned int len,unsigned int offs,u64 lblk_num,gfp_t gfp_flags)48 static inline struct page *fscrypt_encrypt_page(const struct inode *inode,
49 						struct page *page,
50 						unsigned int len,
51 						unsigned int offs,
52 						u64 lblk_num, gfp_t gfp_flags)
53 {
54 	return ERR_PTR(-EOPNOTSUPP);
55 }
56 
fscrypt_decrypt_page(const struct inode * inode,struct page * page,unsigned int len,unsigned int offs,u64 lblk_num)57 static inline int fscrypt_decrypt_page(const struct inode *inode,
58 				       struct page *page,
59 				       unsigned int len, unsigned int offs,
60 				       u64 lblk_num)
61 {
62 	return -EOPNOTSUPP;
63 }
64 
fscrypt_control_page(struct page * page)65 static inline struct page *fscrypt_control_page(struct page *page)
66 {
67 	WARN_ON_ONCE(1);
68 	return ERR_PTR(-EINVAL);
69 }
70 
fscrypt_restore_control_page(struct page * page)71 static inline void fscrypt_restore_control_page(struct page *page)
72 {
73 	return;
74 }
75 
76 /* policy.c */
fscrypt_ioctl_set_policy(struct file * filp,const void __user * arg)77 static inline int fscrypt_ioctl_set_policy(struct file *filp,
78 					   const void __user *arg)
79 {
80 	return -EOPNOTSUPP;
81 }
82 
fscrypt_ioctl_get_policy(struct file * filp,void __user * arg)83 static inline int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
84 {
85 	return -EOPNOTSUPP;
86 }
87 
fscrypt_has_permitted_context(struct inode * parent,struct inode * child)88 static inline int fscrypt_has_permitted_context(struct inode *parent,
89 						struct inode *child)
90 {
91 	return 0;
92 }
93 
fscrypt_inherit_context(struct inode * parent,struct inode * child,void * fs_data,bool preload)94 static inline int fscrypt_inherit_context(struct inode *parent,
95 					  struct inode *child,
96 					  void *fs_data, bool preload)
97 {
98 	return -EOPNOTSUPP;
99 }
100 
101 /* keyinfo.c */
fscrypt_get_encryption_info(struct inode * inode)102 static inline int fscrypt_get_encryption_info(struct inode *inode)
103 {
104 	return -EOPNOTSUPP;
105 }
106 
fscrypt_put_encryption_info(struct inode * inode)107 static inline void fscrypt_put_encryption_info(struct inode *inode)
108 {
109 	return;
110 }
111 
112  /* fname.c */
fscrypt_setup_filename(struct inode * dir,const struct qstr * iname,int lookup,struct fscrypt_name * fname)113 static inline int fscrypt_setup_filename(struct inode *dir,
114 					 const struct qstr *iname,
115 					 int lookup, struct fscrypt_name *fname)
116 {
117 	if (IS_ENCRYPTED(dir))
118 		return -EOPNOTSUPP;
119 
120 	memset(fname, 0, sizeof(*fname));
121 	fname->usr_fname = iname;
122 	fname->disk_name.name = (unsigned char *)iname->name;
123 	fname->disk_name.len = iname->len;
124 	return 0;
125 }
126 
fscrypt_free_filename(struct fscrypt_name * fname)127 static inline void fscrypt_free_filename(struct fscrypt_name *fname)
128 {
129 	return;
130 }
131 
fscrypt_fname_alloc_buffer(const struct inode * inode,u32 max_encrypted_len,struct fscrypt_str * crypto_str)132 static inline int fscrypt_fname_alloc_buffer(const struct inode *inode,
133 					     u32 max_encrypted_len,
134 					     struct fscrypt_str *crypto_str)
135 {
136 	return -EOPNOTSUPP;
137 }
138 
fscrypt_fname_free_buffer(struct fscrypt_str * crypto_str)139 static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
140 {
141 	return;
142 }
143 
fscrypt_fname_disk_to_usr(struct inode * inode,u32 hash,u32 minor_hash,const struct fscrypt_str * iname,struct fscrypt_str * oname)144 static inline int fscrypt_fname_disk_to_usr(struct inode *inode,
145 					    u32 hash, u32 minor_hash,
146 					    const struct fscrypt_str *iname,
147 					    struct fscrypt_str *oname)
148 {
149 	return -EOPNOTSUPP;
150 }
151 
fscrypt_match_name(const struct fscrypt_name * fname,const u8 * de_name,u32 de_name_len)152 static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
153 				      const u8 *de_name, u32 de_name_len)
154 {
155 	/* Encryption support disabled; use standard comparison */
156 	if (de_name_len != fname->disk_name.len)
157 		return false;
158 	return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
159 }
160 
161 /* bio.c */
fscrypt_decrypt_bio(struct bio * bio)162 static inline void fscrypt_decrypt_bio(struct bio *bio)
163 {
164 }
165 
fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx * ctx,struct bio * bio)166 static inline void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx,
167 					       struct bio *bio)
168 {
169 }
170 
fscrypt_pullback_bio_page(struct page ** page,bool restore)171 static inline void fscrypt_pullback_bio_page(struct page **page, bool restore)
172 {
173 	return;
174 }
175 
fscrypt_zeroout_range(const struct inode * inode,pgoff_t lblk,sector_t pblk,unsigned int len)176 static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
177 					sector_t pblk, unsigned int len)
178 {
179 	return -EOPNOTSUPP;
180 }
181 
182 /* hooks.c */
183 
fscrypt_file_open(struct inode * inode,struct file * filp)184 static inline int fscrypt_file_open(struct inode *inode, struct file *filp)
185 {
186 	if (IS_ENCRYPTED(inode))
187 		return -EOPNOTSUPP;
188 	return 0;
189 }
190 
__fscrypt_prepare_link(struct inode * inode,struct inode * dir,struct dentry * dentry)191 static inline int __fscrypt_prepare_link(struct inode *inode, struct inode *dir,
192 					 struct dentry *dentry)
193 {
194 	return -EOPNOTSUPP;
195 }
196 
__fscrypt_prepare_rename(struct inode * old_dir,struct dentry * old_dentry,struct inode * new_dir,struct dentry * new_dentry,unsigned int flags)197 static inline int __fscrypt_prepare_rename(struct inode *old_dir,
198 					   struct dentry *old_dentry,
199 					   struct inode *new_dir,
200 					   struct dentry *new_dentry,
201 					   unsigned int flags)
202 {
203 	return -EOPNOTSUPP;
204 }
205 
__fscrypt_prepare_lookup(struct inode * dir,struct dentry * dentry,struct fscrypt_name * fname)206 static inline int __fscrypt_prepare_lookup(struct inode *dir,
207 					   struct dentry *dentry,
208 					   struct fscrypt_name *fname)
209 {
210 	return -EOPNOTSUPP;
211 }
212 
__fscrypt_prepare_symlink(struct inode * dir,unsigned int len,unsigned int max_len,struct fscrypt_str * disk_link)213 static inline int __fscrypt_prepare_symlink(struct inode *dir,
214 					    unsigned int len,
215 					    unsigned int max_len,
216 					    struct fscrypt_str *disk_link)
217 {
218 	return -EOPNOTSUPP;
219 }
220 
__fscrypt_encrypt_symlink(struct inode * inode,const char * target,unsigned int len,struct fscrypt_str * disk_link)221 static inline int __fscrypt_encrypt_symlink(struct inode *inode,
222 					    const char *target,
223 					    unsigned int len,
224 					    struct fscrypt_str *disk_link)
225 {
226 	return -EOPNOTSUPP;
227 }
228 
fscrypt_get_symlink(struct inode * inode,const void * caddr,unsigned int max_size,struct delayed_call * done)229 static inline const char *fscrypt_get_symlink(struct inode *inode,
230 					      const void *caddr,
231 					      unsigned int max_size,
232 					      struct delayed_call *done)
233 {
234 	return ERR_PTR(-EOPNOTSUPP);
235 }
236 
fscrypt_symlink_getattr(const struct path * path,struct kstat * stat)237 static inline int fscrypt_symlink_getattr(const struct path *path,
238 					  struct kstat *stat)
239 {
240 	return -EOPNOTSUPP;
241 }
242 
243 #endif	/* _LINUX_FSCRYPT_NOTSUPP_H */
244