nfsm_subs.h revision 1.32 1 1.32 yamt /* $NetBSD: nfsm_subs.h,v 1.32 2003/09/26 11:51:53 yamt Exp $ */
2 1.5 cgd
3 1.1 mycroft /*
4 1.4 mycroft * Copyright (c) 1989, 1993
5 1.4 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 mycroft *
7 1.1 mycroft * This code is derived from software contributed to Berkeley by
8 1.1 mycroft * Rick Macklem at The University of Guelph.
9 1.1 mycroft *
10 1.1 mycroft * Redistribution and use in source and binary forms, with or without
11 1.1 mycroft * modification, are permitted provided that the following conditions
12 1.1 mycroft * are met:
13 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.1 mycroft * notice, this list of conditions and the following disclaimer.
15 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.1 mycroft * documentation and/or other materials provided with the distribution.
18 1.31 agc * 3. Neither the name of the University nor the names of its contributors
19 1.1 mycroft * may be used to endorse or promote products derived from this software
20 1.1 mycroft * without specific prior written permission.
21 1.1 mycroft *
22 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 mycroft * SUCH DAMAGE.
33 1.1 mycroft *
34 1.9 fvdl * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95
35 1.1 mycroft */
36 1.1 mycroft
37 1.9 fvdl
38 1.9 fvdl #ifndef _NFS_NFSM_SUBS_H_
39 1.9 fvdl #define _NFS_NFSM_SUBS_H_
40 1.9 fvdl
41 1.9 fvdl
42 1.1 mycroft /*
43 1.1 mycroft * These macros do strange and peculiar things to mbuf chains for
44 1.1 mycroft * the assistance of the nfs code. To attempt to use them for any
45 1.1 mycroft * other purpose will be dangerous. (they make weird assumptions)
46 1.1 mycroft */
47 1.1 mycroft
48 1.1 mycroft /*
49 1.1 mycroft * First define what the actual subs. return
50 1.1 mycroft */
51 1.9 fvdl
52 1.1 mycroft #define M_HASCL(m) ((m)->m_flags & M_EXT)
53 1.1 mycroft #define NFSMINOFF(m) \
54 1.1 mycroft if (M_HASCL(m)) \
55 1.1 mycroft (m)->m_data = (m)->m_ext.ext_buf; \
56 1.4 mycroft else if ((m)->m_flags & M_PKTHDR) \
57 1.4 mycroft (m)->m_data = (m)->m_pktdat; \
58 1.1 mycroft else \
59 1.1 mycroft (m)->m_data = (m)->m_dat
60 1.1 mycroft #define NFSMADV(m, s) (m)->m_data += (s)
61 1.15 thorpej #define NFSMSIZ(m) ((M_HASCL(m)) ? (m)->m_ext.ext_size : \
62 1.15 thorpej (((m)->m_flags & M_PKTHDR) ? MHLEN : MLEN))
63 1.1 mycroft
64 1.1 mycroft /*
65 1.1 mycroft * Now for the macros that do the simple stuff and call the functions
66 1.1 mycroft * for the hard stuff.
67 1.1 mycroft * These macros use several vars. declared in nfsm_reqhead and these
68 1.1 mycroft * vars. must not be used elsewhere unless you are careful not to corrupt
69 1.1 mycroft * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
70 1.1 mycroft * that may be used so long as the value is not expected to retained
71 1.1 mycroft * after a macro.
72 1.1 mycroft * I know, this is kind of dorkey, but it makes the actual op functions
73 1.1 mycroft * fairly clean and deals with the mess caused by the xdr discriminating
74 1.1 mycroft * unions.
75 1.1 mycroft */
76 1.1 mycroft
77 1.1 mycroft #define nfsm_build(a,c,s) \
78 1.4 mycroft { if ((s) > M_TRAILINGSPACE(mb)) { \
79 1.23 matt struct mbuf *mb2; \
80 1.23 matt mb2 = m_get(M_WAIT, MT_DATA); \
81 1.23 matt MCLAIM(mb2, &nfs_mowner); \
82 1.1 mycroft if ((s) > MLEN) \
83 1.1 mycroft panic("build > MLEN"); \
84 1.1 mycroft mb->m_next = mb2; \
85 1.1 mycroft mb = mb2; \
86 1.1 mycroft mb->m_len = 0; \
87 1.1 mycroft bpos = mtod(mb, caddr_t); \
88 1.1 mycroft } \
89 1.1 mycroft (a) = (c)(bpos); \
90 1.1 mycroft mb->m_len += (s); \
91 1.4 mycroft bpos += (s); }
92 1.1 mycroft
93 1.14 fvdl #define nfsm_aligned(p) ALIGNED_POINTER(p,u_int32_t)
94 1.12 fvdl
95 1.9 fvdl #define nfsm_dissect(a, c, s) \
96 1.4 mycroft { t1 = mtod(md, caddr_t)+md->m_len-dpos; \
97 1.12 fvdl if (t1 >= (s) && nfsm_aligned(dpos)) { \
98 1.1 mycroft (a) = (c)(dpos); \
99 1.1 mycroft dpos += (s); \
100 1.9 fvdl } else if ((t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2)) != 0){ \
101 1.9 fvdl error = t1; \
102 1.1 mycroft m_freem(mrep); \
103 1.1 mycroft goto nfsmout; \
104 1.1 mycroft } else { \
105 1.1 mycroft (a) = (c)cp2; \
106 1.4 mycroft } }
107 1.1 mycroft
108 1.26 drochner #define nfsm_fhtom(n, v3) \
109 1.9 fvdl { if (v3) { \
110 1.26 drochner t2 = nfsm_rndup((n)->n_fhsize) + NFSX_UNSIGNED; \
111 1.9 fvdl if (t2 <= M_TRAILINGSPACE(mb)) { \
112 1.9 fvdl nfsm_build(tl, u_int32_t *, t2); \
113 1.26 drochner *tl++ = txdr_unsigned((n)->n_fhsize); \
114 1.9 fvdl *(tl + ((t2>>2) - 2)) = 0; \
115 1.26 drochner memcpy((caddr_t)tl,(caddr_t)(n)->n_fhp, \
116 1.26 drochner (n)->n_fhsize); \
117 1.9 fvdl } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, \
118 1.26 drochner (caddr_t)(n)->n_fhp, \
119 1.26 drochner (n)->n_fhsize)) != 0) { \
120 1.9 fvdl error = t2; \
121 1.9 fvdl m_freem(mreq); \
122 1.9 fvdl goto nfsmout; \
123 1.9 fvdl } \
124 1.9 fvdl } else { \
125 1.9 fvdl nfsm_build(cp, caddr_t, NFSX_V2FH); \
126 1.26 drochner memcpy(cp, (caddr_t)(n)->n_fhp, NFSX_V2FH); \
127 1.9 fvdl } }
128 1.9 fvdl
129 1.9 fvdl #define nfsm_srvfhtom(f, v3) \
130 1.9 fvdl { if (v3) { \
131 1.9 fvdl nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3FH); \
132 1.9 fvdl *tl++ = txdr_unsigned(NFSX_V3FH); \
133 1.18 perry memcpy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \
134 1.9 fvdl } else { \
135 1.9 fvdl nfsm_build(cp, caddr_t, NFSX_V2FH); \
136 1.18 perry memcpy(cp, (caddr_t)(f), NFSX_V2FH); \
137 1.9 fvdl } }
138 1.9 fvdl
139 1.9 fvdl #define nfsm_srvpostop_fh(f) \
140 1.9 fvdl { nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \
141 1.9 fvdl *tl++ = nfs_true; \
142 1.9 fvdl *tl++ = txdr_unsigned(NFSX_V3FH); \
143 1.18 perry memcpy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \
144 1.9 fvdl }
145 1.9 fvdl
146 1.30 fvdl #define nfsm_mtofh(d, v, v3, f) \
147 1.9 fvdl { struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \
148 1.9 fvdl if (v3) { \
149 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
150 1.9 fvdl (f) = fxdr_unsigned(int, *tl); \
151 1.9 fvdl } else \
152 1.9 fvdl (f) = 1; \
153 1.9 fvdl if (f) { \
154 1.9 fvdl nfsm_getfh(ttfhp, ttfhsize, (v3)); \
155 1.9 fvdl if ((t1 = nfs_nget((d)->v_mount, ttfhp, ttfhsize, \
156 1.30 fvdl &ttnp)) != 0) { \
157 1.9 fvdl error = t1; \
158 1.9 fvdl m_freem(mrep); \
159 1.9 fvdl goto nfsmout; \
160 1.9 fvdl } \
161 1.9 fvdl (v) = NFSTOV(ttnp); \
162 1.9 fvdl } \
163 1.9 fvdl if (v3) { \
164 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
165 1.9 fvdl if (f) \
166 1.9 fvdl (f) = fxdr_unsigned(int, *tl); \
167 1.9 fvdl else if (fxdr_unsigned(int, *tl)) \
168 1.9 fvdl nfsm_adv(NFSX_V3FATTR); \
169 1.1 mycroft } \
170 1.9 fvdl if (f) \
171 1.22 yamt nfsm_loadattr((v), (struct vattr *)0, 0); \
172 1.1 mycroft }
173 1.1 mycroft
174 1.9 fvdl #define nfsm_getfh(f, s, v3) \
175 1.9 fvdl { if (v3) { \
176 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
177 1.9 fvdl if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \
178 1.9 fvdl (s) > NFSX_V3FHMAX) { \
179 1.9 fvdl m_freem(mrep); \
180 1.9 fvdl error = EBADRPC; \
181 1.9 fvdl goto nfsmout; \
182 1.9 fvdl } \
183 1.9 fvdl } else \
184 1.9 fvdl (s) = NFSX_V2FH; \
185 1.9 fvdl nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); }
186 1.9 fvdl
187 1.22 yamt #define nfsm_loadattr(v, a, flags) \
188 1.9 fvdl { struct vnode *ttvp = (v); \
189 1.22 yamt if ((t1 = nfsm_loadattrcache(&ttvp, &md, &dpos, (a), (flags))) \
190 1.22 yamt != 0) { \
191 1.9 fvdl error = t1; \
192 1.1 mycroft m_freem(mrep); \
193 1.1 mycroft goto nfsmout; \
194 1.1 mycroft } \
195 1.9 fvdl (v) = ttvp; }
196 1.9 fvdl
197 1.22 yamt #define nfsm_postop_attr(v, f, flags) \
198 1.9 fvdl { struct vnode *ttvp = (v); \
199 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
200 1.9 fvdl if (((f) = fxdr_unsigned(int, *tl)) != 0) { \
201 1.17 fvdl if ((t1 = nfsm_loadattrcache(&ttvp, &md, &dpos, \
202 1.22 yamt (struct vattr *)0, (flags))) != 0) { \
203 1.9 fvdl error = t1; \
204 1.9 fvdl (f) = 0; \
205 1.9 fvdl m_freem(mrep); \
206 1.9 fvdl goto nfsmout; \
207 1.9 fvdl } \
208 1.9 fvdl (v) = ttvp; \
209 1.9 fvdl } }
210 1.9 fvdl
211 1.9 fvdl /* Used as (f) for nfsm_wcc_data() */
212 1.9 fvdl #define NFSV3_WCCRATTR 0
213 1.9 fvdl #define NFSV3_WCCCHK 1
214 1.9 fvdl
215 1.22 yamt #define nfsm_wcc_data(v, f, flags) \
216 1.9 fvdl { int ttattrf, ttretf = 0; \
217 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
218 1.9 fvdl if (*tl == nfs_true) { \
219 1.9 fvdl nfsm_dissect(tl, u_int32_t *, 6 * NFSX_UNSIGNED); \
220 1.32 yamt if (f) { \
221 1.32 yamt struct timespec mtime; \
222 1.32 yamt fxdr_nfsv3time(tl + 2, &mtime); \
223 1.32 yamt ttretf = timespeccmp(&VTONFS(v)->n_mtime, \
224 1.32 yamt &mtime, ==); \
225 1.32 yamt } \
226 1.9 fvdl } \
227 1.22 yamt nfsm_postop_attr((v), ttattrf, (flags)); \
228 1.9 fvdl if (f) { \
229 1.9 fvdl (f) = ttretf; \
230 1.9 fvdl } else { \
231 1.9 fvdl (f) = ttattrf; \
232 1.9 fvdl } }
233 1.9 fvdl
234 1.20 fvdl /* If full is true, set all fields, otherwise just set mode and time fields */
235 1.20 fvdl #define nfsm_v3attrbuild(a, full) \
236 1.20 fvdl { if ((a)->va_mode != (mode_t)VNOVAL) { \
237 1.20 fvdl nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
238 1.20 fvdl *tl++ = nfs_true; \
239 1.20 fvdl *tl = txdr_unsigned((a)->va_mode); \
240 1.20 fvdl } else { \
241 1.20 fvdl nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
242 1.20 fvdl *tl = nfs_false; \
243 1.20 fvdl } \
244 1.20 fvdl if ((full) && (a)->va_uid != (uid_t)VNOVAL) { \
245 1.20 fvdl nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
246 1.20 fvdl *tl++ = nfs_true; \
247 1.20 fvdl *tl = txdr_unsigned((a)->va_uid); \
248 1.20 fvdl } else { \
249 1.20 fvdl nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
250 1.20 fvdl *tl = nfs_false; \
251 1.20 fvdl } \
252 1.20 fvdl if ((full) && (a)->va_gid != (gid_t)VNOVAL) { \
253 1.20 fvdl nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
254 1.20 fvdl *tl++ = nfs_true; \
255 1.20 fvdl *tl = txdr_unsigned((a)->va_gid); \
256 1.20 fvdl } else { \
257 1.20 fvdl nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
258 1.20 fvdl *tl = nfs_false; \
259 1.20 fvdl } \
260 1.20 fvdl if ((full) && (a)->va_size != VNOVAL) { \
261 1.20 fvdl nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \
262 1.20 fvdl *tl++ = nfs_true; \
263 1.20 fvdl txdr_hyper((a)->va_size, tl); \
264 1.20 fvdl } else { \
265 1.20 fvdl nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
266 1.20 fvdl *tl = nfs_false; \
267 1.20 fvdl } \
268 1.20 fvdl if ((a)->va_atime.tv_sec != VNOVAL) { \
269 1.20 fvdl if ((a)->va_atime.tv_sec != time.tv_sec) { \
270 1.20 fvdl nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \
271 1.20 fvdl *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
272 1.20 fvdl txdr_nfsv3time(&(a)->va_atime, tl); \
273 1.20 fvdl } else { \
274 1.20 fvdl nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
275 1.20 fvdl *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
276 1.20 fvdl } \
277 1.20 fvdl } else { \
278 1.20 fvdl nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
279 1.20 fvdl *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \
280 1.20 fvdl } \
281 1.20 fvdl if ((a)->va_mtime.tv_sec != VNOVAL) { \
282 1.20 fvdl if ((a)->va_mtime.tv_sec != time.tv_sec) { \
283 1.20 fvdl nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \
284 1.20 fvdl *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
285 1.20 fvdl txdr_nfsv3time(&(a)->va_mtime, tl); \
286 1.20 fvdl } else { \
287 1.20 fvdl nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
288 1.20 fvdl *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
289 1.20 fvdl } \
290 1.20 fvdl } else { \
291 1.20 fvdl nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
292 1.20 fvdl *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \
293 1.20 fvdl } \
294 1.9 fvdl }
295 1.20 fvdl
296 1.1 mycroft
297 1.1 mycroft #define nfsm_strsiz(s,m) \
298 1.25 yamt { nfsm_dissect(tl,uint32_t *,NFSX_UNSIGNED); \
299 1.25 yamt if (((s) = fxdr_unsigned(uint32_t,*tl)) > (m)) { \
300 1.1 mycroft m_freem(mrep); \
301 1.1 mycroft error = EBADRPC; \
302 1.1 mycroft goto nfsmout; \
303 1.4 mycroft } }
304 1.1 mycroft
305 1.9 fvdl #define nfsm_srvnamesiz(s) \
306 1.25 yamt { nfsm_dissect(tl,uint32_t *,NFSX_UNSIGNED); \
307 1.25 yamt if (((s) = fxdr_unsigned(uint32_t,*tl)) > NFS_MAXNAMLEN) \
308 1.9 fvdl error = NFSERR_NAMETOL; \
309 1.9 fvdl if (error) \
310 1.9 fvdl nfsm_reply(0); \
311 1.9 fvdl }
312 1.9 fvdl
313 1.1 mycroft #define nfsm_mtouio(p,s) \
314 1.1 mycroft if ((s) > 0 && \
315 1.9 fvdl (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \
316 1.9 fvdl error = t1; \
317 1.1 mycroft m_freem(mrep); \
318 1.1 mycroft goto nfsmout; \
319 1.1 mycroft }
320 1.1 mycroft
321 1.1 mycroft #define nfsm_uiotom(p,s) \
322 1.9 fvdl if ((t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) != 0) { \
323 1.9 fvdl error = t1; \
324 1.1 mycroft m_freem(mreq); \
325 1.1 mycroft goto nfsmout; \
326 1.1 mycroft }
327 1.1 mycroft
328 1.26 drochner #define nfsm_reqhead(n,a,s) \
329 1.26 drochner mb = mreq = nfsm_reqh((n),(a),(s),&bpos)
330 1.1 mycroft
331 1.1 mycroft #define nfsm_reqdone m_freem(mrep); \
332 1.1 mycroft nfsmout:
333 1.1 mycroft
334 1.1 mycroft #define nfsm_rndup(a) (((a)+3)&(~0x3))
335 1.28 yamt #define nfsm_padlen(a) (nfsm_rndup(a) - (a))
336 1.1 mycroft
337 1.4 mycroft #define nfsm_request(v, t, p, c) \
338 1.8 christos if ((error = nfs_request((v), mreq, (t), (p), \
339 1.9 fvdl (c), &mrep, &md, &dpos)) != 0) { \
340 1.9 fvdl if (error & NFSERR_RETERR) \
341 1.9 fvdl error &= ~NFSERR_RETERR; \
342 1.9 fvdl else \
343 1.9 fvdl goto nfsmout; \
344 1.9 fvdl }
345 1.1 mycroft
346 1.1 mycroft #define nfsm_strtom(a,s,m) \
347 1.1 mycroft if ((s) > (m)) { \
348 1.1 mycroft m_freem(mreq); \
349 1.1 mycroft error = ENAMETOOLONG; \
350 1.1 mycroft goto nfsmout; \
351 1.1 mycroft } \
352 1.1 mycroft t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \
353 1.4 mycroft if (t2 <= M_TRAILINGSPACE(mb)) { \
354 1.7 cgd nfsm_build(tl,u_int32_t *,t2); \
355 1.1 mycroft *tl++ = txdr_unsigned(s); \
356 1.1 mycroft *(tl+((t2>>2)-2)) = 0; \
357 1.18 perry memcpy((caddr_t)tl, (const char *)(a), (s)); \
358 1.9 fvdl } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s))) != 0) { \
359 1.9 fvdl error = t2; \
360 1.1 mycroft m_freem(mreq); \
361 1.1 mycroft goto nfsmout; \
362 1.1 mycroft }
363 1.1 mycroft
364 1.1 mycroft #define nfsm_srvdone \
365 1.1 mycroft nfsmout: \
366 1.1 mycroft return(error)
367 1.1 mycroft
368 1.1 mycroft #define nfsm_reply(s) \
369 1.1 mycroft { \
370 1.4 mycroft nfsd->nd_repstat = error; \
371 1.9 fvdl if (error && !(nfsd->nd_flag & ND_NFSV3)) \
372 1.9 fvdl (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
373 1.4 mycroft mrq, &mb, &bpos); \
374 1.1 mycroft else \
375 1.9 fvdl (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
376 1.4 mycroft mrq, &mb, &bpos); \
377 1.10 fvdl if (mrep != NULL) { \
378 1.10 fvdl m_freem(mrep); \
379 1.10 fvdl mrep = NULL; \
380 1.10 fvdl } \
381 1.1 mycroft mreq = *mrq; \
382 1.9 fvdl if (error && (!(nfsd->nd_flag & ND_NFSV3) || \
383 1.9 fvdl error == EBADRPC)) \
384 1.1 mycroft return(0); \
385 1.1 mycroft }
386 1.1 mycroft
387 1.9 fvdl #define nfsm_writereply(s, v3) \
388 1.9 fvdl { \
389 1.9 fvdl nfsd->nd_repstat = error; \
390 1.9 fvdl if (error && !(v3)) \
391 1.9 fvdl (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
392 1.9 fvdl &mreq, &mb, &bpos); \
393 1.9 fvdl else \
394 1.9 fvdl (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
395 1.9 fvdl &mreq, &mb, &bpos); \
396 1.9 fvdl }
397 1.9 fvdl
398 1.1 mycroft #define nfsm_adv(s) \
399 1.9 fvdl { t1 = mtod(md, caddr_t)+md->m_len-dpos; \
400 1.1 mycroft if (t1 >= (s)) { \
401 1.1 mycroft dpos += (s); \
402 1.9 fvdl } else if ((t1 = nfs_adv(&md, &dpos, (s), t1)) != 0) { \
403 1.9 fvdl error = t1; \
404 1.1 mycroft m_freem(mrep); \
405 1.1 mycroft goto nfsmout; \
406 1.9 fvdl } }
407 1.1 mycroft
408 1.1 mycroft #define nfsm_srvmtofh(f) \
409 1.16 fvdl { int fhlen = NFSX_V3FH; \
410 1.16 fvdl if (nfsd->nd_flag & ND_NFSV3) { \
411 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
412 1.16 fvdl fhlen = fxdr_unsigned(int, *tl); \
413 1.16 fvdl if (fhlen == 0) { \
414 1.18 perry memset((caddr_t)(f), 0, NFSX_V3FH); \
415 1.16 fvdl } else if (fhlen != NFSX_V3FH) { \
416 1.9 fvdl error = EBADRPC; \
417 1.9 fvdl nfsm_reply(0); \
418 1.9 fvdl } \
419 1.9 fvdl } \
420 1.16 fvdl if (fhlen != 0) { \
421 1.16 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_V3FH); \
422 1.18 perry memcpy( (caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \
423 1.16 fvdl if ((nfsd->nd_flag & ND_NFSV3) == 0) \
424 1.16 fvdl nfsm_adv(NFSX_V2FH - NFSX_V3FH); \
425 1.16 fvdl } \
426 1.16 fvdl }
427 1.1 mycroft
428 1.1 mycroft #define nfsm_clget \
429 1.1 mycroft if (bp >= be) { \
430 1.4 mycroft if (mp == mb) \
431 1.4 mycroft mp->m_len += bp-bpos; \
432 1.23 matt mp = m_get(M_WAIT, MT_DATA); \
433 1.24 matt MCLAIM(mp, &nfs_mowner); \
434 1.23 matt m_clget(mp, M_WAIT); \
435 1.1 mycroft mp->m_len = NFSMSIZ(mp); \
436 1.4 mycroft mp2->m_next = mp; \
437 1.4 mycroft mp2 = mp; \
438 1.1 mycroft bp = mtod(mp, caddr_t); \
439 1.1 mycroft be = bp+mp->m_len; \
440 1.1 mycroft } \
441 1.7 cgd tl = (u_int32_t *)bp
442 1.1 mycroft
443 1.9 fvdl #define nfsm_srvfillattr(a, f) \
444 1.9 fvdl nfsm_srvfattr(nfsd, (a), (f))
445 1.9 fvdl
446 1.9 fvdl #define nfsm_srvwcc_data(br, b, ar, a) \
447 1.9 fvdl nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos)
448 1.9 fvdl
449 1.9 fvdl #define nfsm_srvpostop_attr(r, a) \
450 1.9 fvdl nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos)
451 1.9 fvdl
452 1.9 fvdl #define nfsm_srvsattr(a) \
453 1.9 fvdl { nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
454 1.9 fvdl if (*tl == nfs_true) { \
455 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
456 1.9 fvdl (a)->va_mode = nfstov_mode(*tl); \
457 1.9 fvdl } \
458 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
459 1.9 fvdl if (*tl == nfs_true) { \
460 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
461 1.9 fvdl (a)->va_uid = fxdr_unsigned(uid_t, *tl); \
462 1.9 fvdl } \
463 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
464 1.9 fvdl if (*tl == nfs_true) { \
465 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
466 1.9 fvdl (a)->va_gid = fxdr_unsigned(gid_t, *tl); \
467 1.9 fvdl } \
468 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
469 1.9 fvdl if (*tl == nfs_true) { \
470 1.9 fvdl nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
471 1.19 fair (a)->va_size = fxdr_hyper(tl); \
472 1.9 fvdl } \
473 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
474 1.9 fvdl switch (fxdr_unsigned(int, *tl)) { \
475 1.9 fvdl case NFSV3SATTRTIME_TOCLIENT: \
476 1.9 fvdl nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
477 1.9 fvdl fxdr_nfsv3time(tl, &(a)->va_atime); \
478 1.9 fvdl break; \
479 1.9 fvdl case NFSV3SATTRTIME_TOSERVER: \
480 1.9 fvdl (a)->va_atime.tv_sec = time.tv_sec; \
481 1.9 fvdl (a)->va_atime.tv_nsec = time.tv_usec * 1000; \
482 1.21 wrstuden (a)->va_vaflags |= VA_UTIMES_NULL; \
483 1.9 fvdl break; \
484 1.9 fvdl }; \
485 1.9 fvdl nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
486 1.9 fvdl switch (fxdr_unsigned(int, *tl)) { \
487 1.9 fvdl case NFSV3SATTRTIME_TOCLIENT: \
488 1.9 fvdl nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
489 1.9 fvdl fxdr_nfsv3time(tl, &(a)->va_mtime); \
490 1.21 wrstuden (a)->va_vaflags &= ~VA_UTIMES_NULL; \
491 1.9 fvdl break; \
492 1.9 fvdl case NFSV3SATTRTIME_TOSERVER: \
493 1.9 fvdl (a)->va_mtime.tv_sec = time.tv_sec; \
494 1.9 fvdl (a)->va_mtime.tv_nsec = time.tv_usec * 1000; \
495 1.21 wrstuden (a)->va_vaflags |= VA_UTIMES_NULL; \
496 1.9 fvdl break; \
497 1.9 fvdl }; }
498 1.1 mycroft
499 1.9 fvdl #endif
500