nfs.h 13 KB

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