xref: /freebsd/sys/rpc/rpcm_subs.h (revision 29363fb446372cb3f10bc98664e9767c53fbb457)
11bf87204SAlfred Perlstein /*	$OpenBSD: nfsm_subs.h,v 1.11 2000/01/05 20:50:52 millert Exp $	*/
21bf87204SAlfred Perlstein /*	$NetBSD: nfsm_subs.h,v 1.10 1996/03/20 21:59:56 fvdl Exp $	*/
31bf87204SAlfred Perlstein 
460727d8bSWarner Losh /*-
5*51369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
6*51369649SPedro F. Giffuni  *
71bf87204SAlfred Perlstein  * copyright (c) 2003
81bf87204SAlfred Perlstein  * the regents of the university of michigan
91bf87204SAlfred Perlstein  * all rights reserved
101bf87204SAlfred Perlstein  *
111bf87204SAlfred Perlstein  * permission is granted to use, copy, create derivative works and redistribute
121bf87204SAlfred Perlstein  * this software and such derivative works for any purpose, so long as the name
131bf87204SAlfred Perlstein  * of the university of michigan is not used in any advertising or publicity
141bf87204SAlfred Perlstein  * pertaining to the use or distribution of this software without specific,
151bf87204SAlfred Perlstein  * written prior authorization.  if the above copyright notice or any other
161bf87204SAlfred Perlstein  * identification of the university of michigan is included in any copy of any
171bf87204SAlfred Perlstein  * portion of this software, then the disclaimer below must also be included.
181bf87204SAlfred Perlstein  *
191bf87204SAlfred Perlstein  * this software is provided as is, without representation from the university
201bf87204SAlfred Perlstein  * of michigan as to its fitness for any purpose, and without warranty by the
211bf87204SAlfred Perlstein  * university of michigan of any kind, either express or implied, including
221bf87204SAlfred Perlstein  * without limitation the implied warranties of merchantability and fitness for
231bf87204SAlfred Perlstein  * a particular purpose. the regents of the university of michigan shall not be
241bf87204SAlfred Perlstein  * liable for any damages, including special, indirect, incidental, or
251bf87204SAlfred Perlstein  * consequential damages, with respect to any claim arising out of or in
261bf87204SAlfred Perlstein  * connection with the use of the software, even if it has been or is hereafter
271bf87204SAlfred Perlstein  * advised of the possibility of such damages.
281bf87204SAlfred Perlstein  */
291bf87204SAlfred Perlstein 
3060727d8bSWarner Losh /*-
311bf87204SAlfred Perlstein  * Copyright (c) 1989, 1993
321bf87204SAlfred Perlstein  *	The Regents of the University of California.  All rights reserved.
331bf87204SAlfred Perlstein  *
341bf87204SAlfred Perlstein  * This code is derived from software contributed to Berkeley by
351bf87204SAlfred Perlstein  * Rick Macklem at The University of Guelph.
361bf87204SAlfred Perlstein  *
371bf87204SAlfred Perlstein  * Redistribution and use in source and binary forms, with or without
381bf87204SAlfred Perlstein  * modification, are permitted provided that the following conditions
391bf87204SAlfred Perlstein  * are met:
401bf87204SAlfred Perlstein  * 1. Redistributions of source code must retain the above copyright
411bf87204SAlfred Perlstein  *    notice, this list of conditions and the following disclaimer.
421bf87204SAlfred Perlstein  * 2. Redistributions in binary form must reproduce the above copyright
431bf87204SAlfred Perlstein  *    notice, this list of conditions and the following disclaimer in the
441bf87204SAlfred Perlstein  *    documentation and/or other materials provided with the distribution.
45fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
461bf87204SAlfred Perlstein  *    may be used to endorse or promote products derived from this software
471bf87204SAlfred Perlstein  *    without specific prior written permission.
481bf87204SAlfred Perlstein  *
491bf87204SAlfred Perlstein  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
501bf87204SAlfred Perlstein  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
511bf87204SAlfred Perlstein  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
521bf87204SAlfred Perlstein  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
531bf87204SAlfred Perlstein  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
541bf87204SAlfred Perlstein  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
551bf87204SAlfred Perlstein  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
561bf87204SAlfred Perlstein  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
571bf87204SAlfred Perlstein  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
581bf87204SAlfred Perlstein  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
591bf87204SAlfred Perlstein  * SUCH DAMAGE.
601bf87204SAlfred Perlstein  */
611bf87204SAlfred Perlstein 
621bf87204SAlfred Perlstein 
631bf87204SAlfred Perlstein #ifndef _RPC_RPCM_SUBS_H_
641bf87204SAlfred Perlstein #define _RPC_RPCM_SUBS_H_
651bf87204SAlfred Perlstein 
661bf87204SAlfred Perlstein 
671bf87204SAlfred Perlstein /*
681bf87204SAlfred Perlstein  * Now for the macros that do the simple stuff and call the functions
691bf87204SAlfred Perlstein  * for the hard stuff.
701bf87204SAlfred Perlstein  * These macros use several vars. declared in rpcm_reqhead and these
711bf87204SAlfred Perlstein  * vars. must not be used elsewhere unless you are careful not to corrupt
721bf87204SAlfred Perlstein  * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
731bf87204SAlfred Perlstein  * that may be used so long as the value is not expected to retained
741bf87204SAlfred Perlstein  * after a macro.
751bf87204SAlfred Perlstein  * I know, this is kind of dorkey, but it makes the actual op functions
761bf87204SAlfred Perlstein  * fairly clean and deals with the mess caused by the xdr discriminating
771bf87204SAlfred Perlstein  * unions.
781bf87204SAlfred Perlstein  */
791bf87204SAlfred Perlstein 
801bf87204SAlfred Perlstein #define	rpcm_build(a,c,s) \
811bf87204SAlfred Perlstein 		{ if ((s) > M_TRAILINGSPACE(mb)) { \
82bd54830bSGleb Smirnoff 			mb2 = m_get(M_WAITOK, MT_DATA); \
831bf87204SAlfred Perlstein 			if ((s) > MLEN) \
841bf87204SAlfred Perlstein 				panic("build > MLEN"); \
851bf87204SAlfred Perlstein 			mb->m_next = mb2; \
861bf87204SAlfred Perlstein 			mb = mb2; \
871bf87204SAlfred Perlstein 			mb->m_len = 0; \
881bf87204SAlfred Perlstein 			bpos = mtod(mb, caddr_t); \
891bf87204SAlfred Perlstein 		} \
901bf87204SAlfred Perlstein 		(a) = (c)(bpos); \
911bf87204SAlfred Perlstein 		mb->m_len += (s); \
921bf87204SAlfred Perlstein 		bpos += (s); }
931bf87204SAlfred Perlstein 
941bf87204SAlfred Perlstein #define	rpcm_dissect(a, c, s) \
951bf87204SAlfred Perlstein 		{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
961bf87204SAlfred Perlstein 		if (t1 >= (s)) { \
971bf87204SAlfred Perlstein 			(a) = (c)(dpos); \
981bf87204SAlfred Perlstein 			dpos += (s); \
991bf87204SAlfred Perlstein 		} else if ((t1 = rpcm_disct(&md, &dpos, (s), t1, &cp2)) != 0){ \
1001bf87204SAlfred Perlstein 			error = t1; \
1011bf87204SAlfred Perlstein 			goto rpcmout; \
1021bf87204SAlfred Perlstein 		} else { \
1031bf87204SAlfred Perlstein 			(a) = (c)cp2; \
1041bf87204SAlfred Perlstein 		} }
1051bf87204SAlfred Perlstein 
1061bf87204SAlfred Perlstein #if 0
1071bf87204SAlfred Perlstein #define rpcm_mtouio(p,s) \
1081bf87204SAlfred Perlstein 		if ((s) > 0 && \
1091bf87204SAlfred Perlstein 		   (t1 = rpcm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \
1101bf87204SAlfred Perlstein 			error = t1; \
1111bf87204SAlfred Perlstein 			goto rpcmout; \
1121bf87204SAlfred Perlstein 		}
1131bf87204SAlfred Perlstein #endif
1141bf87204SAlfred Perlstein 
1151bf87204SAlfred Perlstein #define rpcm_rndup(a)	(((a)+3)&(~0x3))
1161bf87204SAlfred Perlstein 
1171bf87204SAlfred Perlstein #define	rpcm_adv(s) \
1181bf87204SAlfred Perlstein 		{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
1191bf87204SAlfred Perlstein 		if (t1 >= (s)) { \
1201bf87204SAlfred Perlstein 			dpos += (s); \
1211bf87204SAlfred Perlstein 		} else if ((t1 = rpc_adv(&md, &dpos, (s), t1)) != 0) { \
1221bf87204SAlfred Perlstein 			error = t1; \
1231bf87204SAlfred Perlstein 			goto rpcmout; \
1241bf87204SAlfred Perlstein 		} }
1251bf87204SAlfred Perlstein 
1261bf87204SAlfred Perlstein #define RPCMADV(m, s)   (m)->m_data += (s)
1271bf87204SAlfred Perlstein 
1281bf87204SAlfred Perlstein #endif /* _RPC_RPCM_SUBS_H_ */
129