nfsd.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. * linux/include/linux/nfsd/nfsd.h
  3. *
  4. * Hodge-podge collection of knfsd-related stuff.
  5. * I will sort this out later.
  6. *
  7. * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
  8. */
  9. #ifndef LINUX_NFSD_NFSD_H
  10. #define LINUX_NFSD_NFSD_H
  11. #include <linux/config.h>
  12. #include <linux/types.h>
  13. #include <linux/unistd.h>
  14. #include <linux/dirent.h>
  15. #include <linux/fs.h>
  16. #include <linux/mount.h>
  17. #include <linux/nfsd/debug.h>
  18. #include <linux/nfsd/nfsfh.h>
  19. #include <linux/nfsd/export.h>
  20. #include <linux/nfsd/auth.h>
  21. #include <linux/nfsd/stats.h>
  22. #include <linux/nfsd/interface.h>
  23. /*
  24. * nfsd version
  25. */
  26. #define NFSD_VERSION "0.5"
  27. #define NFSD_SUPPORTED_MINOR_VERSION 0
  28. #ifdef __KERNEL__
  29. /*
  30. * Special flags for nfsd_permission. These must be different from MAY_READ,
  31. * MAY_WRITE, and MAY_EXEC.
  32. */
  33. #define MAY_NOP 0
  34. #define MAY_SATTR 8
  35. #define MAY_TRUNC 16
  36. #define MAY_LOCK 32
  37. #define MAY_OWNER_OVERRIDE 64
  38. #define MAY_LOCAL_ACCESS 128 /* IRIX doing local access check on device special file*/
  39. #if (MAY_SATTR | MAY_TRUNC | MAY_LOCK | MAY_OWNER_OVERRIDE | MAY_LOCAL_ACCESS) & (MAY_READ | MAY_WRITE | MAY_EXEC)
  40. # error "please use a different value for MAY_SATTR or MAY_TRUNC or MAY_LOCK or MAY_LOCAL_ACCESS or MAY_OWNER_OVERRIDE."
  41. #endif
  42. #define MAY_CREATE (MAY_EXEC|MAY_WRITE)
  43. #define MAY_REMOVE (MAY_EXEC|MAY_WRITE|MAY_TRUNC)
  44. /*
  45. * Callback function for readdir
  46. */
  47. struct readdir_cd {
  48. int err; /* 0, nfserr, or nfserr_eof */
  49. };
  50. typedef int (*encode_dent_fn)(struct readdir_cd *, const char *,
  51. int, loff_t, ino_t, unsigned int);
  52. typedef int (*nfsd_dirop_t)(struct inode *, struct dentry *, int, int);
  53. extern struct svc_program nfsd_program;
  54. extern struct svc_version nfsd_version2, nfsd_version3,
  55. nfsd_version4;
  56. /*
  57. * Function prototypes.
  58. */
  59. int nfsd_svc(unsigned short port, int nrservs);
  60. int nfsd_dispatch(struct svc_rqst *rqstp, u32 *statp);
  61. /* nfsd/vfs.c */
  62. int fh_lock_parent(struct svc_fh *, struct dentry *);
  63. int nfsd_racache_init(int);
  64. void nfsd_racache_shutdown(void);
  65. int nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
  66. struct svc_export **expp);
  67. int nfsd_lookup(struct svc_rqst *, struct svc_fh *,
  68. const char *, int, struct svc_fh *);
  69. int nfsd_setattr(struct svc_rqst *, struct svc_fh *,
  70. struct iattr *, int, time_t);
  71. #ifdef CONFIG_NFSD_V4
  72. int nfsd4_set_nfs4_acl(struct svc_rqst *, struct svc_fh *,
  73. struct nfs4_acl *);
  74. int nfsd4_get_nfs4_acl(struct svc_rqst *, struct dentry *, struct nfs4_acl **);
  75. #endif /* CONFIG_NFSD_V4 */
  76. int nfsd_create(struct svc_rqst *, struct svc_fh *,
  77. char *name, int len, struct iattr *attrs,
  78. int type, dev_t rdev, struct svc_fh *res);
  79. #ifdef CONFIG_NFSD_V3
  80. int nfsd_access(struct svc_rqst *, struct svc_fh *, u32 *, u32 *);
  81. int nfsd_create_v3(struct svc_rqst *, struct svc_fh *,
  82. char *name, int len, struct iattr *attrs,
  83. struct svc_fh *res, int createmode,
  84. u32 *verifier, int *truncp);
  85. int nfsd_commit(struct svc_rqst *, struct svc_fh *,
  86. loff_t, unsigned long);
  87. #endif /* CONFIG_NFSD_V3 */
  88. int nfsd_open(struct svc_rqst *, struct svc_fh *, int,
  89. int, struct file **);
  90. void nfsd_close(struct file *);
  91. int nfsd_read(struct svc_rqst *, struct svc_fh *, struct file *,
  92. loff_t, struct kvec *, int, unsigned long *);
  93. int nfsd_write(struct svc_rqst *, struct svc_fh *,struct file *,
  94. loff_t, struct kvec *,int, unsigned long, int *);
  95. int nfsd_readlink(struct svc_rqst *, struct svc_fh *,
  96. char *, int *);
  97. int nfsd_symlink(struct svc_rqst *, struct svc_fh *,
  98. char *name, int len, char *path, int plen,
  99. struct svc_fh *res, struct iattr *);
  100. int nfsd_link(struct svc_rqst *, struct svc_fh *,
  101. char *, int, struct svc_fh *);
  102. int nfsd_rename(struct svc_rqst *,
  103. struct svc_fh *, char *, int,
  104. struct svc_fh *, char *, int);
  105. int nfsd_remove(struct svc_rqst *,
  106. struct svc_fh *, char *, int);
  107. int nfsd_unlink(struct svc_rqst *, struct svc_fh *, int type,
  108. char *name, int len);
  109. int nfsd_truncate(struct svc_rqst *, struct svc_fh *,
  110. unsigned long size);
  111. int nfsd_readdir(struct svc_rqst *, struct svc_fh *,
  112. loff_t *, struct readdir_cd *, encode_dent_fn);
  113. int nfsd_statfs(struct svc_rqst *, struct svc_fh *,
  114. struct kstatfs *);
  115. int nfsd_notify_change(struct inode *, struct iattr *);
  116. int nfsd_permission(struct svc_export *, struct dentry *, int);
  117. /*
  118. * NFSv4 State
  119. */
  120. #ifdef CONFIG_NFSD_V4
  121. int nfs4_state_init(void);
  122. void nfs4_state_shutdown(void);
  123. time_t nfs4_lease_time(void);
  124. void nfs4_reset_lease(time_t leasetime);
  125. #else
  126. static inline int nfs4_state_init(void){return 0;}
  127. static inline void nfs4_state_shutdown(void){}
  128. static inline time_t nfs4_lease_time(void){return 0;}
  129. static inline void nfs4_reset_lease(time_t leasetime){}
  130. #endif
  131. /*
  132. * lockd binding
  133. */
  134. void nfsd_lockd_init(void);
  135. void nfsd_lockd_shutdown(void);
  136. /*
  137. * These macros provide pre-xdr'ed values for faster operation.
  138. */
  139. #define nfs_ok __constant_htonl(NFS_OK)
  140. #define nfserr_perm __constant_htonl(NFSERR_PERM)
  141. #define nfserr_noent __constant_htonl(NFSERR_NOENT)
  142. #define nfserr_io __constant_htonl(NFSERR_IO)
  143. #define nfserr_nxio __constant_htonl(NFSERR_NXIO)
  144. #define nfserr_eagain __constant_htonl(NFSERR_EAGAIN)
  145. #define nfserr_acces __constant_htonl(NFSERR_ACCES)
  146. #define nfserr_exist __constant_htonl(NFSERR_EXIST)
  147. #define nfserr_xdev __constant_htonl(NFSERR_XDEV)
  148. #define nfserr_nodev __constant_htonl(NFSERR_NODEV)
  149. #define nfserr_notdir __constant_htonl(NFSERR_NOTDIR)
  150. #define nfserr_isdir __constant_htonl(NFSERR_ISDIR)
  151. #define nfserr_inval __constant_htonl(NFSERR_INVAL)
  152. #define nfserr_fbig __constant_htonl(NFSERR_FBIG)
  153. #define nfserr_nospc __constant_htonl(NFSERR_NOSPC)
  154. #define nfserr_rofs __constant_htonl(NFSERR_ROFS)
  155. #define nfserr_mlink __constant_htonl(NFSERR_MLINK)
  156. #define nfserr_opnotsupp __constant_htonl(NFSERR_OPNOTSUPP)
  157. #define nfserr_nametoolong __constant_htonl(NFSERR_NAMETOOLONG)
  158. #define nfserr_notempty __constant_htonl(NFSERR_NOTEMPTY)
  159. #define nfserr_dquot __constant_htonl(NFSERR_DQUOT)
  160. #define nfserr_stale __constant_htonl(NFSERR_STALE)
  161. #define nfserr_remote __constant_htonl(NFSERR_REMOTE)
  162. #define nfserr_wflush __constant_htonl(NFSERR_WFLUSH)
  163. #define nfserr_badhandle __constant_htonl(NFSERR_BADHANDLE)
  164. #define nfserr_notsync __constant_htonl(NFSERR_NOT_SYNC)
  165. #define nfserr_badcookie __constant_htonl(NFSERR_BAD_COOKIE)
  166. #define nfserr_notsupp __constant_htonl(NFSERR_NOTSUPP)
  167. #define nfserr_toosmall __constant_htonl(NFSERR_TOOSMALL)
  168. #define nfserr_serverfault __constant_htonl(NFSERR_SERVERFAULT)
  169. #define nfserr_badtype __constant_htonl(NFSERR_BADTYPE)
  170. #define nfserr_jukebox __constant_htonl(NFSERR_JUKEBOX)
  171. #define nfserr_denied __constant_htonl(NFSERR_DENIED)
  172. #define nfserr_deadlock __constant_htonl(NFSERR_DEADLOCK)
  173. #define nfserr_expired __constant_htonl(NFSERR_EXPIRED)
  174. #define nfserr_bad_cookie __constant_htonl(NFSERR_BAD_COOKIE)
  175. #define nfserr_same __constant_htonl(NFSERR_SAME)
  176. #define nfserr_clid_inuse __constant_htonl(NFSERR_CLID_INUSE)
  177. #define nfserr_stale_clientid __constant_htonl(NFSERR_STALE_CLIENTID)
  178. #define nfserr_resource __constant_htonl(NFSERR_RESOURCE)
  179. #define nfserr_nofilehandle __constant_htonl(NFSERR_NOFILEHANDLE)
  180. #define nfserr_minor_vers_mismatch __constant_htonl(NFSERR_MINOR_VERS_MISMATCH)
  181. #define nfserr_share_denied __constant_htonl(NFSERR_SHARE_DENIED)
  182. #define nfserr_stale_stateid __constant_htonl(NFSERR_STALE_STATEID)
  183. #define nfserr_old_stateid __constant_htonl(NFSERR_OLD_STATEID)
  184. #define nfserr_bad_stateid __constant_htonl(NFSERR_BAD_STATEID)
  185. #define nfserr_bad_seqid __constant_htonl(NFSERR_BAD_SEQID)
  186. #define nfserr_symlink __constant_htonl(NFSERR_SYMLINK)
  187. #define nfserr_not_same __constant_htonl(NFSERR_NOT_SAME)
  188. #define nfserr_restorefh __constant_htonl(NFSERR_RESTOREFH)
  189. #define nfserr_attrnotsupp __constant_htonl(NFSERR_ATTRNOTSUPP)
  190. #define nfserr_bad_xdr __constant_htonl(NFSERR_BAD_XDR)
  191. #define nfserr_openmode __constant_htonl(NFSERR_OPENMODE)
  192. #define nfserr_locks_held __constant_htonl(NFSERR_LOCKS_HELD)
  193. #define nfserr_op_illegal __constant_htonl(NFSERR_OP_ILLEGAL)
  194. #define nfserr_grace __constant_htonl(NFSERR_GRACE)
  195. #define nfserr_no_grace __constant_htonl(NFSERR_NO_GRACE)
  196. #define nfserr_reclaim_bad __constant_htonl(NFSERR_RECLAIM_BAD)
  197. #define nfserr_badname __constant_htonl(NFSERR_BADNAME)
  198. #define nfserr_cb_path_down __constant_htonl(NFSERR_CB_PATH_DOWN)
  199. /* error codes for internal use */
  200. /* if a request fails due to kmalloc failure, it gets dropped.
  201. * Client should resend eventually
  202. */
  203. #define nfserr_dropit __constant_htonl(30000)
  204. /* end-of-file indicator in readdir */
  205. #define nfserr_eof __constant_htonl(30001)
  206. /* Check for dir entries '.' and '..' */
  207. #define isdotent(n, l) (l < 3 && n[0] == '.' && (l == 1 || n[1] == '.'))
  208. /*
  209. * Time of server startup
  210. */
  211. extern struct timeval nfssvc_boot;
  212. static inline int is_fsid(struct svc_fh *fh, struct knfsd_fh *reffh)
  213. {
  214. if (fh->fh_export->ex_flags & NFSEXP_FSID) {
  215. struct vfsmount *mnt = fh->fh_export->ex_mnt;
  216. if (!old_valid_dev(mnt->mnt_sb->s_dev) ||
  217. (reffh->fh_version == 1 && reffh->fh_fsid_type == 1))
  218. return 1;
  219. }
  220. return 0;
  221. }
  222. #ifdef CONFIG_NFSD_V4
  223. /* before processing a COMPOUND operation, we have to check that there
  224. * is enough space in the buffer for XDR encode to succeed. otherwise,
  225. * we might process an operation with side effects, and be unable to
  226. * tell the client that the operation succeeded.
  227. *
  228. * COMPOUND_SLACK_SPACE - this is the minimum amount of buffer space
  229. * needed to encode an "ordinary" _successful_ operation. (GETATTR,
  230. * READ, READDIR, and READLINK have their own buffer checks.) if we
  231. * fall below this level, we fail the next operation with NFS4ERR_RESOURCE.
  232. *
  233. * COMPOUND_ERR_SLACK_SPACE - this is the minimum amount of buffer space
  234. * needed to encode an operation which has failed with NFS4ERR_RESOURCE.
  235. * care is taken to ensure that we never fall below this level for any
  236. * reason.
  237. */
  238. #define COMPOUND_SLACK_SPACE 140 /* OP_GETFH */
  239. #define COMPOUND_ERR_SLACK_SPACE 12 /* OP_SETATTR */
  240. #define NFSD_LEASE_TIME (nfs4_lease_time())
  241. #define NFSD_LAUNDROMAT_MINTIMEOUT 10 /* seconds */
  242. /*
  243. * The following attributes are currently not supported by the NFSv4 server:
  244. * ARCHIVE (deprecated anyway)
  245. * FS_LOCATIONS (will be supported eventually)
  246. * HIDDEN (unlikely to be supported any time soon)
  247. * MIMETYPE (unlikely to be supported any time soon)
  248. * QUOTA_* (will be supported in a forthcoming patch)
  249. * SYSTEM (unlikely to be supported any time soon)
  250. * TIME_BACKUP (unlikely to be supported any time soon)
  251. * TIME_CREATE (unlikely to be supported any time soon)
  252. */
  253. #define NFSD_SUPPORTED_ATTRS_WORD0 \
  254. (FATTR4_WORD0_SUPPORTED_ATTRS | FATTR4_WORD0_TYPE | FATTR4_WORD0_FH_EXPIRE_TYPE \
  255. | FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE | FATTR4_WORD0_LINK_SUPPORT \
  256. | FATTR4_WORD0_SYMLINK_SUPPORT | FATTR4_WORD0_NAMED_ATTR | FATTR4_WORD0_FSID \
  257. | FATTR4_WORD0_UNIQUE_HANDLES | FATTR4_WORD0_LEASE_TIME | FATTR4_WORD0_RDATTR_ERROR \
  258. | FATTR4_WORD0_ACLSUPPORT | FATTR4_WORD0_CANSETTIME | FATTR4_WORD0_CASE_INSENSITIVE \
  259. | FATTR4_WORD0_CASE_PRESERVING | FATTR4_WORD0_CHOWN_RESTRICTED \
  260. | FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FILEID | FATTR4_WORD0_FILES_AVAIL \
  261. | FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_HOMOGENEOUS \
  262. | FATTR4_WORD0_MAXFILESIZE | FATTR4_WORD0_MAXLINK | FATTR4_WORD0_MAXNAME \
  263. | FATTR4_WORD0_MAXREAD | FATTR4_WORD0_MAXWRITE | FATTR4_WORD0_ACL)
  264. #define NFSD_SUPPORTED_ATTRS_WORD1 \
  265. (FATTR4_WORD1_MODE | FATTR4_WORD1_NO_TRUNC | FATTR4_WORD1_NUMLINKS \
  266. | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP | FATTR4_WORD1_RAWDEV \
  267. | FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | FATTR4_WORD1_SPACE_TOTAL \
  268. | FATTR4_WORD1_SPACE_USED | FATTR4_WORD1_TIME_ACCESS | FATTR4_WORD1_TIME_ACCESS_SET \
  269. | FATTR4_WORD1_TIME_DELTA | FATTR4_WORD1_TIME_METADATA \
  270. | FATTR4_WORD1_TIME_MODIFY | FATTR4_WORD1_TIME_MODIFY_SET | FATTR4_WORD1_MOUNTED_ON_FILEID)
  271. /* These will return ERR_INVAL if specified in GETATTR or READDIR. */
  272. #define NFSD_WRITEONLY_ATTRS_WORD1 \
  273. (FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET)
  274. /* These are the only attrs allowed in CREATE/OPEN/SETATTR. */
  275. #define NFSD_WRITEABLE_ATTRS_WORD0 \
  276. (FATTR4_WORD0_SIZE | FATTR4_WORD0_ACL )
  277. #define NFSD_WRITEABLE_ATTRS_WORD1 \
  278. (FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP \
  279. | FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_METADATA | FATTR4_WORD1_TIME_MODIFY_SET)
  280. #endif /* CONFIG_NFSD_V4 */
  281. #endif /* __KERNEL__ */
  282. #endif /* LINUX_NFSD_NFSD_H */