xref: /freebsd/sys/rpc/rpcm_subs.h (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1 /* $FreeBSD$ */
2 /*	$OpenBSD: nfsm_subs.h,v 1.11 2000/01/05 20:50:52 millert Exp $	*/
3 /*	$NetBSD: nfsm_subs.h,v 1.10 1996/03/20 21:59:56 fvdl Exp $	*/
4 
5 /*-
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * copyright (c) 2003
9  * the regents of the university of michigan
10  * all rights reserved
11  *
12  * permission is granted to use, copy, create derivative works and redistribute
13  * this software and such derivative works for any purpose, so long as the name
14  * of the university of michigan is not used in any advertising or publicity
15  * pertaining to the use or distribution of this software without specific,
16  * written prior authorization.  if the above copyright notice or any other
17  * identification of the university of michigan is included in any copy of any
18  * portion of this software, then the disclaimer below must also be included.
19  *
20  * this software is provided as is, without representation from the university
21  * of michigan as to its fitness for any purpose, and without warranty by the
22  * university of michigan of any kind, either express or implied, including
23  * without limitation the implied warranties of merchantability and fitness for
24  * a particular purpose. the regents of the university of michigan shall not be
25  * liable for any damages, including special, indirect, incidental, or
26  * consequential damages, with respect to any claim arising out of or in
27  * connection with the use of the software, even if it has been or is hereafter
28  * advised of the possibility of such damages.
29  */
30 
31 /*-
32  * Copyright (c) 1989, 1993
33  *	The Regents of the University of California.  All rights reserved.
34  *
35  * This code is derived from software contributed to Berkeley by
36  * Rick Macklem at The University of Guelph.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. Neither the name of the University nor the names of its contributors
47  *    may be used to endorse or promote products derived from this software
48  *    without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60  * SUCH DAMAGE.
61  *
62  *	@(#)nfsm_subs.h	8.2 (Berkeley) 3/30/95
63  */
64 
65 
66 #ifndef _RPC_RPCM_SUBS_H_
67 #define _RPC_RPCM_SUBS_H_
68 
69 
70 /*
71  * Now for the macros that do the simple stuff and call the functions
72  * for the hard stuff.
73  * These macros use several vars. declared in rpcm_reqhead and these
74  * vars. must not be used elsewhere unless you are careful not to corrupt
75  * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
76  * that may be used so long as the value is not expected to retained
77  * after a macro.
78  * I know, this is kind of dorkey, but it makes the actual op functions
79  * fairly clean and deals with the mess caused by the xdr discriminating
80  * unions.
81  */
82 
83 #define	rpcm_build(a,c,s) \
84 		{ if ((s) > M_TRAILINGSPACE(mb)) { \
85 			mb2 = m_get(M_WAITOK, MT_DATA); \
86 			if ((s) > MLEN) \
87 				panic("build > MLEN"); \
88 			mb->m_next = mb2; \
89 			mb = mb2; \
90 			mb->m_len = 0; \
91 			bpos = mtod(mb, caddr_t); \
92 		} \
93 		(a) = (c)(bpos); \
94 		mb->m_len += (s); \
95 		bpos += (s); }
96 
97 #define	rpcm_dissect(a, c, s) \
98 		{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
99 		if (t1 >= (s)) { \
100 			(a) = (c)(dpos); \
101 			dpos += (s); \
102 		} else if ((t1 = rpcm_disct(&md, &dpos, (s), t1, &cp2)) != 0){ \
103 			error = t1; \
104 			goto rpcmout; \
105 		} else { \
106 			(a) = (c)cp2; \
107 		} }
108 
109 #if 0
110 #define rpcm_mtouio(p,s) \
111 		if ((s) > 0 && \
112 		   (t1 = rpcm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \
113 			error = t1; \
114 			goto rpcmout; \
115 		}
116 #endif
117 
118 #define rpcm_rndup(a)	(((a)+3)&(~0x3))
119 
120 #define	rpcm_adv(s) \
121 		{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
122 		if (t1 >= (s)) { \
123 			dpos += (s); \
124 		} else if ((t1 = rpc_adv(&md, &dpos, (s), t1)) != 0) { \
125 			error = t1; \
126 			goto rpcmout; \
127 		} }
128 
129 #define RPCMADV(m, s)   (m)->m_data += (s)
130 
131 #endif /* _RPC_RPCM_SUBS_H_ */
132