4 * Copyright (C) 1997, Stephen Tweedie
6 * Provide stub functions for unreadable inodes
10 #include <linux/stat.h>
11 #include <linux/time.h>
12 #include <linux/smp_lock.h>
15 * The follow_link operation is special: it must behave as a no-op
16 * so that a bad root inode can at least be unmounted. To do this
17 * we must dput() the base and return the dentry with a dget().
19 static int bad_follow_link(struct dentry
*dent
, struct nameidata
*nd
)
21 return vfs_follow_link(nd
, ERR_PTR(-EIO
));
24 static int return_EIO(void)
29 #define EIO_ERROR ((void *) (return_EIO))
31 static struct file_operations bad_file_ops
=
48 struct inode_operations bad_inode_ops
=
59 .readlink
= EIO_ERROR
,
60 .follow_link
= bad_follow_link
,
61 .truncate
= EIO_ERROR
,
62 .permission
= EIO_ERROR
,
68 * When a filesystem is unable to read an inode due to an I/O error in
69 * its read_inode() function, it can call make_bad_inode() to return a
70 * set of stubs which will return EIO errors as required.
72 * We only need to do limited initialisation: all other fields are
73 * preinitialised to zero automatically.
77 * make_bad_inode - mark an inode bad due to an I/O error
78 * @inode: Inode to mark bad
80 * When an inode cannot be read due to a media or remote network
81 * failure this function makes the inode "bad" and causes I/O operations
82 * on it to fail from this point on.
85 void make_bad_inode(struct inode
* inode
)
87 remove_inode_hash(inode
);
89 inode
->i_mode
= S_IFREG
;
90 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
91 inode
->i_op
= &bad_inode_ops
;
92 inode
->i_fop
= &bad_file_ops
;
96 * This tests whether an inode has been flagged as bad. The test uses
97 * &bad_inode_ops to cover the case of invalidated inodes as well as
98 * those created by make_bad_inode() above.
102 * is_bad_inode - is an inode errored
103 * @inode: inode to test
105 * Returns true if the inode in question has been marked as bad.
108 int is_bad_inode(struct inode
* inode
)
110 return (inode
->i_op
== &bad_inode_ops
);