VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / 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  *  Fabian Frederick : August 2003 - All file operations assigned to EIO
9  */
10
11 #include <linux/fs.h>
12 #include <linux/module.h>
13 #include <linux/stat.h>
14 #include <linux/time.h>
15 #include <linux/smp_lock.h>
16 #include <linux/namei.h>
17
18 /*
19  * The follow_link operation is special: it must behave as a no-op
20  * so that a bad root inode can at least be unmounted. To do this
21  * we must dput() the base and return the dentry with a dget().
22  */
23 static int bad_follow_link(struct dentry *dent, struct nameidata *nd)
24 {
25         nd_set_link(nd, ERR_PTR(-EIO));
26         return 0;
27 }
28
29 static int return_EIO(void)
30 {
31         return -EIO;
32 }
33
34 #define EIO_ERROR ((void *) (return_EIO))
35
36 static struct file_operations bad_file_ops =
37 {
38         .llseek         = EIO_ERROR,
39         .aio_read       = EIO_ERROR,
40         .read           = EIO_ERROR,
41         .write          = EIO_ERROR,
42         .aio_write      = EIO_ERROR,
43         .readdir        = EIO_ERROR,
44         .poll           = EIO_ERROR,
45         .ioctl          = EIO_ERROR,
46         .mmap           = EIO_ERROR,
47         .open           = EIO_ERROR,
48         .flush          = EIO_ERROR,
49         .release        = EIO_ERROR,
50         .fsync          = EIO_ERROR,
51         .aio_fsync      = EIO_ERROR,
52         .fasync         = EIO_ERROR,
53         .lock           = EIO_ERROR,
54         .readv          = EIO_ERROR,
55         .writev         = EIO_ERROR,
56         .sendfile       = EIO_ERROR,
57         .sendpage       = EIO_ERROR,
58         .get_unmapped_area = EIO_ERROR,
59 };
60
61 struct inode_operations bad_inode_ops =
62 {
63         .create         = EIO_ERROR,
64         .lookup         = EIO_ERROR,
65         .link           = EIO_ERROR,
66         .unlink         = EIO_ERROR,
67         .symlink        = EIO_ERROR,
68         .mkdir          = EIO_ERROR,
69         .rmdir          = EIO_ERROR,
70         .mknod          = EIO_ERROR,
71         .rename         = EIO_ERROR,
72         .readlink       = EIO_ERROR,
73         .follow_link    = bad_follow_link,
74         .truncate       = EIO_ERROR,
75         .permission     = EIO_ERROR,
76         .getattr        = EIO_ERROR,
77         .setattr        = EIO_ERROR,
78         .setxattr       = EIO_ERROR,
79         .getxattr       = EIO_ERROR,
80         .listxattr      = EIO_ERROR,
81         .removexattr    = EIO_ERROR,
82 };
83
84
85 /*
86  * When a filesystem is unable to read an inode due to an I/O error in
87  * its read_inode() function, it can call make_bad_inode() to return a
88  * set of stubs which will return EIO errors as required. 
89  *
90  * We only need to do limited initialisation: all other fields are
91  * preinitialised to zero automatically.
92  */
93  
94 /**
95  *      make_bad_inode - mark an inode bad due to an I/O error
96  *      @inode: Inode to mark bad
97  *
98  *      When an inode cannot be read due to a media or remote network
99  *      failure this function makes the inode "bad" and causes I/O operations
100  *      on it to fail from this point on.
101  */
102  
103 void make_bad_inode(struct inode * inode) 
104 {
105         remove_inode_hash(inode);
106
107         inode->i_mode = S_IFREG;
108         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
109         inode->i_op = &bad_inode_ops;   
110         inode->i_fop = &bad_file_ops;   
111 }
112 EXPORT_SYMBOL(make_bad_inode);
113
114 /*
115  * This tests whether an inode has been flagged as bad. The test uses
116  * &bad_inode_ops to cover the case of invalidated inodes as well as
117  * those created by make_bad_inode() above.
118  */
119  
120 /**
121  *      is_bad_inode - is an inode errored
122  *      @inode: inode to test
123  *
124  *      Returns true if the inode in question has been marked as bad.
125  */
126  
127 int is_bad_inode(struct inode * inode) 
128 {
129         return (inode->i_op == &bad_inode_ops); 
130 }
131
132 EXPORT_SYMBOL(is_bad_inode);