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 _NFSCLIENT_NFSM_SUBS_H_
3783651Speter#define _NFSCLIENT_NFSM_SUBS_H_
3822521Sdyson
3983651Speter#include <nfs/nfs_common.h>
402175Spaul
4183651Speter#define	nfsv2tov_type(a)	nv2tov_type[fxdr_unsigned(u_int32_t,(a))&0x7]
4283651Speter
4333054Sbdestruct ucred;
4433054Sbdestruct vnode;
459336Sdfr
461541Srgrimes/*
471541Srgrimes * These macros do strange and peculiar things to mbuf chains for
481541Srgrimes * the assistance of the nfs code. To attempt to use them for any
491541Srgrimes * other purpose will be dangerous. (they make weird assumptions)
501541Srgrimes */
511541Srgrimes
521541Srgrimes/*
531541Srgrimes * First define what the actual subs. return
541541Srgrimes */
55176224Sjhbu_int32_t nfs_xid_gen(void);
5683651Speterstruct mbuf *nfsm_reqhead(struct vnode *vp, u_long procid, int hsiz);
571541Srgrimes
581541Srgrimes#define	M_HASCL(m)	((m)->m_flags & M_EXT)
591541Srgrimes#define	NFSMINOFF(m) \
6050053Speter	do { \
611541Srgrimes		if (M_HASCL(m)) \
621541Srgrimes			(m)->m_data = (m)->m_ext.ext_buf; \
631541Srgrimes		else if ((m)->m_flags & M_PKTHDR) \
641541Srgrimes			(m)->m_data = (m)->m_pktdat; \
651541Srgrimes		else \
6650053Speter			(m)->m_data = (m)->m_dat; \
6750053Speter	} while (0)
681541Srgrimes#define	NFSMSIZ(m)	((M_HASCL(m))?MCLBYTES: \
691541Srgrimes				(((m)->m_flags & M_PKTHDR)?MHLEN:MLEN))
701541Srgrimes
711541Srgrimes/*
721541Srgrimes * Now for the macros that do the simple stuff and call the functions
731541Srgrimes * for the hard stuff.
741541Srgrimes * These macros use several vars. declared in nfsm_reqhead and these
751541Srgrimes * vars. must not be used elsewhere unless you are careful not to corrupt
761541Srgrimes * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
771541Srgrimes * that may be used so long as the value is not expected to retained
781541Srgrimes * after a macro.
791541Srgrimes * I know, this is kind of dorkey, but it makes the actual op functions
801541Srgrimes * fairly clean and deals with the mess caused by the xdr discriminating
811541Srgrimes * unions.
821541Srgrimes */
831541Srgrimes
8484079Speter
8584079Speter/* *********************************** */
8684079Speter/* Request generation phase macros */
8784079Speter
8888091Siedowseint	nfsm_fhtom_xx(struct vnode *v, int v3, struct mbuf **mb,
8988091Siedowse	    caddr_t *bpos);
9088091Siedowsevoid	nfsm_v3attrbuild_xx(struct vattr *va, int full, struct mbuf **mb,
9188091Siedowse	    caddr_t *bpos);
9288091Siedowseint	nfsm_strtom_xx(const char *a, int s, int m, struct mbuf **mb,
9388091Siedowse	    caddr_t *bpos);
941541Srgrimes
9584079Speter#define nfsm_bcheck(t1, mreq) \
9683651Speterdo { \
9783651Speter	if (t1) { \
9883651Speter		error = t1; \
9983651Speter		m_freem(mreq); \
10083651Speter		goto nfsmout; \
10183651Speter	} \
10283651Speter} while (0)
1031541Srgrimes
10484079Speter#define nfsm_fhtom(v, v3) \
10584079Speterdo { \
10684079Speter	int32_t t1; \
10788091Siedowse	t1 = nfsm_fhtom_xx((v), (v3), &mb, &bpos); \
10884079Speter	nfsm_bcheck(t1, mreq); \
10984079Speter} while (0)
11084079Speter
11184079Speter/* If full is true, set all fields, otherwise just set mode and time fields */
11284079Speter#define nfsm_v3attrbuild(a, full) \
11388091Siedowse	nfsm_v3attrbuild_xx(a, full, &mb, &bpos)
11484079Speter
11584079Speter#define nfsm_uiotom(p, s) \
11684079Speterdo { \
11784079Speter	int t1; \
11884079Speter	t1 = nfsm_uiotombuf((p), &mb, (s), &bpos); \
11984079Speter	nfsm_bcheck(t1, mreq); \
12084079Speter} while (0)
12184079Speter
12284079Speter#define	nfsm_strtom(a, s, m) \
12384079Speterdo { \
12484079Speter	int t1; \
12588091Siedowse	t1 = nfsm_strtom_xx((a), (s), (m), &mb, &bpos); \
12684079Speter	nfsm_bcheck(t1, mreq); \
12784079Speter} while (0)
12884079Speter
12984079Speter/* *********************************** */
13084079Speter/* Send the request */
13184079Speter
13284079Speter#define	nfsm_request(v, t, p, c) \
13384079Speterdo { \
134138496Sps	sigset_t oldset; \
135138496Sps	nfs_set_sigmask(p, &oldset); \
13684079Speter	error = nfs_request((v), mreq, (t), (p), (c), &mrep, &md, &dpos); \
137138496Sps	nfs_restore_sigmask(p, &oldset); \
13884079Speter	if (error != 0) { \
13984079Speter		if (error & NFSERR_RETERR) \
14084079Speter			error &= ~NFSERR_RETERR; \
14184079Speter		else \
14284079Speter			goto nfsmout; \
14384079Speter	} \
14484079Speter} while (0)
14584079Speter
14684079Speter/* *********************************** */
14784079Speter/* Reply interpretation phase macros */
14884079Speter
14984079Speterint	nfsm_mtofh_xx(struct vnode *d, struct vnode **v, int v3, int *f,
15084079Speter	    struct mbuf **md, caddr_t *dpos);
15188091Siedowseint	nfsm_getfh_xx(nfsfh_t **f, int *s, int v3, struct mbuf **md,
15288091Siedowse	    caddr_t *dpos);
15388091Siedowseint	nfsm_loadattr_xx(struct vnode **v, struct vattr *va, struct mbuf **md,
15488091Siedowse	    caddr_t *dpos);
155233285Sjhbint	nfsm_postop_attr_xx(struct vnode **v, int *f, struct vattr *va,
156233285Sjhb	    struct mbuf **md, caddr_t *dpos);
15788091Siedowseint	nfsm_wcc_data_xx(struct vnode **v, int *f, struct mbuf **md,
15888091Siedowse	    caddr_t *dpos);
15984079Speter
1609336Sdfr#define nfsm_mtofh(d, v, v3, f) \
16183651Speterdo { \
16283651Speter	int32_t t1; \
16388091Siedowse	t1 = nfsm_mtofh_xx((d), &(v), (v3), &(f), &md, &dpos); \
16484079Speter	nfsm_dcheck(t1, mrep); \
16583651Speter} while (0)
1661541Srgrimes
1679336Sdfr#define nfsm_getfh(f, s, v3) \
16883651Speterdo { \
16983651Speter	int32_t t1; \
17088091Siedowse	t1 = nfsm_getfh_xx(&(f), &(s), (v3), &md, &dpos); \
17184079Speter	nfsm_dcheck(t1, mrep); \
17283651Speter} while (0)
1739336Sdfr
1749336Sdfr#define	nfsm_loadattr(v, a) \
17583651Speterdo { \
17683651Speter	int32_t t1; \
17788091Siedowse	t1 = nfsm_loadattr_xx(&v, a, &md, &dpos); \
17884079Speter	nfsm_dcheck(t1, mrep); \
17983651Speter} while (0)
1801541Srgrimes
1819336Sdfr#define	nfsm_postop_attr(v, f) \
18283651Speterdo { \
18383651Speter	int32_t t1; \
184233285Sjhb	t1 = nfsm_postop_attr_xx(&v, &f, NULL, &md, &dpos);	\
18584079Speter	nfsm_dcheck(t1, mrep); \
18683651Speter} while (0)
1879336Sdfr
188233285Sjhb#define	nfsm_postop_attr_va(v, f, va)		\
189233285Sjhbdo { \
190233285Sjhb	int32_t t1; \
191233285Sjhb	t1 = nfsm_postop_attr_xx(&v, &f, va, &md, &dpos);	\
192233285Sjhb	nfsm_dcheck(t1, mrep); \
193233285Sjhb} while (0)
194233285Sjhb
1959336Sdfr/* Used as (f) for nfsm_wcc_data() */
1969336Sdfr#define NFSV3_WCCRATTR	0
1979336Sdfr#define NFSV3_WCCCHK	1
1989336Sdfr
1999336Sdfr#define	nfsm_wcc_data(v, f) \
20083651Speterdo { \
20183651Speter	int32_t t1; \
20288091Siedowse	t1 = nfsm_wcc_data_xx(&v, &f, &md, &dpos); \
20384079Speter	nfsm_dcheck(t1, mrep); \
20483651Speter} while (0)
2059336Sdfr
2062175Spaul#endif
207