blob: bb53728c7a31b0abee8f5080ae25e162ff74f203 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Paul Gortmaker630d9c42011-11-16 23:57:37 -050012#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/stat.h>
14#include <linux/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/namei.h>
Eric Sandeenbe6aab02007-01-05 16:36:36 -080016#include <linux/poll.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Eric Sandeenbe6aab02007-01-05 16:36:36 -080018static int bad_file_open(struct inode *inode, struct file *filp)
19{
20 return -EIO;
21}
22
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080023static const struct file_operations bad_file_ops =
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Eric Sandeenbe6aab02007-01-05 16:36:36 -080025 .open = bad_file_open,
Linus Torvalds1da177e2005-04-16 15:20:36 -070026};
27
Eric Sandeenbe6aab02007-01-05 16:36:36 -080028static int bad_inode_create (struct inode *dir, struct dentry *dentry,
Al Viroebfc3b42012-06-10 18:05:36 -040029 umode_t mode, bool excl)
Eric Sandeenbe6aab02007-01-05 16:36:36 -080030{
31 return -EIO;
32}
33
34static struct dentry *bad_inode_lookup(struct inode *dir,
Al Viro00cd8dd2012-06-10 17:13:09 -040035 struct dentry *dentry, unsigned int flags)
Eric Sandeenbe6aab02007-01-05 16:36:36 -080036{
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,
Al Viro18bb1db2011-07-26 01:41:39 -040058 umode_t mode)
Eric Sandeenbe6aab02007-01-05 16:36:36 -080059{
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,
Al Viro1a67aaf2011-07-26 01:52:52 -040069 umode_t mode, dev_t rdev)
Eric Sandeenbe6aab02007-01-05 16:36:36 -080070{
71 return -EIO;
72}
73
Miklos Szeredia0dbc562014-07-23 15:15:31 +020074static 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)
Eric Sandeenbe6aab02007-01-05 16:36:36 -080077{
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
Al Viro10556cb22011-06-20 19:28:19 -040087static int bad_inode_permission(struct inode *inode, int mask)
Eric Sandeenbe6aab02007-01-05 16:36:36 -080088{
89 return -EIO;
90}
91
David Howellsa528d352017-01-31 16:46:22 +000092static int bad_inode_getattr(const struct path *path, struct kstat *stat,
93 u32 request_mask, unsigned int query_flags)
Eric Sandeenbe6aab02007-01-05 16:36:36 -080094{
95 return -EIO;
96}
97
98static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
99{
100 return -EIO;
101}
102
Eric Sandeenbe6aab02007-01-05 16:36:36 -0800103static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
104 size_t buffer_size)
105{
106 return -EIO;
107}
108
Miklos Szeredi3f9ca752016-12-09 11:57:43 +0100109static 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
Arjan van de Ven754661f2007-02-12 00:55:38 -0800153static const struct inode_operations bad_inode_ops =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Eric Sandeenbe6aab02007-01-05 16:36:36 -0800155 .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,
Miklos Szeredi2773bf02016-09-27 11:03:58 +0200163 .rename = bad_inode_rename2,
Eric Sandeenbe6aab02007-01-05 16:36:36 -0800164 .readlink = bad_inode_readlink,
Eric Sandeenbe6aab02007-01-05 16:36:36 -0800165 .permission = bad_inode_permission,
166 .getattr = bad_inode_getattr,
167 .setattr = bad_inode_setattr,
Eric Sandeenbe6aab02007-01-05 16:36:36 -0800168 .listxattr = bad_inode_listxattr,
Miklos Szeredi3f9ca752016-12-09 11:57:43 +0100169 .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,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176};
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
Eric Sandeenbe6aab02007-01-05 16:36:36 -0800197void make_bad_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
199 remove_inode_hash(inode);
200
201 inode->i_mode = S_IFREG;
202 inode->i_atime = inode->i_mtime = inode->i_ctime =
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700203 current_time(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 inode->i_op = &bad_inode_ops;
Andreas Gruenbacher5f6e59a2016-09-29 17:48:40 +0200205 inode->i_opflags &= ~IOP_XATTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 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
Yaowei Bai0e3ef1f2015-11-19 21:00:11 +0800223bool is_bad_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
225 return (inode->i_op == &bad_inode_ops);
226}
227
228EXPORT_SYMBOL(is_bad_inode);
David Howellsb46980f2008-02-07 00:15:27 -0800229
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);