nfsargs.h revision 36503
1/*
2 * Copyright (c) 1989, 1993, 1995
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 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This product includes software developed by the University of
19 *	California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 *	@(#)nfs.h	8.4 (Berkeley) 5/1/95
37 * $Id: nfs.h,v 1.36 1998/05/24 14:41:47 peter Exp $
38 */
39
40#ifndef _NFS_NFS_H_
41#define _NFS_NFS_H_
42
43/*
44 * Tunable constants for nfs
45 */
46
47#define	NFS_MAXIOVEC	34
48#define NFS_TICKINTVL	5		/* Desired time for a tick (msec) */
49#define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
50#define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
51#define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
52#define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
53#define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
54#define	NFS_MAXREXMIT	100		/* Stop counting after this many */
55#define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
56#define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
57#define	NFS_MAXGRPS	16		/* Max. size of groups list */
58#ifndef NFS_MINATTRTIMO
59#define	NFS_MINATTRTIMO 3		/* VREG attrib cache timeout in sec */
60#endif
61#ifndef NFS_MAXATTRTIMO
62#define	NFS_MAXATTRTIMO 60
63#endif
64#ifndef NFS_MINDIRATTRTIMO
65#define	NFS_MINDIRATTRTIMO 30		/* VDIR attrib cache timeout in sec */
66#endif
67#ifndef NFS_MAXDIRATTRTIMO
68#define	NFS_MAXDIRATTRTIMO 60
69#endif
70#define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
71#define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
72#define NFS_READDIRSIZE	8192		/* Def. readdir size */
73#define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
74#define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
75#define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
76#define	NFS_MAXASYNCDAEMON 	20	/* Max. number async_daemons runnable */
77#define NFS_MAXGATHERDELAY	100	/* Max. write gather delay (msec) */
78#ifndef NFS_GATHERDELAY
79#define NFS_GATHERDELAY		10	/* Default write gather delay (msec) */
80#endif
81#define	NFS_DIRBLKSIZ	4096		/* Must be a multiple of DIRBLKSIZ */
82#ifdef KERNEL
83#define	DIRBLKSIZ	512		/* XXX we used to use ufs's DIRBLKSIZ */
84#endif
85
86/*
87 * Oddballs
88 */
89#define	NMOD(a)		((a) % nfs_asyncdaemons)
90#define NFS_CMPFH(n, f, s) \
91	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
92#define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
93#define NFS_SRVMAXDATA(n) \
94		(((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
95		 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
96
97/*
98 * XXX
99 * The B_INVAFTERWRITE flag should be set to whatever is required by the
100 * buffer cache code to say "Invalidate the block after it is written back".
101 */
102#define	B_INVAFTERWRITE	B_NOCACHE
103
104/*
105 * The IO_METASYNC flag should be implemented for local file systems.
106 * (Until then, it is nothin at all.)
107 */
108#ifndef IO_METASYNC
109#define IO_METASYNC	0
110#endif
111
112/*
113 * Expected allocation sizes for major data structures. If the actual size
114 * of the structure exceeds these sizes, then malloc() will be allocating
115 * almost twice the memory required. This is used in nfs_init() to warn
116 * the sysadmin that the size of a structure should be reduced.
117 * (These sizes are always a power of 2. If the kernel malloc() changes
118 *  to one that does not allocate space in powers of 2 size, then this all
119 *  becomes bunk!)
120 */
121#define NFS_SVCALLOC	256
122#define NFS_UIDALLOC	128
123
124/*
125 * Arguments to mount NFS
126 */
127#define NFS_ARGSVERSION	3		/* change when nfs_args changes */
128struct nfs_args {
129	int		version;	/* args structure version number */
130	struct sockaddr	*addr;		/* file server address */
131	int		addrlen;	/* length of address */
132	int		sotype;		/* Socket type */
133	int		proto;		/* and Protocol */
134	u_char		*fh;		/* File handle to be mounted */
135	int		fhsize;		/* Size, in bytes, of fh */
136	int		flags;		/* flags */
137	int		wsize;		/* write size in bytes */
138	int		rsize;		/* read size in bytes */
139	int		readdirsize;	/* readdir size in bytes */
140	int		timeo;		/* initial timeout in .1 secs */
141	int		retrans;	/* times to retry send */
142	int		maxgrouplist;	/* Max. size of group list */
143	int		readahead;	/* # of blocks to readahead */
144	int		leaseterm;	/* Term (sec) of lease */
145	int		deadthresh;	/* Retrans threshold */
146	char		*hostname;	/* server's name */
147	int		acregmin;	/* cache attrs for reg files min time */
148	int		acregmax;	/* cache attrs for reg files max time */
149	int		acdirmin;	/* cache attrs for dirs min time */
150	int		acdirmax;	/* cache attrs for dirs max time */
151};
152
153/*
154 * NFS mount option flags
155 */
156#define	NFSMNT_SOFT		0x00000001  /* soft mount (hard is default) */
157#define	NFSMNT_WSIZE		0x00000002  /* set write size */
158#define	NFSMNT_RSIZE		0x00000004  /* set read size */
159#define	NFSMNT_TIMEO		0x00000008  /* set initial timeout */
160#define	NFSMNT_RETRANS		0x00000010  /* set number of request retries */
161#define	NFSMNT_MAXGRPS		0x00000020  /* set maximum grouplist size */
162#define	NFSMNT_INT		0x00000040  /* allow interrupts on hard mount */
163#define	NFSMNT_NOCONN		0x00000080  /* Don't Connect the socket */
164#define	NFSMNT_NQNFS		0x00000100  /* Use Nqnfs protocol */
165#define	NFSMNT_NFSV3		0x00000200  /* Use NFS Version 3 protocol */
166#define	NFSMNT_KERB		0x00000400  /* Use Kerberos authentication */
167#define	NFSMNT_DUMBTIMR		0x00000800  /* Don't estimate rtt dynamically */
168#define	NFSMNT_LEASETERM	0x00001000  /* set lease term (nqnfs) */
169#define	NFSMNT_READAHEAD	0x00002000  /* set read ahead */
170#define	NFSMNT_DEADTHRESH	0x00004000  /* set dead server retry thresh */
171#define	NFSMNT_RESVPORT		0x00008000  /* Allocate a reserved port */
172#define	NFSMNT_RDIRPLUS		0x00010000  /* Use Readdirplus for V3 */
173#define	NFSMNT_READDIRSIZE	0x00020000  /* Set readdir size */
174#define	NFSMNT_ACREGMIN		0x00040000
175#define	NFSMNT_ACREGMAX		0x00080000
176#define	NFSMNT_ACDIRMIN		0x00100000
177#define	NFSMNT_ACDIRMAX		0x00200000
178
179#define NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
180#define NFSSTA_GOTPATHCONF	0x00080000  /* Got the V3 pathconf info */
181#define NFSSTA_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
182#define	NFSSTA_MNTD		0x00200000  /* Mnt server for mnt point */
183#define	NFSSTA_DISMINPROG	0x00400000  /* Dismount in progress */
184#define	NFSSTA_DISMNT		0x00800000  /* Dismounted */
185#define	NFSSTA_SNDLOCK		0x01000000  /* Send socket lock */
186#define	NFSSTA_WANTSND		0x02000000  /* Want above */
187#define	NFSSTA_RCVLOCK		0x04000000  /* Rcv socket lock */
188#define	NFSSTA_WANTRCV		0x08000000  /* Want above */
189#define	NFSSTA_WAITAUTH		0x10000000  /* Wait for authentication */
190#define	NFSSTA_HASAUTH		0x20000000  /* Has authenticator */
191#define	NFSSTA_WANTAUTH		0x40000000  /* Wants an authenticator */
192#define	NFSSTA_AUTHERR		0x80000000  /* Authentication error */
193
194/*
195 * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
196 * should ever try and use it.
197 */
198struct nfsd_args {
199	int	sock;		/* Socket to serve */
200	caddr_t	name;		/* Client addr for connection based sockets */
201	int	namelen;	/* Length of name */
202};
203
204struct nfsd_srvargs {
205	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
206	uid_t		nsd_uid;	/* Effective uid mapped to cred */
207	u_long		nsd_haddr;	/* Ip address of client */
208	struct ucred	nsd_cr;		/* Cred. uid maps to */
209	int		nsd_authlen;	/* Length of auth string (ret) */
210	u_char		*nsd_authstr;	/* Auth string (ret) */
211	int		nsd_verflen;	/* and the verfier */
212	u_char		*nsd_verfstr;
213	struct timeval	nsd_timestamp;	/* timestamp from verifier */
214	u_long		nsd_ttl;	/* credential ttl (sec) */
215	NFSKERBKEY_T	nsd_key;	/* Session key */
216};
217
218struct nfsd_cargs {
219	char		*ncd_dirp;	/* Mount dir path */
220	uid_t		ncd_authuid;	/* Effective uid */
221	int		ncd_authtype;	/* Type of authenticator */
222	int		ncd_authlen;	/* Length of authenticator string */
223	u_char		*ncd_authstr;	/* Authenticator string */
224	int		ncd_verflen;	/* and the verifier */
225	u_char		*ncd_verfstr;
226	NFSKERBKEY_T	ncd_key;	/* Session key */
227};
228
229/*
230 * XXX to allow amd to include nfs.h without nfsproto.h
231 */
232#ifdef NFS_NPROCS
233/*
234 * Stats structure
235 */
236struct nfsstats {
237	int	attrcache_hits;
238	int	attrcache_misses;
239	int	lookupcache_hits;
240	int	lookupcache_misses;
241	int	direofcache_hits;
242	int	direofcache_misses;
243	int	biocache_reads;
244	int	read_bios;
245	int	read_physios;
246	int	biocache_writes;
247	int	write_bios;
248	int	write_physios;
249	int	biocache_readlinks;
250	int	readlink_bios;
251	int	biocache_readdirs;
252	int	readdir_bios;
253	int	rpccnt[NFS_NPROCS];
254	int	rpcretries;
255	int	srvrpccnt[NFS_NPROCS];
256	int	srvrpc_errs;
257	int	srv_errs;
258	int	rpcrequests;
259	int	rpctimeouts;
260	int	rpcunexpected;
261	int	rpcinvalid;
262	int	srvcache_inproghits;
263	int	srvcache_idemdonehits;
264	int	srvcache_nonidemdonehits;
265	int	srvcache_misses;
266	int	srvnqnfs_leases;
267	int	srvnqnfs_maxleases;
268	int	srvnqnfs_getleases;
269	int	srvvop_writes;
270};
271#endif
272
273/*
274 * Flags for nfssvc() system call.
275 */
276#define	NFSSVC_BIOD	0x002
277#define	NFSSVC_NFSD	0x004
278#define	NFSSVC_ADDSOCK	0x008
279#define	NFSSVC_AUTHIN	0x010
280#define	NFSSVC_GOTAUTH	0x040
281#define	NFSSVC_AUTHINFAIL 0x080
282#define	NFSSVC_MNTD	0x100
283
284/*
285 * fs.nfs sysctl(3) identifiers
286 */
287#define NFS_NFSSTATS	1		/* struct: struct nfsstats */
288#define NFS_NFSPRIVPORT	2		/* int: prohibit nfs to resvports */
289
290#define FS_NFS_NAMES { \
291		       { 0, 0 }, \
292		       { "nfsstats", CTLTYPE_STRUCT }, \
293		       { "nfsprivport", CTLTYPE_INT }, \
294}
295
296#ifdef KERNEL
297
298#ifdef MALLOC_DECLARE
299MALLOC_DECLARE(M_NFSREQ);
300MALLOC_DECLARE(M_NFSDIROFF);
301MALLOC_DECLARE(M_NFSRVDESC);
302MALLOC_DECLARE(M_NFSUID);
303MALLOC_DECLARE(M_NQLEASE);
304MALLOC_DECLARE(M_NFSD);
305MALLOC_DECLARE(M_NFSBIGFH);
306MALLOC_DECLARE(M_NFSHASH);
307#endif
308
309#ifdef ZONE_INTERRUPT
310extern vm_zone_t nfsmount_zone;
311#endif
312
313struct uio; struct buf; struct vattr; struct nameidata;	/* XXX */
314
315/*
316 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
317 * What should be in this set is open to debate, but I believe that since
318 * I/O system calls on ufs are never interrupted by signals the set should
319 * be minimal. My reasoning is that many current programs that use signals
320 * such as SIGALRM will not expect file I/O system calls to be interrupted
321 * by them and break.
322 */
323#define	NFSINT_SIGMASK	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
324			 sigmask(SIGHUP)|sigmask(SIGQUIT))
325
326/*
327 * Socket errors ignored for connectionless sockets??
328 * For now, ignore them all
329 */
330#define	NFSIGNORE_SOERROR(s, e) \
331		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
332		((s) & PR_CONNREQUIRED) == 0)
333
334/*
335 * Nfs outstanding request list element
336 */
337struct nfsreq {
338	TAILQ_ENTRY(nfsreq) r_chain;
339	struct mbuf	*r_mreq;
340	struct mbuf	*r_mrep;
341	struct mbuf	*r_md;
342	caddr_t		r_dpos;
343	struct nfsmount *r_nmp;
344	struct vnode	*r_vp;
345	u_long		r_xid;
346	int		r_flags;	/* flags on request, see below */
347	int		r_retry;	/* max retransmission count */
348	int		r_rexmit;	/* current retrans count */
349	int		r_timer;	/* tick counter on reply */
350	u_int32_t	r_procnum;	/* NFS procedure number */
351	int		r_rtt;		/* RTT for rpc */
352	struct proc	*r_procp;	/* Proc that did I/O system call */
353};
354
355/*
356 * Queue head for nfsreq's
357 */
358extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
359
360/* Flag values for r_flags */
361#define R_TIMING	0x01		/* timing request (in mntp) */
362#define R_SENT		0x02		/* request has been sent */
363#define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
364#define	R_INTR		0x08		/* intr mnt, signal pending */
365#define	R_SOCKERR	0x10		/* Fatal error on socket */
366#define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
367#define	R_MUSTRESEND	0x40		/* Must resend request */
368#define	R_GETONEREP	0x80		/* Probe for one reply only */
369
370/*
371 * A list of nfssvc_sock structures is maintained with all the sockets
372 * that require service by the nfsd.
373 * The nfsuid structs hang off of the nfssvc_sock structs in both lru
374 * and uid hash lists.
375 */
376#ifndef NFS_UIDHASHSIZ
377#define	NFS_UIDHASHSIZ	29	/* Tune the size of nfssvc_sock with this */
378#endif
379#define	NUIDHASH(sock, uid) \
380	(&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
381#ifndef NFS_WDELAYHASHSIZ
382#define	NFS_WDELAYHASHSIZ 16	/* and with this */
383#endif
384#define	NWDELAYHASH(sock, f) \
385	(&(sock)->ns_wdelayhashtbl[(*((u_long *)(f))) % NFS_WDELAYHASHSIZ])
386#ifndef NFS_MUIDHASHSIZ
387#define NFS_MUIDHASHSIZ	63	/* Tune the size of nfsmount with this */
388#endif
389#define	NMUIDHASH(nmp, uid) \
390	(&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
391#define	NFSNOHASH(fhsum) \
392	(&nfsnodehashtbl[(fhsum) & nfsnodehash])
393
394/*
395 * Network address hash list element
396 */
397union nethostaddr {
398	u_long had_inetaddr;
399	struct sockaddr *had_nam;
400};
401
402struct nfsuid {
403	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
404	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
405	int		nu_flag;	/* Flags */
406	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
407	struct ucred	nu_cr;		/* Cred uid mapped to */
408	int		nu_expire;	/* Expiry time (sec) */
409	struct timeval	nu_timestamp;	/* Kerb. timestamp */
410	u_long		nu_nickname;	/* Nickname on server */
411	NFSKERBKEY_T	nu_key;		/* and session key */
412};
413
414#define	nu_inetaddr	nu_haddr.had_inetaddr
415#define	nu_nam		nu_haddr.had_nam
416/* Bits for nu_flag */
417#define	NU_INETADDR	0x1
418#define NU_NAM		0x2
419#define NU_NETFAM(u)	(((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
420
421struct nfsrv_rec {
422	STAILQ_ENTRY(nfsrv_rec) nr_link;
423	struct sockaddr	*nr_address;
424	struct mbuf	*nr_packet;
425};
426
427struct nfssvc_sock {
428	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
429	TAILQ_HEAD(, nfsuid) ns_uidlruhead;
430	struct file	*ns_fp;
431	struct socket	*ns_so;
432	struct sockaddr	*ns_nam;
433	struct mbuf	*ns_raw;
434	struct mbuf	*ns_rawend;
435	STAILQ_HEAD(, nfsrv_rec) ns_rec;
436	struct mbuf	*ns_frag;
437	int		ns_flag;
438	int		ns_solock;
439	int		ns_cc;
440	int		ns_reclen;
441	int		ns_numuids;
442	u_long		ns_sref;
443	LIST_HEAD(, nfsrv_descript) ns_tq;	/* Write gather lists */
444	LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
445	LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
446};
447
448/* Bits for "ns_flag" */
449#define	SLP_VALID	0x01
450#define	SLP_DOREC	0x02
451#define	SLP_NEEDQ	0x04
452#define	SLP_DISCONN	0x08
453#define	SLP_GETSTREAM	0x10
454#define	SLP_LASTFRAG	0x20
455#define SLP_ALLFLAGS	0xff
456
457extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
458extern int nfssvc_sockhead_flag;
459#define	SLP_INIT	0x01
460#define	SLP_WANTINIT	0x02
461
462/*
463 * One of these structures is allocated for each nfsd.
464 */
465struct nfsd {
466	TAILQ_ENTRY(nfsd) nfsd_chain;	/* List of all nfsd's */
467	int		nfsd_flag;	/* NFSD_ flags */
468	struct nfssvc_sock *nfsd_slp;	/* Current socket */
469	int		nfsd_authlen;	/* Authenticator len */
470	u_char		nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
471	int		nfsd_verflen;	/* and the Verifier */
472	u_char		nfsd_verfstr[RPCVERF_MAXSIZ];
473	struct proc	*nfsd_procp;	/* Proc ptr */
474	struct nfsrv_descript *nfsd_nd;	/* Associated nfsrv_descript */
475};
476
477/* Bits for "nfsd_flag" */
478#define	NFSD_WAITING	0x01
479#define	NFSD_REQINPROG	0x02
480#define	NFSD_NEEDAUTH	0x04
481#define	NFSD_AUTHFAIL	0x08
482
483/*
484 * This structure is used by the server for describing each request.
485 * Some fields are used only when write request gathering is performed.
486 */
487struct nfsrv_descript {
488	u_quad_t		nd_time;	/* Write deadline (usec) */
489	off_t			nd_off;		/* Start byte offset */
490	off_t			nd_eoff;	/* and end byte offset */
491	LIST_ENTRY(nfsrv_descript) nd_hash;	/* Hash list */
492	LIST_ENTRY(nfsrv_descript) nd_tq;		/* and timer list */
493	LIST_HEAD(,nfsrv_descript) nd_coalesce;	/* coalesced writes */
494	struct mbuf		*nd_mrep;	/* Request mbuf list */
495	struct mbuf		*nd_md;		/* Current dissect mbuf */
496	struct mbuf		*nd_mreq;	/* Reply mbuf list */
497	struct sockaddr		*nd_nam;	/* and socket addr */
498	struct sockaddr		*nd_nam2;	/* return socket addr */
499	caddr_t			nd_dpos;	/* Current dissect pos */
500	u_int32_t		nd_procnum;	/* RPC # */
501	int			nd_stable;	/* storage type */
502	int			nd_flag;	/* nd_flag */
503	int			nd_len;		/* Length of this write */
504	int			nd_repstat;	/* Reply status */
505	u_long			nd_retxid;	/* Reply xid */
506	u_long			nd_duration;	/* Lease duration */
507	struct timeval		nd_starttime;	/* Time RPC initiated */
508	fhandle_t		nd_fh;		/* File handle */
509	struct ucred		nd_cr;		/* Credentials */
510};
511
512/* Bits for "nd_flag" */
513#define	ND_READ		LEASE_READ
514#define ND_WRITE	LEASE_WRITE
515#define ND_CHECK	0x04
516#define ND_LEASE	(ND_READ | ND_WRITE | ND_CHECK)
517#define ND_NFSV3	0x08
518#define ND_NQNFS	0x10
519#define ND_KERBNICK	0x20
520#define ND_KERBFULL	0x40
521#define ND_KERBAUTH	(ND_KERBNICK | ND_KERBFULL)
522
523extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
524extern int nfsd_head_flag;
525#define	NFSD_CHECKSLP	0x01
526
527/*
528 * These macros compare nfsrv_descript structures.
529 */
530#define NFSW_CONTIG(o, n) \
531		((o)->nd_eoff >= (n)->nd_off && \
532		 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
533
534#define NFSW_SAMECRED(o, n) \
535	(((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
536 	 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
537		sizeof (struct ucred)))
538
539/*
540 * Defines for WebNFS
541 */
542
543#define WEBNFS_ESC_CHAR		'%'
544#define WEBNFS_SPECCHAR_START	0x80
545
546#define WEBNFS_NATIVE_CHAR	0x80
547/*
548 * ..
549 * Possibly more here in the future.
550 */
551
552/*
553 * Macro for converting escape characters in WebNFS pathnames.
554 * Should really be in libkern.
555 */
556
557#define HEXTOC(c) \
558	((c) >= 'a' ? ((c) - ('a' - 10)) : \
559	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
560#define HEXSTRTOI(p) \
561	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
562
563#ifdef NFS_DEBUG
564
565extern int nfs_debug;
566#define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
567#define NFS_DEBUG_WG		2 /* server write gathering */
568#define NFS_DEBUG_RC		4 /* server request caching */
569
570#define NFS_DPF(cat, args)					\
571	do {							\
572		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
573	} while (0)
574
575#else
576
577#define NFS_DPF(cat, args)
578
579#endif
580
581u_quad_t nfs_curusec __P((void));
582int	nfs_init __P((struct vfsconf *vfsp));
583int	nfs_reply __P((struct nfsreq *));
584int	nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
585int	nfs_send __P((struct socket *, struct sockaddr *, struct mbuf *,
586		      struct nfsreq *));
587int	nfs_rephead __P((int, struct nfsrv_descript *, struct nfssvc_sock *,
588			 int, int, u_quad_t *, struct mbuf **, struct mbuf **,
589			 caddr_t *));
590int	nfs_sndlock __P((int *, int *, struct nfsreq *));
591void	nfs_sndunlock __P((int *, int *));
592int	nfs_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
593int	nfs_vinvalbuf __P((struct vnode *, int, struct ucred *, struct proc *,
594			   int));
595int	nfs_readrpc __P((struct vnode *, struct uio *, struct ucred *));
596int	nfs_writerpc __P((struct vnode *, struct uio *, struct ucred *, int *,
597			  int *));
598int	nfs_readdirrpc __P((struct vnode *, struct uio *, struct ucred *));
599int	nfs_asyncio __P((struct buf *, struct ucred *));
600int	nfs_doio __P((struct buf *, struct ucred *, struct proc *));
601int	nfs_readlinkrpc __P((struct vnode *, struct uio *, struct ucred *));
602int	nfs_sigintr __P((struct nfsmount *, struct nfsreq *, struct proc *));
603int	nfs_readdirplusrpc __P((struct vnode *, struct uio *, struct ucred *));
604int	nfsm_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
605void	nfsm_srvfattr __P((struct nfsrv_descript *, struct vattr *,
606			   struct nfs_fattr *));
607void	nfsm_srvwcc __P((struct nfsrv_descript *, int, struct vattr *, int,
608			 struct vattr *, struct mbuf **, char **));
609void	nfsm_srvpostopattr __P((struct nfsrv_descript *, int, struct vattr *,
610				struct mbuf **, char **));
611int	netaddr_match __P((int, union nethostaddr *, struct sockaddr *));
612int	nfs_request __P((struct vnode *, struct mbuf *, int, struct proc *,
613			 struct ucred *, struct mbuf **, struct mbuf **,
614			 caddr_t *));
615int	nfs_loadattrcache __P((struct vnode **, struct mbuf **, caddr_t *,
616			       struct vattr *));
617int	nfs_namei __P((struct nameidata *, fhandle_t *, int,
618		       struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
619		       caddr_t *, struct vnode **, struct proc *, int, int));
620void	nfsm_adj __P((struct mbuf *, int, int));
621int	nfsm_mbuftouio __P((struct mbuf **, struct uio *, int, caddr_t *));
622void	nfsrv_initcache __P((void));
623int	nfs_getauth __P((struct nfsmount *, struct nfsreq *, struct ucred *,
624			 char **, int *, char *, int *, NFSKERBKEY_T));
625int	nfs_getnickauth __P((struct nfsmount *, struct ucred *, char **,
626			     int *, char *, int));
627int	nfs_savenickauth __P((struct nfsmount *, struct ucred *, int,
628			      NFSKERBKEY_T, struct mbuf **, char **,
629			      struct mbuf *));
630int	nfs_adv __P((struct mbuf **, caddr_t *, int, int));
631void	nfs_nhinit __P((void));
632void	nfs_timer __P((void*));
633u_long	nfs_hash __P((nfsfh_t *, int));
634int	nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *,
635			 struct nfsrv_descript **));
636int	nfsrv_getcache __P((struct nfsrv_descript *, struct nfssvc_sock *,
637			    struct mbuf **));
638void	nfsrv_updatecache __P((struct nfsrv_descript *, int, struct mbuf *));
639void	nfsrv_cleancache __P((void));
640int	nfs_connect __P((struct nfsmount *, struct nfsreq *));
641void	nfs_disconnect __P((struct nfsmount *));
642int	nfs_getattrcache __P((struct vnode *, struct vattr *));
643int	nfsm_strtmbuf __P((struct mbuf **, char **, char *, long));
644int	nfs_bioread __P((struct vnode *, struct uio *, int, struct ucred *,
645			 int));
646int	nfsm_uiotombuf __P((struct uio *, struct mbuf **, int, caddr_t *));
647void	nfsrv_init __P((int));
648void	nfs_clearcommit __P((struct mount *));
649int	nfsrv_errmap __P((struct nfsrv_descript *, int));
650void	nfsrvw_sort __P((gid_t *, int));
651void	nfsrv_setcred __P((struct ucred *, struct ucred *));
652int	nfs_writebp __P((struct buf *, int));
653int	nfsrv_object_create __P((struct vnode *));
654void	nfsrv_wakenfsd __P((struct nfssvc_sock *slp));
655int	nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *,
656			       struct proc *, struct mbuf **));
657int	nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *,
658			struct proc *p));
659
660int	nfsrv3_access __P((struct nfsrv_descript *nfsd,
661			   struct nfssvc_sock *slp,
662			   struct proc *procp, struct mbuf **mrq));
663int	nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
664			  struct proc *procp, struct mbuf **mrq));
665int	nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
666			  struct proc *procp, struct mbuf **mrq));
667int	nfsrv_fhtovp __P((fhandle_t *, int, struct vnode **, struct ucred *,
668			  struct nfssvc_sock *, struct sockaddr *, int *,
669			  int, int));
670int	nfsrv_setpublicfs __P((struct mount *, struct netexport *,
671			       struct export_args *));
672int	nfs_ispublicfh __P((fhandle_t *));
673int	nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
674			  struct proc *procp, struct mbuf **mrq));
675int	nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
676			   struct proc *procp, struct mbuf **mrq));
677int	nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
678			struct proc *procp, struct mbuf **mrq));
679int	nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
680			  struct proc *procp, struct mbuf **mrq));
681int	nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
682			 struct proc *procp, struct mbuf **mrq));
683int	nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
684			 struct proc *procp, struct mbuf **mrq));
685int	nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
686			struct proc *procp, struct mbuf **mrq));
687int	nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
688			struct proc *procp, struct mbuf **mrq));
689int	nfsrv_pathconf __P((struct nfsrv_descript *nfsd,
690			    struct nfssvc_sock *slp, struct proc *procp,
691			    struct mbuf **mrq));
692int	nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
693			struct proc *procp, struct mbuf **mrq));
694int	nfsrv_readdir __P((struct nfsrv_descript *nfsd,
695			   struct nfssvc_sock *slp,
696			   struct proc *procp, struct mbuf **mrq));
697int	nfsrv_readdirplus __P((struct nfsrv_descript *nfsd,
698			       struct nfssvc_sock *slp, struct proc *procp,
699			       struct mbuf **mrq));
700int	nfsrv_readlink __P((struct nfsrv_descript *nfsd,
701			    struct nfssvc_sock *slp, struct proc *procp,
702			    struct mbuf **mrq));
703int	nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
704			  struct proc *procp, struct mbuf **mrq));
705int	nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
706			  struct proc *procp, struct mbuf **mrq));
707int	nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
708			 struct proc *procp, struct mbuf **mrq));
709int	nfsrv_setattr __P((struct nfsrv_descript *nfsd,
710			   struct nfssvc_sock *slp,
711			   struct proc *procp, struct mbuf **mrq));
712int	nfsrv_statfs __P((struct nfsrv_descript *nfsd,
713			  struct nfssvc_sock *slp,
714			  struct proc *procp, struct mbuf **mrq));
715int	nfsrv_symlink __P((struct nfsrv_descript *nfsd,
716			   struct nfssvc_sock *slp,
717			   struct proc *procp, struct mbuf **mrq));
718int	nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
719			 struct proc *procp, struct mbuf **mrq));
720void	nfsrv_rcv __P((struct socket *so, caddr_t arg, int waitflag));
721void	nfsrv_slpderef __P((struct nfssvc_sock *slp));
722#endif	/* KERNEL */
723
724#endif
725