file.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "ext2.h"
  23. #include "xattr.h"
  24. #include "acl.h"
  25. /*
  26. * Called when filp is released. This happens when all file descriptors
  27. * for a single struct file are closed. Note that different open() calls
  28. * for the same file yield different struct file structures.
  29. */
  30. static int ext2_release_file (struct inode * inode, struct file * filp)
  31. {
  32. if (filp->f_mode & FMODE_WRITE) {
  33. mutex_lock(&EXT2_I(inode)->truncate_mutex);
  34. ext2_discard_reservation(inode);
  35. mutex_unlock(&EXT2_I(inode)->truncate_mutex);
  36. }
  37. return 0;
  38. }
  39. int ext2_fsync(struct file *file, struct dentry *dentry, int datasync)
  40. {
  41. int ret;
  42. struct super_block *sb = dentry->d_inode->i_sb;
  43. struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping;
  44. ret = simple_fsync(file, dentry, datasync);
  45. if (ret == -EIO || test_and_clear_bit(AS_EIO, &mapping->flags)) {
  46. /* We don't really know where the IO error happened... */
  47. ext2_error(sb, __func__,
  48. "detected IO error when writing metadata buffers");
  49. ret = -EIO;
  50. }
  51. return ret;
  52. }
  53. /*
  54. * We have mostly NULL's here: the current defaults are ok for
  55. * the ext2 filesystem.
  56. */
  57. const struct file_operations ext2_file_operations = {
  58. .llseek = generic_file_llseek,
  59. .read = do_sync_read,
  60. .write = do_sync_write,
  61. .aio_read = generic_file_aio_read,
  62. .aio_write = generic_file_aio_write,
  63. .unlocked_ioctl = ext2_ioctl,
  64. #ifdef CONFIG_COMPAT
  65. .compat_ioctl = ext2_compat_ioctl,
  66. #endif
  67. .mmap = generic_file_mmap,
  68. .open = generic_file_open,
  69. .release = ext2_release_file,
  70. .fsync = ext2_fsync,
  71. .splice_read = generic_file_splice_read,
  72. .splice_write = generic_file_splice_write,
  73. };
  74. #ifdef CONFIG_EXT2_FS_XIP
  75. const struct file_operations ext2_xip_file_operations = {
  76. .llseek = generic_file_llseek,
  77. .read = xip_file_read,
  78. .write = xip_file_write,
  79. .unlocked_ioctl = ext2_ioctl,
  80. #ifdef CONFIG_COMPAT
  81. .compat_ioctl = ext2_compat_ioctl,
  82. #endif
  83. .mmap = xip_file_mmap,
  84. .open = generic_file_open,
  85. .release = ext2_release_file,
  86. .fsync = ext2_fsync,
  87. };
  88. #endif
  89. const struct inode_operations ext2_file_inode_operations = {
  90. .truncate = ext2_truncate,
  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. .check_acl = ext2_check_acl,
  99. .fiemap = ext2_fiemap,
  100. };