4 * Copyright (C) 1997, Stephen Tweedie
6 * Provide stub functions for unreadable inodes
8 * Fabian Frederick : August 2003 - All file operations assigned to EIO
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>
18 static int bad_file_open(struct inode
*inode
, struct file
*filp
)
23 static const struct file_operations bad_file_ops
=
25 .open
= bad_file_open
,
28 static int bad_inode_create (struct inode
*dir
, struct dentry
*dentry
,
29 umode_t mode
, bool excl
)
34 static struct dentry
*bad_inode_lookup(struct inode
*dir
,
35 struct dentry
*dentry
, unsigned int flags
)
40 static int bad_inode_link (struct dentry
*old_dentry
, struct inode
*dir
,
41 struct dentry
*dentry
)
46 static int bad_inode_unlink(struct inode
*dir
, struct dentry
*dentry
)
51 static int bad_inode_symlink (struct inode
*dir
, struct dentry
*dentry
,
57 static int bad_inode_mkdir(struct inode
*dir
, struct dentry
*dentry
,
63 static int bad_inode_rmdir (struct inode
*dir
, struct dentry
*dentry
)
68 static int bad_inode_mknod (struct inode
*dir
, struct dentry
*dentry
,
69 umode_t mode
, dev_t rdev
)
74 static int bad_inode_rename2(struct inode
*old_dir
, struct dentry
*old_dentry
,
75 struct inode
*new_dir
, struct dentry
*new_dentry
,
81 static int bad_inode_readlink(struct dentry
*dentry
, char __user
*buffer
,
87 static int bad_inode_permission(struct inode
*inode
, int mask
)
92 static int bad_inode_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
,
98 static int bad_inode_setattr(struct dentry
*direntry
, struct iattr
*attrs
)
103 static ssize_t
bad_inode_listxattr(struct dentry
*dentry
, char *buffer
,
109 static const char *bad_inode_get_link(struct dentry
*dentry
,
111 struct delayed_call
*done
)
113 return ERR_PTR(-EIO
);
116 static struct posix_acl
*bad_inode_get_acl(struct inode
*inode
, int type
)
118 return ERR_PTR(-EIO
);
121 static int bad_inode_fiemap(struct inode
*inode
,
122 struct fiemap_extent_info
*fieinfo
, u64 start
,
128 static int bad_inode_update_time(struct inode
*inode
, struct timespec
*time
,
134 static 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
)
141 static int bad_inode_tmpfile(struct inode
*inode
, struct dentry
*dentry
,
147 static int bad_inode_set_acl(struct inode
*inode
, struct posix_acl
*acl
,
153 static const struct inode_operations bad_inode_ops
=
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
,
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.
184 * We only need to do limited initialisation: all other fields are
185 * preinitialised to zero automatically.
189 * make_bad_inode - mark an inode bad due to an I/O error
190 * @inode: Inode to mark bad
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.
197 void make_bad_inode(struct inode
*inode
)
199 remove_inode_hash(inode
);
201 inode
->i_mode
= S_IFREG
;
202 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
=
204 inode
->i_op
= &bad_inode_ops
;
205 inode
->i_opflags
&= ~IOP_XATTR
;
206 inode
->i_fop
= &bad_file_ops
;
208 EXPORT_SYMBOL(make_bad_inode
);
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.
217 * is_bad_inode - is an inode errored
218 * @inode: inode to test
220 * Returns true if the inode in question has been marked as bad.
223 bool is_bad_inode(struct inode
*inode
)
225 return (inode
->i_op
== &bad_inode_ops
);
228 EXPORT_SYMBOL(is_bad_inode
);
231 * iget_failed - Mark an under-construction inode as dead and release it
232 * @inode: The inode to discard
234 * Mark an under-construction inode as dead and release it.
236 void iget_failed(struct inode
*inode
)
238 make_bad_inode(inode
);
239 unlock_new_inode(inode
);
242 EXPORT_SYMBOL(iget_failed
);