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/module.h>
13 #include <linux/stat.h>
14 #include <linux/time.h>
15 #include <linux/smp_lock.h>
18 * The follow_link operation is special: it must behave as a no-op
19 * so that a bad root inode can at least be unmounted. To do this
20 * we must dput() the base and return the dentry with a dget().
22 static int bad_follow_link(struct dentry *dent, struct nameidata *nd)
24 nd_set_link(nd, ERR_PTR(-EIO));
28 static int return_EIO(void)
33 #define EIO_ERROR ((void *) (return_EIO))
35 static struct file_operations bad_file_ops =
38 .aio_read = EIO_ERROR,
41 .aio_write = EIO_ERROR,
50 .aio_fsync = EIO_ERROR,
55 .sendfile = EIO_ERROR,
56 .sendpage = EIO_ERROR,
57 .get_unmapped_area = EIO_ERROR,
60 struct inode_operations bad_inode_ops =
71 .readlink = EIO_ERROR,
72 .follow_link = bad_follow_link,
73 .truncate = EIO_ERROR,
74 .permission = EIO_ERROR,
77 .setxattr = EIO_ERROR,
78 .getxattr = EIO_ERROR,
79 .listxattr = EIO_ERROR,
80 .removexattr = EIO_ERROR,
85 * When a filesystem is unable to read an inode due to an I/O error in
86 * its read_inode() function, it can call make_bad_inode() to return a
87 * set of stubs which will return EIO errors as required.
89 * We only need to do limited initialisation: all other fields are
90 * preinitialised to zero automatically.
94 * make_bad_inode - mark an inode bad due to an I/O error
95 * @inode: Inode to mark bad
97 * When an inode cannot be read due to a media or remote network
98 * failure this function makes the inode "bad" and causes I/O operations
99 * on it to fail from this point on.
102 void make_bad_inode(struct inode * inode)
104 remove_inode_hash(inode);
106 inode->i_mode = S_IFREG;
107 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
108 inode->i_op = &bad_inode_ops;
109 inode->i_fop = &bad_file_ops;
111 EXPORT_SYMBOL(make_bad_inode);
114 * This tests whether an inode has been flagged as bad. The test uses
115 * &bad_inode_ops to cover the case of invalidated inodes as well as
116 * those created by make_bad_inode() above.
120 * is_bad_inode - is an inode errored
121 * @inode: inode to test
123 * Returns true if the inode in question has been marked as bad.
126 int is_bad_inode(struct inode * inode)
128 return (inode->i_op == &bad_inode_ops);
131 EXPORT_SYMBOL(is_bad_inode);