bad_inode.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
  87. size_t buffer_size)
  88. {
  89. return -EIO;
  90. }
  91. static const char *bad_inode_get_link(struct dentry *dentry,
  92. struct inode *inode,
  93. struct delayed_call *done)
  94. {
  95. return ERR_PTR(-EIO);
  96. }
  97. static struct posix_acl *bad_inode_get_acl(struct inode *inode, int type)
  98. {
  99. return ERR_PTR(-EIO);
  100. }
  101. static int bad_inode_fiemap(struct inode *inode,
  102. struct fiemap_extent_info *fieinfo, u64 start,
  103. u64 len)
  104. {
  105. return -EIO;
  106. }
  107. static int bad_inode_update_time(struct inode *inode, struct timespec *time,
  108. int flags)
  109. {
  110. return -EIO;
  111. }
  112. static int bad_inode_atomic_open(struct inode *inode, struct dentry *dentry,
  113. struct file *file, unsigned int open_flag,
  114. umode_t create_mode, int *opened)
  115. {
  116. return -EIO;
  117. }
  118. static int bad_inode_tmpfile(struct inode *inode, struct dentry *dentry,
  119. umode_t mode)
  120. {
  121. return -EIO;
  122. }
  123. static int bad_inode_set_acl(struct inode *inode, struct posix_acl *acl,
  124. int type)
  125. {
  126. return -EIO;
  127. }
  128. static const struct inode_operations bad_inode_ops =
  129. {
  130. .create = bad_inode_create,
  131. .lookup = bad_inode_lookup,
  132. .link = bad_inode_link,
  133. .unlink = bad_inode_unlink,
  134. .symlink = bad_inode_symlink,
  135. .mkdir = bad_inode_mkdir,
  136. .rmdir = bad_inode_rmdir,
  137. .mknod = bad_inode_mknod,
  138. .rename = bad_inode_rename2,
  139. .readlink = bad_inode_readlink,
  140. .permission = bad_inode_permission,
  141. .getattr = bad_inode_getattr,
  142. .setattr = bad_inode_setattr,
  143. .listxattr = bad_inode_listxattr,
  144. .get_link = bad_inode_get_link,
  145. .get_acl = bad_inode_get_acl,
  146. .fiemap = bad_inode_fiemap,
  147. .update_time = bad_inode_update_time,
  148. .atomic_open = bad_inode_atomic_open,
  149. .tmpfile = bad_inode_tmpfile,
  150. .set_acl = bad_inode_set_acl,
  151. };
  152. /*
  153. * When a filesystem is unable to read an inode due to an I/O error in
  154. * its read_inode() function, it can call make_bad_inode() to return a
  155. * set of stubs which will return EIO errors as required.
  156. *
  157. * We only need to do limited initialisation: all other fields are
  158. * preinitialised to zero automatically.
  159. */
  160. /**
  161. * make_bad_inode - mark an inode bad due to an I/O error
  162. * @inode: Inode to mark bad
  163. *
  164. * When an inode cannot be read due to a media or remote network
  165. * failure this function makes the inode "bad" and causes I/O operations
  166. * on it to fail from this point on.
  167. */
  168. void make_bad_inode(struct inode *inode)
  169. {
  170. remove_inode_hash(inode);
  171. inode->i_mode = S_IFREG;
  172. inode->i_atime = inode->i_mtime = inode->i_ctime =
  173. current_time(inode);
  174. inode->i_op = &bad_inode_ops;
  175. inode->i_opflags &= ~IOP_XATTR;
  176. inode->i_fop = &bad_file_ops;
  177. }
  178. EXPORT_SYMBOL(make_bad_inode);
  179. /*
  180. * This tests whether an inode has been flagged as bad. The test uses
  181. * &bad_inode_ops to cover the case of invalidated inodes as well as
  182. * those created by make_bad_inode() above.
  183. */
  184. /**
  185. * is_bad_inode - is an inode errored
  186. * @inode: inode to test
  187. *
  188. * Returns true if the inode in question has been marked as bad.
  189. */
  190. bool is_bad_inode(struct inode *inode)
  191. {
  192. return (inode->i_op == &bad_inode_ops);
  193. }
  194. EXPORT_SYMBOL(is_bad_inode);
  195. /**
  196. * iget_failed - Mark an under-construction inode as dead and release it
  197. * @inode: The inode to discard
  198. *
  199. * Mark an under-construction inode as dead and release it.
  200. */
  201. void iget_failed(struct inode *inode)
  202. {
  203. make_bad_inode(inode);
  204. unlock_new_inode(inode);
  205. iput(inode);
  206. }
  207. EXPORT_SYMBOL(iget_failed);