nfs_common.h revision 84002
11541Srgrimes/*
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 * 3. All advertising materials mentioning features or use of this software
171541Srgrimes *    must display the following acknowledgement:
181541Srgrimes *	This product includes software developed by the University of
191541Srgrimes *	California, Berkeley and its contributors.
201541Srgrimes * 4. Neither the name of the University nor the names of its contributors
211541Srgrimes *    may be used to endorse or promote products derived from this software
221541Srgrimes *    without specific prior written permission.
231541Srgrimes *
241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341541Srgrimes * SUCH DAMAGE.
351541Srgrimes *
3622521Sdyson *	@(#)nfsm_subs.h	8.2 (Berkeley) 3/30/95
3750477Speter * $FreeBSD: head/sys/nfs/nfs_common.h 84002 2001-09-27 02:33:36Z peter $
381541Srgrimes */
391541Srgrimes
4022521Sdyson
4183651Speter#ifndef _NFS_NFS_COMMON_H_
4283651Speter#define _NFS_NFS_COMMON_H_
432175Spaul
4483651Speterextern enum vtype nv3tov_type[];
4583651Speterextern nfstype nfsv3_type[];
469336Sdfr
4783651Speter#define	vtonfsv2_mode(t, m) \
4883651Speter    txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : MAKEIMODE((t), (m)))
491541Srgrimes
5083651Speter#define	nfsv3tov_type(a)	nv3tov_type[fxdr_unsigned(u_int32_t,(a))&0x7]
5183651Speter#define	vtonfsv3_type(a)	txdr_unsigned(nfsv3_type[((int32_t)(a))])
521541Srgrimes
5383651Speter#define NFSMADV(m, s) \
5450053Speter	do { \
5550053Speter		(m)->m_data += (s); \
5650053Speter	} while (0)
571541Srgrimes
5883651Speterint	nfs_adv(struct mbuf **, caddr_t *, int, int);
5984002Spetervoid	*nfsm_build_xx(int s, struct mbuf **mb, caddr_t *bpos);
6083651Speterint	nfsm_dissect_xx(void **a, int s, struct mbuf **md, caddr_t *dpos);
6183651Speterint	nfsm_strsiz_xx(int *s, int m, u_int32_t **tl, struct mbuf **mb,
6283651Speter	    caddr_t *bpos);
6383651Speterint	nfsm_adv_xx(int s, u_int32_t **tl, struct mbuf **md, caddr_t *dpos);
6483651Speteru_quad_t nfs_curusec(void);
6583651Speterint	nfsm_disct(struct mbuf **, caddr_t *, int, int, caddr_t *);
661541Srgrimes
6784002Speter#define	nfsm_build(c, s) \
6884002Speter	(c)nfsm_build_xx((s), &mb, &bpos); \
691541Srgrimes
7083651Speter/* XXX 'c' arg (type) is not used */
719336Sdfr#define	nfsm_dissect(a, c, s) \
7283651Speterdo { \
7383651Speter	int t1; \
7483651Speter	t1 = nfsm_dissect_xx((void **)&(a), (s), &md, &dpos); \
7583651Speter	if (t1) { \
7683651Speter		error = t1; \
7783651Speter		m_freem(mrep); \
7883651Speter		mrep = NULL; \
7983651Speter		goto nfsmout; \
8083651Speter	} \
8183651Speter} while (0)
829336Sdfr
831541Srgrimes#define	nfsm_strsiz(s,m) \
8483651Speterdo { \
8583651Speter	int t1; \
8683651Speter	t1 = nfsm_strsiz_xx(&(s), (m), &tl, &md, &dpos); \
8783651Speter	if (t1) { \
8883651Speter		error = t1; \
8983651Speter		m_freem(mrep); \
9083651Speter		mrep = NULL; \
9183651Speter		goto nfsmout; \
9283651Speter	} \
9383651Speter} while(0)
941541Srgrimes
951541Srgrimes#define nfsm_mtouio(p,s) \
9683651Speterdo {\
9783651Speter	int32_t t1; \
9883651Speter	if ((s) > 0 && (t1 = nfsm_mbuftouio(&md, (p), (s), &dpos)) != 0) { \
9983651Speter		error = t1; \
10050053Speter		m_freem(mrep); \
10183651Speter		mrep = NULL; \
10283651Speter		goto nfsmout; \
10383651Speter	} \
10483651Speter} while (0)
1051541Srgrimes
1061541Srgrimes#define nfsm_rndup(a)	(((a)+3)&(~0x3))
1071541Srgrimes
1081541Srgrimes#define	nfsm_adv(s) \
10983651Speterdo { \
11083651Speter	int t1; \
11183651Speter	t1 = nfsm_adv_xx((s), &tl, &md, &dpos); \
11283651Speter	if (t1) { \
11383651Speter		error = t1; \
11483651Speter		m_freem(mrep); \
11583651Speter		mrep = NULL; \
11683651Speter		goto nfsmout; \
11783651Speter	} \
11883651Speter} while (0)
1199336Sdfr
1202175Spaul#endif
121