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/smp_lock.h>
16
17
18
19
20
21
22static int bad_follow_link(struct dentry *dent, struct nameidata *nd)
23{
24 return vfs_follow_link(nd, ERR_PTR(-EIO));
25}
26
27static int return_EIO(void)
28{
29 return -EIO;
30}
31
32#define EIO_ERROR ((void *) (return_EIO))
33
34static struct file_operations bad_file_ops =
35{
36 .llseek = EIO_ERROR,
37 .aio_read = EIO_ERROR,
38 .read = EIO_ERROR,
39 .write = EIO_ERROR,
40 .aio_write = EIO_ERROR,
41 .readdir = EIO_ERROR,
42 .poll = EIO_ERROR,
43 .ioctl = EIO_ERROR,
44 .mmap = EIO_ERROR,
45 .open = EIO_ERROR,
46 .flush = EIO_ERROR,
47 .release = EIO_ERROR,
48 .fsync = EIO_ERROR,
49 .aio_fsync = EIO_ERROR,
50 .fasync = EIO_ERROR,
51 .lock = EIO_ERROR,
52 .readv = EIO_ERROR,
53 .writev = EIO_ERROR,
54 .sendfile = EIO_ERROR,
55 .sendpage = EIO_ERROR,
56 .get_unmapped_area = EIO_ERROR,
57};
58
59struct inode_operations bad_inode_ops =
60{
61 .create = EIO_ERROR,
62 .lookup = EIO_ERROR,
63 .link = EIO_ERROR,
64 .unlink = EIO_ERROR,
65 .symlink = EIO_ERROR,
66 .mkdir = EIO_ERROR,
67 .rmdir = EIO_ERROR,
68 .mknod = EIO_ERROR,
69 .rename = EIO_ERROR,
70 .readlink = EIO_ERROR,
71 .follow_link = bad_follow_link,
72 .truncate = EIO_ERROR,
73 .permission = EIO_ERROR,
74 .getattr = EIO_ERROR,
75 .setattr = EIO_ERROR,
76 .setxattr = EIO_ERROR,
77 .getxattr = EIO_ERROR,
78 .listxattr = EIO_ERROR,
79 .removexattr = EIO_ERROR,
80};
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101void make_bad_inode(struct inode * inode)
102{
103 remove_inode_hash(inode);
104
105 inode->i_mode = S_IFREG;
106 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
107 inode->i_op = &bad_inode_ops;
108 inode->i_fop = &bad_file_ops;
109}
110EXPORT_SYMBOL(make_bad_inode);
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125int is_bad_inode(struct inode * inode)
126{
127 return (inode->i_op == &bad_inode_ops);
128}
129
130EXPORT_SYMBOL(is_bad_inode);
131