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