]>
git.saurik.com Git - apple/xnu.git/blob - bsd/nfs/nfsm_subs.h
2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30 * Copyright (c) 1989, 1993
31 * The Regents of the University of California. All rights reserved.
33 * This code is derived from software contributed to Berkeley by
34 * Rick Macklem at The University of Guelph.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95
65 * FreeBSD-Id: nfsm_subs.h,v 1.13 1997/07/16 09:06:30 dfr Exp $
69 #ifndef _NFS_NFSM_SUBS_H_
70 #define _NFS_NFSM_SUBS_H_
72 #include <sys/appleapiopts.h>
74 #ifdef __APPLE_API_PRIVATE
76 int nfsm_rpchead(struct nfsreq
*, int, mbuf_t
, u_int64_t
*, mbuf_t
*);
77 int nfsm_rpchead2(int, int, int, int, int, int, kauth_cred_t
, struct nfsreq
*, mbuf_t
, u_int64_t
*, mbuf_t
*);
79 int nfsm_chain_new_mbuf(struct nfsm_chain
*, size_t);
80 int nfsm_chain_add_opaque_f(struct nfsm_chain
*, const u_char
*, uint32_t);
81 int nfsm_chain_add_opaque_nopad_f(struct nfsm_chain
*, const u_char
*, uint32_t);
82 int nfsm_chain_add_uio(struct nfsm_chain
*, struct uio
*, uint32_t);
83 int nfsm_chain_add_fattr4_f(struct nfsm_chain
*, struct vnode_attr
*, struct nfsmount
*);
84 int nfsm_chain_add_v2sattr_f(struct nfsm_chain
*, struct vnode_attr
*, uint32_t);
85 int nfsm_chain_add_v3sattr_f(struct nfsm_chain
*, struct vnode_attr
*);
87 int nfsm_chain_advance(struct nfsm_chain
*, uint32_t);
88 int nfsm_chain_offset(struct nfsm_chain
*);
89 int nfsm_chain_reverse(struct nfsm_chain
*, uint32_t);
90 int nfsm_chain_get_opaque_pointer_f(struct nfsm_chain
*, uint32_t, u_char
**);
91 int nfsm_chain_get_opaque_f(struct nfsm_chain
*, uint32_t, u_char
*);
92 int nfsm_chain_get_uio(struct nfsm_chain
*, uint32_t, struct uio
*);
93 int nfsm_chain_get_fh_attr(struct nfsm_chain
*, nfsnode_t
,
94 vfs_context_t
, int, uint64_t *, fhandle_t
*, struct nfs_vattr
*);
95 int nfsm_chain_get_wcc_data_f(struct nfsm_chain
*, nfsnode_t
, struct timespec
*, int *, u_int64_t
*);
98 void nfsm_adj(mbuf_t
, int, int);
99 int nfsm_mbuf_get_list(size_t, mbuf_t
*, int *);
101 int nfsm_chain_add_fattr(struct nfsrv_descript
*, struct nfsm_chain
*, struct vnode_attr
*);
102 int nfsm_chain_add_wcc_data_f(struct nfsrv_descript
*, struct nfsm_chain
*, int,
103 struct vnode_attr
*, int, struct vnode_attr
*);
104 int nfsm_chain_get_path_namei(struct nfsm_chain
*, uint32_t, struct nameidata
*);
105 int nfsm_chain_get_sattr(struct nfsrv_descript
*, struct nfsm_chain
*, struct vnode_attr
*);
106 int nfsm_chain_trim_data(struct nfsm_chain
*, int, int *);
107 #endif /* NFSSERVER */
109 /* check name length */
110 #define nfsm_name_len_check(E, ND, LEN) \
113 if (((ND)->nd_vers == NFS_VER2) && ((LEN) > NFS_MAXNAMLEN)) \
114 (E) = NFSERR_NAMETOL; \
119 #define nfsm_assert(E, COND, ERR) \
126 /* Initialize a vnode_attr to retrieve attributes for the NFS server. */
127 #define nfsm_srv_vattr_init(VAP, VERS) \
130 VATTR_WANTED((VAP), va_type); \
131 VATTR_WANTED((VAP), va_mode); \
132 VATTR_WANTED((VAP), va_nlink); \
133 VATTR_WANTED((VAP), va_uid); \
134 VATTR_WANTED((VAP), va_gid); \
135 VATTR_WANTED((VAP), va_data_size); \
136 VATTR_WANTED((VAP), va_data_alloc); \
137 VATTR_WANTED((VAP), va_rdev); \
138 VATTR_WANTED((VAP), va_fsid); \
139 VATTR_WANTED((VAP), va_fileid); \
140 VATTR_WANTED((VAP), va_access_time); \
141 VATTR_WANTED((VAP), va_modify_time); \
142 VATTR_WANTED((VAP), va_change_time); \
143 if ((VERS) == NFS_VER2) \
144 VATTR_WANTED((VAP), va_iosize); \
147 /* Initialize a vnode_attr to retrieve pre-operation attributes for the NFS server. */
148 #define nfsm_srv_pre_vattr_init(VAP) \
151 VATTR_WANTED((VAP), va_data_size); \
152 VATTR_WANTED((VAP), va_modify_time); \
153 VATTR_WANTED((VAP), va_change_time); \
156 /* round up to a multiple of 4 */
157 #define nfsm_rndup(a) (((a)+3)&(~0x3))
159 #define nfsm_pad(a) (nfsm_rndup(a) - (a))
162 * control flow macros:
163 * go to the appropriate label on condition
165 #define nfsmout_if(E) do { if (E) goto nfsmout; } while (0)
166 #define nfsmerr_if(E) do { if (E) goto nfsmerr; } while (0)
169 * For NFS v2 errors and EBADRPC, the reply contains only the error.
170 * This macro is used to skip any reply building code and go straight
171 * to nfsmout instead.
173 #define nfsmout_on_status(ND, E) \
175 if (((ND)->nd_repstat == EBADRPC) || \
176 ((ND)->nd_repstat && ((ND)->nd_vers == NFS_VER2))) { \
182 /* initialize an mbuf chain */
183 #define nfsm_chain_null(NMC) \
185 (NMC)->nmc_mhead = (NMC)->nmc_mcur = NULL; \
186 (NMC)->nmc_ptr = NULL; \
189 /* cleanup an mbuf chain */
190 #define nfsm_chain_cleanup(NMC) \
192 if (!(NMC)->nmc_mhead) break; \
193 mbuf_freem((NMC)->nmc_mhead); \
194 nfsm_chain_null(NMC); \
197 /* get an mbuf given a size hint */
198 #define nfsm_mbuf_get(E, MBP, SIZEHINT) \
201 if ((size_t)(SIZEHINT) >= nfs_mbuf_minclsize) \
202 (E) = mbuf_mclget(MBUF_WAITOK, MBUF_TYPE_DATA, (MBP)); \
204 (E) = mbuf_get(MBUF_WAITOK, MBUF_TYPE_DATA, (MBP)); \
209 * macros for building NFS mbuf chains
212 /* prepare an mbuf chain for building starting with the given mbuf */
213 #define nfsm_chain_init(NMC, MB) \
215 (NMC)->nmc_mhead = (MB); \
216 (NMC)->nmc_mcur = (NMC)->nmc_mhead; \
217 (NMC)->nmc_ptr = mbuf_data((NMC)->nmc_mcur); \
218 (NMC)->nmc_left = mbuf_trailingspace((NMC)->nmc_mcur); \
219 (NMC)->nmc_flags = 0; \
222 /* prepare an mbuf chain for building starting with a newly allocated mbuf */
223 #define nfsm_chain_build_alloc_init(E, NMC, SIZEHINT) \
226 nfsm_mbuf_get((E), &ncbimb, (SIZEHINT)); \
228 nfsm_chain_init((NMC), ncbimb); \
231 /* done building an mbuf chain */
232 #define nfsm_chain_build_done(E, NMC) \
234 if ((E) || !(NMC)->nmc_mcur) break; \
235 /* cap off current mbuf */ \
236 mbuf_setlen((NMC)->nmc_mcur, \
237 (NMC)->nmc_ptr - (caddr_t)mbuf_data((NMC)->nmc_mcur)); \
241 * set the TCP record mark at the head of an mbuf chain -
242 * assumes 4 bytes are already allocated in the head mbuf
244 #define nfsm_chain_set_recmark(E, NMC, VAL) \
247 *((uint32_t*)mbuf_data((NMC)->nmc_mhead)) \
248 = txdr_unsigned(VAL); \
251 /* make sure there's room for size bytes in current mbuf */
252 #define nfsm_chain_check_size(E, NMC, SIZE) \
255 if ((NMC)->nmc_left < (SIZE)) { \
256 (E) = nfsm_chain_new_mbuf((NMC), (SIZE)); \
257 if (!(E) && ((NMC)->nmc_left < (SIZE))) \
262 /* add a 32bit value to an mbuf chain extending if necessary */
263 #define nfsm_chain_add_32(E, NMC, VAL) \
265 nfsm_chain_check_size((E), (NMC), NFSX_UNSIGNED); \
267 *((uint32_t*)(NMC)->nmc_ptr) = txdr_unsigned(VAL); \
268 (NMC)->nmc_ptr += NFSX_UNSIGNED; \
269 (NMC)->nmc_left -= NFSX_UNSIGNED; \
272 /* add a 64bit value to an mbuf chain */
273 #define nfsm_chain_add_64(E, NMC, VAL) \
276 nfsm_chain_check_size((E), (NMC), 2 * NFSX_UNSIGNED); \
279 txdr_hyper(&__tmp64, (NMC)->nmc_ptr); \
280 (NMC)->nmc_ptr += 2 * NFSX_UNSIGNED; \
281 (NMC)->nmc_left -= 2 * NFSX_UNSIGNED; \
284 /* zero the last 4 bytes for a range of opaque */
285 /* data to make sure any pad bytes will be zero. */
286 #define nfsm_chain_zero_opaque_pad(BUF, LEN) \
287 *(((uint32_t*)(BUF))+((nfsm_rndup(LEN)>>2)-1)) = 0
289 /* add buffer of opaque data to an mbuf chain */
290 #define nfsm_chain_add_opaque(E, NMC, BUF, LEN) \
292 uint32_t rndlen = nfsm_rndup(LEN); \
294 if ((NMC)->nmc_left < rndlen) { \
295 (E) = nfsm_chain_add_opaque_f((NMC), (const u_char*)(BUF), (LEN)); \
298 nfsm_chain_zero_opaque_pad((NMC)->nmc_ptr, (LEN)); \
299 bcopy((BUF), (NMC)->nmc_ptr, (LEN)); \
300 (NMC)->nmc_ptr += rndlen; \
301 (NMC)->nmc_left -= rndlen; \
304 /* add buffer of opaque data to an mbuf chain without padding */
305 #define nfsm_chain_add_opaque_nopad(E, NMC, BUF, LEN) \
308 if ((NMC)->nmc_left < (uint32_t) (LEN)) { \
309 (E) = nfsm_chain_add_opaque_nopad_f((NMC), (const u_char*)(BUF), (LEN)); \
312 bcopy((BUF), (NMC)->nmc_ptr, (LEN)); \
313 (NMC)->nmc_ptr += (LEN); \
314 (NMC)->nmc_left -= (LEN); \
317 /* finish an mbuf in a chain to allow subsequent insertion */
318 #define nfsm_chain_finish_mbuf(E, NMC) \
321 mbuf_setlen((NMC)->nmc_mcur, \
322 (NMC)->nmc_ptr - (caddr_t)mbuf_data((NMC)->nmc_mcur)); \
323 (NMC)->nmc_left = 0; \
326 /* add a file handle to an mbuf chain */
327 #define nfsm_chain_add_fh(E, NMC, VERS, FHP, FHLEN) \
330 if ((VERS) != NFS_VER2) \
331 nfsm_chain_add_32((E), (NMC), (FHLEN)); \
332 nfsm_chain_add_opaque((E), (NMC), (FHP), (FHLEN)); \
335 /* add a string to an mbuf chain */
336 #define nfsm_chain_add_string(E, NMC, STR, LEN) \
338 nfsm_chain_add_32((E), (NMC), (LEN)); \
339 nfsm_chain_add_opaque((E), (NMC), (STR), (LEN)); \
342 /* add an NFSv2 time to an mbuf chain */
343 #define nfsm_chain_add_v2time(E, NMC, TVP) \
346 nfsm_chain_add_32((E), (NMC), (TVP)->tv_sec); \
347 nfsm_chain_add_32((E), (NMC), ((TVP)->tv_nsec != -1) ? \
348 ((uint32_t)(TVP)->tv_nsec / 1000) : 0xffffffff); \
350 /* no time... use -1 */ \
351 nfsm_chain_add_32((E), (NMC), -1); \
352 nfsm_chain_add_32((E), (NMC), -1); \
356 /* add an NFSv3 time to an mbuf chain */
357 #define nfsm_chain_add_v3time(E, NMC, TVP) \
359 nfsm_chain_add_32((E), (NMC), (TVP)->tv_sec); \
360 nfsm_chain_add_32((E), (NMC), (TVP)->tv_nsec); \
363 /* add an NFS v2 or v3 time to an mbuf chain */
364 #define nfsm_chain_add_time(E, NMC, VERS, TVP) \
366 if ((VERS) == NFS_VER2) { \
367 nfsm_chain_add_v2time((E), (NMC), (TVP)); \
369 nfsm_chain_add_v3time((E), (NMC), (TVP)); \
373 /* add an NFSv3 postop file handle to an mbuf chain */
374 #define nfsm_chain_add_postop_fh(E, NMC, FHP, FHLEN) \
376 nfsm_chain_add_32((E), (NMC), TRUE); \
377 nfsm_chain_add_fh((E), (NMC), NFS_VER3, (FHP), (FHLEN)); \
380 /* add NFSv3 postop attributes to an mbuf chain */
381 #define nfsm_chain_add_postop_attr(E, ND, NMC, ATTRERR, VAP) \
385 nfsm_chain_add_32((E), (NMC), FALSE); \
388 nfsm_chain_add_32((E), (NMC), TRUE); \
390 (E) = nfsm_chain_add_fattr((ND), (NMC), (VAP)); \
393 /* Add an NFSv2 "sattr" structure to an mbuf chain */
394 #define nfsm_chain_add_v2sattr(E, NMC, VAP, SZRDEV) \
397 (E) = nfsm_chain_add_v2sattr_f((NMC), (VAP), (SZRDEV)); \
400 /* Add an NFSv3 "sattr" structure to an mbuf chain */
401 #define nfsm_chain_add_v3sattr(E, NMC, VAP) \
404 (E) = nfsm_chain_add_v3sattr_f((NMC), (VAP)); \
407 /* Add an NFSv4 "fattr" structure to an mbuf chain */
408 #define nfsm_chain_add_fattr4(E, NMC, VAP, NMP) \
411 (E) = nfsm_chain_add_fattr4_f((NMC), (VAP), (NMP)); \
414 /* add NFSv3 WCC data to an mbuf chain */
415 #define nfsm_chain_add_wcc_data(E, ND, NMC, PREERR, PREVAP, POSTERR, POSTVAP) \
418 (E) = nfsm_chain_add_wcc_data_f((ND), (NMC), \
419 (PREERR), (PREVAP), (POSTERR), (POSTVAP)); \
422 /* add NFSv4 COMPOUND header */
423 #define nfsm_chain_add_compound_header(E, NMC, TAG, NUMOPS) \
425 if ((TAG) && strlen(TAG)) \
426 nfsm_chain_add_string((E), (NMC), (TAG), strlen(TAG)); \
428 nfsm_chain_add_32((E), (NMC), 0); \
429 nfsm_chain_add_32((E), (NMC), 0); /*minorversion*/ \
430 nfsm_chain_add_32((E), (NMC), (NUMOPS)); \
433 /* add NFSv4 attr bitmap */
434 #define nfsm_chain_add_bitmap(E, NMC, B, LEN) \
437 nfsm_chain_add_32((E), (NMC), (LEN)); \
438 for (__i=0; __i < (LEN); __i++) \
439 nfsm_chain_add_32((E), (NMC), (B)[__i]); \
442 /* add NFSv4 attr bitmap masked with the given mask */
443 #define nfsm_chain_add_bitmap_masked(E, NMC, B, LEN, MASK) \
446 nfsm_chain_add_32((E), (NMC), (LEN)); \
447 for (__i=0; __i < (LEN); __i++) \
448 nfsm_chain_add_32((E), (NMC), ((B)[__i] & (MASK)[__i])); \
452 * macros for dissecting NFS mbuf chains
455 /* prepare an mbuf chain for dissection starting with the given mbuf */
456 #define nfsm_chain_dissect_init(E, NMC, H) \
462 (NMC)->nmc_mcur = (NMC)->nmc_mhead = (H); \
463 (NMC)->nmc_ptr = mbuf_data(H); \
464 (NMC)->nmc_left = mbuf_len(H); \
467 /* skip a number of bytes in an mbuf chain */
468 #define nfsm_chain_adv(E, NMC, LEN) \
471 if ((NMC)->nmc_left >= (uint32_t)(LEN)) { \
472 (NMC)->nmc_left -= (LEN); \
473 (NMC)->nmc_ptr += (LEN); \
475 (E) = nfsm_chain_advance((NMC), (LEN)); \
479 /* get a 32bit value from an mbuf chain */
480 #define nfsm_chain_get_32(E, NMC, LVAL) \
482 uint32_t __tmp32, *__tmpptr; \
484 if ((NMC)->nmc_left >= NFSX_UNSIGNED) { \
485 __tmpptr = (uint32_t*)(NMC)->nmc_ptr; \
486 (NMC)->nmc_left -= NFSX_UNSIGNED; \
487 (NMC)->nmc_ptr += NFSX_UNSIGNED; \
489 __tmpptr = &__tmp32; \
490 (E) = nfsm_chain_get_opaque_f((NMC), NFSX_UNSIGNED, (u_char*)__tmpptr); \
493 (LVAL) = fxdr_unsigned(uint32_t, *__tmpptr); \
496 /* get a 64bit value from an mbuf chain */
497 #define nfsm_chain_get_64(E, NMC, LVAL) \
499 uint64_t __tmp64, *__tmpptr; \
501 if ((NMC)->nmc_left >= 2 * NFSX_UNSIGNED) { \
502 __tmpptr = (uint64_t*)(NMC)->nmc_ptr; \
503 (NMC)->nmc_left -= 2 * NFSX_UNSIGNED; \
504 (NMC)->nmc_ptr += 2 * NFSX_UNSIGNED; \
506 __tmpptr = &__tmp64; \
507 (E) = nfsm_chain_get_opaque_f((NMC), 2 * NFSX_UNSIGNED, (u_char*)__tmpptr); \
510 fxdr_hyper(__tmpptr, &(LVAL)); \
513 /* get a pointer to the next consecutive bytes in an mbuf chain */
514 #define nfsm_chain_get_opaque_pointer(E, NMC, LEN, PTR) \
517 if ((NMC)->nmc_left >= (uint32_t)(LEN)) { \
518 (PTR) = (void*)(NMC)->nmc_ptr; \
519 (NMC)->nmc_left -= nfsm_rndup(LEN); \
520 (NMC)->nmc_ptr += nfsm_rndup(LEN); \
522 (E) = nfsm_chain_get_opaque_pointer_f((NMC), (LEN), (u_char**)&(PTR)); \
526 /* copy the next consecutive bytes of opaque data from an mbuf chain */
527 #define nfsm_chain_get_opaque(E, NMC, LEN, PTR) \
530 if ((NMC)->nmc_left >= (LEN)) { \
531 u_char *__tmpptr = (u_char*)(NMC)->nmc_ptr; \
532 (NMC)->nmc_left -= nfsm_rndup(LEN); \
533 (NMC)->nmc_ptr += nfsm_rndup(LEN); \
534 bcopy(__tmpptr, (PTR), (LEN)); \
536 (E) = nfsm_chain_get_opaque_f((NMC), (LEN), (u_char*)(PTR)); \
540 /* get the size of and a pointer to a file handle in an mbuf chain */
541 #define nfsm_chain_get_fh_ptr(E, NMC, VERS, FHP, FHSIZE) \
543 if ((VERS) != NFS_VER2) \
544 nfsm_chain_get_32((E), (NMC), (FHSIZE)); \
546 (FHSIZE) = NFSX_V2FH;\
547 nfsm_chain_get_opaque_pointer((E), (NMC), (FHSIZE), (FHP));\
550 /* get the size of and data for a file handle in an mbuf chain */
551 #define nfsm_chain_get_fh(E, NMC, VERS, FHP) \
553 if ((VERS) != NFS_VER2) \
554 nfsm_chain_get_32((E), (NMC), (FHP)->fh_len); \
556 (FHP)->fh_len = NFSX_V2FH;\
557 nfsm_chain_get_opaque((E), (NMC), (uint32_t)(FHP)->fh_len, (FHP)->fh_data);\
562 /* get an NFS v2 or v3 time from an mbuf chain */
563 #define nfsm_chain_get_time(E, NMC, VERS, TSEC, TNSEC) \
565 nfsm_chain_get_32((E), (NMC), (TSEC)); \
566 nfsm_chain_get_32((E), (NMC), (TNSEC)); \
567 if ((E) || ((VERS) != NFS_VER2)) break; \
568 if ((uint32_t)(TNSEC) == 0xffffffff) \
574 /* get postop attributes from an mbuf chain */
575 #define nfsm_chain_postop_attr_get(E, NMC, F, VAP) \
578 if ((E) || !(NMC)->nmc_mhead) break; \
579 nfsm_chain_get_32((E), (NMC), (F)); \
580 if ((E) || !(F)) break; \
581 if (((E) = nfs_parsefattr((NMC), NFS_VER3, (VAP)))) \
585 /* update a node's attribute cache with postop attributes from an mbuf chain */
586 /* (F returns whether the attributes were updated or not) */
587 #define nfsm_chain_postop_attr_update_flag(E, NMC, NP, F, X) \
589 struct nfs_vattr ttvattr; \
590 nfsm_chain_postop_attr_get((E), (NMC), (F), &ttvattr); \
591 if ((E) || !(F)) break; \
592 if (((E) = nfs_loadattrcache((NP), &ttvattr, (X), 1))) { \
600 /* update a node's attribute cache with postop attributes from an mbuf chain */
601 #define nfsm_chain_postop_attr_update(E, NMC, NP, X) \
603 int __dummy_flag = 0; \
604 nfsm_chain_postop_attr_update_flag((E), (NMC), (NP), __dummy_flag, (X)); \
607 /* get and process NFSv3 WCC data from an mbuf chain */
608 #define nfsm_chain_get_wcc_data(E, NMC, NP, PREMTIME, NEWPOSTATTR, X) \
611 (E) = nfsm_chain_get_wcc_data_f((NMC), (NP), (PREMTIME), (NEWPOSTATTR), (X)); \
614 /* update a node's attribute cache with attributes from an mbuf chain */
615 #define nfsm_chain_loadattr(E, NMC, NP, VERS, A, X) \
617 struct nfs_vattr ttvattr, *ttnvap; \
619 ttnvap = (A) ? (A) : &ttvattr; \
620 if ((VERS) == NFS_VER4) { \
621 NFS_CLEAR_ATTRIBUTES(ttnvap->nva_bitmap); \
622 (E) = nfs4_parsefattr((NMC), NULL, ttnvap, NULL, NULL); \
624 (E) = nfs_parsefattr((NMC), (VERS), ttnvap); \
627 (E) = nfs_loadattrcache((NP), ttnvap, (X), 0); \
630 /* get NFSv4 attr bitmap */
631 #define nfsm_chain_get_bitmap(E, NMC, B, LEN) \
633 uint32_t __len, __i; \
634 nfsm_chain_get_32((E), (NMC), __len); \
636 for (__i=0; __i < MIN(__len, (LEN)); __i++) \
637 nfsm_chain_get_32((E), (NMC), (B)[__i]); \
639 for (; __i < (LEN); __i++) \
644 #define nfsm_chain_skip_tag(E, NMC) \
647 nfsm_chain_get_32((E), (NMC), __val); \
648 nfsm_chain_adv((E), (NMC), nfsm_rndup(__val)); \
651 #define nfsm_chain_op_check(E, NMC, OP) \
653 uint32_t __val = 0; \
654 nfsm_chain_get_32((E), (NMC), __val); \
655 nfsm_assert((E), (__val == (OP)), EBADRPC); \
656 nfsm_chain_get_32((E), (NMC), __val); \
657 nfsm_assert((E), (__val == NFS_OK), __val); \
660 #define nfsm_chain_check_change_info(E, NMC, DNP) \
662 uint64_t __ci_before, __ci_after; \
663 uint32_t __ci_atomic = 0; \
664 nfsm_chain_get_32((E), (NMC), __ci_atomic); \
665 nfsm_chain_get_64((E), (NMC), __ci_before); \
666 nfsm_chain_get_64((E), (NMC), __ci_after); \
668 if (__ci_atomic && (__ci_before == (DNP)->n_ncchange)) \
669 (DNP)->n_ncchange = __ci_after; \
671 cache_purge(NFSTOV(DNP)); \
674 #endif /* __APPLE_API_PRIVATE */
675 #endif /* _NFS_NFSM_SUBS_H_ */