bad_inode.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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/export.h>
  12. #include <linux/stat.h>
  13. #include <linux/time.h>
  14. #include <linux/namei.h>
  15. #include <linux/poll.h>
  16. static int bad_file_open(struct inode *inode, struct file *filp)
  17. {
  18. return -EIO;
  19. }
  20. static const struct file_operations bad_file_ops =
  21. {
  22. .open = bad_file_open,
  23. };
  24. static int bad_inode_create (struct inode *dir, struct dentry *dentry,
  25. umode_t mode, bool excl)
  26. {
  27. return -EIO;
  28. }
  29. static struct dentry *bad_inode_lookup(struct inode *dir,
  30. struct dentry *dentry, unsigned int flags)
  31. {
  32. return ERR_PTR(-EIO);
  33. }
  34. static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
  35. struct dentry *dentry)
  36. {
  37. return -EIO;
  38. }
  39. static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
  40. {
  41. return -EIO;
  42. }
  43. static int bad_inode_symlink (struct inode *dir, struct dentry *dentry,
  44. const char *symname)
  45. {
  46. return -EIO;
  47. }
  48. static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry,
  49. umode_t mode)
  50. {
  51. return -EIO;
  52. }
  53. static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
  54. {
  55. return -EIO;
  56. }
  57. static int bad_inode_mknod (struct inode *dir, struct dentry *dentry,
  58. umode_t mode, dev_t rdev)
  59. {
  60. return -EIO;
  61. }
  62. static int bad_inode_rename2(struct inode *old_dir, struct dentry *old_dentry,
  63. struct inode *new_dir, struct dentry *new_dentry,
  64. unsigned int flags)
  65. {
  66. return -EIO;
  67. }
  68. static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
  69. int buflen)
  70. {
  71. return -EIO;
  72. }
  73. static int bad_inode_permission(struct inode *inode, int mask)
  74. {
  75. return -EIO;
  76. }
  77. static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
  78. struct kstat *stat)
  79. {
  80. return -EIO;
  81. }
  82. static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
  83. {
  84. return -EIO;
  85. }
  86. static int bad_inode_setxattr(struct dentry *dentry, const char *name,
  87. const void *value, size_t size, int flags)
  88. {
  89. return -EIO;
  90. }
  91. static ssize_t bad_inode_getxattr(struct dentry *dentry, const char *name,
  92. void *buffer, size_t size)
  93. {
  94. return -EIO;
  95. }
  96. static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
  97. size_t buffer_size)
  98. {
  99. return -EIO;
  100. }
  101. static int bad_inode_removexattr(struct dentry *dentry, const char *name)
  102. {
  103. return -EIO;
  104. }
  105. static const struct inode_operations bad_inode_ops =
  106. {
  107. .create = bad_inode_create,
  108. .lookup = bad_inode_lookup,
  109. .link = bad_inode_link,
  110. .unlink = bad_inode_unlink,
  111. .symlink = bad_inode_symlink,
  112. .mkdir = bad_inode_mkdir,
  113. .rmdir = bad_inode_rmdir,
  114. .mknod = bad_inode_mknod,
  115. .rename2 = bad_inode_rename2,
  116. .readlink = bad_inode_readlink,
  117. /* follow_link must be no-op, otherwise unmounting this inode
  118. won't work */
  119. /* put_link returns void */
  120. /* truncate returns void */
  121. .permission = bad_inode_permission,
  122. .getattr = bad_inode_getattr,
  123. .setattr = bad_inode_setattr,
  124. .setxattr = bad_inode_setxattr,
  125. .getxattr = bad_inode_getxattr,
  126. .listxattr = bad_inode_listxattr,
  127. .removexattr = bad_inode_removexattr,
  128. };
  129. /*
  130. * When a filesystem is unable to read an inode due to an I/O error in
  131. * its read_inode() function, it can call make_bad_inode() to return a
  132. * set of stubs which will return EIO errors as required.
  133. *
  134. * We only need to do limited initialisation: all other fields are
  135. * preinitialised to zero automatically.
  136. */
  137. /**
  138. * make_bad_inode - mark an inode bad due to an I/O error
  139. * @inode: Inode to mark bad
  140. *
  141. * When an inode cannot be read due to a media or remote network
  142. * failure this function makes the inode "bad" and causes I/O operations
  143. * on it to fail from this point on.
  144. */
  145. void make_bad_inode(struct inode *inode)
  146. {
  147. remove_inode_hash(inode);
  148. inode->i_mode = S_IFREG;
  149. inode->i_atime = inode->i_mtime = inode->i_ctime =
  150. current_fs_time(inode->i_sb);
  151. inode->i_op = &bad_inode_ops;
  152. inode->i_fop = &bad_file_ops;
  153. }
  154. EXPORT_SYMBOL(make_bad_inode);
  155. /*
  156. * This tests whether an inode has been flagged as bad. The test uses
  157. * &bad_inode_ops to cover the case of invalidated inodes as well as
  158. * those created by make_bad_inode() above.
  159. */
  160. /**
  161. * is_bad_inode - is an inode errored
  162. * @inode: inode to test
  163. *
  164. * Returns true if the inode in question has been marked as bad.
  165. */
  166. int is_bad_inode(struct inode *inode)
  167. {
  168. return (inode->i_op == &bad_inode_ops);
  169. }
  170. EXPORT_SYMBOL(is_bad_inode);
  171. /**
  172. * iget_failed - Mark an under-construction inode as dead and release it
  173. * @inode: The inode to discard
  174. *
  175. * Mark an under-construction inode as dead and release it.
  176. */
  177. void iget_failed(struct inode *inode)
  178. {
  179. make_bad_inode(inode);
  180. unlock_new_inode(inode);
  181. iput(inode);
  182. }
  183. EXPORT_SYMBOL(iget_failed);