1 // SPDX-License-Identifier: GPL-2.0 << 2 /* 1 /* 3 * linux/fs/bad_inode.c 2 * linux/fs/bad_inode.c 4 * 3 * 5 * Copyright (C) 1997, Stephen Tweedie 4 * Copyright (C) 1997, Stephen Tweedie 6 * 5 * 7 * Provide stub functions for unreadable inod 6 * Provide stub functions for unreadable inodes 8 * 7 * 9 * Fabian Frederick : August 2003 - All file 8 * Fabian Frederick : August 2003 - All file operations assigned to EIO 10 */ 9 */ 11 10 12 #include <linux/fs.h> 11 #include <linux/fs.h> 13 #include <linux/export.h> !! 12 #include <linux/module.h> 14 #include <linux/stat.h> 13 #include <linux/stat.h> 15 #include <linux/time.h> 14 #include <linux/time.h> 16 #include <linux/namei.h> !! 15 #include <linux/smp_lock.h> 17 #include <linux/poll.h> << 18 #include <linux/fiemap.h> << 19 16 20 static int bad_file_open(struct inode *inode, !! 17 /* 21 { !! 18 * The follow_link operation is special: it must behave as a no-op 22 return -EIO; !! 19 * so that a bad root inode can at least be unmounted. To do this 23 } !! 20 * we must dput() the base and return the dentry with a dget(). 24 !! 21 */ 25 static const struct file_operations bad_file_o !! 22 static int bad_follow_link(struct dentry *dent, struct nameidata *nd) 26 { << 27 .open = bad_file_open, << 28 }; << 29 << 30 static int bad_inode_create(struct mnt_idmap * << 31 struct inode *dir, << 32 umode_t mode, bool << 33 { << 34 return -EIO; << 35 } << 36 << 37 static struct dentry *bad_inode_lookup(struct << 38 struct dentry *dentry, << 39 { << 40 return ERR_PTR(-EIO); << 41 } << 42 << 43 static int bad_inode_link (struct dentry *old_ << 44 struct dentry *dentry) << 45 { << 46 return -EIO; << 47 } << 48 << 49 static int bad_inode_unlink(struct inode *dir, << 50 { << 51 return -EIO; << 52 } << 53 << 54 static int bad_inode_symlink(struct mnt_idmap << 55 struct inode *dir << 56 const char *symna << 57 { << 58 return -EIO; << 59 } << 60 << 61 static int bad_inode_mkdir(struct mnt_idmap *i << 62 struct dentry *dent << 63 { << 64 return -EIO; << 65 } << 66 << 67 static int bad_inode_rmdir (struct inode *dir, << 68 { << 69 return -EIO; << 70 } << 71 << 72 static int bad_inode_mknod(struct mnt_idmap *i << 73 struct dentry *dent << 74 { << 75 return -EIO; << 76 } << 77 << 78 static int bad_inode_rename2(struct mnt_idmap << 79 struct inode *old << 80 struct inode *new << 81 unsigned int flag << 82 { << 83 return -EIO; << 84 } << 85 << 86 static int bad_inode_readlink(struct dentry *d << 87 int buflen) << 88 { << 89 return -EIO; << 90 } << 91 << 92 static int bad_inode_permission(struct mnt_idm << 93 struct inode * << 94 { << 95 return -EIO; << 96 } << 97 << 98 static int bad_inode_getattr(struct mnt_idmap << 99 const struct path << 100 u32 request_mask, << 101 { << 102 return -EIO; << 103 } << 104 << 105 static int bad_inode_setattr(struct mnt_idmap << 106 struct dentry *di << 107 { << 108 return -EIO; << 109 } << 110 << 111 static ssize_t bad_inode_listxattr(struct dent << 112 size_t buffer_size) << 113 { << 114 return -EIO; << 115 } << 116 << 117 static const char *bad_inode_get_link(struct d << 118 struct i << 119 struct d << 120 { << 121 return ERR_PTR(-EIO); << 122 } << 123 << 124 static struct posix_acl *bad_inode_get_acl(str << 125 { << 126 return ERR_PTR(-EIO); << 127 } << 128 << 129 static int bad_inode_fiemap(struct inode *inod << 130 struct fiemap_exte << 131 u64 len) << 132 { 23 { 133 return -EIO; !! 24 return vfs_follow_link(nd, ERR_PTR(-EIO)); 134 } 25 } 135 26 136 static int bad_inode_update_time(struct inode !! 27 static int return_EIO(void) 137 { 28 { 138 return -EIO; 29 return -EIO; 139 } 30 } 140 31 141 static int bad_inode_atomic_open(struct inode !! 32 #define EIO_ERROR ((void *) (return_EIO)) 142 struct file * << 143 umode_t creat << 144 { << 145 return -EIO; << 146 } << 147 33 148 static int bad_inode_tmpfile(struct mnt_idmap !! 34 static struct file_operations bad_file_ops = 149 struct inode *ino << 150 umode_t mode) << 151 { 35 { 152 return -EIO; !! 36 .llseek = EIO_ERROR, 153 } !! 37 .aio_read = EIO_ERROR, 154 !! 38 .read = EIO_ERROR, 155 static int bad_inode_set_acl(struct mnt_idmap !! 39 .write = EIO_ERROR, 156 struct dentry *de !! 40 .aio_write = EIO_ERROR, 157 int type) !! 41 .readdir = EIO_ERROR, 158 { !! 42 .poll = EIO_ERROR, 159 return -EIO; !! 43 .ioctl = EIO_ERROR, 160 } !! 44 .mmap = EIO_ERROR, >> 45 .open = EIO_ERROR, >> 46 .flush = EIO_ERROR, >> 47 .release = EIO_ERROR, >> 48 .fsync = EIO_ERROR, >> 49 .aio_fsync = EIO_ERROR, >> 50 .fasync = EIO_ERROR, >> 51 .lock = EIO_ERROR, >> 52 .readv = EIO_ERROR, >> 53 .writev = EIO_ERROR, >> 54 .sendfile = EIO_ERROR, >> 55 .sendpage = EIO_ERROR, >> 56 .get_unmapped_area = EIO_ERROR, >> 57 }; 161 58 162 static const struct inode_operations bad_inode !! 59 struct inode_operations bad_inode_ops = 163 { 60 { 164 .create = bad_inode_create, !! 61 .create = EIO_ERROR, 165 .lookup = bad_inode_lookup, !! 62 .lookup = EIO_ERROR, 166 .link = bad_inode_link, !! 63 .link = EIO_ERROR, 167 .unlink = bad_inode_unlink, !! 64 .unlink = EIO_ERROR, 168 .symlink = bad_inode_symlink, !! 65 .symlink = EIO_ERROR, 169 .mkdir = bad_inode_mkdir, !! 66 .mkdir = EIO_ERROR, 170 .rmdir = bad_inode_rmdir, !! 67 .rmdir = EIO_ERROR, 171 .mknod = bad_inode_mknod, !! 68 .mknod = EIO_ERROR, 172 .rename = bad_inode_rename2, !! 69 .rename = EIO_ERROR, 173 .readlink = bad_inode_readlink, !! 70 .readlink = EIO_ERROR, 174 .permission = bad_inode_permission !! 71 .follow_link = bad_follow_link, 175 .getattr = bad_inode_getattr, !! 72 .truncate = EIO_ERROR, 176 .setattr = bad_inode_setattr, !! 73 .permission = EIO_ERROR, 177 .listxattr = bad_inode_listxattr, !! 74 .getattr = EIO_ERROR, 178 .get_link = bad_inode_get_link, !! 75 .setattr = EIO_ERROR, 179 .get_inode_acl = bad_inode_get_acl, !! 76 .setxattr = EIO_ERROR, 180 .fiemap = bad_inode_fiemap, !! 77 .getxattr = EIO_ERROR, 181 .update_time = bad_inode_update_tim !! 78 .listxattr = EIO_ERROR, 182 .atomic_open = bad_inode_atomic_ope !! 79 .removexattr = EIO_ERROR, 183 .tmpfile = bad_inode_tmpfile, << 184 .set_acl = bad_inode_set_acl, << 185 }; 80 }; 186 81 187 82 188 /* 83 /* 189 * When a filesystem is unable to read an inod 84 * When a filesystem is unable to read an inode due to an I/O error in 190 * its read_inode() function, it can call make 85 * its read_inode() function, it can call make_bad_inode() to return a 191 * set of stubs which will return EIO errors a 86 * set of stubs which will return EIO errors as required. 192 * 87 * 193 * We only need to do limited initialisation: 88 * We only need to do limited initialisation: all other fields are 194 * preinitialised to zero automatically. 89 * preinitialised to zero automatically. 195 */ 90 */ 196 91 197 /** 92 /** 198 * make_bad_inode - mark an inode bad due 93 * make_bad_inode - mark an inode bad due to an I/O error 199 * @inode: Inode to mark bad 94 * @inode: Inode to mark bad 200 * 95 * 201 * When an inode cannot be read due to a 96 * When an inode cannot be read due to a media or remote network 202 * failure this function makes the inode 97 * failure this function makes the inode "bad" and causes I/O operations 203 * on it to fail from this point on. 98 * on it to fail from this point on. 204 */ 99 */ 205 100 206 void make_bad_inode(struct inode *inode) !! 101 void make_bad_inode(struct inode * inode) 207 { 102 { 208 remove_inode_hash(inode); 103 remove_inode_hash(inode); 209 104 210 inode->i_mode = S_IFREG; 105 inode->i_mode = S_IFREG; 211 simple_inode_init_ts(inode); !! 106 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 212 inode->i_op = &bad_inode_ops; 107 inode->i_op = &bad_inode_ops; 213 inode->i_opflags &= ~IOP_XATTR; << 214 inode->i_fop = &bad_file_ops; 108 inode->i_fop = &bad_file_ops; 215 } 109 } 216 EXPORT_SYMBOL(make_bad_inode); 110 EXPORT_SYMBOL(make_bad_inode); 217 111 218 /* 112 /* 219 * This tests whether an inode has been flagge 113 * This tests whether an inode has been flagged as bad. The test uses 220 * &bad_inode_ops to cover the case of invalid 114 * &bad_inode_ops to cover the case of invalidated inodes as well as 221 * those created by make_bad_inode() above. 115 * those created by make_bad_inode() above. 222 */ 116 */ 223 117 224 /** 118 /** 225 * is_bad_inode - is an inode errored 119 * is_bad_inode - is an inode errored 226 * @inode: inode to test 120 * @inode: inode to test 227 * 121 * 228 * Returns true if the inode in question 122 * Returns true if the inode in question has been marked as bad. 229 */ 123 */ 230 124 231 bool is_bad_inode(struct inode *inode) !! 125 int is_bad_inode(struct inode * inode) 232 { 126 { 233 return (inode->i_op == &bad_inode_ops) 127 return (inode->i_op == &bad_inode_ops); 234 } 128 } 235 129 236 EXPORT_SYMBOL(is_bad_inode); 130 EXPORT_SYMBOL(is_bad_inode); 237 << 238 /** << 239 * iget_failed - Mark an under-construction in << 240 * @inode: The inode to discard << 241 * << 242 * Mark an under-construction inode as dead an << 243 */ << 244 void iget_failed(struct inode *inode) << 245 { << 246 make_bad_inode(inode); << 247 unlock_new_inode(inode); << 248 iput(inode); << 249 } << 250 EXPORT_SYMBOL(iget_failed); << 251 131
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.