bad_inode.c 7.9 KB

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