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