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/namei.h> 16#include <linux/poll.h> 17 18 19static loff_t bad_file_llseek(struct file *file, loff_t offset, int origin) 20{ 21 return -EIO; 22} 23 24static ssize_t bad_file_read(struct file *filp, char __user *buf, 25 size_t size, loff_t *ppos) 26{ 27 return -EIO; 28} 29 30static ssize_t bad_file_write(struct file *filp, const char __user *buf, 31 size_t siz, loff_t *ppos) 32{ 33 return -EIO; 34} 35 36static ssize_t bad_file_aio_read(struct kiocb *iocb, const struct iovec *iov, 37 unsigned long nr_segs, loff_t pos) 38{ 39 return -EIO; 40} 41 42static ssize_t bad_file_aio_write(struct kiocb *iocb, const struct iovec *iov, 43 unsigned long nr_segs, loff_t pos) 44{ 45 return -EIO; 46} 47 48static int bad_file_readdir(struct file *filp, void *dirent, filldir_t filldir) 49{ 50 return -EIO; 51} 52 53static unsigned int bad_file_poll(struct file *filp, poll_table *wait) 54{ 55 return POLLERR; 56} 57 58static int bad_file_ioctl (struct inode *inode, struct file *filp, 59 unsigned int cmd, unsigned long arg) 60{ 61 return -EIO; 62} 63 64static long bad_file_unlocked_ioctl(struct file *file, unsigned cmd, 65 unsigned long arg) 66{ 67 return -EIO; 68} 69 70static long bad_file_compat_ioctl(struct file *file, unsigned int cmd, 71 unsigned long arg) 72{ 73 return -EIO; 74} 75 76static int bad_file_mmap(struct file *file, struct vm_area_struct *vma) 77{ 78 return -EIO; 79} 80 81static int bad_file_open(struct inode *inode, struct file *filp) 82{ 83 return -EIO; 84} 85 86static int bad_file_flush(struct file *file, fl_owner_t id) 87{ 88 return -EIO; 89} 90 91static int bad_file_release(struct inode *inode, struct file *filp) 92{ 93 return -EIO; 94} 95 96static int bad_file_fsync(struct file *file, struct dentry *dentry, 97 int datasync) 98{ 99 return -EIO; 100} 101 102static int bad_file_aio_fsync(struct kiocb *iocb, int datasync) 103{ 104 return -EIO; 105} 106 107static int bad_file_fasync(int fd, struct file *filp, int on) 108{ 109 return -EIO; 110} 111 112static int bad_file_lock(struct file *file, int cmd, struct file_lock *fl) 113{ 114 return -EIO; 115} 116 117static ssize_t bad_file_sendfile(struct file *in_file, loff_t *ppos, 118 size_t count, read_actor_t actor, void *target) 119{ 120 return -EIO; 121} 122 123static ssize_t bad_file_sendpage(struct file *file, struct page *page, 124 int off, size_t len, loff_t *pos, int more) 125{ 126 return -EIO; 127} 128 129static unsigned long bad_file_get_unmapped_area(struct file *file, 130 unsigned long addr, unsigned long len, 131 unsigned long pgoff, unsigned long flags) 132{ 133 return -EIO; 134} 135 136static int bad_file_check_flags(int flags) 137{ 138 return -EIO; 139} 140 141static int bad_file_dir_notify(struct file *file, unsigned long arg) 142{ 143 return -EIO; 144} 145 146static int bad_file_flock(struct file *filp, int cmd, struct file_lock *fl) 147{ 148 return -EIO; 149} 150 151static ssize_t bad_file_splice_write(struct pipe_inode_info *pipe, 152 struct file *out, loff_t *ppos, size_t len, 153 unsigned int flags) 154{ 155 return -EIO; 156} 157 158static ssize_t bad_file_splice_read(struct file *in, loff_t *ppos, 159 struct pipe_inode_info *pipe, size_t len, 160 unsigned int flags) 161{ 162 return -EIO; 163} 164 165static const struct file_operations bad_file_ops = 166{ 167 .llseek = bad_file_llseek, 168 .read = bad_file_read, 169 .write = bad_file_write, 170 .aio_read = bad_file_aio_read, 171 .aio_write = bad_file_aio_write, 172 .readdir = bad_file_readdir, 173 .poll = bad_file_poll, 174 .ioctl = bad_file_ioctl, 175 .unlocked_ioctl = bad_file_unlocked_ioctl, 176 .compat_ioctl = bad_file_compat_ioctl, 177 .mmap = bad_file_mmap, 178 .open = bad_file_open, 179 .flush = bad_file_flush, 180 .release = bad_file_release, 181 .fsync = bad_file_fsync, 182 .aio_fsync = bad_file_aio_fsync, 183 .fasync = bad_file_fasync, 184 .lock = bad_file_lock, 185 .sendfile = bad_file_sendfile, 186 .sendpage = bad_file_sendpage, 187 .get_unmapped_area = bad_file_get_unmapped_area, 188 .check_flags = bad_file_check_flags, 189 .dir_notify = bad_file_dir_notify, 190 .flock = bad_file_flock, 191 .splice_write = bad_file_splice_write, 192 .splice_read = bad_file_splice_read, 193}; 194 195static int bad_inode_create (struct inode *dir, struct dentry *dentry, 196 int mode, struct nameidata *nd) 197{ 198 return -EIO; 199} 200 201static struct dentry *bad_inode_lookup(struct inode *dir, 202 struct dentry *dentry, struct nameidata *nd) 203{ 204 return ERR_PTR(-EIO); 205} 206 207static int bad_inode_link (struct dentry *old_dentry, struct inode *dir, 208 struct dentry *dentry) 209{ 210 return -EIO; 211} 212 213static int bad_inode_unlink(struct inode *dir, struct dentry *dentry) 214{ 215 return -EIO; 216} 217 218static int bad_inode_symlink (struct inode *dir, struct dentry *dentry, 219 const char *symname) 220{ 221 return -EIO; 222} 223 224static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry, 225 int mode) 226{ 227 return -EIO; 228} 229 230static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry) 231{ 232 return -EIO; 233} 234 235static int bad_inode_mknod (struct inode *dir, struct dentry *dentry, 236 int mode, dev_t rdev) 237{ 238 return -EIO; 239} 240 241static int bad_inode_rename (struct inode *old_dir, struct dentry *old_dentry, 242 struct inode *new_dir, struct dentry *new_dentry) 243{ 244 return -EIO; 245} 246 247static int bad_inode_readlink(struct dentry *dentry, char __user *buffer, 248 int buflen) 249{ 250 return -EIO; 251} 252 253static int bad_inode_permission(struct inode *inode, int mask, 254 struct nameidata *nd) 255{ 256 return -EIO; 257} 258 259static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, 260 struct kstat *stat) 261{ 262 return -EIO; 263} 264 265static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs) 266{ 267 return -EIO; 268} 269 270static int bad_inode_setxattr(struct dentry *dentry, const char *name, 271 const void *value, size_t size, int flags) 272{ 273 return -EIO; 274} 275 276static ssize_t bad_inode_getxattr(struct dentry *dentry, const char *name, 277 void *buffer, size_t size) 278{ 279 return -EIO; 280} 281 282static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer, 283 size_t buffer_size) 284{ 285 return -EIO; 286} 287 288static int bad_inode_removexattr(struct dentry *dentry, const char *name) 289{ 290 return -EIO; 291} 292 293static const struct inode_operations bad_inode_ops = 294{ 295 .create = bad_inode_create, 296 .lookup = bad_inode_lookup, 297 .link = bad_inode_link, 298 .unlink = bad_inode_unlink, 299 .symlink = bad_inode_symlink, 300 .mkdir = bad_inode_mkdir, 301 .rmdir = bad_inode_rmdir, 302 .mknod = bad_inode_mknod, 303 .rename = bad_inode_rename, 304 .readlink = bad_inode_readlink, 305 /* follow_link must be no-op, otherwise unmounting this inode 306 won't work */ 307 /* put_link returns void */ 308 /* truncate returns void */ 309 .permission = bad_inode_permission, 310 .getattr = bad_inode_getattr, 311 .setattr = bad_inode_setattr, 312 .setxattr = bad_inode_setxattr, 313 .getxattr = bad_inode_getxattr, 314 .listxattr = bad_inode_listxattr, 315 .removexattr = bad_inode_removexattr, 316 /* truncate_range returns void */ 317}; 318 319 320/* 321 * When a filesystem is unable to read an inode due to an I/O error in 322 * its read_inode() function, it can call make_bad_inode() to return a 323 * set of stubs which will return EIO errors as required. 324 * 325 * We only need to do limited initialisation: all other fields are 326 * preinitialised to zero automatically. 327 */ 328 329/** 330 * make_bad_inode - mark an inode bad due to an I/O error 331 * @inode: Inode to mark bad 332 * 333 * When an inode cannot be read due to a media or remote network 334 * failure this function makes the inode "bad" and causes I/O operations 335 * on it to fail from this point on. 336 */ 337 338void make_bad_inode(struct inode *inode) 339{ 340 remove_inode_hash(inode); 341 342 inode->i_mode = S_IFREG; 343 inode->i_atime = inode->i_mtime = inode->i_ctime = 344 current_fs_time(inode->i_sb); 345 inode->i_op = &bad_inode_ops; 346 inode->i_fop = &bad_file_ops; 347} 348EXPORT_SYMBOL(make_bad_inode); 349 350/* 351 * This tests whether an inode has been flagged as bad. The test uses 352 * &bad_inode_ops to cover the case of invalidated inodes as well as 353 * those created by make_bad_inode() above. 354 */ 355 356/** 357 * is_bad_inode - is an inode errored 358 * @inode: inode to test 359 * 360 * Returns true if the inode in question has been marked as bad. 361 */ 362 363int is_bad_inode(struct inode *inode) 364{ 365 return (inode->i_op == &bad_inode_ops); 366} 367 368EXPORT_SYMBOL(is_bad_inode); 369