1
2
3
4
5
6
7
8
9#include <linux/fs.h>
10#include <linux/stat.h>
11#include <linux/time.h>
12#include <linux/smp_lock.h>
13
14
15
16
17
18
19static int bad_follow_link(struct dentry *dent, struct nameidata *nd)
20{
21 return vfs_follow_link(nd, ERR_PTR(-EIO));
22}
23
24static int return_EIO(void)
25{
26 return -EIO;
27}
28
29#define EIO_ERROR ((void *) (return_EIO))
30
31static struct file_operations bad_file_ops =
32{
33 .llseek = EIO_ERROR,
34 .read = EIO_ERROR,
35 .write = EIO_ERROR,
36 .readdir = EIO_ERROR,
37 .poll = EIO_ERROR,
38 .ioctl = EIO_ERROR,
39 .mmap = EIO_ERROR,
40 .open = EIO_ERROR,
41 .flush = EIO_ERROR,
42 .release = EIO_ERROR,
43 .fsync = EIO_ERROR,
44 .fasync = EIO_ERROR,
45 .lock = EIO_ERROR,
46};
47
48struct inode_operations bad_inode_ops =
49{
50 .create = EIO_ERROR,
51 .lookup = EIO_ERROR,
52 .link = EIO_ERROR,
53 .unlink = EIO_ERROR,
54 .symlink = EIO_ERROR,
55 .mkdir = EIO_ERROR,
56 .rmdir = EIO_ERROR,
57 .mknod = EIO_ERROR,
58 .rename = EIO_ERROR,
59 .readlink = EIO_ERROR,
60 .follow_link = bad_follow_link,
61 .truncate = EIO_ERROR,
62 .permission = EIO_ERROR,
63 .getattr = EIO_ERROR,
64};
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85void make_bad_inode(struct inode * inode)
86{
87 inode->i_mode = S_IFREG;
88 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
89 inode->i_op = &bad_inode_ops;
90 inode->i_fop = &bad_file_ops;
91}
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106int is_bad_inode(struct inode * inode)
107{
108 return (inode->i_op == &bad_inode_ops);
109}
110