nfsproto.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /* $OpenBSD: nfsproto.h,v 1.10 2009/07/08 14:39:31 thib Exp $ */
  2. /* $NetBSD: nfsproto.h,v 1.1 1996/02/18 11:54:06 fvdl Exp $ */
  3. /*
  4. * Copyright (c) 1989, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * This code is derived from software contributed to Berkeley by
  8. * Rick Macklem at The University of Guelph.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the University nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * @(#)nfsproto.h 8.2 (Berkeley) 3/30/95
  35. */
  36. #ifndef _NFS_NFSPROTO_H_
  37. #define _NFS_NFSPROTO_H_
  38. /*
  39. * Constants as defined in the Sun NFS Version 2 and 3 specs.
  40. * "NFS: Network File System Protocol Specification" RFC1094
  41. * and in the "NFS: Network File System Version 3 Protocol
  42. * Specification"
  43. */
  44. #define NFS_PORT 2049
  45. #define NFS_PROG 100003
  46. #define NFS_VER2 2
  47. #define NFS_VER3 3
  48. #define NFS_VER4 4
  49. #define NFS_V2MAXDATA 8192
  50. #define NFS_MAXDGRAMDATA 32768
  51. #define NFS_MAXDATA MAXBSIZE
  52. #define NFS_MAXPATHLEN 1024
  53. #define NFS_MAXNAMLEN 255
  54. #define NFS_MAXPKTHDR 404
  55. #define NFS_MAXPACKET (NFS_MAXPKTHDR + NFS_MAXDATA)
  56. #define NFS_MINPACKET 20
  57. #define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */
  58. /* Stat numbers for rpc returns (version 2 and 3) */
  59. #define NFS_OK 0
  60. #define NFSERR_PERM 1
  61. #define NFSERR_NOENT 2
  62. #define NFSERR_IO 5
  63. #define NFSERR_NXIO 6
  64. #define NFSERR_ACCES 13
  65. #define NFSERR_EXIST 17
  66. #define NFSERR_XDEV 18 /* Version 3 only */
  67. #define NFSERR_NODEV 19
  68. #define NFSERR_NOTDIR 20
  69. #define NFSERR_ISDIR 21
  70. #define NFSERR_INVAL 22 /* Version 3 only */
  71. #define NFSERR_FBIG 27
  72. #define NFSERR_NOSPC 28
  73. #define NFSERR_ROFS 30
  74. #define NFSERR_MLINK 31 /* Version 3 only */
  75. #define NFSERR_NAMETOL 63
  76. #define NFSERR_NOTEMPTY 66
  77. #define NFSERR_DQUOT 69
  78. #define NFSERR_STALE 70
  79. #define NFSERR_REMOTE 71 /* Version 3 only */
  80. #define NFSERR_WFLUSH 99 /* Version 2 only */
  81. #define NFSERR_BADHANDLE 10001 /* The rest Version 3 only */
  82. #define NFSERR_NOT_SYNC 10002
  83. #define NFSERR_BAD_COOKIE 10003
  84. #define NFSERR_NOTSUPP 10004
  85. #define NFSERR_TOOSMALL 10005
  86. #define NFSERR_SERVERFAULT 10006
  87. #define NFSERR_BADTYPE 10007
  88. #define NFSERR_JUKEBOX 10008
  89. #define NFSERR_TRYLATER NFSERR_JUKEBOX
  90. #define NFSERR_STALEWRITEVERF 30001 /* Fake return for nfs_commit() */
  91. #define NFSERR_RETVOID 0x20000000 /* Return void, not error */
  92. #define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */
  93. #define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */
  94. /* Sizes in bytes of various nfs rpc components */
  95. #define NFSX_UNSIGNED 4
  96. /* specific to NFS Version 2 */
  97. #define NFSX_V2FH 32
  98. #define NFSX_V2FATTR 68
  99. #define NFSX_V2SATTR 32
  100. #define NFSX_V2COOKIE 4
  101. #define NFSX_V2STATFS 20
  102. /* specific to NFS Version 3 */
  103. #define NFSX_V3FH (sizeof (fhandle_t)) /* size this server uses */
  104. #define NFSX_V3FHMAX 64 /* max. allowed by protocol */
  105. #define NFSX_V3FATTR 84
  106. #define NFSX_V3SATTR 60 /* max. all fields filled in */
  107. #define NFSX_V3SRVSATTR (sizeof (struct nfsv3_sattr))
  108. #define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED)
  109. #define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED)
  110. #define NFSX_V3COOKIEVERF 8
  111. #define NFSX_V3WRITEVERF 8
  112. #define NFSX_V3CREATEVERF 8
  113. #define NFSX_V3STATFS 52
  114. #define NFSX_V3FSINFO 48
  115. #define NFSX_V3PATHCONF 24
  116. /* variants for both versions */
  117. #define NFSX_FH(v3) ((v3) ? (NFSX_V3FHMAX + NFSX_UNSIGNED) : \
  118. NFSX_V2FH)
  119. #define NFSX_SRVFH(v3) ((v3) ? NFSX_V3FH : NFSX_V2FH)
  120. #define NFSX_FATTR(v3) ((v3) ? NFSX_V3FATTR : NFSX_V2FATTR)
  121. #define NFSX_PREOPATTR(v3) ((v3) ? (7 * NFSX_UNSIGNED) : 0)
  122. #define NFSX_POSTOPATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : 0)
  123. #define NFSX_POSTOPORFATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : \
  124. NFSX_V2FATTR)
  125. #define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0)
  126. #define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR)
  127. #define NFSX_SATTR(v3) ((v3) ? NFSX_V3SATTR : NFSX_V2SATTR)
  128. #define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0)
  129. #define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0)
  130. #define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \
  131. (2 * NFSX_UNSIGNED))
  132. #define NFSX_STATFS(v3) ((v3) ? NFSX_V3STATFS : NFSX_V2STATFS)
  133. /* nfs rpc procedure numbers (before version mapping) */
  134. #define NFSPROC_NULL 0
  135. #define NFSPROC_GETATTR 1
  136. #define NFSPROC_SETATTR 2
  137. #define NFSPROC_LOOKUP 3
  138. #define NFSPROC_ACCESS 4
  139. #define NFSPROC_READLINK 5
  140. #define NFSPROC_READ 6
  141. #define NFSPROC_WRITE 7
  142. #define NFSPROC_CREATE 8
  143. #define NFSPROC_MKDIR 9
  144. #define NFSPROC_SYMLINK 10
  145. #define NFSPROC_MKNOD 11
  146. #define NFSPROC_REMOVE 12
  147. #define NFSPROC_RMDIR 13
  148. #define NFSPROC_RENAME 14
  149. #define NFSPROC_LINK 15
  150. #define NFSPROC_READDIR 16
  151. #define NFSPROC_READDIRPLUS 17
  152. #define NFSPROC_FSSTAT 18
  153. #define NFSPROC_FSINFO 19
  154. #define NFSPROC_PATHCONF 20
  155. #define NFSPROC_COMMIT 21
  156. #define NFSPROC_NOOP 22
  157. #define NFS_NPROCS 23
  158. /* Actual Version 2 procedure numbers */
  159. #define NFSV2PROC_NULL 0
  160. #define NFSV2PROC_GETATTR 1
  161. #define NFSV2PROC_SETATTR 2
  162. #define NFSV2PROC_NOOP 3
  163. #define NFSV2PROC_ROOT NFSV2PROC_NOOP /* Obsolete */
  164. #define NFSV2PROC_LOOKUP 4
  165. #define NFSV2PROC_READLINK 5
  166. #define NFSV2PROC_READ 6
  167. #define NFSV2PROC_WRITECACHE NFSV2PROC_NOOP /* Obsolete */
  168. #define NFSV2PROC_WRITE 8
  169. #define NFSV2PROC_CREATE 9
  170. #define NFSV2PROC_REMOVE 10
  171. #define NFSV2PROC_RENAME 11
  172. #define NFSV2PROC_LINK 12
  173. #define NFSV2PROC_SYMLINK 13
  174. #define NFSV2PROC_MKDIR 14
  175. #define NFSV2PROC_RMDIR 15
  176. #define NFSV2PROC_READDIR 16
  177. #define NFSV2PROC_STATFS 17
  178. /*
  179. * Constants used by the Version 3 protocol for various RPCs
  180. */
  181. #define NFSV3SATTRTIME_DONTCHANGE 0
  182. #define NFSV3SATTRTIME_TOSERVER 1
  183. #define NFSV3SATTRTIME_TOCLIENT 2
  184. #define NFSV3ACCESS_READ 0x01
  185. #define NFSV3ACCESS_LOOKUP 0x02
  186. #define NFSV3ACCESS_MODIFY 0x04
  187. #define NFSV3ACCESS_EXTEND 0x08
  188. #define NFSV3ACCESS_DELETE 0x10
  189. #define NFSV3ACCESS_EXECUTE 0x20
  190. #define NFSV3WRITE_UNSTABLE 0
  191. #define NFSV3WRITE_DATASYNC 1
  192. #define NFSV3WRITE_FILESYNC 2
  193. #define NFSV3CREATE_UNCHECKED 0
  194. #define NFSV3CREATE_GUARDED 1
  195. #define NFSV3CREATE_EXCLUSIVE 2
  196. #define NFSV3FSINFO_LINK 0x01
  197. #define NFSV3FSINFO_SYMLINK 0x02
  198. #define NFSV3FSINFO_HOMOGENEOUS 0x08
  199. #define NFSV3FSINFO_CANSETTIME 0x10
  200. /* Conversion macros */
  201. #define vtonfsv2_mode(t,m) \
  202. txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \
  203. MAKEIMODE((t), (m)))
  204. #define vtonfsv3_mode(m) txdr_unsigned((m) & 07777)
  205. #define nfstov_mode(a) (fxdr_unsigned(u_int16_t, (a))&07777)
  206. #define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((int32_t)(a))])
  207. #define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((int32_t)(a))])
  208. #define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_int32_t,(a))&0x7]
  209. #define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_int32_t,(a))&0x7]
  210. /* File types */
  211. typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5,
  212. NFSOCK=6, NFFIFO=7 } nfstype;
  213. /* Structs for common parts of the rpc's */
  214. /*
  215. * File Handle (32 bytes for version 2), variable up to 64 for version 3.
  216. */
  217. #ifndef NFS_MAXFHSIZE
  218. #define NFS_MAXFHSIZE 64
  219. #endif
  220. union nfsfh {
  221. fhandle_t fh_generic;
  222. u_char fh_bytes[NFS_MAXFHSIZE];
  223. };
  224. typedef union nfsfh nfsfh_t;
  225. struct nfsv2_time {
  226. u_int32_t nfsv2_sec;
  227. u_int32_t nfsv2_usec;
  228. };
  229. typedef struct nfsv2_time nfstime2;
  230. struct nfsv3_time {
  231. u_int32_t nfsv3_sec;
  232. u_int32_t nfsv3_nsec;
  233. };
  234. typedef struct nfsv3_time nfstime3;
  235. /*
  236. * Quads are defined as arrays of 2 longs to ensure dense packing for the
  237. * protocol and to facilitate xdr conversion.
  238. */
  239. struct nfs_uquad {
  240. u_int32_t nfsuquad[2];
  241. };
  242. typedef struct nfs_uquad nfsuint64;
  243. /*
  244. * NFS Version 3 special file number.
  245. */
  246. struct nfsv3_spec {
  247. u_int32_t specdata1;
  248. u_int32_t specdata2;
  249. };
  250. typedef struct nfsv3_spec nfsv3spec;
  251. /*
  252. * File attributes and setable attributes. These structures cover both
  253. * NFS version 2 and the version 3 protocol. Note that the union is only
  254. * used so that one pointer can refer to both variants. These structures
  255. * go out on the wire and must be densely packed, so no quad data types
  256. * are used. (all fields are longs or u_longs or structures of same)
  257. * NB: You can't do sizeof(struct nfs_fattr), you must use the
  258. * NFSX_FATTR(v3) macro.
  259. */
  260. struct nfs_fattr {
  261. u_int32_t fa_type;
  262. u_int32_t fa_mode;
  263. u_int32_t fa_nlink;
  264. u_int32_t fa_uid;
  265. u_int32_t fa_gid;
  266. union {
  267. struct {
  268. u_int32_t nfsv2fa_size;
  269. u_int32_t nfsv2fa_blocksize;
  270. u_int32_t nfsv2fa_rdev;
  271. u_int32_t nfsv2fa_blocks;
  272. u_int32_t nfsv2fa_fsid;
  273. u_int32_t nfsv2fa_fileid;
  274. nfstime2 nfsv2fa_atime;
  275. nfstime2 nfsv2fa_mtime;
  276. nfstime2 nfsv2fa_ctime;
  277. } fa_nfsv2;
  278. struct {
  279. nfsuint64 nfsv3fa_size;
  280. nfsuint64 nfsv3fa_used;
  281. nfsv3spec nfsv3fa_rdev;
  282. nfsuint64 nfsv3fa_fsid;
  283. nfsuint64 nfsv3fa_fileid;
  284. nfstime3 nfsv3fa_atime;
  285. nfstime3 nfsv3fa_mtime;
  286. nfstime3 nfsv3fa_ctime;
  287. } fa_nfsv3;
  288. } fa_un;
  289. };
  290. /* and some ugly defines for accessing union components */
  291. #define fa2_size fa_un.fa_nfsv2.nfsv2fa_size
  292. #define fa2_blocksize fa_un.fa_nfsv2.nfsv2fa_blocksize
  293. #define fa2_rdev fa_un.fa_nfsv2.nfsv2fa_rdev
  294. #define fa2_blocks fa_un.fa_nfsv2.nfsv2fa_blocks
  295. #define fa2_fsid fa_un.fa_nfsv2.nfsv2fa_fsid
  296. #define fa2_fileid fa_un.fa_nfsv2.nfsv2fa_fileid
  297. #define fa2_atime fa_un.fa_nfsv2.nfsv2fa_atime
  298. #define fa2_mtime fa_un.fa_nfsv2.nfsv2fa_mtime
  299. #define fa2_ctime fa_un.fa_nfsv2.nfsv2fa_ctime
  300. #define fa3_size fa_un.fa_nfsv3.nfsv3fa_size
  301. #define fa3_used fa_un.fa_nfsv3.nfsv3fa_used
  302. #define fa3_rdev fa_un.fa_nfsv3.nfsv3fa_rdev
  303. #define fa3_fsid fa_un.fa_nfsv3.nfsv3fa_fsid
  304. #define fa3_fileid fa_un.fa_nfsv3.nfsv3fa_fileid
  305. #define fa3_atime fa_un.fa_nfsv3.nfsv3fa_atime
  306. #define fa3_mtime fa_un.fa_nfsv3.nfsv3fa_mtime
  307. #define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime
  308. struct nfsv2_sattr {
  309. u_int32_t sa_mode;
  310. u_int32_t sa_uid;
  311. u_int32_t sa_gid;
  312. u_int32_t sa_size;
  313. nfstime2 sa_atime;
  314. nfstime2 sa_mtime;
  315. };
  316. /*
  317. * NFS Version 3 sattr structure for the new node creation case.
  318. */
  319. struct nfsv3_sattr {
  320. u_int32_t sa_modetrue;
  321. u_int32_t sa_mode;
  322. u_int32_t sa_uidfalse;
  323. u_int32_t sa_gidfalse;
  324. u_int32_t sa_sizefalse;
  325. u_int32_t sa_atimetype;
  326. nfstime3 sa_atime;
  327. u_int32_t sa_mtimetype;
  328. nfstime3 sa_mtime;
  329. };
  330. struct nfs_statfs {
  331. union {
  332. struct {
  333. u_int32_t nfsv2sf_tsize;
  334. u_int32_t nfsv2sf_bsize;
  335. u_int32_t nfsv2sf_blocks;
  336. u_int32_t nfsv2sf_bfree;
  337. u_int32_t nfsv2sf_bavail;
  338. } sf_nfsv2;
  339. struct {
  340. nfsuint64 nfsv3sf_tbytes;
  341. nfsuint64 nfsv3sf_fbytes;
  342. nfsuint64 nfsv3sf_abytes;
  343. nfsuint64 nfsv3sf_tfiles;
  344. nfsuint64 nfsv3sf_ffiles;
  345. nfsuint64 nfsv3sf_afiles;
  346. u_int32_t nfsv3sf_invarsec;
  347. } sf_nfsv3;
  348. } sf_un;
  349. };
  350. #define sf_tsize sf_un.sf_nfsv2.nfsv2sf_tsize
  351. #define sf_bsize sf_un.sf_nfsv2.nfsv2sf_bsize
  352. #define sf_blocks sf_un.sf_nfsv2.nfsv2sf_blocks
  353. #define sf_bfree sf_un.sf_nfsv2.nfsv2sf_bfree
  354. #define sf_bavail sf_un.sf_nfsv2.nfsv2sf_bavail
  355. #define sf_tbytes sf_un.sf_nfsv3.nfsv3sf_tbytes
  356. #define sf_fbytes sf_un.sf_nfsv3.nfsv3sf_fbytes
  357. #define sf_abytes sf_un.sf_nfsv3.nfsv3sf_abytes
  358. #define sf_tfiles sf_un.sf_nfsv3.nfsv3sf_tfiles
  359. #define sf_ffiles sf_un.sf_nfsv3.nfsv3sf_ffiles
  360. #define sf_afiles sf_un.sf_nfsv3.nfsv3sf_afiles
  361. #define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec
  362. struct nfsv3_fsinfo {
  363. u_int32_t fs_rtmax;
  364. u_int32_t fs_rtpref;
  365. u_int32_t fs_rtmult;
  366. u_int32_t fs_wtmax;
  367. u_int32_t fs_wtpref;
  368. u_int32_t fs_wtmult;
  369. u_int32_t fs_dtpref;
  370. nfsuint64 fs_maxfilesize;
  371. nfstime3 fs_timedelta;
  372. u_int32_t fs_properties;
  373. };
  374. struct nfsv3_pathconf {
  375. u_int32_t pc_linkmax;
  376. u_int32_t pc_namemax;
  377. u_int32_t pc_notrunc;
  378. u_int32_t pc_chownrestricted;
  379. u_int32_t pc_caseinsensitive;
  380. u_int32_t pc_casepreserving;
  381. };
  382. #endif