1139823Simp/*- 21541Srgrimes * Copyright (c) 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * This code is derived from software contributed to Berkeley by 61541Srgrimes * Rick Macklem at The University of Guelph. 71541Srgrimes * 81541Srgrimes * Redistribution and use in source and binary forms, with or without 91541Srgrimes * modification, are permitted provided that the following conditions 101541Srgrimes * are met: 111541Srgrimes * 1. Redistributions of source code must retain the above copyright 121541Srgrimes * notice, this list of conditions and the following disclaimer. 131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer in the 151541Srgrimes * documentation and/or other materials provided with the distribution. 161541Srgrimes * 4. Neither the name of the University nor the names of its contributors 171541Srgrimes * may be used to endorse or promote products derived from this software 181541Srgrimes * without specific prior written permission. 191541Srgrimes * 201541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301541Srgrimes * SUCH DAMAGE. 311541Srgrimes * 3222521Sdyson * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 3350477Speter * $FreeBSD$ 341541Srgrimes */ 351541Srgrimes 3683651Speter#ifndef _NFS_NFS_COMMON_H_ 3783651Speter#define _NFS_NFS_COMMON_H_ 382175Spaul 3983651Speterextern enum vtype nv3tov_type[]; 4083651Speterextern nfstype nfsv3_type[]; 419336Sdfr 4283651Speter#define vtonfsv2_mode(t, m) \ 4383651Speter txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : MAKEIMODE((t), (m))) 441541Srgrimes 4583651Speter#define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_int32_t,(a))&0x7] 4683651Speter#define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((int32_t)(a))]) 471541Srgrimes 4883651Speterint nfs_adv(struct mbuf **, caddr_t *, int, int); 49138463Spsvoid *nfsm_disct(struct mbuf **, caddr_t *, int, int, int); 50203732Smariusint nfs_realign(struct mbuf **, int); 511541Srgrimes 5284079Speter/* ****************************** */ 5384079Speter/* Build request/reply phase macros */ 5484079Speter 5584079Spetervoid *nfsm_build_xx(int s, struct mbuf **mb, caddr_t *bpos); 5684079Speter 5784002Speter#define nfsm_build(c, s) \ 5884057Speter (c)nfsm_build_xx((s), &mb, &bpos) 591541Srgrimes 6084079Speter/* ****************************** */ 6184079Speter/* Interpretation phase macros */ 6284079Speter 6384079Spetervoid *nfsm_dissect_xx(int s, struct mbuf **md, caddr_t *dpos); 64138463Spsvoid *nfsm_dissect_xx_nonblock(int s, struct mbuf **md, caddr_t *dpos); 6588091Siedowseint nfsm_strsiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos); 6688091Siedowseint nfsm_adv_xx(int s, struct mbuf **md, caddr_t *dpos); 6784079Speter 6884079Speter/* Error check helpers */ 6984079Speter#define nfsm_dcheck(t1, mrep) \ 7084079Speterdo { \ 7184079Speter if (t1 != 0) { \ 7284079Speter error = t1; \ 7384079Speter m_freem((mrep)); \ 7484079Speter (mrep) = NULL; \ 7584079Speter goto nfsmout; \ 7684079Speter } \ 7784079Speter} while (0) 7884079Speter 7984079Speter#define nfsm_dcheckp(retp, mrep) \ 8084079Speterdo { \ 8184079Speter if (retp == NULL) { \ 8284079Speter error = EBADRPC; \ 8384079Speter m_freem((mrep)); \ 8484079Speter (mrep) = NULL; \ 8584079Speter goto nfsmout; \ 8684079Speter } \ 8784079Speter} while (0) 88203731Smarius 8984057Speter#define nfsm_dissect(c, s) \ 9084057Speter({ \ 9184057Speter void *ret; \ 9284057Speter ret = nfsm_dissect_xx((s), &md, &dpos); \ 9384079Speter nfsm_dcheckp(ret, mrep); \ 9484057Speter (c)ret; \ 9584057Speter}) 969336Sdfr 97138463Sps#define nfsm_dissect_nonblock(c, s) \ 98138463Sps({ \ 99138463Sps void *ret; \ 100138463Sps ret = nfsm_dissect_xx_nonblock((s), &md, &dpos); \ 101138463Sps nfsm_dcheckp(ret, mrep); \ 102138463Sps (c)ret; \ 103138463Sps}) 104138463Sps 1051541Srgrimes#define nfsm_strsiz(s,m) \ 10683651Speterdo { \ 10783651Speter int t1; \ 10888091Siedowse t1 = nfsm_strsiz_xx(&(s), (m), &md, &dpos); \ 10984079Speter nfsm_dcheck(t1, mrep); \ 11083651Speter} while(0) 1111541Srgrimes 1121541Srgrimes#define nfsm_mtouio(p,s) \ 11383651Speterdo {\ 11484079Speter int32_t t1 = 0; \ 11584079Speter if ((s) > 0) \ 11684079Speter t1 = nfsm_mbuftouio(&md, (p), (s), &dpos); \ 11784079Speter nfsm_dcheck(t1, mrep); \ 11883651Speter} while (0) 1191541Srgrimes 1201541Srgrimes#define nfsm_rndup(a) (((a)+3)&(~0x3)) 1211541Srgrimes 1221541Srgrimes#define nfsm_adv(s) \ 12383651Speterdo { \ 12483651Speter int t1; \ 12588091Siedowse t1 = nfsm_adv_xx((s), &md, &dpos); \ 12684079Speter nfsm_dcheck(t1, mrep); \ 12783651Speter} while (0) 1289336Sdfr 129148008Sps#ifdef __NO_STRICT_ALIGNMENT 130148008Sps#define nfsm_aligned(p, t) 1 131148008Sps#else 132148008Sps#define nfsm_aligned(p, t) ((((u_long)(p)) & (sizeof(t) - 1)) == 0) 1332175Spaul#endif 134148008Sps 135148008Sps#endif 136