Loading...
1/*
2 * linux/fs/bad_inode.c
3 *
4 * Copyright (C) 1997, Stephen Tweedie
5 *
6 * Provide stub functions for unreadable inodes
7 *
8 * Fabian Frederick : August 2003 - All file operations assigned to EIO
9 */
10
11#include <linux/fs.h>
12#include <linux/export.h>
13#include <linux/stat.h>
14#include <linux/time.h>
15#include <linux/namei.h>
16#include <linux/poll.h>
17
18static int bad_file_open(struct inode *inode, struct file *filp)
19{
20 return -EIO;
21}
22
23static const struct file_operations bad_file_ops =
24{
25 .open = bad_file_open,
26};
27
28static int bad_inode_create (struct inode *dir, struct dentry *dentry,
29 umode_t mode, bool excl)
30{
31 return -EIO;
32}
33
34static struct dentry *bad_inode_lookup(struct inode *dir,
35 struct dentry *dentry, unsigned int flags)
36{
37 return ERR_PTR(-EIO);
38}
39
40static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
41 struct dentry *dentry)
42{
43 return -EIO;
44}
45
46static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
47{
48 return -EIO;
49}
50
51static int bad_inode_symlink (struct inode *dir, struct dentry *dentry,
52 const char *symname)
53{
54 return -EIO;
55}
56
57static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry,
58 umode_t mode)
59{
60 return -EIO;
61}
62
63static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
64{
65 return -EIO;
66}
67
68static int bad_inode_mknod (struct inode *dir, struct dentry *dentry,
69 umode_t mode, dev_t rdev)
70{
71 return -EIO;
72}
73
74static int bad_inode_rename2(struct inode *old_dir, struct dentry *old_dentry,
75 struct inode *new_dir, struct dentry *new_dentry,
76 unsigned int flags)
77{
78 return -EIO;
79}
80
81static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
82 int buflen)
83{
84 return -EIO;
85}
86
87static int bad_inode_permission(struct inode *inode, int mask)
88{
89 return -EIO;
90}
91
92static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
93 struct kstat *stat)
94{
95 return -EIO;
96}
97
98static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
99{
100 return -EIO;
101}
102
103static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
104 size_t buffer_size)
105{
106 return -EIO;
107}
108
109static const char *bad_inode_get_link(struct dentry *dentry,
110 struct inode *inode,
111 struct delayed_call *done)
112{
113 return ERR_PTR(-EIO);
114}
115
116static struct posix_acl *bad_inode_get_acl(struct inode *inode, int type)
117{
118 return ERR_PTR(-EIO);
119}
120
121static int bad_inode_fiemap(struct inode *inode,
122 struct fiemap_extent_info *fieinfo, u64 start,
123 u64 len)
124{
125 return -EIO;
126}
127
128static int bad_inode_update_time(struct inode *inode, struct timespec *time,
129 int flags)
130{
131 return -EIO;
132}
133
134static int bad_inode_atomic_open(struct inode *inode, struct dentry *dentry,
135 struct file *file, unsigned int open_flag,
136 umode_t create_mode, int *opened)
137{
138 return -EIO;
139}
140
141static int bad_inode_tmpfile(struct inode *inode, struct dentry *dentry,
142 umode_t mode)
143{
144 return -EIO;
145}
146
147static int bad_inode_set_acl(struct inode *inode, struct posix_acl *acl,
148 int type)
149{
150 return -EIO;
151}
152
153static const struct inode_operations bad_inode_ops =
154{
155 .create = bad_inode_create,
156 .lookup = bad_inode_lookup,
157 .link = bad_inode_link,
158 .unlink = bad_inode_unlink,
159 .symlink = bad_inode_symlink,
160 .mkdir = bad_inode_mkdir,
161 .rmdir = bad_inode_rmdir,
162 .mknod = bad_inode_mknod,
163 .rename = bad_inode_rename2,
164 .readlink = bad_inode_readlink,
165 .permission = bad_inode_permission,
166 .getattr = bad_inode_getattr,
167 .setattr = bad_inode_setattr,
168 .listxattr = bad_inode_listxattr,
169 .get_link = bad_inode_get_link,
170 .get_acl = bad_inode_get_acl,
171 .fiemap = bad_inode_fiemap,
172 .update_time = bad_inode_update_time,
173 .atomic_open = bad_inode_atomic_open,
174 .tmpfile = bad_inode_tmpfile,
175 .set_acl = bad_inode_set_acl,
176};
177
178
179/*
180 * When a filesystem is unable to read an inode due to an I/O error in
181 * its read_inode() function, it can call make_bad_inode() to return a
182 * set of stubs which will return EIO errors as required.
183 *
184 * We only need to do limited initialisation: all other fields are
185 * preinitialised to zero automatically.
186 */
187
188/**
189 * make_bad_inode - mark an inode bad due to an I/O error
190 * @inode: Inode to mark bad
191 *
192 * When an inode cannot be read due to a media or remote network
193 * failure this function makes the inode "bad" and causes I/O operations
194 * on it to fail from this point on.
195 */
196
197void make_bad_inode(struct inode *inode)
198{
199 remove_inode_hash(inode);
200
201 inode->i_mode = S_IFREG;
202 inode->i_atime = inode->i_mtime = inode->i_ctime =
203 current_time(inode);
204 inode->i_op = &bad_inode_ops;
205 inode->i_opflags &= ~IOP_XATTR;
206 inode->i_fop = &bad_file_ops;
207}
208EXPORT_SYMBOL(make_bad_inode);
209
210/*
211 * This tests whether an inode has been flagged as bad. The test uses
212 * &bad_inode_ops to cover the case of invalidated inodes as well as
213 * those created by make_bad_inode() above.
214 */
215
216/**
217 * is_bad_inode - is an inode errored
218 * @inode: inode to test
219 *
220 * Returns true if the inode in question has been marked as bad.
221 */
222
223bool is_bad_inode(struct inode *inode)
224{
225 return (inode->i_op == &bad_inode_ops);
226}
227
228EXPORT_SYMBOL(is_bad_inode);
229
230/**
231 * iget_failed - Mark an under-construction inode as dead and release it
232 * @inode: The inode to discard
233 *
234 * Mark an under-construction inode as dead and release it.
235 */
236void iget_failed(struct inode *inode)
237{
238 make_bad_inode(inode);
239 unlock_new_inode(inode);
240 iput(inode);
241}
242EXPORT_SYMBOL(iget_failed);
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/bad_inode.c
4 *
5 * Copyright (C) 1997, Stephen Tweedie
6 *
7 * Provide stub functions for unreadable inodes
8 *
9 * Fabian Frederick : August 2003 - All file operations assigned to EIO
10 */
11
12#include <linux/fs.h>
13#include <linux/export.h>
14#include <linux/stat.h>
15#include <linux/time.h>
16#include <linux/namei.h>
17#include <linux/poll.h>
18#include <linux/fiemap.h>
19
20static int bad_file_open(struct inode *inode, struct file *filp)
21{
22 return -EIO;
23}
24
25static const struct file_operations bad_file_ops =
26{
27 .open = bad_file_open,
28};
29
30static int bad_inode_create (struct inode *dir, struct dentry *dentry,
31 umode_t mode, bool excl)
32{
33 return -EIO;
34}
35
36static struct dentry *bad_inode_lookup(struct inode *dir,
37 struct dentry *dentry, unsigned int flags)
38{
39 return ERR_PTR(-EIO);
40}
41
42static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
43 struct dentry *dentry)
44{
45 return -EIO;
46}
47
48static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
49{
50 return -EIO;
51}
52
53static int bad_inode_symlink (struct inode *dir, struct dentry *dentry,
54 const char *symname)
55{
56 return -EIO;
57}
58
59static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry,
60 umode_t mode)
61{
62 return -EIO;
63}
64
65static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
66{
67 return -EIO;
68}
69
70static int bad_inode_mknod (struct inode *dir, struct dentry *dentry,
71 umode_t mode, dev_t rdev)
72{
73 return -EIO;
74}
75
76static int bad_inode_rename2(struct inode *old_dir, struct dentry *old_dentry,
77 struct inode *new_dir, struct dentry *new_dentry,
78 unsigned int flags)
79{
80 return -EIO;
81}
82
83static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
84 int buflen)
85{
86 return -EIO;
87}
88
89static int bad_inode_permission(struct inode *inode, int mask)
90{
91 return -EIO;
92}
93
94static int bad_inode_getattr(const struct path *path, struct kstat *stat,
95 u32 request_mask, unsigned int query_flags)
96{
97 return -EIO;
98}
99
100static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
101{
102 return -EIO;
103}
104
105static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
106 size_t buffer_size)
107{
108 return -EIO;
109}
110
111static const char *bad_inode_get_link(struct dentry *dentry,
112 struct inode *inode,
113 struct delayed_call *done)
114{
115 return ERR_PTR(-EIO);
116}
117
118static struct posix_acl *bad_inode_get_acl(struct inode *inode, int type)
119{
120 return ERR_PTR(-EIO);
121}
122
123static int bad_inode_fiemap(struct inode *inode,
124 struct fiemap_extent_info *fieinfo, u64 start,
125 u64 len)
126{
127 return -EIO;
128}
129
130static int bad_inode_update_time(struct inode *inode, struct timespec64 *time,
131 int flags)
132{
133 return -EIO;
134}
135
136static int bad_inode_atomic_open(struct inode *inode, struct dentry *dentry,
137 struct file *file, unsigned int open_flag,
138 umode_t create_mode)
139{
140 return -EIO;
141}
142
143static int bad_inode_tmpfile(struct inode *inode, struct dentry *dentry,
144 umode_t mode)
145{
146 return -EIO;
147}
148
149static int bad_inode_set_acl(struct inode *inode, struct posix_acl *acl,
150 int type)
151{
152 return -EIO;
153}
154
155static const struct inode_operations bad_inode_ops =
156{
157 .create = bad_inode_create,
158 .lookup = bad_inode_lookup,
159 .link = bad_inode_link,
160 .unlink = bad_inode_unlink,
161 .symlink = bad_inode_symlink,
162 .mkdir = bad_inode_mkdir,
163 .rmdir = bad_inode_rmdir,
164 .mknod = bad_inode_mknod,
165 .rename = bad_inode_rename2,
166 .readlink = bad_inode_readlink,
167 .permission = bad_inode_permission,
168 .getattr = bad_inode_getattr,
169 .setattr = bad_inode_setattr,
170 .listxattr = bad_inode_listxattr,
171 .get_link = bad_inode_get_link,
172 .get_acl = bad_inode_get_acl,
173 .fiemap = bad_inode_fiemap,
174 .update_time = bad_inode_update_time,
175 .atomic_open = bad_inode_atomic_open,
176 .tmpfile = bad_inode_tmpfile,
177 .set_acl = bad_inode_set_acl,
178};
179
180
181/*
182 * When a filesystem is unable to read an inode due to an I/O error in
183 * its read_inode() function, it can call make_bad_inode() to return a
184 * set of stubs which will return EIO errors as required.
185 *
186 * We only need to do limited initialisation: all other fields are
187 * preinitialised to zero automatically.
188 */
189
190/**
191 * make_bad_inode - mark an inode bad due to an I/O error
192 * @inode: Inode to mark bad
193 *
194 * When an inode cannot be read due to a media or remote network
195 * failure this function makes the inode "bad" and causes I/O operations
196 * on it to fail from this point on.
197 */
198
199void make_bad_inode(struct inode *inode)
200{
201 remove_inode_hash(inode);
202
203 inode->i_mode = S_IFREG;
204 inode->i_atime = inode->i_mtime = inode->i_ctime =
205 current_time(inode);
206 inode->i_op = &bad_inode_ops;
207 inode->i_opflags &= ~IOP_XATTR;
208 inode->i_fop = &bad_file_ops;
209}
210EXPORT_SYMBOL(make_bad_inode);
211
212/*
213 * This tests whether an inode has been flagged as bad. The test uses
214 * &bad_inode_ops to cover the case of invalidated inodes as well as
215 * those created by make_bad_inode() above.
216 */
217
218/**
219 * is_bad_inode - is an inode errored
220 * @inode: inode to test
221 *
222 * Returns true if the inode in question has been marked as bad.
223 */
224
225bool is_bad_inode(struct inode *inode)
226{
227 return (inode->i_op == &bad_inode_ops);
228}
229
230EXPORT_SYMBOL(is_bad_inode);
231
232/**
233 * iget_failed - Mark an under-construction inode as dead and release it
234 * @inode: The inode to discard
235 *
236 * Mark an under-construction inode as dead and release it.
237 */
238void iget_failed(struct inode *inode)
239{
240 make_bad_inode(inode);
241 unlock_new_inode(inode);
242 iput(inode);
243}
244EXPORT_SYMBOL(iget_failed);