file.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/fs/sysv/file.c
  4. *
  5. * minix/file.c
  6. * Copyright (C) 1991, 1992 Linus Torvalds
  7. *
  8. * coh/file.c
  9. * Copyright (C) 1993 Pascal Haible, Bruno Haible
  10. *
  11. * sysv/file.c
  12. * Copyright (C) 1993 Bruno Haible
  13. *
  14. * SystemV/Coherent regular file handling primitives
  15. */
  16. #include "sysv.h"
  17. /*
  18. * We have mostly NULLs here: the current defaults are OK for
  19. * the coh filesystem.
  20. */
  21. const struct file_operations sysv_file_operations = {
  22. .llseek = generic_file_llseek,
  23. .read_iter = generic_file_read_iter,
  24. .write_iter = generic_file_write_iter,
  25. .mmap = generic_file_mmap,
  26. .fsync = generic_file_fsync,
  27. .splice_read = generic_file_splice_read,
  28. };
  29. static int sysv_setattr(struct dentry *dentry, struct iattr *attr)
  30. {
  31. struct inode *inode = d_inode(dentry);
  32. int error;
  33. error = setattr_prepare(dentry, attr);
  34. if (error)
  35. return error;
  36. if ((attr->ia_valid & ATTR_SIZE) &&
  37. attr->ia_size != i_size_read(inode)) {
  38. error = inode_newsize_ok(inode, attr->ia_size);
  39. if (error)
  40. return error;
  41. truncate_setsize(inode, attr->ia_size);
  42. sysv_truncate(inode);
  43. }
  44. setattr_copy(inode, attr);
  45. mark_inode_dirty(inode);
  46. return 0;
  47. }
  48. const struct inode_operations sysv_file_inode_operations = {
  49. .setattr = sysv_setattr,
  50. .getattr = sysv_getattr,
  51. };