vfs.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 1995-1997 Olaf Kirch <[email protected]>
  4. */
  5. #ifndef LINUX_NFSD_VFS_H
  6. #define LINUX_NFSD_VFS_H
  7. #include <linux/fs.h>
  8. #include <linux/posix_acl.h>
  9. #include "nfsfh.h"
  10. #include "nfsd.h"
  11. /*
  12. * Flags for nfsd_permission
  13. */
  14. #define NFSD_MAY_NOP 0
  15. #define NFSD_MAY_EXEC 0x001 /* == MAY_EXEC */
  16. #define NFSD_MAY_WRITE 0x002 /* == MAY_WRITE */
  17. #define NFSD_MAY_READ 0x004 /* == MAY_READ */
  18. #define NFSD_MAY_SATTR 0x008
  19. #define NFSD_MAY_TRUNC 0x010
  20. #define NFSD_MAY_LOCK 0x020
  21. #define NFSD_MAY_MASK 0x03f
  22. /* extra hints to permission and open routines: */
  23. #define NFSD_MAY_OWNER_OVERRIDE 0x040
  24. #define NFSD_MAY_LOCAL_ACCESS 0x080 /* for device special files */
  25. #define NFSD_MAY_BYPASS_GSS_ON_ROOT 0x100
  26. #define NFSD_MAY_NOT_BREAK_LEASE 0x200
  27. #define NFSD_MAY_BYPASS_GSS 0x400
  28. #define NFSD_MAY_READ_IF_EXEC 0x800
  29. #define NFSD_MAY_64BIT_COOKIE 0x1000 /* 64 bit readdir cookies for >= NFSv3 */
  30. #define NFSD_MAY_CREATE (NFSD_MAY_EXEC|NFSD_MAY_WRITE)
  31. #define NFSD_MAY_REMOVE (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC)
  32. struct nfsd_file;
  33. /*
  34. * Callback function for readdir
  35. */
  36. typedef int (*nfsd_filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
  37. /* nfsd/vfs.c */
  38. struct nfsd_attrs {
  39. struct iattr *na_iattr; /* input */
  40. struct xdr_netobj *na_seclabel; /* input */
  41. struct posix_acl *na_pacl; /* input */
  42. struct posix_acl *na_dpacl; /* input */
  43. int na_labelerr; /* output */
  44. int na_aclerr; /* output */
  45. };
  46. static inline void nfsd_attrs_free(struct nfsd_attrs *attrs)
  47. {
  48. posix_acl_release(attrs->na_pacl);
  49. posix_acl_release(attrs->na_dpacl);
  50. }
  51. int nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
  52. struct svc_export **expp);
  53. __be32 nfsd_lookup(struct svc_rqst *, struct svc_fh *,
  54. const char *, unsigned int, struct svc_fh *);
  55. __be32 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *,
  56. const char *, unsigned int,
  57. struct svc_export **, struct dentry **);
  58. __be32 nfsd_setattr(struct svc_rqst *, struct svc_fh *,
  59. struct nfsd_attrs *, int, time64_t);
  60. int nfsd_mountpoint(struct dentry *, struct svc_export *);
  61. #ifdef CONFIG_NFSD_V4
  62. __be32 nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,
  63. struct file *, loff_t, loff_t, int);
  64. __be32 nfsd4_clone_file_range(struct svc_rqst *rqstp,
  65. struct nfsd_file *nf_src, u64 src_pos,
  66. struct nfsd_file *nf_dst, u64 dst_pos,
  67. u64 count, bool sync);
  68. #endif /* CONFIG_NFSD_V4 */
  69. __be32 nfsd_create_locked(struct svc_rqst *, struct svc_fh *,
  70. struct nfsd_attrs *attrs, int type, dev_t rdev,
  71. struct svc_fh *res);
  72. __be32 nfsd_create(struct svc_rqst *, struct svc_fh *,
  73. char *name, int len, struct nfsd_attrs *attrs,
  74. int type, dev_t rdev, struct svc_fh *res);
  75. __be32 nfsd_access(struct svc_rqst *, struct svc_fh *, u32 *, u32 *);
  76. __be32 nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
  77. struct svc_fh *resfhp, struct nfsd_attrs *iap);
  78. __be32 nfsd_commit(struct svc_rqst *rqst, struct svc_fh *fhp,
  79. struct nfsd_file *nf, u64 offset, u32 count,
  80. __be32 *verf);
  81. #ifdef CONFIG_NFSD_V4
  82. __be32 nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
  83. char *name, void **bufp, int *lenp);
  84. __be32 nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
  85. char **bufp, int *lenp);
  86. __be32 nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
  87. char *name);
  88. __be32 nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
  89. char *name, void *buf, u32 len, u32 flags);
  90. #endif
  91. int nfsd_open_break_lease(struct inode *, int);
  92. __be32 nfsd_open(struct svc_rqst *, struct svc_fh *, umode_t,
  93. int, struct file **);
  94. __be32 nfsd_open_verified(struct svc_rqst *, struct svc_fh *,
  95. int, struct file **);
  96. __be32 nfsd_splice_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
  97. struct file *file, loff_t offset,
  98. unsigned long *count,
  99. u32 *eof);
  100. __be32 nfsd_readv(struct svc_rqst *rqstp, struct svc_fh *fhp,
  101. struct file *file, loff_t offset,
  102. struct kvec *vec, int vlen,
  103. unsigned long *count,
  104. u32 *eof);
  105. __be32 nfsd_read(struct svc_rqst *, struct svc_fh *,
  106. loff_t, struct kvec *, int, unsigned long *,
  107. u32 *eof);
  108. __be32 nfsd_write(struct svc_rqst *, struct svc_fh *, loff_t,
  109. struct kvec *, int, unsigned long *,
  110. int stable, __be32 *verf);
  111. __be32 nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
  112. struct nfsd_file *nf, loff_t offset,
  113. struct kvec *vec, int vlen, unsigned long *cnt,
  114. int stable, __be32 *verf);
  115. __be32 nfsd_readlink(struct svc_rqst *, struct svc_fh *,
  116. char *, int *);
  117. __be32 nfsd_symlink(struct svc_rqst *, struct svc_fh *,
  118. char *name, int len, char *path,
  119. struct nfsd_attrs *attrs,
  120. struct svc_fh *res);
  121. __be32 nfsd_link(struct svc_rqst *, struct svc_fh *,
  122. char *, int, struct svc_fh *);
  123. ssize_t nfsd_copy_file_range(struct file *, u64,
  124. struct file *, u64, u64);
  125. __be32 nfsd_rename(struct svc_rqst *,
  126. struct svc_fh *, char *, int,
  127. struct svc_fh *, char *, int);
  128. __be32 nfsd_unlink(struct svc_rqst *, struct svc_fh *, int type,
  129. char *name, int len);
  130. __be32 nfsd_readdir(struct svc_rqst *, struct svc_fh *,
  131. loff_t *, struct readdir_cd *, nfsd_filldir_t);
  132. __be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *,
  133. struct kstatfs *, int access);
  134. __be32 nfsd_permission(struct svc_rqst *, struct svc_export *,
  135. struct dentry *, int);
  136. static inline int fh_want_write(struct svc_fh *fh)
  137. {
  138. int ret;
  139. if (fh->fh_want_write)
  140. return 0;
  141. ret = mnt_want_write(fh->fh_export->ex_path.mnt);
  142. if (!ret)
  143. fh->fh_want_write = true;
  144. return ret;
  145. }
  146. static inline void fh_drop_write(struct svc_fh *fh)
  147. {
  148. if (fh->fh_want_write) {
  149. fh->fh_want_write = false;
  150. mnt_drop_write(fh->fh_export->ex_path.mnt);
  151. }
  152. }
  153. static inline __be32 fh_getattr(const struct svc_fh *fh, struct kstat *stat)
  154. {
  155. struct path p = {.mnt = fh->fh_export->ex_path.mnt,
  156. .dentry = fh->fh_dentry};
  157. return nfserrno(vfs_getattr(&p, stat, STATX_BASIC_STATS,
  158. AT_STATX_SYNC_AS_STAT));
  159. }
  160. #endif /* LINUX_NFSD_VFS_H */