xref: /titanic_52/usr/src/uts/common/nfs/nfs.h (revision b49b27dcb66b2c7f4a23f7bc158e2dde5cd79030)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23  *
24  * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
25  * Copyright (c) 2013 by Delphix. All rights reserved.
26  */
27 
28 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
29 /*	  All Rights Reserved  	*/
30 
31 #ifndef	_NFS_NFS_H
32 #define	_NFS_NFS_H
33 
34 /*	nfs.h 2.38 88/08/19 SMI 	*/
35 
36 #include <sys/isa_defs.h>
37 #include <sys/vfs.h>
38 #include <sys/stream.h>
39 #include <rpc/types.h>
40 #include <sys/types32.h>
41 #ifdef _KERNEL
42 #include <rpc/rpc_rdma.h>
43 #include <rpc/rpc.h>
44 #include <sys/fcntl.h>
45 #include <sys/kstat.h>
46 #include <sys/dirent.h>
47 #include <sys/zone.h>
48 #include <sys/tsol/label.h>
49 #include <sys/nvpair.h>
50 #include <nfs/mount.h>
51 #include <sys/vfs_opreg.h>
52 #endif
53 #include <vm/page.h>
54 #include <rpc/rpc_sztypes.h>
55 #include <sys/sysmacros.h>
56 #ifdef	__cplusplus
57 extern "C" {
58 #endif
59 
60 /*
61  * remote file service numbers
62  */
63 #define	NFS_PROGRAM	((rpcprog_t)100003)
64 #define	NFS_VERSMIN	((rpcvers_t)2)
65 #define	NFS_VERSMAX	((rpcvers_t)4)
66 #define	NFS_VERSION	((rpcvers_t)2)
67 #define	NFS_PORT	2049
68 
69 /*
70  * Used to determine registration and service handling of versions
71  */
72 #define	NFS_VERSMIN_DEFAULT	((rpcvers_t)2)
73 #define	NFS_VERSMAX_DEFAULT	((rpcvers_t)4)
74 
75 extern rpcvers_t nfs_versmin;
76 extern rpcvers_t nfs_versmax;
77 
78 /*
79  * Default delegation setting for the server ==> "on"
80  */
81 #define	NFS_SERVER_DELEGATION_DEFAULT	(TRUE)
82 
83 /* Maximum size of data portion of a remote request */
84 #define	NFS_MAXDATA	8192
85 #define	NFS_MAXNAMLEN	255
86 #define	NFS_MAXPATHLEN	1024
87 
88 /*
89  * Rpc retransmission parameters
90  */
91 #define	NFS_TIMEO	11	/* initial timeout for clts in 10th of a sec */
92 #define	NFS_RETRIES	5	/* times to retry request */
93 #define	NFS_COTS_TIMEO	600	/* initial timeout for cots in 10th of a sec */
94 
95 /*
96  * The value of UID_NOBODY/GID_NOBODY presented to the world via NFS.
97  * UID_NOBODY/GID_NOBODY is translated to NFS_UID_NOBODY/NFS_GID_NOBODY
98  * when being sent out over the network and NFS_UID_NOBODY/NFS_GID_NOBODY
99  * is translated to UID_NOBODY/GID_NOBODY when received.
100  */
101 #define	NFS_UID_NOBODY	-2
102 #define	NFS_GID_NOBODY	-2
103 
104 /*
105  * maximum transfer size for different interfaces
106  */
107 #define	ECTSIZE	2048
108 #define	IETSIZE	8192
109 
110 /*
111  * WebNFS error status
112  */
113 enum wnfsstat {
114 	WNFSERR_CLNT_FLAVOR = 20001	/* invalid client sec flavor */
115 };
116 
117 /*
118  * Error status
119  * Should include all possible net errors.
120  * For now we just cast errno into an enum nfsstat.
121  */
122 enum nfsstat {
123 	NFS_OK = 0,			/* no error */
124 	NFSERR_PERM = 1,		/* Not owner */
125 	NFSERR_NOENT = 2,		/* No such file or directory */
126 	NFSERR_IO = 5,			/* I/O error */
127 	NFSERR_NXIO = 6,		/* No such device or address */
128 	NFSERR_ACCES = 13,		/* Permission denied */
129 	NFSERR_EXIST = 17,		/* File exists */
130 	NFSERR_XDEV = 18,		/* Cross-device link */
131 	NFSERR_NODEV = 19,		/* No such device */
132 	NFSERR_NOTDIR = 20,		/* Not a directory */
133 	NFSERR_ISDIR = 21,		/* Is a directory */
134 	NFSERR_INVAL = 22,		/* Invalid argument */
135 	NFSERR_FBIG = 27,		/* File too large */
136 	NFSERR_NOSPC = 28,		/* No space left on device */
137 	NFSERR_ROFS = 30,		/* Read-only file system */
138 	NFSERR_OPNOTSUPP = 45,		/* Operation not supported */
139 	NFSERR_NAMETOOLONG = 63,	/* File name too long */
140 	NFSERR_NOTEMPTY = 66,		/* Directory not empty */
141 	NFSERR_DQUOT = 69,		/* Disc quota exceeded */
142 	NFSERR_STALE = 70,		/* Stale NFS file handle */
143 	NFSERR_REMOTE = 71,		/* Object is remote */
144 	NFSERR_WFLUSH = 99		/* write cache flushed */
145 };
146 
147 typedef enum nfsstat nfsstat;
148 
149 /*
150  * File types
151  */
152 enum nfsftype {
153 	NFNON,
154 	NFREG,		/* regular file */
155 	NFDIR,		/* directory */
156 	NFBLK,		/* block special */
157 	NFCHR,		/* character special */
158 	NFLNK,		/* symbolic link */
159 	NFSOC		/* socket */
160 };
161 
162 /*
163  * Macros for converting device numbers to and from the format
164  * SunOS 4.x used. SVR4 uses 14 bit majors and 18 bits minors,
165  * SunOS 4.x used 8 bit majors and 8 bit minors. It isn't sufficient
166  * to use the cmpdev() and expdev() macros because they only compress
167  * 7 bit (and smaller) majors. We must compress 8 bit majors too.
168  * If the major or minor exceeds 8 bits, then we send it out in
169  * full 32 bit format and hope that the peer can deal with it.
170  */
171 
172 #define	SO4_BITSMAJOR	8	/* # of SunOS 4.x major device bits */
173 #define	SO4_BITSMINOR	8	/* # of SunOS 4.x minor device bits */
174 #define	SO4_MAXMAJ	0xff	/* SunOS 4.x max major value */
175 #define	SO4_MAXMIN	0xff	/* SunOS 4.x max minor value */
176 
177 /*
178  * Convert to over-the-wire device number format
179  */
180 #define	nfsv2_cmpdev(x) \
181 	((uint32_t) \
182 	((getmajor(x) > SO4_MAXMAJ || getminor(x) > SO4_MAXMIN) ? NODEV : \
183 	((getmajor(x) << SO4_BITSMINOR) | (getminor(x) & SO4_MAXMIN))))
184 
185 /*
186  * Convert from over-the-wire format to SVR4 device number format
187  */
188 #define	nfsv2_expdev(x) \
189 	makedevice((((x) >> SO4_BITSMINOR) & SO4_MAXMAJ), (x) & SO4_MAXMIN)
190 
191 /*
192  * Special kludge for fifos (named pipes)  [to adhere to NFS Protocol Spec]
193  *
194  * VFIFO is not in the protocol spec (VNON will be replaced by VFIFO)
195  * so the over-the-wire representation is VCHR with a '-1' device number.
196  *
197  * NOTE: This kludge becomes unnecessary with the Protocol Revision,
198  *	 but it may be necessary to support it (backwards compatibility).
199  */
200 #define	NFS_FIFO_TYPE	NFCHR
201 #define	NFS_FIFO_MODE	S_IFCHR
202 #define	NFS_FIFO_DEV	((uint32_t)-1)
203 
204 /* identify fifo in nfs attributes */
205 #define	NA_ISFIFO(NA)	(((NA)->na_type == NFS_FIFO_TYPE) && \
206 			    ((NA)->na_rdev == NFS_FIFO_DEV))
207 
208 /* set fifo in nfs attributes */
209 #define	NA_SETFIFO(NA)	{ \
210 		(NA)->na_type = NFS_FIFO_TYPE; \
211 		(NA)->na_rdev = NFS_FIFO_DEV; \
212 		(NA)->na_mode = ((NA)->na_mode & ~S_IFMT) | NFS_FIFO_MODE; \
213 		}
214 
215 /*
216  * Check for time overflow using a kernel tunable to determine whether
217  * we should accept or reject an unsigned 32-bit time value. Time value in NFS
218  * v2/3 protocol is unsigned 32 bit, but ILP32 kernel only allows 31 bits.
219  * In nfsv4, time value is a signed 64 bit, so needs to be checked for
220  * overflow as well (e.g. for setattr). So define the tunable as follows:
221  * nfs_allow_preepoch_time is TRUE if pre-epoch (negative) times are allowed
222  * and is FALSE (the default) otherwise. For nfsv2/3 this means that
223  * if negative times are allowed, the uint32_t time value is interpreted
224  * as a signed int, otherwise as a large positive number. For nfsv4,
225  * we use the value as is - except that if negative times are not allowed,
226  * we will not accept a negative value otw.
227  *
228  * So for nfsv2/3 (uint32_t):
229  *
230  * If nfs_allow_preepoch_time is
231  * FALSE, the maximum time value is INT32_MAX for 32-bit kernels and
232  * UINT32_MAX for 64-bit kernels (to allow times larger than 2038)
233  * and the minimum is zero. Note that in that case, a 32-bit application
234  * running on a 64-bit kernel will not be able to access files with
235  * the larger time values.
236  * If nfs_allow_preepoch_time is TRUE, the maximum time value is INT32_MAX
237  * for both kernel configurations and the minimum is INT32_MIN.
238  *
239  * And for nfsv4 (int64_t):
240  *
241  * nfsv4 allows for negative values in the protocol, and has a 64-bit
242  * time field, so nfs_allow_preepoch_time can be ignored.
243  */
244 #ifdef _KERNEL
245 
246 extern bool_t		nfs_allow_preepoch_time;
247 
248 #ifdef _LP64
249 
250 /*
251  * If no negative otw values are allowed, may use the full 32-bits of the
252  * time to represent time later than 2038, by presenting the value as an
253  * unsigned (but this can only be used by 64-bit apps due to cstat32
254  * restrictions). If negative values are allowed, cannot represent times
255  * after 2038. Either way, all 32 bits have a valid representation.
256  */
257 
258 /* Check if nfstime4 seconds (int64_t) can be stored in the system time */
259 #define	NFS4_TIME_OK(tt)	TRUE
260 
261 
262 #define	NFS3_TIME_OVERFLOW(tt)	(FALSE)
263 #define	NFS2_TIME_OVERFLOW(tt)	(FALSE)
264 
265 /*
266  * check if a time_t (int64_t) is ok when preepoch times are allowed -
267  * nfsv2/3: every 32-bit value is accepted, but can't overflow 64->32.
268  * nfsv4: every value is valid.
269  */
270 #define	NFS_PREEPOCH_TIME_T_OK(tt)					\
271 	(((tt) >= (time_t)INT32_MIN) && ((tt) <= (time_t)INT32_MAX))
272 
273 /*
274  * check if a time_t (int64_t) is ok when preepoch times are not allowed -
275  * nfsv2/3: every positive 32-bit value is accepted, but can't overflow 64->32.
276  * nfsv4: every value is valid.
277  */
278 #define	NFS_NO_PREEPOCH_TIME_T_OK(tt)					\
279 	(((tt) >= 0) && ((tt) <= (time_t)(ulong_t)UINT32_MAX))
280 
281 #else /* not _LP64 */
282 
283 /*
284  * Cannot represent times after 2038 in a 32-bit kernel, but we may wish to
285  * restrict the use of negative values (which violate the protocol).
286  * So if negative times allowed, all uint32 time values are valid. Otherwise
287  * only those which are less than INT32_MAX (msb=0).
288  *
289  * NFSv4 uses int64_t for the time, so in a 32-bit kernel the nfsv4 value
290  * must fit in an int32_t.
291  */
292 
293 /* Only allow signed 32-bit time values */
294 
295 /* Check if an nfstime4 (int64_t) can be stored in the system time */
296 #define	NFS4_TIME_OK(tt)						\
297 	(((tt) <= INT32_MAX) &&	((tt) >= INT32_MIN))
298 
299 #define	NFS3_TIME_OVERFLOW(tt)	((tt) > INT32_MAX)
300 #define	NFS2_TIME_OVERFLOW(tt)	((tt) > INT32_MAX)
301 
302 /*
303  * check if a time_t (int32_t) is ok when preepoch times are allowed -
304  * every 32-bit value is accepted
305  */
306 #define	NFS_PREEPOCH_TIME_T_OK(tt)	TRUE
307 
308 /*
309  * check if a time_t (int32_t) is ok when preepoch times are not allowed -
310  * only positive values are accepted.
311  */
312 #define	NFS_NO_PREEPOCH_TIME_T_OK(tt)	((tt) >= 0)
313 
314 #endif /* _LP64 */
315 
316 /* Check if an nfstime3 (uint32_t) can be stored in the system time */
317 #define	NFS3_TIME_OK(tt)						\
318 	(nfs_allow_preepoch_time || (!NFS3_TIME_OVERFLOW(tt)))
319 
320 /* Check if an nfs2_timeval (uint32_t) can be stored in the system time. */
321 #define	NFS2_TIME_OK(tt)						\
322 	(nfs_allow_preepoch_time || (!NFS2_TIME_OVERFLOW(tt)))
323 
324 /*
325  * Test if time_t (signed long) can be sent over the wire - for v2/3 only if:
326  * 1. The time value can fit in a uint32_t; and
327  * 2. Either the time value is positive or allow preepoch times.
328  * No restrictions for nfsv4.
329  */
330 #define	NFS_TIME_T_OK(tt)						\
331 	(nfs_allow_preepoch_time ?					\
332 		NFS_PREEPOCH_TIME_T_OK(tt) : NFS_NO_PREEPOCH_TIME_T_OK(tt))
333 
334 #define	NFS4_TIME_T_OK(tt)		TRUE
335 
336 /* Test if all attr times are valid */
337 #define	NFS_VAP_TIME_OK(vap)						\
338 	(nfs_allow_preepoch_time ?					\
339 		(NFS_PREEPOCH_TIME_T_OK((vap)->va_atime.tv_sec) &&	\
340 		NFS_PREEPOCH_TIME_T_OK((vap)->va_mtime.tv_sec) &&	\
341 		NFS_PREEPOCH_TIME_T_OK((vap)->va_ctime.tv_sec)) :	\
342 		(NFS_NO_PREEPOCH_TIME_T_OK((vap)->va_atime.tv_sec) &&	\
343 		NFS_NO_PREEPOCH_TIME_T_OK((vap)->va_mtime.tv_sec) &&	\
344 		NFS_NO_PREEPOCH_TIME_T_OK((vap)->va_ctime.tv_sec)))
345 
346 #define	NFS4_VAP_TIME_OK(vap)			TRUE
347 
348 /*
349  * To extend the sign or not extend the sign, that is the question.
350  * Note: The correct way is to code a macro:
351  * #define	NFS_TIME_T_CONVERT(tt)					\
352  *	(nfs_allow_preepoch_time ? (int32_t)(tt) : (uint32_t)(tt))
353  * But the 64-bit compiler does not extend the sign in that case (why?)
354  * so we'll do it the ugly way...
355  */
356 #define	NFS_TIME_T_CONVERT(systt, tt)		\
357 	if (nfs_allow_preepoch_time) {		\
358 		systt = (int32_t)(tt);		\
359 	} else {				\
360 		systt = (uint32_t)(tt);		\
361 	}
362 
363 /* macro to check for overflowed time attribute fields - version 3 */
364 #define	NFS3_FATTR_TIME_OK(attrs)			\
365 	(NFS3_TIME_OK((attrs)->atime.seconds) &&	\
366 	NFS3_TIME_OK((attrs)->mtime.seconds) &&		\
367 	NFS3_TIME_OK((attrs)->ctime.seconds))
368 
369 /* macro to check for overflowed time attribute fields - version 2 */
370 #define	NFS2_FATTR_TIME_OK(attrs)			\
371 	(NFS2_TIME_OK((attrs)->na_atime.tv_sec) &&	\
372 	NFS2_TIME_OK((attrs)->na_mtime.tv_sec) &&	\
373 	NFS2_TIME_OK((attrs)->na_ctime.tv_sec))
374 
375 /* Check that a size3 value is not overflowed */
376 #define	NFS3_SIZE_OK(size)	((size) <= MAXOFFSET_T)
377 
378 #endif /* _KERNEL */
379 
380 /*
381  * Size of an fhandle in bytes
382  */
383 #define	NFS_FHSIZE	32
384 
385 struct nfs_fid {
386 	ushort_t nf_len;
387 	ushort_t nf_pad;
388 	char	nf_data[NFS_FHSIZE];
389 };
390 
391 /*
392  * "Legacy" filehandles use NFS_FHMAXDATA (10) byte fids. Filesystems that
393  * return a larger fid than NFS_FHMAXDATA, such as ZFS's .zfs snapshot
394  * directory, can use up to (((64 - 8) / 2) - 2) bytes for their fid.
395  * This currently holds for both NFSv3 and NFSv4.
396  */
397 #define	NFS_FHMAXDATA		10
398 #define	NFS_FH3MAXDATA		26
399 #define	NFS_FH4MAXDATA		26
400 
401 /*
402  * The original nfs file handle size for version 3 was 32 which was
403  * the same in version 2; now we're making it bigger to to deal with
404  * ZFS snapshot FIDs.
405  *
406  * If the size of fhandle3_t changes or if Version 3 uses some other
407  * filehandle format, this constant may need to change.
408  */
409 
410 #define	NFS3_OLDFHSIZE	32
411 #define	NFS3_MAXFHSIZE	64
412 
413 /*
414  * This is the actual definition of a legacy filehandle.  There is some
415  * dependence on this layout in NFS-related code, particularly in the
416  * user-level lock manager, so be careful about changing it.
417  *
418  * Currently only NFSv2 uses this structure.
419  */
420 
421 typedef struct svcfh {
422 	fsid_t	fh_fsid;			/* filesystem id */
423 	ushort_t fh_len;			/* file number length */
424 	char	fh_data[NFS_FHMAXDATA];		/* and data */
425 	ushort_t fh_xlen;			/* export file number length */
426 	char	fh_xdata[NFS_FHMAXDATA];	/* and data */
427 } fhandle_t;
428 
429 /*
430  * This is the in-memory structure for an NFSv3 extended filehandle.
431  */
432 typedef struct {
433 	fsid_t	_fh3_fsid;			/* filesystem id */
434 	ushort_t _fh3_len;			/* file number length */
435 	char	_fh3_data[NFS_FH3MAXDATA];		/* and data */
436 	ushort_t _fh3_xlen;			/* export file number length */
437 	char	_fh3_xdata[NFS_FH3MAXDATA];	/* and data */
438 } fhandle3_t;
439 
440 /*
441  * This is the in-memory structure for an NFSv4 extended filehandle.
442  */
443 typedef struct {
444 	fsid_t	fhx_fsid;			/* filesystem id */
445 	ushort_t fhx_len;			/* file number length */
446 	char	fhx_data[NFS_FH4MAXDATA];	/* and data */
447 	ushort_t fhx_xlen;			/* export file number length */
448 	char	fhx_xdata[NFS_FH4MAXDATA];	/* and data */
449 } fhandle4_t;
450 
451 /*
452  * Arguments to remote write and writecache
453  */
454 /*
455  * The `over the wire' representation of the first four arguments.
456  */
457 struct otw_nfswriteargs {
458 	fhandle_t	otw_wa_fhandle;
459 	uint32_t	otw_wa_begoff;
460 	uint32_t	otw_wa_offset;
461 	uint32_t	otw_wa_totcount;
462 };
463 
464 struct nfswriteargs {
465 	struct otw_nfswriteargs *wa_args;	/* ptr to the otw arguments */
466 	struct otw_nfswriteargs wa_args_buf;	/* space for otw arguments */
467 	uint32_t	wa_count;
468 	char		*wa_data;	/* data to write (up to NFS_MAXDATA) */
469 	mblk_t		*wa_mblk;	/* pointer to mblks containing data */
470 #ifdef _KERNEL
471 	/* rdma related info */
472 	struct clist	*wa_rlist;
473 	CONN		*wa_conn;
474 #endif /* _KERNEL */
475 };
476 #define	wa_fhandle	wa_args->otw_wa_fhandle
477 #define	wa_begoff	wa_args->otw_wa_begoff
478 #define	wa_offset	wa_args->otw_wa_offset
479 #define	wa_totcount	wa_args->otw_wa_totcount
480 
481 /*
482  * NFS timeval struct using unsigned int as specified in V2 protocol.
483  * tv_sec and tv_usec used to match existing code.
484  */
485 struct nfs2_timeval {
486 	uint32_t tv_sec;
487 	uint32_t tv_usec;
488 };
489 typedef struct nfs2_timeval nfs2_timeval;
490 
491 /*
492  * File attributes
493  */
494 struct nfsfattr {
495 	enum nfsftype	na_type;	/* file type */
496 	uint32_t	na_mode;	/* protection mode bits */
497 	uint32_t	na_nlink;	/* # hard links */
498 	uint32_t	na_uid;		/* owner user id */
499 	uint32_t	na_gid;		/* owner group id */
500 	uint32_t	na_size;	/* file size in bytes */
501 	uint32_t	na_blocksize;	/* preferred block size */
502 	uint32_t	na_rdev;	/* special device # */
503 	uint32_t	na_blocks;	/* Kb of disk used by file */
504 	uint32_t	na_fsid;	/* device # */
505 	uint32_t	na_nodeid;	/* inode # */
506 	struct nfs2_timeval na_atime;	/* time of last access */
507 	struct nfs2_timeval na_mtime;	/* time of last modification */
508 	struct nfs2_timeval na_ctime;	/* time of last change */
509 };
510 
511 #define	n2v_type(x)	(NA_ISFIFO(x) ? VFIFO : nf_to_vt[(x)->na_type])
512 #define	n2v_rdev(x)	(NA_ISFIFO(x) ? 0 : (x)->na_rdev)
513 
514 /*
515  * Arguments to remote read
516  */
517 struct nfsreadargs {
518 	fhandle_t	ra_fhandle;	/* handle for file */
519 	uint32_t	ra_offset;	/* byte offset in file */
520 	uint32_t	ra_count;	/* immediate read count */
521 	uint32_t	ra_totcount;	/* total read cnt (from this offset) */
522 #ifdef _KERNEL
523 	/* used in rdma transports */
524 	caddr_t		ra_data;	/* destination for read data */
525 	struct clist	*ra_wlist;
526 	CONN		*ra_conn;
527 #endif
528 };
529 
530 /*
531  * Status OK portion of remote read reply
532  */
533 struct nfsrrok {
534 	struct nfsfattr	rrok_attr;	/* attributes, need for pagin */
535 	uint32_t	rrok_count;	/* bytes of data */
536 	char		*rrok_data;	/* data (up to NFS_MAXDATA bytes) */
537 	uint_t		rrok_bufsize;	/* size of kmem_alloc'd buffer */
538 	mblk_t		*rrok_mp;	/* mblk_t contains data for reply */
539 #ifdef _KERNEL
540 	uint_t		rrok_wlist_len;
541 	struct clist    *rrok_wlist;
542 #endif
543 };
544 
545 /*
546  * Reply from remote read
547  */
548 struct nfsrdresult {
549 	nfsstat	rr_status;			/* status of read */
550 	union {
551 		struct nfsrrok	rr_ok_u;	/* attributes, need for pagin */
552 	} rr_u;
553 };
554 #define	rr_ok		rr_u.rr_ok_u
555 #define	rr_attr		rr_u.rr_ok_u.rrok_attr
556 #define	rr_count	rr_u.rr_ok_u.rrok_count
557 #define	rr_bufsize	rr_u.rr_ok_u.rrok_bufsize
558 #define	rr_data		rr_u.rr_ok_u.rrok_data
559 #define	rr_mp		rr_u.rr_ok_u.rrok_mp
560 
561 /*
562  * File attributes which can be set
563  */
564 struct nfssattr {
565 	uint32_t	sa_mode;	/* protection mode bits */
566 	uint32_t	sa_uid;		/* owner user id */
567 	uint32_t	sa_gid;		/* owner group id */
568 	uint32_t	sa_size;	/* file size in bytes */
569 	struct nfs2_timeval sa_atime;	/* time of last access */
570 	struct nfs2_timeval sa_mtime;	/* time of last modification */
571 };
572 
573 
574 /*
575  * Reply status with file attributes
576  */
577 struct nfsattrstat {
578 	nfsstat	ns_status;			/* reply status */
579 	union {
580 		struct nfsfattr ns_attr_u;	/* NFS_OK: file attributes */
581 	} ns_u;
582 };
583 #define	ns_attr	ns_u.ns_attr_u
584 
585 
586 /*
587  * NFS_OK part of read sym link reply union
588  */
589 struct nfssrok {
590 	uint32_t srok_count;	/* size of string */
591 	char	*srok_data;	/* string (up to NFS_MAXPATHLEN bytes) */
592 };
593 
594 /*
595  * Result of reading symbolic link
596  */
597 struct nfsrdlnres {
598 	nfsstat	rl_status;			/* status of symlink read */
599 	union {
600 		struct nfssrok	rl_srok_u;	/* name of linked to */
601 	} rl_u;
602 };
603 #define	rl_srok		rl_u.rl_srok_u
604 #define	rl_count	rl_u.rl_srok_u.srok_count
605 #define	rl_data		rl_u.rl_srok_u.srok_data
606 
607 
608 /*
609  * Arguments to readdir
610  */
611 struct nfsrddirargs {
612 	fhandle_t rda_fh;	/* directory handle */
613 	uint32_t rda_offset;	/* offset in directory (opaque) */
614 	uint32_t rda_count;	/* number of directory bytes to read */
615 };
616 
617 /*
618  * NFS_OK part of readdir result
619  */
620 struct nfsrdok {
621 	uint32_t rdok_offset;		/* next offset (opaque) */
622 	uint32_t rdok_size;		/* size in bytes of entries */
623 	bool_t	rdok_eof;		/* true if last entry is in result */
624 	struct dirent64 *rdok_entries;	/* variable number of entries */
625 };
626 
627 /*
628  * Readdir result
629  */
630 struct nfsrddirres {
631 	nfsstat	rd_status;
632 	uint_t		rd_bufsize;	/* client request size (not xdr'ed) */
633 	union {
634 		struct nfsrdok rd_rdok_u;
635 	} rd_u;
636 };
637 #define	rd_rdok		rd_u.rd_rdok_u
638 #define	rd_offset	rd_u.rd_rdok_u.rdok_offset
639 #define	rd_size		rd_u.rd_rdok_u.rdok_size
640 #define	rd_eof		rd_u.rd_rdok_u.rdok_eof
641 #define	rd_entries	rd_u.rd_rdok_u.rdok_entries
642 
643 
644 /*
645  * Arguments for directory operations
646  */
647 struct nfsdiropargs {
648 	fhandle_t	*da_fhandle;	/* pointer to directory file handle */
649 	char		*da_name;	/* name (up to NFS_MAXNAMLEN bytes) */
650 	fhandle_t	da_fhandle_buf;	/* directory file handle */
651 	int		da_flags;	/* flags, see below */
652 };
653 #define	DA_FREENAME	1
654 
655 /*
656  * NFS_OK part of directory operation result
657  */
658 struct  nfsdrok {
659 	fhandle_t	drok_fhandle;	/* result file handle */
660 	struct nfsfattr	drok_attr;	/* result file attributes */
661 };
662 
663 /*
664  * Results from directory operation
665  */
666 struct  nfsdiropres {
667 	nfsstat	dr_status;			/* result status */
668 	union {
669 		struct  nfsdrok	dr_drok_u;	/* NFS_OK result */
670 	} dr_u;
671 };
672 #define	dr_drok		dr_u.dr_drok_u
673 #define	dr_fhandle	dr_u.dr_drok_u.drok_fhandle
674 #define	dr_attr		dr_u.dr_drok_u.drok_attr
675 
676 /*
677  * arguments to setattr
678  */
679 struct nfssaargs {
680 	fhandle_t	saa_fh;		/* fhandle of file to be set */
681 	struct nfssattr	saa_sa;		/* new attributes */
682 };
683 
684 /*
685  * arguments to create and mkdir
686  */
687 struct nfscreatargs {
688 	struct nfsdiropargs	ca_da;	/* file name to create and parent dir */
689 	struct nfssattr		*ca_sa;	/* initial attributes */
690 	struct nfssattr		ca_sa_buf;	/* space to store attributes */
691 };
692 
693 /*
694  * arguments to link
695  */
696 struct nfslinkargs {
697 	fhandle_t		*la_from;	/* old file */
698 	fhandle_t		la_from_buf;	/* old file */
699 	struct nfsdiropargs	la_to;		/* new file and parent dir */
700 };
701 
702 /*
703  * arguments to rename
704  */
705 struct nfsrnmargs {
706 	struct nfsdiropargs rna_from;	/* old file and parent dir */
707 	struct nfsdiropargs rna_to;	/* new file and parent dir */
708 };
709 
710 /*
711  * arguments to symlink
712  */
713 struct nfsslargs {
714 	struct nfsdiropargs	sla_from;	/* old file and parent dir */
715 	char			*sla_tnm;	/* new name */
716 	int			sla_tnm_flags;	/* flags for name */
717 	struct nfssattr		*sla_sa;	/* attributes */
718 	struct nfssattr		sla_sa_buf;	/* attributes buffer */
719 };
720 #define	SLA_FREETNM	1
721 
722 /*
723  * NFS_OK part of statfs operation
724  */
725 struct nfsstatfsok {
726 	uint32_t fsok_tsize;	/* preferred transfer size in bytes */
727 	uint32_t fsok_bsize;	/* fundamental file system block size */
728 	uint32_t fsok_blocks;	/* total blocks in file system */
729 	uint32_t fsok_bfree;	/* free blocks in fs */
730 	uint32_t fsok_bavail;	/* free blocks avail to non-superuser */
731 };
732 
733 /*
734  * Results of statfs operation
735  */
736 struct nfsstatfs {
737 	nfsstat	fs_status;			/* result status */
738 	union {
739 		struct	nfsstatfsok fs_fsok_u;	/* NFS_OK result */
740 	} fs_u;
741 };
742 #define	fs_fsok		fs_u.fs_fsok_u
743 #define	fs_tsize	fs_u.fs_fsok_u.fsok_tsize
744 #define	fs_bsize	fs_u.fs_fsok_u.fsok_bsize
745 #define	fs_blocks	fs_u.fs_fsok_u.fsok_blocks
746 #define	fs_bfree	fs_u.fs_fsok_u.fsok_bfree
747 #define	fs_bavail	fs_u.fs_fsok_u.fsok_bavail
748 
749 #ifdef _KERNEL
750 /*
751  * XDR routines for handling structures defined above
752  */
753 bool_t	xdr_attrstat(XDR *, struct nfsattrstat *);
754 bool_t	xdr_fastattrstat(XDR *, struct nfsattrstat *);
755 bool_t	xdr_creatargs(XDR *, struct nfscreatargs *);
756 bool_t	xdr_diropargs(XDR *, struct nfsdiropargs *);
757 bool_t	xdr_diropres(XDR *, struct nfsdiropres *);
758 bool_t	xdr_fastdiropres(XDR *, struct nfsdiropres *);
759 bool_t	xdr_drok(XDR *, struct nfsdrok *);
760 #ifdef _LITTLE_ENDIAN
761 bool_t	xdr_fastdrok(XDR *, struct nfsdrok *);
762 bool_t	xdr_fastfattr(XDR *, struct nfsfattr *);
763 #endif
764 bool_t	xdr_fattr(XDR *, struct nfsfattr *);
765 bool_t	xdr_fhandle(XDR *, fhandle_t *);
766 bool_t	xdr_fastfhandle(XDR *, fhandle_t **);
767 bool_t	xdr_linkargs(XDR *, struct nfslinkargs *);
768 bool_t	xdr_rddirargs(XDR *, struct nfsrddirargs *);
769 bool_t	xdr_putrddirres(XDR *, struct nfsrddirres *);
770 bool_t	xdr_getrddirres(XDR *, struct nfsrddirres *);
771 bool_t	xdr_rdlnres(XDR *, struct nfsrdlnres *);
772 bool_t	xdr_rdresult(XDR *, struct nfsrdresult *);
773 bool_t	xdr_readargs(XDR *, struct nfsreadargs *);
774 bool_t	xdr_readlink(XDR *, fhandle_t *);
775 bool_t	xdr_rnmargs(XDR *, struct nfsrnmargs *);
776 bool_t	xdr_rrok(XDR *, struct nfsrrok *);
777 bool_t	xdr_saargs(XDR *, struct nfssaargs *);
778 bool_t	xdr_sattr(XDR *, struct nfssattr *);
779 bool_t	xdr_slargs(XDR *, struct nfsslargs *);
780 bool_t	xdr_srok(XDR *, struct nfssrok *);
781 bool_t	xdr_nfs2_timeval(XDR *, struct nfs2_timeval *);
782 bool_t	xdr_writeargs(XDR *, struct nfswriteargs *);
783 bool_t	xdr_fsok(XDR *, struct nfsstatfsok *);
784 #ifdef _LITTLE_ENDIAN
785 bool_t	xdr_fastfsok(XDR *, struct nfsstatfsok *);
786 bool_t	xdr_fastenum(XDR *, enum_t *);
787 #endif
788 bool_t	xdr_statfs(XDR *, struct nfsstatfs *);
789 bool_t	xdr_faststatfs(XDR *, struct nfsstatfs *);
790 #endif
791 
792 /*
793  * Remote file service routines
794  */
795 #define	RFS_NULL	0
796 #define	RFS_GETATTR	1
797 #define	RFS_SETATTR	2
798 #define	RFS_ROOT	3
799 #define	RFS_LOOKUP	4
800 #define	RFS_READLINK	5
801 #define	RFS_READ	6
802 #define	RFS_WRITECACHE	7
803 #define	RFS_WRITE	8
804 #define	RFS_CREATE	9
805 #define	RFS_REMOVE	10
806 #define	RFS_RENAME	11
807 #define	RFS_LINK	12
808 #define	RFS_SYMLINK	13
809 #define	RFS_MKDIR	14
810 #define	RFS_RMDIR	15
811 #define	RFS_READDIR	16
812 #define	RFS_STATFS	17
813 #define	RFS_NPROC	18
814 
815 #ifdef _KERNEL
816 /*
817  * The NFS Version 2 service procedures
818  */
819 struct exportinfo;	/* defined in nfs/export.h */
820 struct servinfo;	/* defined in nfs/nfs_clnt.h */
821 struct mntinfo;		/* defined in nfs/nfs_clnt.h */
822 
823 void	rfs_getattr(fhandle_t *, struct nfsattrstat *, struct exportinfo *,
824     struct svc_req *, cred_t *);
825 void	*rfs_getattr_getfh(fhandle_t *);
826 void	rfs_setattr(struct nfssaargs *, struct nfsattrstat *,
827     struct exportinfo *, struct svc_req *, cred_t *);
828 void	*rfs_setattr_getfh(struct nfssaargs *);
829 void	rfs_lookup(struct nfsdiropargs *, struct nfsdiropres *,
830     struct exportinfo *, struct svc_req *, cred_t *);
831 void	*rfs_lookup_getfh(struct nfsdiropargs *);
832 void	rfs_readlink(fhandle_t *, struct nfsrdlnres *, struct exportinfo *,
833     struct svc_req *, cred_t *);
834 void	*rfs_readlink_getfh(fhandle_t *);
835 void	rfs_rlfree(struct nfsrdlnres *);
836 void	rfs_read(struct nfsreadargs *, struct nfsrdresult *,
837     struct exportinfo *, struct svc_req *, cred_t *);
838 void	*rfs_read_getfh(struct nfsreadargs *);
839 void	rfs_rdfree(struct nfsrdresult *);
840 void	rfs_write_sync(struct nfswriteargs *, struct nfsattrstat *,
841     struct exportinfo *, struct svc_req *, cred_t *);
842 void	rfs_write(struct nfswriteargs *, struct nfsattrstat *,
843     struct exportinfo *, struct svc_req *, cred_t *);
844 void	*rfs_write_getfh(struct nfswriteargs *);
845 void	rfs_create(struct nfscreatargs *, struct nfsdiropres *,
846     struct exportinfo *, struct svc_req *, cred_t *);
847 void	*rfs_create_getfh(struct nfscreatargs *);
848 void	rfs_remove(struct nfsdiropargs *, enum nfsstat *, struct exportinfo *,
849     struct svc_req *, cred_t *);
850 void	*rfs_remove_getfh(struct nfsdiropargs *);
851 void	rfs_rename(struct nfsrnmargs *, enum nfsstat *, struct exportinfo *,
852     struct svc_req *, cred_t *);
853 void	*rfs_rename_getfh(struct nfsrnmargs *);
854 void	rfs_link(struct nfslinkargs *, enum nfsstat *, struct exportinfo *,
855     struct svc_req *, cred_t *);
856 void	*rfs_link_getfh(struct nfslinkargs *);
857 void	rfs_symlink(struct nfsslargs *, enum nfsstat *, struct exportinfo *,
858     struct svc_req *, cred_t *);
859 void	*rfs_symlink_getfh(struct nfsslargs *);
860 void	rfs_mkdir(struct nfscreatargs *, struct nfsdiropres *,
861     struct exportinfo *, struct svc_req *, cred_t *);
862 void	*rfs_mkdir_getfh(struct nfscreatargs *);
863 void	rfs_rmdir(struct nfsdiropargs *, enum nfsstat *, struct exportinfo *,
864     struct svc_req *, cred_t *);
865 void	*rfs_rmdir_getfh(struct nfsdiropargs *);
866 void	rfs_readdir(struct nfsrddirargs *, struct nfsrddirres *,
867     struct exportinfo *, struct svc_req *, cred_t *);
868 void	*rfs_readdir_getfh(struct nfsrddirargs *);
869 void	rfs_rddirfree(struct nfsrddirres *);
870 void	rfs_statfs(fhandle_t *, struct nfsstatfs *, struct exportinfo *,
871     struct svc_req *, cred_t *);
872 void	*rfs_statfs_getfh(fhandle_t *);
873 void	rfs_srvrinit(void);
874 void	rfs_srvrfini(void);
875 
876 /*
877  * flags to define path types during Multi Component Lookups
878  * using the public filehandle
879  */
880 #define	URLPATH		0x01	/* Universal Resource Locator path */
881 #define	NATIVEPATH	0x02	/* Native path, i.e., via mount protocol */
882 #define	SECURITY_QUERY	0x04	/* Security query */
883 
884 /* index for svstat_ptr */
885 enum nfs_svccounts {NFS_CALLS, NFS_BADCALLS, NFS_REFERRALS, NFS_REFERLINKS};
886 
887 /*	function defs for NFS kernel */
888 int	nfs_waitfor_purge_complete(vnode_t *);
889 int	nfs_validate_caches(vnode_t *, cred_t *);
890 void	nfs_purge_caches(vnode_t *, int, cred_t *);
891 void	nfs_purge_rddir_cache(vnode_t *);
892 void	nfs_attrcache(vnode_t *, struct nfsfattr *, hrtime_t);
893 int	nfs_cache_fattr(vnode_t *, struct nfsfattr *, vattr_t *, hrtime_t,
894     cred_t *);
895 void	nfs_attr_cache(vnode_t *, vattr_t *, hrtime_t, cred_t *);
896 void	nfs_attrcache_va(vnode_t *, struct vattr *);
897 int	nfs_getattr_otw(vnode_t *, struct vattr *, cred_t *);
898 int	nfsgetattr(vnode_t *, struct vattr *, cred_t *);
899 int	nattr_to_vattr(vnode_t *, struct nfsfattr *, struct vattr *);
900 void	nfs_async_manager(struct vfs *);
901 void	nfs_async_manager_stop(struct vfs *);
902 void	nfs_async_stop(struct vfs *);
903 int	nfs_async_stop_sig(struct vfs *);
904 int	nfs_clntinit(void);
905 void	nfs_clntfini(void);
906 int	nfstsize(void);
907 int	nfs_srvinit(void);
908 void	nfs_srvfini(void);
909 int	vattr_to_sattr(struct vattr *, struct nfssattr *);
910 void	setdiropargs(struct nfsdiropargs *, char *, vnode_t *);
911 int	setdirgid(vnode_t *, gid_t *, cred_t *);
912 int	setdirmode(vnode_t *, mode_t *, cred_t *);
913 int	newnum(void);
914 char	*newname(void);
915 int	nfs_subrinit(void);
916 void	nfs_subrfini(void);
917 enum nfsstat puterrno(int);
918 int	geterrno(enum nfsstat);
919 int	nfsinit(int, char *);
920 void	nfsfini(void);
921 int	nfs_vfsinit(void);
922 void	nfs_vfsfini(void);
923 int	nfs_dump(vnode_t *, caddr_t, offset_t, offset_t, caller_context_t *);
924 void	nfs_perror(int error, char *fmt, ...);
925 void	nfs_cmn_err(int error, int level, char *fmt, ...);
926 int	nfs_addcllock(vnode_t *vp, struct flock64 *bfp);
927 void	nfs_rmcllock(vnode_t *vp, struct flock64 *bfp);
928 void	nfs_lockrelease(vnode_t *vp, int flag, offset_t offset, cred_t *credp);
929 int	vattr_to_nattr(struct vattr *, struct nfsfattr *);
930 int	mount_root(char *, char *, int, struct nfs_args *, int *);
931 void	nfs_lockcompletion(vnode_t *vp, int cmd);
932 void	nfs_add_locking_id(vnode_t *, pid_t, int, char *, int);
933 void	nfs3copyfh(caddr_t, vnode_t *);
934 void	nfscopyfh(caddr_t, vnode_t *);
935 int	nfs3lookup(vnode_t *, char *, vnode_t **, struct pathname *, int,
936     vnode_t *, cred_t *, int);
937 int	nfslookup(vnode_t *, char *, vnode_t **, struct pathname *, int,
938     vnode_t *, cred_t *, int);
939 void	sv_free(struct servinfo *);
940 int	nfsauth_access(struct exportinfo *exi, struct svc_req *req);
941 void	nfsauth_init();
942 void	nfsauth_fini();
943 int	nfs_setopts(vnode_t *vp, model_t model, struct nfs_args *args);
944 int	nfs_mount_label_policy(vfs_t *vfsp, struct netbuf *addr,
945     struct knetconfig *knconf, cred_t *cr);
946 boolean_t nfs_has_ctty(void);
947 void	nfs_srv_stop_all(void);
948 void	nfs_srv_quiesce_all(void);
949 int	rfs4_dss_setpaths(char *, size_t);
950 int	nfs_setmod_check(page_t *pp);
951 
952 extern time_t	rfs4_lease_time;
953 extern time_t	rfs4_grace_period;
954 extern nvlist_t	*rfs4_dss_paths, *rfs4_dss_oldpaths;
955 
956 extern kstat_named_t	*global_svstat_ptr[];
957 
958 extern krwlock_t	rroklock;
959 extern vtype_t		nf_to_vt[];
960 extern kstat_named_t	*rfsproccnt_v2_ptr;
961 extern kmutex_t		nfs_minor_lock;
962 extern int		nfs_major;
963 extern int		nfs_minor;
964 extern vfsops_t		*nfs_vfsops;
965 extern struct vnodeops	*nfs_vnodeops;
966 extern const struct fs_operation_def nfs_vnodeops_template[];
967 extern int		nfsfstyp;
968 extern void		(*nfs_srv_quiesce_func)(void);
969 extern int		(*nfs_srv_dss_func)(char *, size_t);
970 
971 /*
972  * Per-zone stats as consumed by nfsstat(1m)
973  */
974 struct nfs_version_stats {
975 	kstat_named_t	*aclreqcnt_ptr;		/* nfs_acl:0:aclreqcnt_v? */
976 	kstat_named_t	*aclproccnt_ptr;	/* nfs_acl:0:aclproccnt_v? */
977 	kstat_named_t	*rfsreqcnt_ptr;		/* nfs:0:rfsreqcnt_v? */
978 	kstat_named_t	*rfsproccnt_ptr;	/* nfs:0:rfsproccnt_v? */
979 };
980 
981 /*
982  * A bit of asymmetry: nfs:0:nfs_client isn't part of this structure.
983  */
984 struct nfs_stats {
985 	kstat_named_t		*nfs_stats_svstat_ptr[NFS_VERSMAX + 1];
986 	struct nfs_version_stats	nfs_stats_v2;
987 	struct nfs_version_stats	nfs_stats_v3;
988 	struct nfs_version_stats	nfs_stats_v4;
989 };
990 
991 /*
992  * Key used to retrieve counters.
993  */
994 extern zone_key_t nfsstat_zone_key;
995 
996 /*
997  * Zone callback functions.
998  */
999 void	*nfsstat_zone_init(zoneid_t);
1000 void	nfsstat_zone_fini(zoneid_t, void *);
1001 
1002 #endif	/* _KERNEL */
1003 
1004 /*
1005  * Version 3 declarations and definitions.
1006  */
1007 
1008 #define	NFS3_FHSIZE 64
1009 #define	NFS3_COOKIEVERFSIZE 8
1010 #define	NFS3_CREATEVERFSIZE 8
1011 #define	NFS3_WRITEVERFSIZE 8
1012 
1013 typedef char *filename3;
1014 
1015 typedef char *nfspath3;
1016 
1017 #define	nfs3nametoolong	((char *)-1)
1018 
1019 typedef uint64 fileid3;
1020 
1021 typedef uint64 cookie3;
1022 
1023 typedef uint32 uid3;
1024 
1025 typedef uint32 gid3;
1026 
1027 typedef uint64 size3;
1028 
1029 typedef uint64 offset3;
1030 
1031 typedef uint32 mode3;
1032 
1033 typedef uint32 count3;
1034 
1035 /*
1036  * These three are really opaque arrays, but we treat them as
1037  * uint64 for efficiency sake
1038  */
1039 typedef uint64 cookieverf3;
1040 
1041 typedef uint64 createverf3;
1042 
1043 typedef uint64 writeverf3;
1044 
1045 typedef struct nfs_fh3 {
1046 	uint_t fh3_length;
1047 	union nfs_fh3_u {
1048 		struct nfs_fh3_i {
1049 			fhandle3_t fh3_i;
1050 		} nfs_fh3_i;
1051 		char data[NFS3_FHSIZE];
1052 	} fh3_u;
1053 	uint_t fh3_flags;
1054 } nfs_fh3;
1055 #define	fh3_fsid	fh3_u.nfs_fh3_i.fh3_i._fh3_fsid
1056 #define	fh3_len		fh3_u.nfs_fh3_i.fh3_i._fh3_len
1057 #define	fh3_data	fh3_u.nfs_fh3_i.fh3_i._fh3_data
1058 #define	fh3_xlen	fh3_u.nfs_fh3_i.fh3_i._fh3_xlen
1059 #define	fh3_xdata	fh3_u.nfs_fh3_i.fh3_i._fh3_xdata
1060 #define	FH3TOFIDP(fh)	((fid_t *)&((fh)->fh3_len))
1061 #define	FH3TOXFIDP(fh)	((fid_t *)&((fh)->fh3_xlen))
1062 
1063 /*
1064  * nfs_fh3.fh3_flags values
1065  */
1066 #define	FH_WEBNFS	0x1	/* fh is WebNFS overloaded - see makefh3_ol() */
1067 
1068 /*
1069  * Two elements were added to the
1070  * diropargs3 structure for performance (xdr-inlining).
1071  * They are not included as part of the args
1072  * that are encoded or decoded:
1073  * dirp - ptr to the nfs_fh3
1074  * flag indicating when to free the name that was
1075  * allocated during decode.
1076  */
1077 struct diropargs3 {
1078 	nfs_fh3 *dirp;
1079 	nfs_fh3 dir;
1080 	filename3 name;
1081 	int flags;
1082 };
1083 typedef struct diropargs3 diropargs3;
1084 
1085 struct nfstime3 {
1086 	uint32 seconds;
1087 	uint32 nseconds;
1088 };
1089 typedef struct nfstime3 nfstime3;
1090 
1091 struct specdata3 {
1092 	uint32 specdata1;
1093 	uint32 specdata2;
1094 };
1095 typedef struct specdata3 specdata3;
1096 
1097 enum nfsstat3 {
1098 	NFS3_OK = 0,
1099 	NFS3ERR_PERM = 1,
1100 	NFS3ERR_NOENT = 2,
1101 	NFS3ERR_IO = 5,
1102 	NFS3ERR_NXIO = 6,
1103 	NFS3ERR_ACCES = 13,
1104 	NFS3ERR_EXIST = 17,
1105 	NFS3ERR_XDEV = 18,
1106 	NFS3ERR_NODEV = 19,
1107 	NFS3ERR_NOTDIR = 20,
1108 	NFS3ERR_ISDIR = 21,
1109 	NFS3ERR_INVAL = 22,
1110 	NFS3ERR_FBIG = 27,
1111 	NFS3ERR_NOSPC = 28,
1112 	NFS3ERR_ROFS = 30,
1113 	NFS3ERR_MLINK = 31,
1114 	NFS3ERR_NAMETOOLONG = 63,
1115 	NFS3ERR_NOTEMPTY = 66,
1116 	NFS3ERR_DQUOT = 69,
1117 	NFS3ERR_STALE = 70,
1118 	NFS3ERR_REMOTE = 71,
1119 	NFS3ERR_BADHANDLE = 10001,
1120 	NFS3ERR_NOT_SYNC = 10002,
1121 	NFS3ERR_BAD_COOKIE = 10003,
1122 	NFS3ERR_NOTSUPP = 10004,
1123 	NFS3ERR_TOOSMALL = 10005,
1124 	NFS3ERR_SERVERFAULT = 10006,
1125 	NFS3ERR_BADTYPE = 10007,
1126 	NFS3ERR_JUKEBOX = 10008
1127 };
1128 typedef enum nfsstat3 nfsstat3;
1129 
1130 enum ftype3 {
1131 	NF3REG = 1,
1132 	NF3DIR = 2,
1133 	NF3BLK = 3,
1134 	NF3CHR = 4,
1135 	NF3LNK = 5,
1136 	NF3SOCK = 6,
1137 	NF3FIFO = 7
1138 };
1139 typedef enum ftype3 ftype3;
1140 
1141 struct fattr3 {
1142 	ftype3 type;
1143 	mode3 mode;
1144 	uint32 nlink;
1145 	uid3 uid;
1146 	gid3 gid;
1147 	size3 size;
1148 	size3 used;
1149 	specdata3 rdev;
1150 	uint64 fsid;
1151 	fileid3 fileid;
1152 	nfstime3 atime;
1153 	nfstime3 mtime;
1154 	nfstime3 ctime;
1155 };
1156 typedef struct fattr3 fattr3;
1157 
1158 #define	NFS3_SIZEOF_FATTR3	(21)
1159 
1160 #ifdef _KERNEL
1161 struct fattr3_res {
1162 	nfsstat3 status;
1163 	vattr_t *vap;
1164 	vnode_t *vp;
1165 };
1166 typedef struct fattr3_res fattr3_res;
1167 #endif /* _KERNEL */
1168 
1169 struct post_op_attr {
1170 	bool_t attributes;
1171 	fattr3 attr;
1172 };
1173 typedef struct post_op_attr post_op_attr;
1174 
1175 #ifdef _KERNEL
1176 struct post_op_vattr {
1177 	bool_t		attributes;
1178 	fattr3_res	fres;
1179 };
1180 typedef struct post_op_vattr post_op_vattr;
1181 #endif /* _KERNEL */
1182 
1183 struct wcc_attr {
1184 	size3 size;
1185 	nfstime3 mtime;
1186 	nfstime3 ctime;
1187 };
1188 typedef struct wcc_attr wcc_attr;
1189 
1190 struct pre_op_attr {
1191 	bool_t attributes;
1192 	wcc_attr attr;
1193 };
1194 typedef struct pre_op_attr pre_op_attr;
1195 
1196 struct wcc_data {
1197 	pre_op_attr before;
1198 	post_op_attr after;
1199 };
1200 typedef struct wcc_data wcc_data;
1201 
1202 struct post_op_fh3 {
1203 	bool_t handle_follows;
1204 	nfs_fh3 handle;
1205 };
1206 typedef struct post_op_fh3 post_op_fh3;
1207 
1208 enum time_how {
1209 	DONT_CHANGE = 0,
1210 	SET_TO_SERVER_TIME = 1,
1211 	SET_TO_CLIENT_TIME = 2
1212 };
1213 typedef enum time_how time_how;
1214 
1215 struct set_mode3 {
1216 	bool_t set_it;
1217 	mode3 mode;
1218 };
1219 typedef struct set_mode3 set_mode3;
1220 
1221 struct set_uid3 {
1222 	bool_t set_it;
1223 	uid3 uid;
1224 };
1225 typedef struct set_uid3 set_uid3;
1226 
1227 struct set_gid3 {
1228 	bool_t set_it;
1229 	gid3 gid;
1230 };
1231 typedef struct set_gid3 set_gid3;
1232 
1233 struct set_size3 {
1234 	bool_t set_it;
1235 	size3 size;
1236 };
1237 typedef struct set_size3 set_size3;
1238 
1239 struct set_atime {
1240 	time_how set_it;
1241 	nfstime3 atime;
1242 };
1243 typedef struct set_atime set_atime;
1244 
1245 struct set_mtime {
1246 	time_how set_it;
1247 	nfstime3 mtime;
1248 };
1249 typedef struct set_mtime set_mtime;
1250 
1251 struct sattr3 {
1252 	set_mode3 mode;
1253 	set_uid3 uid;
1254 	set_gid3 gid;
1255 	set_size3 size;
1256 	set_atime atime;
1257 	set_mtime mtime;
1258 };
1259 typedef struct sattr3 sattr3;
1260 
1261 /*
1262  * A couple of defines to make resok and resfail look like the
1263  * correct things in a response type independent manner.
1264  */
1265 #define	resok	res_u.ok
1266 #define	resfail	res_u.fail
1267 
1268 struct GETATTR3args {
1269 	nfs_fh3 object;
1270 };
1271 typedef struct GETATTR3args GETATTR3args;
1272 
1273 struct GETATTR3resok {
1274 	fattr3 obj_attributes;
1275 };
1276 typedef struct GETATTR3resok GETATTR3resok;
1277 
1278 struct GETATTR3res {
1279 	nfsstat3 status;
1280 	union {
1281 		GETATTR3resok ok;
1282 	} res_u;
1283 };
1284 typedef struct GETATTR3res GETATTR3res;
1285 
1286 #ifdef _KERNEL
1287 struct GETATTR3vres {
1288 	nfsstat3 status;
1289 	fattr3_res fres;
1290 };
1291 typedef struct GETATTR3vres GETATTR3vres;
1292 #endif /* _KERNEL */
1293 
1294 struct sattrguard3 {
1295 	bool_t check;
1296 	nfstime3 obj_ctime;
1297 };
1298 typedef struct sattrguard3 sattrguard3;
1299 
1300 struct SETATTR3args {
1301 	nfs_fh3 object;
1302 	sattr3 new_attributes;
1303 	sattrguard3 guard;
1304 };
1305 typedef struct SETATTR3args SETATTR3args;
1306 
1307 struct SETATTR3resok {
1308 	wcc_data obj_wcc;
1309 };
1310 typedef struct SETATTR3resok SETATTR3resok;
1311 
1312 struct SETATTR3resfail {
1313 	wcc_data obj_wcc;
1314 };
1315 typedef struct SETATTR3resfail SETATTR3resfail;
1316 
1317 struct SETATTR3res {
1318 	nfsstat3 status;
1319 	union {
1320 		SETATTR3resok ok;
1321 		SETATTR3resfail fail;
1322 	} res_u;
1323 };
1324 typedef struct SETATTR3res SETATTR3res;
1325 
1326 struct LOOKUP3args {
1327 	diropargs3 what;
1328 };
1329 typedef struct LOOKUP3args LOOKUP3args;
1330 
1331 struct LOOKUP3resok {
1332 	nfs_fh3 object;
1333 	post_op_attr obj_attributes;
1334 	post_op_attr dir_attributes;
1335 };
1336 typedef struct LOOKUP3resok LOOKUP3resok;
1337 
1338 struct LOOKUP3resfail {
1339 	post_op_attr dir_attributes;
1340 };
1341 typedef struct LOOKUP3resfail LOOKUP3resfail;
1342 
1343 struct LOOKUP3res {
1344 	nfsstat3 status;
1345 	union {
1346 		LOOKUP3resok ok;
1347 		LOOKUP3resfail fail;
1348 	} res_u;
1349 };
1350 typedef struct LOOKUP3res LOOKUP3res;
1351 
1352 #ifdef _KERNEL
1353 struct LOOKUP3vres {
1354 	nfsstat3 status;
1355 	nfs_fh3 object;
1356 	post_op_vattr dir_attributes;
1357 	post_op_vattr obj_attributes;
1358 };
1359 typedef struct LOOKUP3vres LOOKUP3vres;
1360 #endif /* _KERNEL */
1361 
1362 struct ACCESS3args {
1363 	nfs_fh3 object;
1364 	uint32 access;
1365 };
1366 typedef struct ACCESS3args ACCESS3args;
1367 #define	ACCESS3_READ 0x1
1368 #define	ACCESS3_LOOKUP 0x2
1369 #define	ACCESS3_MODIFY 0x4
1370 #define	ACCESS3_EXTEND 0x8
1371 #define	ACCESS3_DELETE 0x10
1372 #define	ACCESS3_EXECUTE 0x20
1373 
1374 struct ACCESS3resok {
1375 	post_op_attr obj_attributes;
1376 	uint32 access;
1377 };
1378 typedef struct ACCESS3resok ACCESS3resok;
1379 
1380 struct ACCESS3resfail {
1381 	post_op_attr obj_attributes;
1382 };
1383 typedef struct ACCESS3resfail ACCESS3resfail;
1384 
1385 struct ACCESS3res {
1386 	nfsstat3 status;
1387 	union {
1388 		ACCESS3resok ok;
1389 		ACCESS3resfail fail;
1390 	} res_u;
1391 };
1392 typedef struct ACCESS3res ACCESS3res;
1393 
1394 struct READLINK3args {
1395 	nfs_fh3 symlink;
1396 };
1397 typedef struct READLINK3args READLINK3args;
1398 
1399 struct READLINK3resok {
1400 	post_op_attr symlink_attributes;
1401 	nfspath3 data;
1402 };
1403 typedef struct READLINK3resok READLINK3resok;
1404 
1405 struct READLINK3resfail {
1406 	post_op_attr symlink_attributes;
1407 };
1408 typedef struct READLINK3resfail READLINK3resfail;
1409 
1410 struct READLINK3res {
1411 	nfsstat3 status;
1412 	union {
1413 		READLINK3resok ok;
1414 		READLINK3resfail fail;
1415 	} res_u;
1416 };
1417 typedef struct READLINK3res READLINK3res;
1418 
1419 struct READ3args {
1420 	nfs_fh3 file;
1421 	offset3 offset;
1422 	count3 count;
1423 #ifdef _KERNEL
1424 	/* for read using rdma */
1425 	char *res_data_val_alt;
1426 	struct uio *res_uiop;
1427 	struct clist *wlist;
1428 	CONN *conn;
1429 #endif
1430 };
1431 typedef struct READ3args READ3args;
1432 
1433 struct READ3resok {
1434 	post_op_attr file_attributes;
1435 	count3 count;
1436 	bool_t eof;
1437 	struct {
1438 		uint_t data_len;
1439 		char *data_val;
1440 		mblk_t *mp;
1441 	} data;
1442 	uint_t size;
1443 #ifdef _KERNEL
1444 	uint_t wlist_len;
1445 	struct clist *wlist;
1446 	frtn_t zcopy;
1447 #endif
1448 };
1449 typedef struct READ3resok READ3resok;
1450 
1451 struct READ3resfail {
1452 	post_op_attr file_attributes;
1453 };
1454 typedef struct READ3resfail READ3resfail;
1455 
1456 struct READ3res {
1457 	nfsstat3 status;
1458 	union {
1459 		READ3resok ok;
1460 		READ3resfail fail;
1461 	} res_u;
1462 };
1463 typedef struct READ3res READ3res;
1464 
1465 #ifdef _KERNEL
1466 /*
1467  * READ3 reply that directly decodes fattr3 directly into vattr
1468  */
1469 struct READ3vres {
1470 	nfsstat3 status;
1471 	struct post_op_vattr pov;
1472 	count3 count;
1473 	bool_t eof;
1474 	struct {
1475 		uint_t data_len;
1476 		char *data_val;
1477 	} data;
1478 	uint_t size;
1479 
1480 	uint_t wlist_len;
1481 	struct clist *wlist;
1482 };
1483 typedef struct READ3vres READ3vres;
1484 #endif /* _KERNEL */
1485 
1486 /*
1487  * READ3 reply that uiomoves data directly into a struct uio
1488  * ignores any attributes returned
1489  */
1490 struct READ3uiores {
1491 	nfsstat3 status;
1492 	count3 count;
1493 	bool_t eof;
1494 	struct uio *uiop;
1495 	uint_t size;		/* maximum reply size */
1496 #ifdef _KERNEL
1497 	uint_t wlist_len;
1498 	struct clist *wlist;
1499 #endif
1500 };
1501 typedef struct READ3uiores READ3uiores;
1502 
1503 enum stable_how {
1504 	UNSTABLE = 0,
1505 	DATA_SYNC = 1,
1506 	FILE_SYNC = 2
1507 };
1508 typedef enum stable_how stable_how;
1509 
1510 struct WRITE3args {
1511 	nfs_fh3 file;
1512 	offset3 offset;
1513 	count3 count;
1514 	stable_how stable;
1515 	struct {
1516 		uint_t data_len;
1517 		char *data_val;
1518 	} data;
1519 	mblk_t *mblk;
1520 #ifdef _KERNEL
1521 	struct clist *rlist;
1522 	CONN *conn;
1523 #endif
1524 };
1525 typedef struct WRITE3args WRITE3args;
1526 
1527 struct WRITE3resok {
1528 	wcc_data file_wcc;
1529 	count3 count;
1530 	stable_how committed;
1531 	writeverf3 verf;
1532 };
1533 typedef struct WRITE3resok WRITE3resok;
1534 
1535 struct WRITE3resfail {
1536 	wcc_data file_wcc;
1537 };
1538 typedef struct WRITE3resfail WRITE3resfail;
1539 
1540 struct WRITE3res {
1541 	nfsstat3 status;
1542 	union {
1543 		WRITE3resok ok;
1544 		WRITE3resfail fail;
1545 	} res_u;
1546 };
1547 typedef struct WRITE3res WRITE3res;
1548 
1549 enum createmode3 {
1550 	UNCHECKED = 0,
1551 	GUARDED = 1,
1552 	EXCLUSIVE = 2
1553 };
1554 typedef enum createmode3 createmode3;
1555 
1556 struct createhow3 {
1557 	createmode3 mode;
1558 	union {
1559 		sattr3 obj_attributes;
1560 		createverf3 verf;
1561 	} createhow3_u;
1562 };
1563 typedef struct createhow3 createhow3;
1564 
1565 struct CREATE3args {
1566 	diropargs3 where;
1567 	createhow3 how;
1568 };
1569 typedef struct CREATE3args CREATE3args;
1570 
1571 struct CREATE3resok {
1572 	post_op_fh3 obj;
1573 	post_op_attr obj_attributes;
1574 	wcc_data dir_wcc;
1575 };
1576 typedef struct CREATE3resok CREATE3resok;
1577 
1578 struct CREATE3resfail {
1579 	wcc_data dir_wcc;
1580 };
1581 typedef struct CREATE3resfail CREATE3resfail;
1582 
1583 struct CREATE3res {
1584 	nfsstat3 status;
1585 	union {
1586 		CREATE3resok ok;
1587 		CREATE3resfail fail;
1588 	} res_u;
1589 };
1590 typedef struct CREATE3res CREATE3res;
1591 
1592 struct MKDIR3args {
1593 	diropargs3 where;
1594 	sattr3 attributes;
1595 };
1596 typedef struct MKDIR3args MKDIR3args;
1597 
1598 struct MKDIR3resok {
1599 	post_op_fh3 obj;
1600 	post_op_attr obj_attributes;
1601 	wcc_data dir_wcc;
1602 };
1603 typedef struct MKDIR3resok MKDIR3resok;
1604 
1605 struct MKDIR3resfail {
1606 	wcc_data dir_wcc;
1607 };
1608 typedef struct MKDIR3resfail MKDIR3resfail;
1609 
1610 struct MKDIR3res {
1611 	nfsstat3 status;
1612 	union {
1613 		MKDIR3resok ok;
1614 		MKDIR3resfail fail;
1615 	} res_u;
1616 };
1617 typedef struct MKDIR3res MKDIR3res;
1618 
1619 struct symlinkdata3 {
1620 	sattr3 symlink_attributes;
1621 	nfspath3 symlink_data;
1622 };
1623 typedef struct symlinkdata3 symlinkdata3;
1624 
1625 struct SYMLINK3args {
1626 	diropargs3 where;
1627 	symlinkdata3 symlink;
1628 };
1629 typedef struct SYMLINK3args SYMLINK3args;
1630 
1631 struct SYMLINK3resok {
1632 	post_op_fh3 obj;
1633 	post_op_attr obj_attributes;
1634 	wcc_data dir_wcc;
1635 };
1636 typedef struct SYMLINK3resok SYMLINK3resok;
1637 
1638 struct SYMLINK3resfail {
1639 	wcc_data dir_wcc;
1640 };
1641 typedef struct SYMLINK3resfail SYMLINK3resfail;
1642 
1643 struct SYMLINK3res {
1644 	nfsstat3 status;
1645 	union {
1646 		SYMLINK3resok ok;
1647 		SYMLINK3resfail fail;
1648 	} res_u;
1649 };
1650 typedef struct SYMLINK3res SYMLINK3res;
1651 
1652 struct devicedata3 {
1653 	sattr3 dev_attributes;
1654 	specdata3 spec;
1655 };
1656 typedef struct devicedata3 devicedata3;
1657 
1658 struct mknoddata3 {
1659 	ftype3 type;
1660 	union {
1661 		devicedata3 device;
1662 		sattr3 pipe_attributes;
1663 	} mknoddata3_u;
1664 };
1665 typedef struct mknoddata3 mknoddata3;
1666 
1667 struct MKNOD3args {
1668 	diropargs3 where;
1669 	mknoddata3 what;
1670 };
1671 typedef struct MKNOD3args MKNOD3args;
1672 
1673 struct MKNOD3resok {
1674 	post_op_fh3 obj;
1675 	post_op_attr obj_attributes;
1676 	wcc_data dir_wcc;
1677 };
1678 typedef struct MKNOD3resok MKNOD3resok;
1679 
1680 struct MKNOD3resfail {
1681 	wcc_data dir_wcc;
1682 };
1683 typedef struct MKNOD3resfail MKNOD3resfail;
1684 
1685 struct MKNOD3res {
1686 	nfsstat3 status;
1687 	union {
1688 		MKNOD3resok ok;
1689 		MKNOD3resfail fail;
1690 	} res_u;
1691 };
1692 typedef struct MKNOD3res MKNOD3res;
1693 
1694 struct REMOVE3args {
1695 	diropargs3 object;
1696 };
1697 typedef struct REMOVE3args REMOVE3args;
1698 
1699 struct REMOVE3resok {
1700 	wcc_data dir_wcc;
1701 };
1702 typedef struct REMOVE3resok REMOVE3resok;
1703 
1704 struct REMOVE3resfail {
1705 	wcc_data dir_wcc;
1706 };
1707 typedef struct REMOVE3resfail REMOVE3resfail;
1708 
1709 struct REMOVE3res {
1710 	nfsstat3 status;
1711 	union {
1712 		REMOVE3resok ok;
1713 		REMOVE3resfail fail;
1714 	} res_u;
1715 };
1716 typedef struct REMOVE3res REMOVE3res;
1717 
1718 struct RMDIR3args {
1719 	diropargs3 object;
1720 };
1721 typedef struct RMDIR3args RMDIR3args;
1722 
1723 struct RMDIR3resok {
1724 	wcc_data dir_wcc;
1725 };
1726 typedef struct RMDIR3resok RMDIR3resok;
1727 
1728 struct RMDIR3resfail {
1729 	wcc_data dir_wcc;
1730 };
1731 typedef struct RMDIR3resfail RMDIR3resfail;
1732 
1733 struct RMDIR3res {
1734 	nfsstat3 status;
1735 	union {
1736 		RMDIR3resok ok;
1737 		RMDIR3resfail fail;
1738 	} res_u;
1739 };
1740 typedef struct RMDIR3res RMDIR3res;
1741 
1742 struct RENAME3args {
1743 	diropargs3 from;
1744 	diropargs3 to;
1745 };
1746 typedef struct RENAME3args RENAME3args;
1747 
1748 struct RENAME3resok {
1749 	wcc_data fromdir_wcc;
1750 	wcc_data todir_wcc;
1751 };
1752 typedef struct RENAME3resok RENAME3resok;
1753 
1754 struct RENAME3resfail {
1755 	wcc_data fromdir_wcc;
1756 	wcc_data todir_wcc;
1757 };
1758 typedef struct RENAME3resfail RENAME3resfail;
1759 
1760 struct RENAME3res {
1761 	nfsstat3 status;
1762 	union {
1763 		RENAME3resok ok;
1764 		RENAME3resfail fail;
1765 	} res_u;
1766 };
1767 typedef struct RENAME3res RENAME3res;
1768 
1769 struct LINK3args {
1770 	nfs_fh3 file;
1771 	diropargs3 link;
1772 };
1773 typedef struct LINK3args LINK3args;
1774 
1775 struct LINK3resok {
1776 	post_op_attr file_attributes;
1777 	wcc_data linkdir_wcc;
1778 };
1779 typedef struct LINK3resok LINK3resok;
1780 
1781 struct LINK3resfail {
1782 	post_op_attr file_attributes;
1783 	wcc_data linkdir_wcc;
1784 };
1785 typedef struct LINK3resfail LINK3resfail;
1786 
1787 struct LINK3res {
1788 	nfsstat3 status;
1789 	union {
1790 		LINK3resok ok;
1791 		LINK3resfail fail;
1792 	} res_u;
1793 };
1794 typedef struct LINK3res LINK3res;
1795 
1796 struct READDIR3args {
1797 	nfs_fh3 dir;
1798 	cookie3 cookie;
1799 	cookieverf3 cookieverf;
1800 	count3 count;
1801 };
1802 typedef struct READDIR3args READDIR3args;
1803 
1804 struct entry3 {
1805 	fileid3 fileid;
1806 	filename3 name;
1807 	cookie3 cookie;
1808 	struct entry3 *nextentry;
1809 };
1810 typedef struct entry3 entry3;
1811 
1812 struct dirlist3 {
1813 	entry3 *entries;
1814 	bool_t eof;
1815 };
1816 typedef struct dirlist3 dirlist3;
1817 
1818 struct READDIR3resok {
1819 	post_op_attr dir_attributes;
1820 	cookieverf3 cookieverf;
1821 	dirlist3 reply;
1822 	uint_t size;
1823 	uint_t count;
1824 	uint_t freecount;
1825 	cookie3 cookie;
1826 };
1827 typedef struct READDIR3resok READDIR3resok;
1828 
1829 struct READDIR3resfail {
1830 	post_op_attr dir_attributes;
1831 };
1832 typedef struct READDIR3resfail READDIR3resfail;
1833 
1834 struct READDIR3res {
1835 	nfsstat3 status;
1836 	union {
1837 		READDIR3resok ok;
1838 		READDIR3resfail fail;
1839 	} res_u;
1840 };
1841 typedef struct READDIR3res READDIR3res;
1842 
1843 #ifdef _KERNEL
1844 struct READDIR3vres {
1845 	nfsstat3 status;
1846 	post_op_vattr dir_attributes;
1847 	cookieverf3 cookieverf;
1848 	dirent64_t *entries;			/* decoded dirent64s */
1849 	uint_t size;				/* actual size of entries */
1850 	uint_t entries_size;			/* max size of entries */
1851 	off64_t loff;				/* last offset/cookie */
1852 	bool_t eof;				/* End of directory */
1853 };
1854 typedef struct READDIR3vres READDIR3vres;
1855 #endif /* _KERNEL */
1856 
1857 struct READDIRPLUS3args {
1858 	nfs_fh3 dir;
1859 	cookie3 cookie;
1860 	cookieverf3 cookieverf;
1861 	count3 dircount;
1862 	count3 maxcount;
1863 };
1864 typedef struct READDIRPLUS3args READDIRPLUS3args;
1865 
1866 struct entryplus3 {
1867 	fileid3 fileid;
1868 	filename3 name;
1869 	cookie3 cookie;
1870 	post_op_attr name_attributes;
1871 	post_op_fh3 name_handle;
1872 	struct entryplus3 *nextentry;
1873 };
1874 typedef struct entryplus3 entryplus3;
1875 
1876 struct dirlistplus3 {
1877 	entryplus3 *entries;
1878 	bool_t eof;
1879 };
1880 typedef struct dirlistplus3 dirlistplus3;
1881 
1882 struct entryplus3_info {
1883 	post_op_attr attr;
1884 	post_op_fh3 fh;
1885 	uint_t namelen;
1886 };
1887 typedef struct entryplus3_info entryplus3_info;
1888 
1889 struct READDIRPLUS3resok {
1890 	post_op_attr dir_attributes;
1891 	cookieverf3 cookieverf;
1892 	dirlistplus3 reply;
1893 	uint_t size;
1894 	uint_t count;
1895 	uint_t maxcount;
1896 	entryplus3_info *infop;
1897 };
1898 typedef struct READDIRPLUS3resok READDIRPLUS3resok;
1899 
1900 struct READDIRPLUS3resfail {
1901 	post_op_attr dir_attributes;
1902 };
1903 typedef struct READDIRPLUS3resfail READDIRPLUS3resfail;
1904 
1905 struct READDIRPLUS3res {
1906 	nfsstat3 status;
1907 	union {
1908 		READDIRPLUS3resok ok;
1909 		READDIRPLUS3resfail fail;
1910 	} res_u;
1911 };
1912 typedef struct READDIRPLUS3res READDIRPLUS3res;
1913 
1914 #ifdef _KERNEL
1915 struct entryplus3_va_fh {
1916 	int va_valid;
1917 	int fh_valid;
1918 	vattr_t va;
1919 	nfs_fh3 fh;
1920 	char *d_name;		/* back pointer into entries */
1921 };
1922 
1923 struct READDIRPLUS3vres {
1924 	nfsstat3 status;
1925 	post_op_vattr dir_attributes;
1926 	cookieverf3 cookieverf;
1927 	dirent64_t *entries;			/* decoded dirent64s */
1928 	uint_t size;				/* actual size of entries */
1929 	uint_t entries_size;			/* max size of entries */
1930 	bool_t eof;				/* End of directory */
1931 	off64_t loff;				/* last offset/cookie */
1932 	cred_t *credentials;			/* caller's credentials */
1933 	hrtime_t time;				/* time of READDIRPLUS call */
1934 };
1935 typedef struct READDIRPLUS3vres READDIRPLUS3vres;
1936 #endif /* _KERNEL */
1937 
1938 struct FSSTAT3args {
1939 	nfs_fh3 fsroot;
1940 };
1941 typedef struct FSSTAT3args FSSTAT3args;
1942 
1943 struct FSSTAT3resok {
1944 	post_op_attr obj_attributes;
1945 	size3 tbytes;
1946 	size3 fbytes;
1947 	size3 abytes;
1948 	size3 tfiles;
1949 	size3 ffiles;
1950 	size3 afiles;
1951 	uint32 invarsec;
1952 };
1953 typedef struct FSSTAT3resok FSSTAT3resok;
1954 
1955 struct FSSTAT3resfail {
1956 	post_op_attr obj_attributes;
1957 };
1958 typedef struct FSSTAT3resfail FSSTAT3resfail;
1959 
1960 struct FSSTAT3res {
1961 	nfsstat3 status;
1962 	union {
1963 		FSSTAT3resok ok;
1964 		FSSTAT3resfail fail;
1965 	} res_u;
1966 };
1967 typedef struct FSSTAT3res FSSTAT3res;
1968 
1969 struct FSINFO3args {
1970 	nfs_fh3 fsroot;
1971 };
1972 typedef struct FSINFO3args FSINFO3args;
1973 
1974 struct FSINFO3resok {
1975 	post_op_attr obj_attributes;
1976 	uint32 rtmax;
1977 	uint32 rtpref;
1978 	uint32 rtmult;
1979 	uint32 wtmax;
1980 	uint32 wtpref;
1981 	uint32 wtmult;
1982 	uint32 dtpref;
1983 	size3 maxfilesize;
1984 	nfstime3 time_delta;
1985 	uint32 properties;
1986 };
1987 typedef struct FSINFO3resok FSINFO3resok;
1988 
1989 struct FSINFO3resfail {
1990 	post_op_attr obj_attributes;
1991 };
1992 typedef struct FSINFO3resfail FSINFO3resfail;
1993 #define	FSF3_LINK 0x1
1994 #define	FSF3_SYMLINK 0x2
1995 #define	FSF3_HOMOGENEOUS 0x8
1996 #define	FSF3_CANSETTIME 0x10
1997 
1998 struct FSINFO3res {
1999 	nfsstat3 status;
2000 	union {
2001 		FSINFO3resok ok;
2002 		FSINFO3resfail fail;
2003 	} res_u;
2004 };
2005 typedef struct FSINFO3res FSINFO3res;
2006 
2007 struct PATHCONF3args {
2008 	nfs_fh3 object;
2009 };
2010 typedef struct PATHCONF3args PATHCONF3args;
2011 
2012 struct nfs3_pathconf_info {
2013 	uint32 link_max;
2014 	uint32 name_max;
2015 	bool_t no_trunc;
2016 	bool_t chown_restricted;
2017 	bool_t case_insensitive;
2018 	bool_t case_preserving;
2019 };
2020 typedef struct nfs3_pathconf_info nfs3_pathconf_info;
2021 
2022 struct PATHCONF3resok {
2023 	post_op_attr obj_attributes;
2024 	nfs3_pathconf_info info;
2025 };
2026 typedef struct PATHCONF3resok PATHCONF3resok;
2027 
2028 struct PATHCONF3resfail {
2029 	post_op_attr obj_attributes;
2030 };
2031 typedef struct PATHCONF3resfail PATHCONF3resfail;
2032 
2033 struct PATHCONF3res {
2034 	nfsstat3 status;
2035 	union {
2036 		PATHCONF3resok ok;
2037 		PATHCONF3resfail fail;
2038 	} res_u;
2039 };
2040 typedef struct PATHCONF3res PATHCONF3res;
2041 
2042 struct COMMIT3args {
2043 	nfs_fh3 file;
2044 	offset3 offset;
2045 	count3 count;
2046 };
2047 typedef struct COMMIT3args COMMIT3args;
2048 
2049 struct COMMIT3resok {
2050 	wcc_data file_wcc;
2051 	writeverf3 verf;
2052 };
2053 typedef struct COMMIT3resok COMMIT3resok;
2054 
2055 struct COMMIT3resfail {
2056 	wcc_data file_wcc;
2057 };
2058 typedef struct COMMIT3resfail COMMIT3resfail;
2059 
2060 struct COMMIT3res {
2061 	nfsstat3 status;
2062 	union {
2063 		COMMIT3resok ok;
2064 		COMMIT3resfail fail;
2065 	} res_u;
2066 };
2067 typedef struct COMMIT3res COMMIT3res;
2068 
2069 #define	NFS3_PROGRAM ((rpcprog_t)100003)
2070 #define	NFS_V3 ((rpcvers_t)3)
2071 #define	NFSPROC3_NULL ((rpcproc_t)0)
2072 #define	NFSPROC3_GETATTR ((rpcproc_t)1)
2073 #define	NFSPROC3_SETATTR ((rpcproc_t)2)
2074 #define	NFSPROC3_LOOKUP ((rpcproc_t)3)
2075 #define	NFSPROC3_ACCESS ((rpcproc_t)4)
2076 #define	NFSPROC3_READLINK ((rpcproc_t)5)
2077 #define	NFSPROC3_READ ((rpcproc_t)6)
2078 #define	NFSPROC3_WRITE ((rpcproc_t)7)
2079 #define	NFSPROC3_CREATE ((rpcproc_t)8)
2080 #define	NFSPROC3_MKDIR ((rpcproc_t)9)
2081 #define	NFSPROC3_SYMLINK ((rpcproc_t)10)
2082 #define	NFSPROC3_MKNOD ((rpcproc_t)11)
2083 #define	NFSPROC3_REMOVE ((rpcproc_t)12)
2084 #define	NFSPROC3_RMDIR ((rpcproc_t)13)
2085 #define	NFSPROC3_RENAME ((rpcproc_t)14)
2086 #define	NFSPROC3_LINK ((rpcproc_t)15)
2087 #define	NFSPROC3_READDIR ((rpcproc_t)16)
2088 #define	NFSPROC3_READDIRPLUS ((rpcproc_t)17)
2089 #define	NFSPROC3_FSSTAT ((rpcproc_t)18)
2090 #define	NFSPROC3_FSINFO ((rpcproc_t)19)
2091 #define	NFSPROC3_PATHCONF ((rpcproc_t)20)
2092 #define	NFSPROC3_COMMIT ((rpcproc_t)21)
2093 
2094 #ifndef _KERNEL
2095 void		*nfsproc3_null_3();
2096 GETATTR3res	*nfsproc3_getattr_3();
2097 SETATTR3res	*nfsproc3_setattr_3();
2098 LOOKUP3res	*nfsproc3_lookup_3();
2099 ACCESS3res	*nfsproc3_access_3();
2100 READLINK3res	*nfsproc3_readlink_3();
2101 READ3res	*nfsproc3_read_3();
2102 WRITE3res	*nfsproc3_write_3();
2103 CREATE3res	*nfsproc3_create_3();
2104 MKDIR3res	*nfsproc3_mkdir_3();
2105 SYMLINK3res	*nfsproc3_symlink_3();
2106 MKNOD3res	*nfsproc3_mknod_3();
2107 REMOVE3res	*nfsproc3_remove_3();
2108 RMDIR3res	*nfsproc3_rmdir_3();
2109 RENAME3res	*nfsproc3_rename_3();
2110 LINK3res	*nfsproc3_link_3();
2111 READDIR3res	*nfsproc3_readdir_3();
2112 READDIRPLUS3res	*nfsproc3_readdirplus_3();
2113 FSSTAT3res	*nfsproc3_fsstat_3();
2114 FSINFO3res	*nfsproc3_fsinfo_3();
2115 PATHCONF3res	*nfsproc3_pathconf_3();
2116 COMMIT3res	*nfsproc3_commit_3();
2117 #endif	/* !_KERNEL */
2118 
2119 #ifdef _KERNEL
2120 /* the NFS Version 3 XDR functions */
2121 
2122 bool_t xdr_nfs_fh3(XDR *, nfs_fh3 *);
2123 bool_t xdr_nfslog_nfs_fh3(XDR *, nfs_fh3 *);
2124 bool_t xdr_nfs_fh3_server(XDR *, nfs_fh3 *);
2125 bool_t xdr_diropargs3(XDR *, diropargs3 *);
2126 bool_t xdr_post_op_attr(XDR *, post_op_attr *);
2127 bool_t xdr_post_op_fh3(XDR *, post_op_fh3 *);
2128 bool_t xdr_GETATTR3res(XDR *, GETATTR3res *);
2129 bool_t xdr_GETATTR3vres(XDR *, GETATTR3vres *);
2130 bool_t xdr_SETATTR3args(XDR *, SETATTR3args *);
2131 bool_t xdr_SETATTR3res(XDR *, SETATTR3res *);
2132 bool_t xdr_LOOKUP3res(XDR *, LOOKUP3res *);
2133 bool_t xdr_LOOKUP3vres(XDR *, LOOKUP3vres *);
2134 bool_t xdr_ACCESS3args(XDR *, ACCESS3args *);
2135 bool_t xdr_ACCESS3res(XDR *, ACCESS3res *);
2136 bool_t xdr_READLINK3args(XDR *, READLINK3args *);
2137 bool_t xdr_READLINK3res(XDR *, READLINK3res *);
2138 bool_t xdr_READ3args(XDR *, READ3args *);
2139 bool_t xdr_READ3res(XDR *, READ3res *);
2140 bool_t xdr_READ3vres(XDR *, READ3vres *);
2141 bool_t xdr_READ3uiores(XDR *, READ3uiores *);
2142 bool_t xdr_WRITE3args(XDR *, WRITE3args *);
2143 bool_t xdr_WRITE3res(XDR *, WRITE3res *);
2144 bool_t xdr_CREATE3args(XDR *, CREATE3args *);
2145 bool_t xdr_CREATE3res(XDR *, CREATE3res *);
2146 bool_t xdr_MKDIR3args(XDR *, MKDIR3args *);
2147 bool_t xdr_MKDIR3res(XDR *, MKDIR3res *);
2148 bool_t xdr_SYMLINK3args(XDR *, SYMLINK3args *);
2149 bool_t xdr_SYMLINK3res(XDR *, SYMLINK3res *);
2150 bool_t xdr_MKNOD3args(XDR *, MKNOD3args *);
2151 bool_t xdr_MKNOD3res(XDR *, MKNOD3res *);
2152 bool_t xdr_REMOVE3res(XDR *, REMOVE3res *);
2153 bool_t xdr_RMDIR3resfail(XDR *, RMDIR3resfail *);
2154 bool_t xdr_RMDIR3res(XDR *, RMDIR3res *);
2155 bool_t xdr_RENAME3args(XDR *, RENAME3args *);
2156 bool_t xdr_RENAME3res(XDR *, RENAME3res *);
2157 bool_t xdr_LINK3args(XDR *, LINK3args *);
2158 bool_t xdr_LINK3res(XDR *, LINK3res *);
2159 bool_t xdr_READDIR3args(XDR *, READDIR3args *);
2160 bool_t xdr_READDIR3res(XDR *, READDIR3res *);
2161 bool_t xdr_READDIR3vres(XDR *, READDIR3vres *);
2162 bool_t xdr_READDIRPLUS3args(XDR *, READDIRPLUS3args *);
2163 bool_t xdr_READDIRPLUS3res(XDR *, READDIRPLUS3res *);
2164 bool_t xdr_READDIRPLUS3vres(XDR *, READDIRPLUS3vres *);
2165 bool_t xdr_FSSTAT3res(XDR *, FSSTAT3res *);
2166 bool_t xdr_FSINFO3res(XDR *, FSINFO3res *);
2167 bool_t xdr_PATHCONF3res(XDR *, PATHCONF3res *);
2168 bool_t xdr_COMMIT3args(XDR *, COMMIT3args *);
2169 bool_t xdr_COMMIT3res(XDR *, COMMIT3res *);
2170 bool_t xdr_fastnfs_fh3(XDR *, nfs_fh3 **);
2171 
2172 /*
2173  * The NFS Version 3 service procedures.
2174  */
2175 struct exportinfo;	/* defined in nfs/export.h */
2176 struct servinfo;	/* defined in nfs/nfs_clnt.h */
2177 struct mntinfo;		/* defined in nfs/nfs_clnt.h */
2178 struct sec_ol;		/* defined in nfs/export.h */
2179 
2180 void	rfs3_getattr(GETATTR3args *, GETATTR3res *, struct exportinfo *,
2181     struct svc_req *, cred_t *);
2182 void	*rfs3_getattr_getfh(GETATTR3args *);
2183 void	rfs3_setattr(SETATTR3args *, SETATTR3res *, struct exportinfo *,
2184     struct svc_req *, cred_t *);
2185 void	*rfs3_setattr_getfh(SETATTR3args *);
2186 void	rfs3_lookup(LOOKUP3args *, LOOKUP3res *, struct exportinfo *,
2187     struct svc_req *, cred_t *);
2188 void	*rfs3_lookup_getfh(LOOKUP3args *);
2189 void	rfs3_access(ACCESS3args *, ACCESS3res *, struct exportinfo *,
2190     struct svc_req *, cred_t *);
2191 void	*rfs3_access_getfh(ACCESS3args *);
2192 void	rfs3_readlink(READLINK3args *, READLINK3res *, struct exportinfo *,
2193     struct svc_req *, cred_t *);
2194 void	*rfs3_readlink_getfh(READLINK3args *);
2195 void	rfs3_readlink_free(READLINK3res *);
2196 void	rfs3_read(READ3args *, READ3res *, struct exportinfo *,
2197     struct svc_req *, cred_t *);
2198 void	*rfs3_read_getfh(READ3args *);
2199 void	rfs3_read_free(READ3res *);
2200 void	rfs3_write(WRITE3args *, WRITE3res *, struct exportinfo *,
2201     struct svc_req *, cred_t *);
2202 void	*rfs3_write_getfh(WRITE3args *);
2203 void	rfs3_create(CREATE3args *, CREATE3res *, struct exportinfo *,
2204     struct svc_req *, cred_t *);
2205 void	*rfs3_create_getfh(CREATE3args *);
2206 void	rfs3_mkdir(MKDIR3args *, MKDIR3res *, struct exportinfo *,
2207     struct svc_req *, cred_t *);
2208 void	*rfs3_mkdir_getfh(MKDIR3args *);
2209 void	rfs3_symlink(SYMLINK3args *, SYMLINK3res *, struct exportinfo *,
2210     struct svc_req *, cred_t *);
2211 void	*rfs3_symlink_getfh(SYMLINK3args *);
2212 void	rfs3_mknod(MKNOD3args *, MKNOD3res *, struct exportinfo *,
2213     struct svc_req *, cred_t *);
2214 void	*rfs3_mknod_getfh(MKNOD3args *);
2215 void	rfs3_remove(REMOVE3args *, REMOVE3res *, struct exportinfo *,
2216     struct svc_req *, cred_t *);
2217 void	*rfs3_remove_getfh(REMOVE3args *);
2218 void	rfs3_rmdir(RMDIR3args *, RMDIR3res *, struct exportinfo *,
2219     struct svc_req *, cred_t *);
2220 void	*rfs3_rmdir_getfh(RMDIR3args *);
2221 void	rfs3_rename(RENAME3args *, RENAME3res *, struct exportinfo *,
2222     struct svc_req *, cred_t *);
2223 void	*rfs3_rename_getfh(RENAME3args *);
2224 void	rfs3_link(LINK3args *, LINK3res *, struct exportinfo *,
2225     struct svc_req *, cred_t *);
2226 void	*rfs3_link_getfh(LINK3args *);
2227 void	rfs3_readdir(READDIR3args *, READDIR3res *, struct exportinfo *,
2228     struct svc_req *, cred_t *);
2229 void	*rfs3_readdir_getfh(READDIR3args *);
2230 void	rfs3_readdir_free(READDIR3res *);
2231 void	rfs3_readdirplus(READDIRPLUS3args *, READDIRPLUS3res *,
2232     struct exportinfo *, struct svc_req *, cred_t *);
2233 void	*rfs3_readdirplus_getfh(READDIRPLUS3args *);
2234 void	rfs3_readdirplus_free(READDIRPLUS3res *);
2235 void	rfs3_fsstat(FSSTAT3args *, FSSTAT3res *, struct exportinfo *,
2236     struct svc_req *, cred_t *);
2237 void	*rfs3_fsstat_getfh(FSSTAT3args *);
2238 void	rfs3_fsinfo(FSINFO3args *, FSINFO3res *, struct exportinfo *,
2239     struct svc_req *, cred_t *);
2240 void	*rfs3_fsinfo_getfh(FSINFO3args *);
2241 void	rfs3_pathconf(PATHCONF3args *, PATHCONF3res *, struct exportinfo *,
2242     struct svc_req *, cred_t *);
2243 void	*rfs3_pathconf_getfh(PATHCONF3args *);
2244 void	rfs3_commit(COMMIT3args *, COMMIT3res *, struct exportinfo *,
2245     struct svc_req *, cred_t *);
2246 void	*rfs3_commit_getfh(COMMIT3args *);
2247 void	rfs3_srvrinit(void);
2248 void	rfs3_srvrfini(void);
2249 
2250 int	nfs3_validate_caches(vnode_t *, cred_t *);
2251 void	nfs3_cache_post_op_attr(vnode_t *, post_op_attr *, hrtime_t, cred_t *);
2252 void	nfs3_cache_post_op_vattr(vnode_t *, post_op_vattr *, hrtime_t,
2253     cred_t *);
2254 void	nfs3_cache_wcc_data(vnode_t *, wcc_data *, hrtime_t, cred_t *);
2255 void	nfs3_attrcache(vnode_t *, fattr3 *, hrtime_t);
2256 int	nfs3_cache_fattr3(vnode_t *, fattr3 *, vattr_t *, hrtime_t, cred_t *);
2257 int	nfs3_getattr_otw(vnode_t *, struct vattr *, cred_t *);
2258 int	nfs3getattr(vnode_t *, struct vattr *, cred_t *);
2259 int	fattr3_to_vattr(vnode_t *, fattr3 *, struct vattr *);
2260 int	nfs3tsize(void);
2261 uint_t	nfs3_tsize(struct knetconfig *);
2262 uint_t	rfs3_tsize(struct svc_req *);
2263 int	vattr_to_sattr3(struct vattr *, sattr3 *);
2264 void	setdiropargs3(diropargs3 *, char *, vnode_t *);
2265 enum nfsstat3 puterrno3(int);
2266 int	geterrno3(enum nfsstat3);
2267 int	nfs3init(int, char *);
2268 void	nfs3fini(void);
2269 int	nfs3_vfsinit(void);
2270 void	nfs3_vfsfini(void);
2271 void	vattr_to_post_op_attr(struct vattr *, post_op_attr *);
2272 void	mblk_to_iov(mblk_t *, int, struct iovec *);
2273 int	rfs_publicfh_mclookup(char *, vnode_t *, cred_t *, vnode_t **,
2274     struct exportinfo **, struct sec_ol *);
2275 int	rfs_pathname(char *, vnode_t **, vnode_t **, vnode_t *, cred_t *, int);
2276 
2277 extern vtype_t		nf3_to_vt[];
2278 extern kstat_named_t	*rfsproccnt_v3_ptr;
2279 extern vfsops_t		*nfs3_vfsops;
2280 extern struct vnodeops	*nfs3_vnodeops;
2281 extern const struct fs_operation_def nfs3_vnodeops_template[];
2282 
2283 /*
2284  * Some servers do not properly update the attributes of the
2285  * directory when changes are made.  To allow interoperability
2286  * with these broken servers, the nfs_disable_rddir_cache
2287  * parameter can be used to disable readdir response caching.
2288  */
2289 extern int		nfs_disable_rddir_cache;
2290 
2291 /*
2292  * External functions called by the v2/v3 code into the v4 code
2293  */
2294 void	nfs4_clnt_init(void);
2295 void	nfs4_clnt_fini(void);
2296 
2297 /*
2298  * Does NFS4 server have a vnode delegated?  TRUE if so, FALSE if not.
2299  */
2300 bool_t	rfs4_check_delegated(int mode, vnode_t *, bool_t trunc);
2301 /*
2302  * VOP_GETATTR call. If a NFS4 delegation is present on the supplied vnode
2303  * call back to the delegated client to get attributes for AT_MTIME and
2304  * AT_SIZE. Invoke VOP_GETATTR to get all other attributes or all attributes
2305  * if no delegation is present.
2306  */
2307 int	rfs4_delegated_getattr(vnode_t *, vattr_t *, int, cred_t *);
2308 void	rfs4_hold_deleg_policy(void);
2309 void	rfs4_rele_deleg_policy(void);
2310 
2311 int	do_xattr_exists_check(vnode_t *, ulong_t *, cred_t *);
2312 
2313 ts_label_t *nfs_getflabel(vnode_t *, struct exportinfo *);
2314 boolean_t do_rfs_label_check(bslabel_t *, vnode_t *, int, struct exportinfo *);
2315 
2316 /*
2317  * Copy Reduction support.
2318  * xuio_t wrapper with additional private data.
2319  */
2320 
2321 typedef struct nfs_xuio {
2322 	xuio_t nu_uio;
2323 	vnode_t *nu_vp;
2324 	uint_t nu_ref;
2325 	frtn_t nu_frtn;
2326 } nfs_xuio_t;
2327 
2328 xuio_t	*rfs_setup_xuio(vnode_t *);
2329 mblk_t	*uio_to_mblk(uio_t *);
2330 mblk_t	*rfs_read_alloc(uint_t, struct iovec **, int *);
2331 void	rfs_rndup_mblks(mblk_t *, uint_t, int);
2332 void	rfs_free_xuio(void *);
2333 
2334 #endif	/* _KERNEL */
2335 
2336 #ifdef	__cplusplus
2337 }
2338 #endif
2339 
2340 #endif	/* _NFS_NFS_H */
2341