1122698Salfred/* $FreeBSD: releng/10.3/sys/rpc/rpcm_subs.h 248195 2013-03-12 12:17:19Z glebius $ */
2122698Salfred/*	$OpenBSD: nfsm_subs.h,v 1.11 2000/01/05 20:50:52 millert Exp $	*/
3122698Salfred/*	$NetBSD: nfsm_subs.h,v 1.10 1996/03/20 21:59:56 fvdl Exp $	*/
4122698Salfred
5139825Simp/*-
6122698Salfred * copyright (c) 2003
7122698Salfred * the regents of the university of michigan
8122698Salfred * all rights reserved
9122698Salfred *
10122698Salfred * permission is granted to use, copy, create derivative works and redistribute
11122698Salfred * this software and such derivative works for any purpose, so long as the name
12122698Salfred * of the university of michigan is not used in any advertising or publicity
13122698Salfred * pertaining to the use or distribution of this software without specific,
14122698Salfred * written prior authorization.  if the above copyright notice or any other
15122698Salfred * identification of the university of michigan is included in any copy of any
16122698Salfred * portion of this software, then the disclaimer below must also be included.
17122698Salfred *
18122698Salfred * this software is provided as is, without representation from the university
19122698Salfred * of michigan as to its fitness for any purpose, and without warranty by the
20122698Salfred * university of michigan of any kind, either express or implied, including
21122698Salfred * without limitation the implied warranties of merchantability and fitness for
22122698Salfred * a particular purpose. the regents of the university of michigan shall not be
23122698Salfred * liable for any damages, including special, indirect, incidental, or
24122698Salfred * consequential damages, with respect to any claim arising out of or in
25122698Salfred * connection with the use of the software, even if it has been or is hereafter
26122698Salfred * advised of the possibility of such damages.
27122698Salfred */
28122698Salfred
29139825Simp/*-
30122698Salfred * Copyright (c) 1989, 1993
31122698Salfred *	The Regents of the University of California.  All rights reserved.
32122698Salfred *
33122698Salfred * This code is derived from software contributed to Berkeley by
34122698Salfred * Rick Macklem at The University of Guelph.
35122698Salfred *
36122698Salfred * Redistribution and use in source and binary forms, with or without
37122698Salfred * modification, are permitted provided that the following conditions
38122698Salfred * are met:
39122698Salfred * 1. Redistributions of source code must retain the above copyright
40122698Salfred *    notice, this list of conditions and the following disclaimer.
41122698Salfred * 2. Redistributions in binary form must reproduce the above copyright
42122698Salfred *    notice, this list of conditions and the following disclaimer in the
43122698Salfred *    documentation and/or other materials provided with the distribution.
44122698Salfred * 4. Neither the name of the University nor the names of its contributors
45122698Salfred *    may be used to endorse or promote products derived from this software
46122698Salfred *    without specific prior written permission.
47122698Salfred *
48122698Salfred * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49122698Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50122698Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51122698Salfred * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52122698Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53122698Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54122698Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55122698Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56122698Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57122698Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58122698Salfred * SUCH DAMAGE.
59122698Salfred *
60122698Salfred *	@(#)nfsm_subs.h	8.2 (Berkeley) 3/30/95
61122698Salfred */
62122698Salfred
63122698Salfred
64122698Salfred#ifndef _RPC_RPCM_SUBS_H_
65122698Salfred#define _RPC_RPCM_SUBS_H_
66122698Salfred
67122698Salfred
68122698Salfred/*
69122698Salfred * Now for the macros that do the simple stuff and call the functions
70122698Salfred * for the hard stuff.
71122698Salfred * These macros use several vars. declared in rpcm_reqhead and these
72122698Salfred * vars. must not be used elsewhere unless you are careful not to corrupt
73122698Salfred * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
74122698Salfred * that may be used so long as the value is not expected to retained
75122698Salfred * after a macro.
76122698Salfred * I know, this is kind of dorkey, but it makes the actual op functions
77122698Salfred * fairly clean and deals with the mess caused by the xdr discriminating
78122698Salfred * unions.
79122698Salfred */
80122698Salfred
81122698Salfred#define	rpcm_build(a,c,s) \
82122698Salfred		{ if ((s) > M_TRAILINGSPACE(mb)) { \
83248195Sglebius			mb2 = m_get(M_WAITOK, MT_DATA); \
84122698Salfred			if ((s) > MLEN) \
85122698Salfred				panic("build > MLEN"); \
86122698Salfred			mb->m_next = mb2; \
87122698Salfred			mb = mb2; \
88122698Salfred			mb->m_len = 0; \
89122698Salfred			bpos = mtod(mb, caddr_t); \
90122698Salfred		} \
91122698Salfred		(a) = (c)(bpos); \
92122698Salfred		mb->m_len += (s); \
93122698Salfred		bpos += (s); }
94122698Salfred
95122698Salfred#define	rpcm_dissect(a, c, s) \
96122698Salfred		{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
97122698Salfred		if (t1 >= (s)) { \
98122698Salfred			(a) = (c)(dpos); \
99122698Salfred			dpos += (s); \
100122698Salfred		} else if ((t1 = rpcm_disct(&md, &dpos, (s), t1, &cp2)) != 0){ \
101122698Salfred			error = t1; \
102122698Salfred			goto rpcmout; \
103122698Salfred		} else { \
104122698Salfred			(a) = (c)cp2; \
105122698Salfred		} }
106122698Salfred
107122698Salfred#if 0
108122698Salfred#define rpcm_mtouio(p,s) \
109122698Salfred		if ((s) > 0 && \
110122698Salfred		   (t1 = rpcm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \
111122698Salfred			error = t1; \
112122698Salfred			goto rpcmout; \
113122698Salfred		}
114122698Salfred#endif
115122698Salfred
116122698Salfred#define rpcm_rndup(a)	(((a)+3)&(~0x3))
117122698Salfred
118122698Salfred#define	rpcm_adv(s) \
119122698Salfred		{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
120122698Salfred		if (t1 >= (s)) { \
121122698Salfred			dpos += (s); \
122122698Salfred		} else if ((t1 = rpc_adv(&md, &dpos, (s), t1)) != 0) { \
123122698Salfred			error = t1; \
124122698Salfred			goto rpcmout; \
125122698Salfred		} }
126122698Salfred
127122698Salfred#define RPCMADV(m, s)   (m)->m_data += (s)
128122698Salfred
129122698Salfred#endif /* _RPC_RPCM_SUBS_H_ */
130