]> git.saurik.com Git - apple/xnu.git/blame - bsd/nfs/nfsm_subs.h
xnu-792.10.96.tar.gz
[apple/xnu.git] / bsd / nfs / nfsm_subs.h
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
1c79356b 11 *
37839358
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
23/*
24 * Copyright (c) 1989, 1993
25 * The Regents of the University of California. All rights reserved.
26 *
27 * This code is derived from software contributed to Berkeley by
28 * Rick Macklem at The University of Guelph.
29 *
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
32 * are met:
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95
59 * FreeBSD-Id: nfsm_subs.h,v 1.13 1997/07/16 09:06:30 dfr Exp $
60 */
61
62
63#ifndef _NFS_NFSM_SUBS_H_
64#define _NFS_NFSM_SUBS_H_
65
9bccf70c 66#include <sys/appleapiopts.h>
1c79356b 67
9bccf70c 68#ifdef __APPLE_API_PRIVATE
1c79356b
A
69/*
70 * These macros do strange and peculiar things to mbuf chains for
71 * the assistance of the nfs code. To attempt to use them for any
72 * other purpose will be dangerous. (they make weird assumptions)
73 */
74
75/*
76 * First define what the actual subs. return
77 */
91447636
A
78int nfsm_reqh(int hsiz, caddr_t *bposp, mbuf_t *mbp);
79int nfsm_rpchead(struct ucred *cr, int nmflag, int procid,
1c79356b
A
80 int auth_type, int auth_len, char *auth_str,
81 int verf_len, char *verf_str,
91447636
A
82 mbuf_t mrest, int mrest_len,
83 mbuf_t *mbp, u_long *xidp, mbuf_t *mreqp);
1c79356b
A
84
85/*
86 * Now for the macros that do the simple stuff and call the functions
87 * for the hard stuff.
88 * These macros use several vars. declared in nfsm_reqhead and these
89 * vars. must not be used elsewhere unless you are careful not to corrupt
90 * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
91 * that may be used so long as the value is not expected to retained
92 * after a macro.
93 * I know, this is kind of dorkey, but it makes the actual op functions
94 * fairly clean and deals with the mess caused by the xdr discriminating
95 * unions.
96 */
97
98#define nfsm_build(a,c,s) \
91447636
A
99 { if ((s) > mbuf_trailingspace(mb)) { \
100 int __nfsm_error; \
101 __nfsm_error = mbuf_get(MBUF_WAITOK, MBUF_TYPE_DATA, &mb2); \
102 if (__nfsm_error) \
103 panic("nfsm_build mbuf_get error %d", __nfsm_error); \
104 if ((s) > mbuf_maxlen(mb2)) \
105 panic("nfsm_build size error"); \
106 __nfsm_error = mbuf_setnext(mb, mb2); \
107 if (__nfsm_error) \
108 panic("nfsm_build mbuf_setnext error %d", __nfsm_error); \
1c79356b 109 mb = mb2; \
91447636 110 bpos = mbuf_data(mb); \
1c79356b
A
111 } \
112 (a) = (c)(bpos); \
91447636 113 mbuf_setlen(mb, (mbuf_len(mb) + (s))); \
1c79356b
A
114 bpos += (s); }
115
116#define nfsm_dissect(a, c, s) \
91447636 117 { t1 = ((caddr_t)mbuf_data(md)) + mbuf_len(md) - dpos; \
1c79356b
A
118 if (t1 >= (s)) { \
119 (a) = (c)(dpos); \
120 dpos += (s); \
121 } else if ((t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2))) { \
122 error = t1; \
91447636 123 mbuf_freem(mrep); \
1c79356b
A
124 goto nfsmout; \
125 } else { \
126 (a) = (c)cp2; \
127 } }
128
129#define nfsm_fhtom(v, v3) \
130 { if (v3) { \
131 t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \
91447636 132 if (t2 <= mbuf_trailingspace(mb)) { \
1c79356b
A
133 nfsm_build(tl, u_long *, t2); \
134 *tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \
135 *(tl + ((t2>>2) - 2)) = 0; \
136 bcopy((caddr_t)VTONFS(v)->n_fhp,(caddr_t)tl, \
137 VTONFS(v)->n_fhsize); \
138 } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, \
139 (caddr_t)VTONFS(v)->n_fhp, VTONFS(v)->n_fhsize))) { \
140 error = t2; \
91447636 141 mbuf_freem(mreq); \
1c79356b
A
142 goto nfsmout; \
143 } \
144 } else { \
145 nfsm_build(cp, caddr_t, NFSX_V2FH); \
146 bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \
147 } }
148
149#define nfsm_srvfhtom(f, v3) \
150 { if (v3) { \
91447636
A
151 nfsm_build(tl, u_long *, NFSX_UNSIGNED + (unsigned)(f)->nfh_len); \
152 *tl++ = txdr_unsigned((f)->nfh_len); \
153 bcopy((caddr_t)&(f)->nfh_xh, (caddr_t)tl, (f)->nfh_len); \
1c79356b
A
154 } else { \
155 nfsm_build(cp, caddr_t, NFSX_V2FH); \
91447636 156 bcopy((caddr_t)&(f)->nfh_xh, cp, NFSX_V2FH); \
1c79356b
A
157 } }
158
159#define nfsm_srvpostop_fh(f) \
91447636 160 { nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED + (unsigned)(f)->nfh_len); \
1c79356b 161 *tl++ = nfs_true; \
91447636
A
162 *tl++ = txdr_unsigned((f)->nfh_len); \
163 bcopy((caddr_t)&(f)->nfh_xh, (caddr_t)tl, (f)->nfh_len); \
1c79356b
A
164 }
165
91447636
A
166#define nfsm_mtofh(d, cnp, v, v3, xp, f) \
167 { \
168 struct nfsnode *ttnp; u_char *ttfhp = NULL; \
169 int ttfhsize = 0, ttgotfh = 1, ttgotattr = 1, ttgotnode = 0; \
170 struct nfs_vattr ttvattr; \
171 (v) = NULL; \
172 /* XXX would be nice to not bail to nfsmout on error */ \
173 if (v3) { /* check for file handle */ \
1c79356b 174 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
91447636
A
175 ttgotfh = fxdr_unsigned(int, *tl); \
176 } \
177 if (ttgotfh) { \
178 /* get file handle */ \
1c79356b 179 nfsm_getfh(ttfhp, ttfhsize, (v3)); \
1c79356b 180 } \
91447636 181 if (v3) { /* check for attributes */ \
1c79356b 182 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
91447636
A
183 ttgotattr = fxdr_unsigned(int, *tl); \
184 } \
185 /* get attributes */ \
186 if (ttgotattr) { \
187 if (!ttgotfh) { \
1c79356b 188 nfsm_adv(NFSX_V3FATTR); \
91447636
A
189 } else { \
190 nfsm_attr_get(v3, &ttvattr); \
191 } \
192 } else if (ttgotfh) { \
193 /* We need valid attributes in order */ \
194 /* to call nfs_nget/vnode_create(). */ \
195 t1 = nfs_getattr_no_vnode(vnode_mount(d), \
196 ttfhp, ttfhsize, cred, p, &ttvattr, xp); \
197 if (t1) \
198 ttgotattr = 0; \
199 } \
200 if (ttgotfh && ttgotattr) { \
201 int ttngflags = NG_MAKEENTRY; \
202 if ((t1 = nfs_nget(vnode_mount(d), d, cnp, ttfhp, ttfhsize, \
203 &ttvattr, xp, ttngflags, &ttnp))) { \
204 error = t1; \
205 ttgotnode = 0; \
206 } else { \
207 ttgotnode = 1; \
208 (v) = NFSTOV(ttnp); \
209 } \
1c79356b 210 } \
91447636 211 (f) = ttgotnode; \
1c79356b
A
212 }
213
214#define nfsm_getfh(f, s, v3) \
215 { if (v3) { \
216 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
217 if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \
218 (s) > NFSX_V3FHMAX) { \
91447636 219 mbuf_freem(mrep); \
1c79356b
A
220 error = EBADRPC; \
221 goto nfsmout; \
222 } \
91447636 223 } else { \
1c79356b 224 (s) = NFSX_V2FH; \
91447636
A
225 } \
226 nfsm_dissect((f), u_char *, nfsm_rndup(s)); }
1c79356b 227
91447636
A
228#define nfsm_loadattr(v, v3, a, x) \
229 { struct nfs_vattr ttvattr; \
230 if ((t1 = nfs_parsefattr(&md, &dpos, v3, &ttvattr))) { \
1c79356b 231 error = t1; \
91447636 232 mbuf_freem(mrep); \
1c79356b
A
233 goto nfsmout; \
234 } \
91447636
A
235 if ((t1 = nfs_loadattrcache(VTONFS(v), &ttvattr, (x), 0))) { \
236 error = t1; \
237 mbuf_freem(mrep); \
238 goto nfsmout; \
239 } \
240 if (a) { \
241 bcopy(&ttvattr, (a), sizeof(ttvattr)); \
242 } \
243 }
1c79356b 244
91447636
A
245#define nfsm_attr_get(v3, vap) \
246 { \
247 if ((t1 = nfs_parsefattr(&md, &dpos, v3, vap))) { \
248 error = t1; \
249 mbuf_freem(mrep); \
250 goto nfsmout; \
251 } \
252 }
253
254#define nfsm_postop_attr_get(v3, f, vap) \
255 { \
1c79356b
A
256 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
257 if (((f) = fxdr_unsigned(int, *tl))) { \
91447636 258 if ((t1 = nfs_parsefattr(&md, &dpos, v3, vap))) { \
1c79356b
A
259 error = t1; \
260 (f) = 0; \
91447636
A
261 mbuf_freem(mrep); \
262 goto nfsmout; \
263 } \
264 } }
265
266#define nfsm_postop_attr_update(v, v3, f, x) \
267 { \
268 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
269 if (((f) = fxdr_unsigned(int, *tl))) { \
270 struct nfs_vattr ttvattr; \
271 if ((t1 = nfs_parsefattr(&md, &dpos, v3, &ttvattr))) { \
272 error = t1; \
273 (f) = 0; \
274 mbuf_freem(mrep); \
275 goto nfsmout; \
276 } \
277 if ((t1 = nfs_loadattrcache(VTONFS(v), &ttvattr, (x), 1))) { \
278 error = t1; \
279 (f) = 0; \
280 mbuf_freem(mrep); \
1c79356b
A
281 goto nfsmout; \
282 } \
fa4905b1
A
283 if (*(x) == 0) \
284 (f) = 0; \
1c79356b
A
285 } }
286
483a1d10
A
287#define nfsm_wcc_data(v, premtime, newpostattr, x) \
288 { \
1c79356b
A
289 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
290 if (*tl == nfs_true) { \
291 nfsm_dissect(tl, u_long *, 6 * NFSX_UNSIGNED); \
91447636
A
292 (premtime)->tv_sec = fxdr_unsigned(time_t, *(tl + 2)); \
293 (premtime)->tv_nsec = fxdr_unsigned(time_t, *(tl + 3)); \
1c79356b 294 } else { \
91447636
A
295 (premtime)->tv_sec = 0; \
296 (premtime)->tv_nsec = 0; \
483a1d10 297 } \
91447636 298 nfsm_postop_attr_update((v), 1, (newpostattr), (x)); \
483a1d10 299 }
1c79356b 300
91447636
A
301#define nfsm_v3sattr(vap) \
302 {\
303 struct timeval now; \
304 if (VATTR_IS_ACTIVE(vap, va_mode)) { \
305 nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED); \
306 *tl++ = nfs_true; \
307 *tl = txdr_unsigned(vap->va_mode); \
308 } else { \
309 nfsm_build(tl, u_long *, NFSX_UNSIGNED); \
310 *tl = nfs_false; \
311 } \
312 if (VATTR_IS_ACTIVE(vap, va_uid)) { \
313 nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED); \
314 *tl++ = nfs_true; \
315 *tl = txdr_unsigned(vap->va_uid); \
316 } else { \
317 nfsm_build(tl, u_long *, NFSX_UNSIGNED); \
318 *tl = nfs_false; \
319 } \
320 if (VATTR_IS_ACTIVE(vap, va_gid)) { \
321 nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED); \
322 *tl++ = nfs_true; \
323 *tl = txdr_unsigned(vap->va_gid); \
324 } else { \
325 nfsm_build(tl, u_long *, NFSX_UNSIGNED); \
326 *tl = nfs_false; \
327 } \
328 if (VATTR_IS_ACTIVE(vap, va_data_size)) { \
329 nfsm_build(tl, u_long *, 3 * NFSX_UNSIGNED); \
330 *tl++ = nfs_true; \
331 txdr_hyper(&vap->va_data_size, tl); \
332 } else { \
333 nfsm_build(tl, u_long *, NFSX_UNSIGNED); \
334 *tl = nfs_false; \
335 } \
336 microtime(&now); \
337 if (VATTR_IS_ACTIVE(vap, va_access_time)) { \
338 if (vap->va_access_time.tv_sec != now.tv_sec) { \
339 nfsm_build(tl, u_long *, 3 * NFSX_UNSIGNED); \
340 *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
341 txdr_nfsv3time(&vap->va_access_time, tl); \
342 } else { \
343 nfsm_build(tl, u_long *, NFSX_UNSIGNED); \
344 *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
345 } \
346 } else { \
347 nfsm_build(tl, u_long *, NFSX_UNSIGNED); \
348 *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \
349 } \
350 if (VATTR_IS_ACTIVE(vap, va_modify_time)) { \
351 if (vap->va_modify_time.tv_sec != now.tv_sec) { \
352 nfsm_build(tl, u_long *, 3 * NFSX_UNSIGNED); \
353 *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
354 txdr_nfsv3time(&vap->va_modify_time, tl); \
355 } else { \
356 nfsm_build(tl, u_long *, NFSX_UNSIGNED); \
357 *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
358 } \
359 } else { \
360 nfsm_build(tl, u_long *, NFSX_UNSIGNED); \
361 *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \
362 } \
1c79356b
A
363 }
364
91447636 365#define nfsm_strsiz(s,m,v3) \
1c79356b 366 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \
91447636
A
367 (s) = fxdr_unsigned(long,*tl); \
368 if (!(v3) && ((s) > (m))) { \
369 mbuf_freem(mrep); \
1c79356b
A
370 error = EBADRPC; \
371 goto nfsmout; \
372 } }
373
374#define nfsm_srvstrsiz(s,m) \
375 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \
376 if (((s) = fxdr_unsigned(long,*tl)) > (m) || (s) <= 0) { \
377 error = EBADRPC; \
378 nfsm_reply(0); \
379 } }
380
91447636 381#define nfsm_srvnamesiz(s,v3) \
1c79356b 382 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \
91447636
A
383 (s) = fxdr_unsigned(long,*tl); \
384 if (!(v3) && ((s) > NFS_MAXNAMLEN)) \
1c79356b
A
385 error = NFSERR_NAMETOL; \
386 if ((s) <= 0) \
387 error = EBADRPC; \
388 if (error) \
389 nfsm_reply(0); \
390 }
391
392#define nfsm_mtouio(p,s) \
393 if ((s) > 0 && \
394 (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos))) { \
395 error = t1; \
91447636 396 mbuf_freem(mrep); \
1c79356b
A
397 goto nfsmout; \
398 }
399
400#define nfsm_uiotom(p,s) \
401 if ((t1 = nfsm_uiotombuf((p),&mb,(s),&bpos))) { \
402 error = t1; \
91447636 403 mbuf_freem(mreq); \
1c79356b
A
404 goto nfsmout; \
405 }
406
91447636
A
407#define nfsm_reqhead(s) \
408 error = nfsm_reqh((s), &bpos, &mreq); \
409 mb = mreq;
1c79356b 410
91447636 411#define nfsm_reqdone mbuf_freem(mrep); \
1c79356b
A
412 nfsmout:
413
414#define nfsm_rndup(a) (((a)+3)&(~0x3))
415
fa4905b1 416#define nfsm_request(v, t, p, c, x) \
91447636 417 if ((error = nfs_request((v), vnode_mount(v), mreq, (t), (p), \
fa4905b1 418 (c), &mrep, &md, &dpos, (x)))) { \
1c79356b
A
419 if (error & NFSERR_RETERR) \
420 error &= ~NFSERR_RETERR; \
421 else \
422 goto nfsmout; \
1c79356b
A
423 }
424
91447636
A
425#define nfsm_strtom(a,s,m,v3) \
426 if (!(v3) && ((s) > (m))) { \
427 mbuf_freem(mreq); \
1c79356b
A
428 error = ENAMETOOLONG; \
429 goto nfsmout; \
430 } \
431 t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \
91447636 432 if (t2 <= mbuf_trailingspace(mb)) { \
1c79356b
A
433 nfsm_build(tl,u_long *,t2); \
434 *tl++ = txdr_unsigned(s); \
435 *(tl+((t2>>2)-2)) = 0; \
436 bcopy((caddr_t)(a), (caddr_t)tl, (s)); \
437 } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s)))) { \
438 error = t2; \
91447636 439 mbuf_freem(mreq); \
1c79356b
A
440 goto nfsmout; \
441 }
442
443#define nfsm_srvdone \
444 nfsmout: \
445 return(error)
446
447#define nfsm_reply(s) \
448 { \
449 nfsd->nd_repstat = error; \
450 if (error && !(nfsd->nd_flag & ND_NFSV3)) \
91447636 451 nfs_rephead(0, nfsd, slp, error, mrq, &mb, &bpos); \
1c79356b 452 else \
91447636
A
453 nfs_rephead((s), nfsd, slp, error, mrq, &mb, &bpos); \
454 mbuf_freem(mrep); \
e5568f75 455 mrep = NULL; \
1c79356b
A
456 mreq = *mrq; \
457 if (error && (!(nfsd->nd_flag & ND_NFSV3) || \
91447636
A
458 error == EBADRPC)) { \
459 error = 0; \
460 goto nfsmout; \
461 } \
1c79356b
A
462 }
463
464#define nfsm_writereply(s, v3) \
465 { \
466 nfsd->nd_repstat = error; \
467 if (error && !(v3)) \
91447636 468 nfs_rephead(0, nfsd, slp, error, &mreq, &mb, &bpos); \
1c79356b 469 else \
91447636 470 nfs_rephead((s), nfsd, slp, error, &mreq, &mb, &bpos); \
1c79356b
A
471 }
472
473#define nfsm_adv(s) \
91447636 474 { t1 = ((caddr_t)mbuf_data(md)) + mbuf_len(md) - dpos; \
1c79356b
A
475 if (t1 >= (s)) { \
476 dpos += (s); \
477 } else if ((t1 = nfs_adv(&md, &dpos, (s), t1))) { \
478 error = t1; \
91447636 479 mbuf_freem(mrep); \
1c79356b
A
480 goto nfsmout; \
481 } }
482
483#define nfsm_srvmtofh(f) \
91447636
A
484 { \
485 if (nfsd->nd_flag & ND_NFSV3) { \
1c79356b 486 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
91447636
A
487 (f)->nfh_len = fxdr_unsigned(int, *tl); \
488 if (((f)->nfh_len < (int)sizeof(struct nfs_exphandle)) || \
489 ((f)->nfh_len > NFSX_V3FHMAX)) { \
1c79356b
A
490 error = EBADRPC; \
491 nfsm_reply(0); \
492 } \
91447636
A
493 } else { \
494 (f)->nfh_len = NFSX_V2FH; \
1c79356b 495 } \
91447636
A
496 nfsm_dissect(tl, u_long *, (f)->nfh_len); \
497 bcopy((caddr_t)tl, (caddr_t)&(f)->nfh_xh, (f)->nfh_len); \
1c79356b
A
498 }
499
500#define nfsm_clget \
501 if (bp >= be) { \
91447636 502 int __nfsm_error, __nfsm_len; \
1c79356b 503 if (mp == mb) \
91447636
A
504 mbuf_setlen(mp, mbuf_len(mp) + bp - bpos); \
505 mp = NULL; \
506 __nfsm_error = mbuf_mclget(MBUF_WAITOK, MBUF_TYPE_DATA, &mp); \
507 if (__nfsm_error) \
508 panic("nfsm_clget: mbuf_mclget error %d", __nfsm_error); \
509 __nfsm_len = mbuf_maxlen(mp); \
510 mbuf_setlen(mp, __nfsm_len); \
511 __nfsm_error = mbuf_setnext(mp2, mp); \
512 if (__nfsm_error) \
513 panic("nfsm_clget: mbuf_setnext error %d", __nfsm_error); \
1c79356b 514 mp2 = mp; \
91447636
A
515 bp = mbuf_data(mp); \
516 be = bp + __nfsm_len; \
1c79356b
A
517 } \
518 tl = (u_long *)bp
519
91447636
A
520#define nfsm_srv_vattr_init(vap, v3) \
521 { \
522 VATTR_INIT(vap); \
523 VATTR_WANTED((vap), va_type); \
524 VATTR_WANTED((vap), va_mode); \
525 VATTR_WANTED((vap), va_nlink); \
526 VATTR_WANTED((vap), va_uid); \
527 VATTR_WANTED((vap), va_gid); \
528 VATTR_WANTED((vap), va_data_size); \
529 VATTR_WANTED((vap), va_data_alloc); \
530 VATTR_WANTED((vap), va_rdev); \
531 VATTR_WANTED((vap), va_fsid); \
532 VATTR_WANTED((vap), va_fileid); \
533 VATTR_WANTED((vap), va_access_time); \
534 VATTR_WANTED((vap), va_modify_time); \
535 VATTR_WANTED((vap), va_change_time); \
536 if (!v3) VATTR_WANTED((vap), va_iosize); \
537 }
538
539#define nfsm_srv_pre_vattr_init(vap, v3) \
540 { \
541 VATTR_INIT(vap); \
542 VATTR_WANTED((vap), va_data_size); \
543 VATTR_WANTED((vap), va_modify_time); \
544 VATTR_WANTED((vap), va_change_time); \
545 }
546
1c79356b
A
547#define nfsm_srvfillattr(a, f) \
548 nfsm_srvfattr(nfsd, (a), (f))
549
550#define nfsm_srvwcc_data(br, b, ar, a) \
551 nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos)
552
553#define nfsm_srvpostop_attr(r, a) \
554 nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos)
555
556#define nfsm_srvsattr(a) \
55e303ae 557 { \
91447636 558 struct timespec now; \
55e303ae 559 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
1c79356b
A
560 if (*tl == nfs_true) { \
561 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
91447636 562 VATTR_SET(a, va_mode, nfstov_mode(*tl)); \
1c79356b
A
563 } \
564 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
565 if (*tl == nfs_true) { \
566 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
91447636 567 VATTR_SET(a, va_uid, fxdr_unsigned(uid_t, *tl)); \
1c79356b
A
568 } \
569 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
570 if (*tl == nfs_true) { \
571 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
91447636 572 VATTR_SET(a, va_gid, fxdr_unsigned(gid_t, *tl)); \
1c79356b
A
573 } \
574 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
575 if (*tl == nfs_true) { \
576 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
91447636
A
577 fxdr_hyper(tl, &(a)->va_data_size); \
578 VATTR_SET_ACTIVE(a, va_data_size); \
1c79356b
A
579 } \
580 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
91447636 581 nanotime(&now); \
1c79356b
A
582 switch (fxdr_unsigned(int, *tl)) { \
583 case NFSV3SATTRTIME_TOCLIENT: \
584 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
91447636
A
585 fxdr_nfsv3time(tl, &(a)->va_access_time); \
586 VATTR_SET_ACTIVE(a, va_access_time); \
1c79356b
A
587 break; \
588 case NFSV3SATTRTIME_TOSERVER: \
91447636 589 VATTR_SET(a, va_access_time, now); \
1c79356b
A
590 break; \
591 }; \
592 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
593 switch (fxdr_unsigned(int, *tl)) { \
594 case NFSV3SATTRTIME_TOCLIENT: \
595 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
91447636
A
596 fxdr_nfsv3time(tl, &(a)->va_modify_time); \
597 VATTR_SET_ACTIVE(a, va_modify_time); \
1c79356b
A
598 break; \
599 case NFSV3SATTRTIME_TOSERVER: \
91447636 600 VATTR_SET(a, va_modify_time, now); \
1c79356b
A
601 break; \
602 }; }
603
9bccf70c
A
604#endif /* __APPLE_API_PRIVATE */
605#endif /* _NFS_NFSM_SUBS_H_ */