nfs_common.h revision 148008
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: head/sys/nfs/nfs_common.h 148008 2005-07-14 20:08:27Z ps $ 341541Srgrimes */ 351541Srgrimes 3622521Sdyson 3783651Speter#ifndef _NFS_NFS_COMMON_H_ 3883651Speter#define _NFS_NFS_COMMON_H_ 392175Spaul 4083651Speterextern enum vtype nv3tov_type[]; 4183651Speterextern nfstype nfsv3_type[]; 429336Sdfr 4383651Speter#define vtonfsv2_mode(t, m) \ 4483651Speter txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : MAKEIMODE((t), (m))) 451541Srgrimes 4683651Speter#define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_int32_t,(a))&0x7] 4783651Speter#define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((int32_t)(a))]) 481541Srgrimes 4983651Speterint nfs_adv(struct mbuf **, caddr_t *, int, int); 5083651Speteru_quad_t nfs_curusec(void); 51138463Spsvoid *nfsm_disct(struct mbuf **, caddr_t *, int, int, int); 521541Srgrimes 5384079Speter/* ****************************** */ 5484079Speter/* Build request/reply phase macros */ 5584079Speter 5684079Spetervoid *nfsm_build_xx(int s, struct mbuf **mb, caddr_t *bpos); 5784079Speter 5884002Speter#define nfsm_build(c, s) \ 5984057Speter (c)nfsm_build_xx((s), &mb, &bpos) 601541Srgrimes 6184079Speter/* ****************************** */ 6284079Speter/* Interpretation phase macros */ 6384079Speter 6484079Spetervoid *nfsm_dissect_xx(int s, struct mbuf **md, caddr_t *dpos); 65138463Spsvoid *nfsm_dissect_xx_nonblock(int s, struct mbuf **md, caddr_t *dpos); 6688091Siedowseint nfsm_strsiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos); 6788091Siedowseint nfsm_adv_xx(int s, struct mbuf **md, caddr_t *dpos); 6884079Speter 6984079Speter/* Error check helpers */ 7084079Speter#define nfsm_dcheck(t1, mrep) \ 7184079Speterdo { \ 7284079Speter if (t1 != 0) { \ 7384079Speter error = t1; \ 7484079Speter m_freem((mrep)); \ 7584079Speter (mrep) = NULL; \ 7684079Speter goto nfsmout; \ 7784079Speter } \ 7884079Speter} while (0) 7984079Speter 8084079Speter#define nfsm_dcheckp(retp, mrep) \ 8184079Speterdo { \ 8284079Speter if (retp == NULL) { \ 8384079Speter error = EBADRPC; \ 8484079Speter m_freem((mrep)); \ 8584079Speter (mrep) = NULL; \ 8684079Speter goto nfsmout; \ 8784079Speter } \ 8884079Speter} while (0) 8984079Speter 9084057Speter#define nfsm_dissect(c, s) \ 9184057Speter({ \ 9284057Speter void *ret; \ 9384057Speter ret = nfsm_dissect_xx((s), &md, &dpos); \ 9484079Speter nfsm_dcheckp(ret, mrep); \ 9584057Speter (c)ret; \ 9684057Speter}) 979336Sdfr 98138463Sps#define nfsm_dissect_nonblock(c, s) \ 99138463Sps({ \ 100138463Sps void *ret; \ 101138463Sps ret = nfsm_dissect_xx_nonblock((s), &md, &dpos); \ 102138463Sps nfsm_dcheckp(ret, mrep); \ 103138463Sps (c)ret; \ 104138463Sps}) 105138463Sps 1061541Srgrimes#define nfsm_strsiz(s,m) \ 10783651Speterdo { \ 10883651Speter int t1; \ 10988091Siedowse t1 = nfsm_strsiz_xx(&(s), (m), &md, &dpos); \ 11084079Speter nfsm_dcheck(t1, mrep); \ 11183651Speter} while(0) 1121541Srgrimes 1131541Srgrimes#define nfsm_mtouio(p,s) \ 11483651Speterdo {\ 11584079Speter int32_t t1 = 0; \ 11684079Speter if ((s) > 0) \ 11784079Speter t1 = nfsm_mbuftouio(&md, (p), (s), &dpos); \ 11884079Speter nfsm_dcheck(t1, mrep); \ 11983651Speter} while (0) 1201541Srgrimes 1211541Srgrimes#define nfsm_rndup(a) (((a)+3)&(~0x3)) 1221541Srgrimes 1231541Srgrimes#define nfsm_adv(s) \ 12483651Speterdo { \ 12583651Speter int t1; \ 12688091Siedowse t1 = nfsm_adv_xx((s), &md, &dpos); \ 12784079Speter nfsm_dcheck(t1, mrep); \ 12883651Speter} while (0) 1299336Sdfr 130148008Sps#ifdef __NO_STRICT_ALIGNMENT 131148008Sps#define nfsm_aligned(p, t) 1 132148008Sps#else 133148008Sps#define nfsm_aligned(p, t) ((((u_long)(p)) & (sizeof(t) - 1)) == 0) 1342175Spaul#endif 135148008Sps 136148008Sps#endif 137