file.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * linux/fs/ext2/file.c
  3. *
  4. * Copyright (C) 1992, 1993, 1994, 1995
  5. * Remy Card (card@masi.ibp.fr)
  6. * Laboratoire MASI - Institut Blaise Pascal
  7. * Universite Pierre et Marie Curie (Paris VI)
  8. *
  9. * from
  10. *
  11. * linux/fs/minix/file.c
  12. *
  13. * Copyright (C) 1991, 1992 Linus Torvalds
  14. *
  15. * ext2 fs regular file handling primitives
  16. *
  17. * 64-bit file support on 64-bit platforms by Jakub Jelinek
  18. * (jj@sunsite.ms.mff.cuni.cz)
  19. */
  20. #include <linux/time.h>
  21. #include <linux/pagemap.h>
  22. #include <linux/quotaops.h>
  23. #include "ext2.h"
  24. #include "xattr.h"
  25. #include "acl.h"
  26. /*
  27. * Called when filp is released. This happens when all file descriptors
  28. * for a single struct file are closed. Note that different open() calls
  29. * for the same file yield different struct file structures.
  30. */
  31. static int ext2_release_file (struct inode * inode, struct file * filp)
  32. {
  33. if (filp->f_mode & FMODE_WRITE) {
  34. mutex_lock(&EXT2_I(inode)->truncate_mutex);
  35. ext2_discard_reservation(inode);
  36. mutex_unlock(&EXT2_I(inode)->truncate_mutex);
  37. }
  38. return 0;
  39. }
  40. int ext2_fsync(struct file *file, loff_t start, loff_t end, int datasync)
  41. {
  42. int ret;
  43. struct super_block *sb = file->f_mapping->host->i_sb;
  44. struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping;
  45. ret = generic_file_fsync(file, start, end, datasync);
  46. if (ret == -EIO || test_and_clear_bit(AS_EIO, &mapping->flags)) {
  47. /* We don't really know where the IO error happened... */
  48. ext2_error(sb, __func__,
  49. "detected IO error when writing metadata buffers");
  50. ret = -EIO;
  51. }
  52. return ret;
  53. }
  54. /*
  55. * We have mostly NULL's here: the current defaults are ok for
  56. * the ext2 filesystem.
  57. */
  58. const struct file_operations ext2_file_operations = {
  59. .llseek = generic_file_llseek,
  60. .read = do_sync_read,
  61. .write = do_sync_write,
  62. .aio_read = generic_file_aio_read,
  63. .aio_write = generic_file_aio_write,
  64. .unlocked_ioctl = ext2_ioctl,
  65. #ifdef CONFIG_COMPAT
  66. .compat_ioctl = ext2_compat_ioctl,
  67. #endif
  68. .mmap = generic_file_mmap,
  69. .open = dquot_file_open,
  70. .release = ext2_release_file,
  71. .fsync = ext2_fsync,
  72. .splice_read = generic_file_splice_read,
  73. .splice_write = generic_file_splice_write,
  74. };
  75. #ifdef CONFIG_EXT2_FS_XIP
  76. const struct file_operations ext2_xip_file_operations = {
  77. .llseek = generic_file_llseek,
  78. .read = xip_file_read,
  79. .write = xip_file_write,
  80. .unlocked_ioctl = ext2_ioctl,
  81. #ifdef CONFIG_COMPAT
  82. .compat_ioctl = ext2_compat_ioctl,
  83. #endif
  84. .mmap = xip_file_mmap,
  85. .open = dquot_file_open,
  86. .release = ext2_release_file,
  87. .fsync = ext2_fsync,
  88. };
  89. #endif
  90. const struct inode_operations ext2_file_inode_operations = {
  91. #ifdef CONFIG_EXT2_FS_XATTR
  92. .setxattr = generic_setxattr,
  93. .getxattr = generic_getxattr,
  94. .listxattr = ext2_listxattr,
  95. .removexattr = generic_removexattr,
  96. #endif
  97. .setattr = ext2_setattr,
  98. .get_acl = ext2_get_acl,
  99. .fiemap = ext2_fiemap,
  100. };