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/*
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/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, loff_t start, loff_t end,
91 int datasync)
92{
93 return -EIO;
94}
95
96static int bad_file_aio_fsync(struct kiocb *iocb, int datasync)
97{
98 return -EIO;
99}
100
101static int bad_file_fasync(int fd, struct file *filp, int on)
102{
103 return -EIO;
104}
105
106static int bad_file_lock(struct file *file, int cmd, struct file_lock *fl)
107{
108 return -EIO;
109}
110
111static ssize_t bad_file_sendpage(struct file *file, struct page *page,
112 int off, size_t len, loff_t *pos, int more)
113{
114 return -EIO;
115}
116
117static unsigned long bad_file_get_unmapped_area(struct file *file,
118 unsigned long addr, unsigned long len,
119 unsigned long pgoff, unsigned long flags)
120{
121 return -EIO;
122}
123
124static int bad_file_check_flags(int flags)
125{
126 return -EIO;
127}
128
129static int bad_file_flock(struct file *filp, int cmd, struct file_lock *fl)
130{
131 return -EIO;
132}
133
134static ssize_t bad_file_splice_write(struct pipe_inode_info *pipe,
135 struct file *out, loff_t *ppos, size_t len,
136 unsigned int flags)
137{
138 return -EIO;
139}
140
141static ssize_t bad_file_splice_read(struct file *in, loff_t *ppos,
142 struct pipe_inode_info *pipe, size_t len,
143 unsigned int flags)
144{
145 return -EIO;
146}
147
148static const struct file_operations bad_file_ops =
149{
150 .llseek = bad_file_llseek,
151 .read = bad_file_read,
152 .write = bad_file_write,
153 .aio_read = bad_file_aio_read,
154 .aio_write = bad_file_aio_write,
155 .readdir = bad_file_readdir,
156 .poll = bad_file_poll,
157 .unlocked_ioctl = bad_file_unlocked_ioctl,
158 .compat_ioctl = bad_file_compat_ioctl,
159 .mmap = bad_file_mmap,
160 .open = bad_file_open,
161 .flush = bad_file_flush,
162 .release = bad_file_release,
163 .fsync = bad_file_fsync,
164 .aio_fsync = bad_file_aio_fsync,
165 .fasync = bad_file_fasync,
166 .lock = bad_file_lock,
167 .sendpage = bad_file_sendpage,
168 .get_unmapped_area = bad_file_get_unmapped_area,
169 .check_flags = bad_file_check_flags,
170 .flock = bad_file_flock,
171 .splice_write = bad_file_splice_write,
172 .splice_read = bad_file_splice_read,
173};
174
175static int bad_inode_create (struct inode *dir, struct dentry *dentry,
176 int mode, struct nameidata *nd)
177{
178 return -EIO;
179}
180
181static struct dentry *bad_inode_lookup(struct inode *dir,
182 struct dentry *dentry, struct nameidata *nd)
183{
184 return ERR_PTR(-EIO);
185}
186
187static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
188 struct dentry *dentry)
189{
190 return -EIO;
191}
192
193static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
194{
195 return -EIO;
196}
197
198static int bad_inode_symlink (struct inode *dir, struct dentry *dentry,
199 const char *symname)
200{
201 return -EIO;
202}
203
204static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry,
205 int mode)
206{
207 return -EIO;
208}
209
210static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
211{
212 return -EIO;
213}
214
215static int bad_inode_mknod (struct inode *dir, struct dentry *dentry,
216 int mode, dev_t rdev)
217{
218 return -EIO;
219}
220
221static int bad_inode_rename (struct inode *old_dir, struct dentry *old_dentry,
222 struct inode *new_dir, struct dentry *new_dentry)
223{
224 return -EIO;
225}
226
227static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
228 int buflen)
229{
230 return -EIO;
231}
232
233static int bad_inode_permission(struct inode *inode, int mask)
234{
235 return -EIO;
236}
237
238static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
239 struct kstat *stat)
240{
241 return -EIO;
242}
243
244static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
245{
246 return -EIO;
247}
248
249static int bad_inode_setxattr(struct dentry *dentry, const char *name,
250 const void *value, size_t size, int flags)
251{
252 return -EIO;
253}
254
255static ssize_t bad_inode_getxattr(struct dentry *dentry, const char *name,
256 void *buffer, size_t size)
257{
258 return -EIO;
259}
260
261static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
262 size_t buffer_size)
263{
264 return -EIO;
265}
266
267static int bad_inode_removexattr(struct dentry *dentry, const char *name)
268{
269 return -EIO;
270}
271
272static const struct inode_operations bad_inode_ops =
273{
274 .create = bad_inode_create,
275 .lookup = bad_inode_lookup,
276 .link = bad_inode_link,
277 .unlink = bad_inode_unlink,
278 .symlink = bad_inode_symlink,
279 .mkdir = bad_inode_mkdir,
280 .rmdir = bad_inode_rmdir,
281 .mknod = bad_inode_mknod,
282 .rename = bad_inode_rename,
283 .readlink = bad_inode_readlink,
284 /* follow_link must be no-op, otherwise unmounting this inode
285 won't work */
286 /* put_link returns void */
287 /* truncate returns void */
288 .permission = bad_inode_permission,
289 .getattr = bad_inode_getattr,
290 .setattr = bad_inode_setattr,
291 .setxattr = bad_inode_setxattr,
292 .getxattr = bad_inode_getxattr,
293 .listxattr = bad_inode_listxattr,
294 .removexattr = bad_inode_removexattr,
295 /* truncate_range returns void */
296};
297
298
299/*
300 * When a filesystem is unable to read an inode due to an I/O error in
301 * its read_inode() function, it can call make_bad_inode() to return a
302 * set of stubs which will return EIO errors as required.
303 *
304 * We only need to do limited initialisation: all other fields are
305 * preinitialised to zero automatically.
306 */
307
308/**
309 * make_bad_inode - mark an inode bad due to an I/O error
310 * @inode: Inode to mark bad
311 *
312 * When an inode cannot be read due to a media or remote network
313 * failure this function makes the inode "bad" and causes I/O operations
314 * on it to fail from this point on.
315 */
316
317void make_bad_inode(struct inode *inode)
318{
319 remove_inode_hash(inode);
320
321 inode->i_mode = S_IFREG;
322 inode->i_atime = inode->i_mtime = inode->i_ctime =
323 current_fs_time(inode->i_sb);
324 inode->i_op = &bad_inode_ops;
325 inode->i_fop = &bad_file_ops;
326}
327EXPORT_SYMBOL(make_bad_inode);
328
329/*
330 * This tests whether an inode has been flagged as bad. The test uses
331 * &bad_inode_ops to cover the case of invalidated inodes as well as
332 * those created by make_bad_inode() above.
333 */
334
335/**
336 * is_bad_inode - is an inode errored
337 * @inode: inode to test
338 *
339 * Returns true if the inode in question has been marked as bad.
340 */
341
342int is_bad_inode(struct inode *inode)
343{
344 return (inode->i_op == &bad_inode_ops);
345}
346
347EXPORT_SYMBOL(is_bad_inode);
348
349/**
350 * iget_failed - Mark an under-construction inode as dead and release it
351 * @inode: The inode to discard
352 *
353 * Mark an under-construction inode as dead and release it.
354 */
355void iget_failed(struct inode *inode)
356{
357 make_bad_inode(inode);
358 unlock_new_inode(inode);
359 iput(inode);
360}
361EXPORT_SYMBOL(iget_failed);