FreeBSD/Linux Kernel Cross Reference
sys/fs/bad_inode.c
1 /*
2 * linux/fs/bad_inode.c
3 *
4 * Copyright (C) 1997, Stephen Tweedie
5 *
6 * Provide stub functions for unreadable inodes
7 */
8
9 #include <linux/fs.h>
10 #include <linux/stat.h>
11 #include <linux/sched.h>
12
13 /*
14 * The follow_link operation is special: it must behave as a no-op
15 * so that a bad root inode can at least be unmounted. To do this
16 * we must dput() the base and return the dentry with a dget().
17 */
18 static int bad_follow_link(struct dentry *dent, struct nameidata *nd)
19 {
20 return vfs_follow_link(nd, ERR_PTR(-EIO));
21 }
22
23 static int return_EIO(void)
24 {
25 return -EIO;
26 }
27
28 #define EIO_ERROR ((void *) (return_EIO))
29
30 static struct file_operations bad_file_ops =
31 {
32 llseek: EIO_ERROR,
33 read: EIO_ERROR,
34 write: EIO_ERROR,
35 readdir: EIO_ERROR,
36 poll: EIO_ERROR,
37 ioctl: EIO_ERROR,
38 mmap: EIO_ERROR,
39 open: EIO_ERROR,
40 flush: EIO_ERROR,
41 release: EIO_ERROR,
42 fsync: EIO_ERROR,
43 fasync: EIO_ERROR,
44 lock: EIO_ERROR,
45 };
46
47 struct inode_operations bad_inode_ops =
48 {
49 create: EIO_ERROR,
50 lookup: EIO_ERROR,
51 link: EIO_ERROR,
52 unlink: EIO_ERROR,
53 symlink: EIO_ERROR,
54 mkdir: EIO_ERROR,
55 rmdir: EIO_ERROR,
56 mknod: EIO_ERROR,
57 rename: EIO_ERROR,
58 readlink: EIO_ERROR,
59 follow_link: bad_follow_link,
60 truncate: EIO_ERROR,
61 permission: EIO_ERROR,
62 revalidate: EIO_ERROR,
63 };
64
65
66 /*
67 * When a filesystem is unable to read an inode due to an I/O error in
68 * its read_inode() function, it can call make_bad_inode() to return a
69 * set of stubs which will return EIO errors as required.
70 *
71 * We only need to do limited initialisation: all other fields are
72 * preinitialised to zero automatically.
73 */
74
75 /**
76 * make_bad_inode - mark an inode bad due to an I/O error
77 * @inode: Inode to mark bad
78 *
79 * When an inode cannot be read due to a media or remote network
80 * failure this function makes the inode "bad" and causes I/O operations
81 * on it to fail from this point on.
82 */
83
84 void make_bad_inode(struct inode * inode)
85 {
86 inode->i_mode = S_IFREG;
87 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
88 inode->i_op = &bad_inode_ops;
89 inode->i_fop = &bad_file_ops;
90 }
91
92 /*
93 * This tests whether an inode has been flagged as bad. The test uses
94 * &bad_inode_ops to cover the case of invalidated inodes as well as
95 * those created by make_bad_inode() above.
96 */
97
98 /**
99 * is_bad_inode - is an inode errored
100 * @inode: inode to test
101 *
102 * Returns true if the inode in question has been marked as bad.
103 */
104
105 int is_bad_inode(struct inode * inode)
106 {
107 return (inode->i_op == &bad_inode_ops);
108 }
Cache object: c905f2c966ab917d7522c0b91fa40252
|