bad_inode.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #include <linux/fs.h>
  11. #include <linux/module.h>
  12. #include <linux/stat.h>
  13. #include <linux/time.h>
  14. #include <linux/smp_lock.h>
  15. #include <linux/namei.h>
  16. static int return_EIO(void)
  17. {
  18. return -EIO;
  19. }
  20. #define EIO_ERROR ((void *) (return_EIO))
  21. static const struct file_operations bad_file_ops =
  22. {
  23. .llseek = EIO_ERROR,
  24. .aio_read = EIO_ERROR,
  25. .read = EIO_ERROR,
  26. .write = EIO_ERROR,
  27. .aio_write = EIO_ERROR,
  28. .readdir = EIO_ERROR,
  29. .poll = EIO_ERROR,
  30. .ioctl = EIO_ERROR,
  31. .mmap = EIO_ERROR,
  32. .open = EIO_ERROR,
  33. .flush = EIO_ERROR,
  34. .release = EIO_ERROR,
  35. .fsync = EIO_ERROR,
  36. .aio_fsync = EIO_ERROR,
  37. .fasync = EIO_ERROR,
  38. .lock = EIO_ERROR,
  39. .readv = EIO_ERROR,
  40. .writev = EIO_ERROR,
  41. .sendfile = EIO_ERROR,
  42. .sendpage = EIO_ERROR,
  43. .get_unmapped_area = EIO_ERROR,
  44. };
  45. static struct inode_operations bad_inode_ops =
  46. {
  47. .create = EIO_ERROR,
  48. .lookup = EIO_ERROR,
  49. .link = EIO_ERROR,
  50. .unlink = EIO_ERROR,
  51. .symlink = EIO_ERROR,
  52. .mkdir = EIO_ERROR,
  53. .rmdir = EIO_ERROR,
  54. .mknod = EIO_ERROR,
  55. .rename = EIO_ERROR,
  56. .readlink = EIO_ERROR,
  57. /* follow_link must be no-op, otherwise unmounting this inode
  58. won't work */
  59. .truncate = EIO_ERROR,
  60. .permission = EIO_ERROR,
  61. .getattr = EIO_ERROR,
  62. .setattr = EIO_ERROR,
  63. .setxattr = EIO_ERROR,
  64. .getxattr = EIO_ERROR,
  65. .listxattr = EIO_ERROR,
  66. .removexattr = EIO_ERROR,
  67. };
  68. /*
  69. * When a filesystem is unable to read an inode due to an I/O error in
  70. * its read_inode() function, it can call make_bad_inode() to return a
  71. * set of stubs which will return EIO errors as required.
  72. *
  73. * We only need to do limited initialisation: all other fields are
  74. * preinitialised to zero automatically.
  75. */
  76. /**
  77. * make_bad_inode - mark an inode bad due to an I/O error
  78. * @inode: Inode to mark bad
  79. *
  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.
  83. */
  84. void make_bad_inode(struct inode * inode)
  85. {
  86. remove_inode_hash(inode);
  87. inode->i_mode = S_IFREG;
  88. inode->i_atime = inode->i_mtime = inode->i_ctime =
  89. current_fs_time(inode->i_sb);
  90. inode->i_op = &bad_inode_ops;
  91. inode->i_fop = &bad_file_ops;
  92. }
  93. EXPORT_SYMBOL(make_bad_inode);
  94. /*
  95. * This tests whether an inode has been flagged as bad. The test uses
  96. * &bad_inode_ops to cover the case of invalidated inodes as well as
  97. * those created by make_bad_inode() above.
  98. */
  99. /**
  100. * is_bad_inode - is an inode errored
  101. * @inode: inode to test
  102. *
  103. * Returns true if the inode in question has been marked as bad.
  104. */
  105. int is_bad_inode(struct inode * inode)
  106. {
  107. return (inode->i_op == &bad_inode_ops);
  108. }
  109. EXPORT_SYMBOL(is_bad_inode);