xref: /freebsd-11-stable/sys/nfsclient/nfsm_subs.h (revision 4ab2e064d7950be84256d671a7ae93f87cc6aa36)
1 /*-
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Rick Macklem at The University of Guelph.
7  *
8  * 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  * 4. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)nfsm_subs.h	8.2 (Berkeley) 3/30/95
33  * $FreeBSD$
34  */
35 
36 #ifndef _NFSCLIENT_NFSM_SUBS_H_
37 #define _NFSCLIENT_NFSM_SUBS_H_
38 
39 #include <nfs/nfs_common.h>
40 
41 #define	nfsv2tov_type(a)	nv2tov_type[fxdr_unsigned(u_int32_t,(a))&0x7]
42 
43 struct ucred;
44 struct vnode;
45 
46 /*
47  * These macros do strange and peculiar things to mbuf chains for
48  * the assistance of the nfs code. To attempt to use them for any
49  * other purpose will be dangerous. (they make weird assumptions)
50  */
51 
52 /*
53  * First define what the actual subs. return
54  */
55 u_int32_t nfs_xid_gen(void);
56 
57 /* *********************************** */
58 /* Request generation phase macros */
59 
60 int	nfsm_fhtom_xx(struct vnode *v, int v3, struct mbuf **mb,
61 	    caddr_t *bpos);
62 void	nfsm_v3attrbuild_xx(struct vattr *va, int full, struct mbuf **mb,
63 	    caddr_t *bpos);
64 int	nfsm_strtom_xx(const char *a, int s, int m, struct mbuf **mb,
65 	    caddr_t *bpos);
66 
67 #define nfsm_bcheck(t1, mreq) \
68 do { \
69 	if (t1) { \
70 		error = t1; \
71 		m_freem(mreq); \
72 		goto nfsmout; \
73 	} \
74 } while (0)
75 
76 #define nfsm_fhtom(v, v3) \
77 do { \
78 	int32_t t1; \
79 	t1 = nfsm_fhtom_xx((v), (v3), &mb, &bpos); \
80 	nfsm_bcheck(t1, mreq); \
81 } while (0)
82 
83 /* If full is true, set all fields, otherwise just set mode and time fields */
84 #define nfsm_v3attrbuild(a, full) \
85 	nfsm_v3attrbuild_xx(a, full, &mb, &bpos)
86 
87 #define nfsm_uiotom(p, s) \
88 do { \
89 	int t1; \
90 	t1 = nfsm_uiotombuf((p), &mb, (s), &bpos); \
91 	nfsm_bcheck(t1, mreq); \
92 } while (0)
93 
94 #define	nfsm_strtom(a, s, m) \
95 do { \
96 	int t1; \
97 	t1 = nfsm_strtom_xx((a), (s), (m), &mb, &bpos); \
98 	nfsm_bcheck(t1, mreq); \
99 } while (0)
100 
101 /* *********************************** */
102 /* Send the request */
103 
104 #define	nfsm_request(v, t, p, c) \
105 do { \
106 	sigset_t oldset; \
107 	nfs_set_sigmask(p, &oldset); \
108 	error = nfs_request((v), mreq, (t), (p), (c), &mrep, &md, &dpos); \
109 	nfs_restore_sigmask(p, &oldset); \
110 	if (error != 0) { \
111 		if (error & NFSERR_RETERR) \
112 			error &= ~NFSERR_RETERR; \
113 		else \
114 			goto nfsmout; \
115 	} \
116 } while (0)
117 
118 /* *********************************** */
119 /* Reply interpretation phase macros */
120 
121 int	nfsm_mtofh_xx(struct vnode *d, struct vnode **v, int v3, int *f,
122 	    struct mbuf **md, caddr_t *dpos);
123 int	nfsm_getfh_xx(nfsfh_t **f, int *s, int v3, struct mbuf **md,
124 	    caddr_t *dpos);
125 int	nfsm_loadattr_xx(struct vnode **v, struct vattr *va, struct mbuf **md,
126 	    caddr_t *dpos);
127 int	nfsm_postop_attr_xx(struct vnode **v, int *f, struct vattr *va,
128 	    struct mbuf **md, caddr_t *dpos);
129 int	nfsm_wcc_data_xx(struct vnode **v, int *f, struct mbuf **md,
130 	    caddr_t *dpos);
131 
132 #define nfsm_mtofh(d, v, v3, f) \
133 do { \
134 	int32_t t1; \
135 	t1 = nfsm_mtofh_xx((d), &(v), (v3), &(f), &md, &dpos); \
136 	nfsm_dcheck(t1, mrep); \
137 } while (0)
138 
139 #define nfsm_getfh(f, s, v3) \
140 do { \
141 	int32_t t1; \
142 	t1 = nfsm_getfh_xx(&(f), &(s), (v3), &md, &dpos); \
143 	nfsm_dcheck(t1, mrep); \
144 } while (0)
145 
146 #define	nfsm_loadattr(v, a) \
147 do { \
148 	int32_t t1; \
149 	t1 = nfsm_loadattr_xx(&v, a, &md, &dpos); \
150 	nfsm_dcheck(t1, mrep); \
151 } while (0)
152 
153 #define	nfsm_postop_attr(v, f) \
154 do { \
155 	int32_t t1; \
156 	t1 = nfsm_postop_attr_xx(&v, &f, NULL, &md, &dpos);	\
157 	nfsm_dcheck(t1, mrep); \
158 } while (0)
159 
160 #define	nfsm_postop_attr_va(v, f, va)		\
161 do { \
162 	int32_t t1; \
163 	t1 = nfsm_postop_attr_xx(&v, &f, va, &md, &dpos);	\
164 	nfsm_dcheck(t1, mrep); \
165 } while (0)
166 
167 /* Used as (f) for nfsm_wcc_data() */
168 #define NFSV3_WCCRATTR	0
169 #define NFSV3_WCCCHK	1
170 
171 #define	nfsm_wcc_data(v, f) \
172 do { \
173 	int32_t t1; \
174 	t1 = nfsm_wcc_data_xx(&v, &f, &md, &dpos); \
175 	nfsm_dcheck(t1, mrep); \
176 } while (0)
177 
178 #endif
179