xref: /freebsd/sys/fs/nfs/nfscl.h (revision a0b9e2e854027e6ff61fb075a1309dbc71c42b54)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2009 Rick Macklem, University of Guelph
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef	_NFS_NFSCL_H
32 #define	_NFS_NFSCL_H
33 
34 /*
35  * Extra stuff for a NFSv4 nfsnode.
36  * MALLOC'd to the correct length for the name and file handle.
37  * n4_data has the file handle, followed by the file name.
38  * The macro NFS4NODENAME() returns a pointer to the start of the
39  * name.
40  */
41 struct nfsv4node {
42 	u_int16_t	n4_fhlen;
43 	u_int16_t	n4_namelen;
44 	u_int8_t	n4_data[1];
45 };
46 
47 #define	NFS4NODENAME(n)	(&((n)->n4_data[(n)->n4_fhlen]))
48 
49 /*
50  * Just a macro to convert the nfscl_reqstart arguments.
51  */
52 #define	NFSCL_REQSTART(n, p, v) 					\
53 	nfscl_reqstart((n), (p), VFSTONFS((v)->v_mount), 		\
54 	    VTONFS(v)->n_fhp->nfh_fh, VTONFS(v)->n_fhp->nfh_len, NULL,	\
55 	    NULL, 0, 0)
56 
57 /*
58  * These two macros convert between a lease duration and renew interval.
59  * For now, just make the renew interval 1/2 the lease duration.
60  * (They should be inverse operators.)
61  */
62 #define	NFSCL_RENEW(l)	(((l) < 2) ? 1 : ((l) / 2))
63 #define	NFSCL_LEASE(r)	((r) * 2)
64 
65 /* This macro checks to see if a forced dismount is about to occur. */
66 #define	NFSCL_FORCEDISM(m)	(((m)->mnt_kern_flag & MNTK_UNMOUNTF) != 0 || \
67     (VFSTONFS(m)->nm_privflag & NFSMNTP_FORCEDISM) != 0)
68 
69 /*
70  * These flag bits are used for the argument to nfscl_fillsattr() to
71  * indicate special handling of the attributes.
72  */
73 #define	NFSSATTR_FULL		0x1
74 #define	NFSSATTR_SIZE0		0x2
75 #define	NFSSATTR_SIZENEG1	0x4
76 #define	NFSSATTR_SIZERDEV	0x8
77 
78 /* Use this macro for debug printfs. */
79 #define	NFSCL_DEBUG(level, ...)	do {					\
80 		if (nfscl_debuglevel >= (level))			\
81 			printf(__VA_ARGS__);				\
82 	} while (0)
83 
84 #endif	/* _NFS_NFSCL_H */
85