1
2
3
4
5
6
7
8
9
10
11#include <linux/fs.h>
12#include <linux/module.h>
13#include <linux/stat.h>
14#include <linux/time.h>
15#include <linux/namei.h>
16#include <linux/poll.h>
17
18
19static loff_t bad_file_llseek(struct file *file, loff_t offset, int origin)
20{
21 return -EIO;
22}
23
24static ssize_t bad_file_read(struct file *filp, char __user *buf,
25 size_t size, loff_t *ppos)
26{
27 return -EIO;
28}
29
30static ssize_t bad_file_write(struct file *filp, const char __user *buf,
31 size_t siz, loff_t *ppos)
32{
33 return -EIO;
34}
35
36static ssize_t bad_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
37 unsigned long nr_segs, loff_t pos)
38{
39 return -EIO;
40}
41
42static ssize_t bad_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
43 unsigned long nr_segs, loff_t pos)
44{
45 return -EIO;
46}
47
48static int bad_file_readdir(struct file *filp, void *dirent, filldir_t filldir)
49{
50 return -EIO;
51}
52
53static unsigned int bad_file_poll(struct file *filp, poll_table *wait)
54{
55 return POLLERR;
56}
57
58static long bad_file_unlocked_ioctl(struct file *file, unsigned cmd,
59 unsigned long arg)
60{
61 return -EIO;
62}
63
64static long bad_file_compat_ioctl(struct file *file, unsigned int cmd,
65 unsigned long arg)
66{
67 return -EIO;
68}
69
70static int bad_file_mmap(struct file *file, struct vm_area_struct *vma)
71{
72 return -EIO;
73}
74
75static int bad_file_open(struct inode *inode, struct file *filp)
76{
77 return -EIO;
78}
79
80static int bad_file_flush(struct file *file, fl_owner_t id)
81{
82 return -EIO;
83}
84
85static int bad_file_release(struct inode *inode, struct file *filp)
86{
87 return -EIO;
88}
89
90static int bad_file_fsync(struct file *file, int datasync)
91{
92 return -EIO;
93}
94
95static int bad_file_aio_fsync(struct kiocb *iocb, int datasync)
96{
97 return -EIO;
98}
99
100static int bad_file_fasync(int fd, struct file *filp, int on)
101{
102 return -EIO;
103}
104
105static int bad_file_lock(struct file *file, int cmd, struct file_lock *fl)
106{
107 return -EIO;
108}
109
110static ssize_t bad_file_sendpage(struct file *file, struct page *page,
111 int off, size_t len, loff_t *pos, int more)
112{
113 return -EIO;
114}
115
116static unsigned long bad_file_get_unmapped_area(struct file *file,
117 unsigned long addr, unsigned long len,
118 unsigned long pgoff, unsigned long flags)
119{
120 return -EIO;
121}
122
123static int bad_file_check_flags(int flags)
124{
125 return -EIO;
126}
127
128static int bad_file_flock(struct file *filp, int cmd, struct file_lock *fl)
129{
130 return -EIO;
131}
132
133static ssize_t bad_file_splice_write(struct pipe_inode_info *pipe,
134 struct file *out, loff_t *ppos, size_t len,
135 unsigned int flags)
136{
137 return -EIO;
138}
139
140static ssize_t bad_file_splice_read(struct file *in, loff_t *ppos,
141 struct pipe_inode_info *pipe, size_t len,
142 unsigned int flags)
143{
144 return -EIO;
145}
146
147static const struct file_operations bad_file_ops =
148{
149 .llseek = bad_file_llseek,
150 .read = bad_file_read,
151 .write = bad_file_write,
152 .aio_read = bad_file_aio_read,
153 .aio_write = bad_file_aio_write,
154 .readdir = bad_file_readdir,
155 .poll = bad_file_poll,
156 .unlocked_ioctl = bad_file_unlocked_ioctl,
157 .compat_ioctl = bad_file_compat_ioctl,
158 .mmap = bad_file_mmap,
159 .open = bad_file_open,
160 .flush = bad_file_flush,
161 .release = bad_file_release,
162 .fsync = bad_file_fsync,
163 .aio_fsync = bad_file_aio_fsync,
164 .fasync = bad_file_fasync,
165 .lock = bad_file_lock,
166 .sendpage = bad_file_sendpage,
167 .get_unmapped_area = bad_file_get_unmapped_area,
168 .check_flags = bad_file_check_flags,
169 .flock = bad_file_flock,
170 .splice_write = bad_file_splice_write,
171 .splice_read = bad_file_splice_read,
172};
173
174static int bad_inode_create (struct inode *dir, struct dentry *dentry,
175 int mode, struct nameidata *nd)
176{
177 return -EIO;
178}
179
180static struct dentry *bad_inode_lookup(struct inode *dir,
181 struct dentry *dentry, struct nameidata *nd)
182{
183 return ERR_PTR(-EIO);
184}
185
186static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
187 struct dentry *dentry)
188{
189 return -EIO;
190}
191
192static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
193{
194 return -EIO;
195}
196
197static int bad_inode_symlink (struct inode *dir, struct dentry *dentry,
198 const char *symname)
199{
200 return -EIO;
201}
202
203static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry,
204 int mode)
205{
206 return -EIO;
207}
208
209static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
210{
211 return -EIO;
212}
213
214static int bad_inode_mknod (struct inode *dir, struct dentry *dentry,
215 int mode, dev_t rdev)
216{
217 return -EIO;
218}
219
220static int bad_inode_rename (struct inode *old_dir, struct dentry *old_dentry,
221 struct inode *new_dir, struct dentry *new_dentry)
222{
223 return -EIO;
224}
225
226static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
227 int buflen)
228{
229 return -EIO;
230}
231
232static int bad_inode_permission(struct inode *inode, int mask, unsigned int flags)
233{
234 if (flags & IPERM_FLAG_RCU)
235 return -ECHILD;
236
237 return -EIO;
238}
239
240static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
241 struct kstat *stat)
242{
243 return -EIO;
244}
245
246static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
247{
248 return -EIO;
249}
250
251static int bad_inode_setxattr(struct dentry *dentry, const char *name,
252 const void *value, size_t size, int flags)
253{
254 return -EIO;
255}
256
257static ssize_t bad_inode_getxattr(struct dentry *dentry, const char *name,
258 void *buffer, size_t size)
259{
260 return -EIO;
261}
262
263static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
264 size_t buffer_size)
265{
266 return -EIO;
267}
268
269static int bad_inode_removexattr(struct dentry *dentry, const char *name)
270{
271 return -EIO;
272}
273
274static const struct inode_operations bad_inode_ops =
275{
276 .create = bad_inode_create,
277 .lookup = bad_inode_lookup,
278 .link = bad_inode_link,
279 .unlink = bad_inode_unlink,
280 .symlink = bad_inode_symlink,
281 .mkdir = bad_inode_mkdir,
282 .rmdir = bad_inode_rmdir,
283 .mknod = bad_inode_mknod,
284 .rename = bad_inode_rename,
285 .readlink = bad_inode_readlink,
286
287
288
289
290 .permission = bad_inode_permission,
291 .getattr = bad_inode_getattr,
292 .setattr = bad_inode_setattr,
293 .setxattr = bad_inode_setxattr,
294 .getxattr = bad_inode_getxattr,
295 .listxattr = bad_inode_listxattr,
296 .removexattr = bad_inode_removexattr,
297
298};
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319void make_bad_inode(struct inode *inode)
320{
321 remove_inode_hash(inode);
322
323 inode->i_mode = S_IFREG;
324 inode->i_atime = inode->i_mtime = inode->i_ctime =
325 current_fs_time(inode->i_sb);
326 inode->i_op = &bad_inode_ops;
327 inode->i_fop = &bad_file_ops;
328}
329EXPORT_SYMBOL(make_bad_inode);
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344int is_bad_inode(struct inode *inode)
345{
346 return (inode->i_op == &bad_inode_ops);
347}
348
349EXPORT_SYMBOL(is_bad_inode);
350
351
352
353
354
355
356
357void iget_failed(struct inode *inode)
358{
359 make_bad_inode(inode);
360 unlock_new_inode(inode);
361 iput(inode);
362}
363EXPORT_SYMBOL(iget_failed);
364