Home | History | Annotate | Line # | Download | only in nfs
nfsm_subs.h revision 1.23
      1  1.23      matt /*	$NetBSD: nfsm_subs.h,v 1.23 2003/02/26 06:31:20 matt Exp $	*/
      2   1.5       cgd 
      3   1.1   mycroft /*
      4   1.4   mycroft  * Copyright (c) 1989, 1993
      5   1.4   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1   mycroft  *
      7   1.1   mycroft  * This code is derived from software contributed to Berkeley by
      8   1.1   mycroft  * Rick Macklem at The University of Guelph.
      9   1.1   mycroft  *
     10   1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     11   1.1   mycroft  * modification, are permitted provided that the following conditions
     12   1.1   mycroft  * are met:
     13   1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     14   1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     15   1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     17   1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     18   1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     19   1.1   mycroft  *    must display the following acknowledgement:
     20   1.1   mycroft  *	This product includes software developed by the University of
     21   1.1   mycroft  *	California, Berkeley and its contributors.
     22   1.1   mycroft  * 4. Neither the name of the University nor the names of its contributors
     23   1.1   mycroft  *    may be used to endorse or promote products derived from this software
     24   1.1   mycroft  *    without specific prior written permission.
     25   1.1   mycroft  *
     26   1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27   1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28   1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29   1.1   mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30   1.1   mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31   1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32   1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33   1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34   1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35   1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36   1.1   mycroft  * SUCH DAMAGE.
     37   1.1   mycroft  *
     38   1.9      fvdl  *	@(#)nfsm_subs.h	8.2 (Berkeley) 3/30/95
     39   1.1   mycroft  */
     40   1.1   mycroft 
     41   1.9      fvdl 
     42   1.9      fvdl #ifndef _NFS_NFSM_SUBS_H_
     43   1.9      fvdl #define _NFS_NFSM_SUBS_H_
     44   1.9      fvdl 
     45   1.9      fvdl 
     46   1.1   mycroft /*
     47   1.1   mycroft  * These macros do strange and peculiar things to mbuf chains for
     48   1.1   mycroft  * the assistance of the nfs code. To attempt to use them for any
     49   1.1   mycroft  * other purpose will be dangerous. (they make weird assumptions)
     50   1.1   mycroft  */
     51   1.1   mycroft 
     52   1.1   mycroft /*
     53   1.1   mycroft  * First define what the actual subs. return
     54   1.1   mycroft  */
     55   1.9      fvdl 
     56   1.1   mycroft #define	M_HASCL(m)	((m)->m_flags & M_EXT)
     57   1.1   mycroft #define	NFSMINOFF(m) \
     58   1.1   mycroft 		if (M_HASCL(m)) \
     59   1.1   mycroft 			(m)->m_data = (m)->m_ext.ext_buf; \
     60   1.4   mycroft 		else if ((m)->m_flags & M_PKTHDR) \
     61   1.4   mycroft 			(m)->m_data = (m)->m_pktdat; \
     62   1.1   mycroft 		else \
     63   1.1   mycroft 			(m)->m_data = (m)->m_dat
     64   1.1   mycroft #define	NFSMADV(m, s)	(m)->m_data += (s)
     65  1.15   thorpej #define	NFSMSIZ(m)	((M_HASCL(m)) ? (m)->m_ext.ext_size : \
     66  1.15   thorpej 				(((m)->m_flags & M_PKTHDR) ? MHLEN : MLEN))
     67   1.1   mycroft 
     68   1.1   mycroft /*
     69   1.1   mycroft  * Now for the macros that do the simple stuff and call the functions
     70   1.1   mycroft  * for the hard stuff.
     71   1.1   mycroft  * These macros use several vars. declared in nfsm_reqhead and these
     72   1.1   mycroft  * vars. must not be used elsewhere unless you are careful not to corrupt
     73   1.1   mycroft  * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
     74   1.1   mycroft  * that may be used so long as the value is not expected to retained
     75   1.1   mycroft  * after a macro.
     76   1.1   mycroft  * I know, this is kind of dorkey, but it makes the actual op functions
     77   1.1   mycroft  * fairly clean and deals with the mess caused by the xdr discriminating
     78   1.1   mycroft  * unions.
     79   1.1   mycroft  */
     80   1.1   mycroft 
     81   1.1   mycroft #define	nfsm_build(a,c,s) \
     82   1.4   mycroft 		{ if ((s) > M_TRAILINGSPACE(mb)) { \
     83  1.23      matt 			struct mbuf *mb2; \
     84  1.23      matt 			mb2 = m_get(M_WAIT, MT_DATA); \
     85  1.23      matt 			MCLAIM(mb2, &nfs_mowner); \
     86   1.1   mycroft 			if ((s) > MLEN) \
     87   1.1   mycroft 				panic("build > MLEN"); \
     88   1.1   mycroft 			mb->m_next = mb2; \
     89   1.1   mycroft 			mb = mb2; \
     90   1.1   mycroft 			mb->m_len = 0; \
     91   1.1   mycroft 			bpos = mtod(mb, caddr_t); \
     92   1.1   mycroft 		} \
     93   1.1   mycroft 		(a) = (c)(bpos); \
     94   1.1   mycroft 		mb->m_len += (s); \
     95   1.4   mycroft 		bpos += (s); }
     96   1.1   mycroft 
     97  1.14      fvdl #define nfsm_aligned(p) ALIGNED_POINTER(p,u_int32_t)
     98  1.12      fvdl 
     99   1.9      fvdl #define	nfsm_dissect(a, c, s) \
    100   1.4   mycroft 		{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
    101  1.12      fvdl 		if (t1 >= (s) && nfsm_aligned(dpos)) { \
    102   1.1   mycroft 			(a) = (c)(dpos); \
    103   1.1   mycroft 			dpos += (s); \
    104   1.9      fvdl 		} else if ((t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2)) != 0){ \
    105   1.9      fvdl 			error = t1; \
    106   1.1   mycroft 			m_freem(mrep); \
    107   1.1   mycroft 			goto nfsmout; \
    108   1.1   mycroft 		} else { \
    109   1.1   mycroft 			(a) = (c)cp2; \
    110   1.4   mycroft 		} }
    111   1.1   mycroft 
    112   1.9      fvdl #define nfsm_fhtom(v, v3) \
    113   1.9      fvdl 	      { if (v3) { \
    114   1.9      fvdl 			t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \
    115   1.9      fvdl 			if (t2 <= M_TRAILINGSPACE(mb)) { \
    116   1.9      fvdl 				nfsm_build(tl, u_int32_t *, t2); \
    117   1.9      fvdl 				*tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \
    118   1.9      fvdl 				*(tl + ((t2>>2) - 2)) = 0; \
    119  1.18     perry 				memcpy((caddr_t)tl,(caddr_t)VTONFS(v)->n_fhp, \
    120   1.9      fvdl 					VTONFS(v)->n_fhsize); \
    121   1.9      fvdl 			} else if ((t2 = nfsm_strtmbuf(&mb, &bpos, \
    122   1.9      fvdl 				(caddr_t)VTONFS(v)->n_fhp, \
    123   1.9      fvdl 				  VTONFS(v)->n_fhsize)) != 0) { \
    124   1.9      fvdl 				error = t2; \
    125   1.9      fvdl 				m_freem(mreq); \
    126   1.9      fvdl 				goto nfsmout; \
    127   1.9      fvdl 			} \
    128   1.9      fvdl 		} else { \
    129   1.9      fvdl 			nfsm_build(cp, caddr_t, NFSX_V2FH); \
    130  1.18     perry 			memcpy(cp, (caddr_t)VTONFS(v)->n_fhp, NFSX_V2FH); \
    131   1.9      fvdl 		} }
    132   1.9      fvdl 
    133   1.9      fvdl #define nfsm_srvfhtom(f, v3) \
    134   1.9      fvdl 		{ if (v3) { \
    135   1.9      fvdl 			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3FH); \
    136   1.9      fvdl 			*tl++ = txdr_unsigned(NFSX_V3FH); \
    137  1.18     perry 			memcpy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \
    138   1.9      fvdl 		} else { \
    139   1.9      fvdl 			nfsm_build(cp, caddr_t, NFSX_V2FH); \
    140  1.18     perry 			memcpy(cp, (caddr_t)(f), NFSX_V2FH); \
    141   1.9      fvdl 		} }
    142   1.9      fvdl 
    143   1.9      fvdl #define nfsm_srvpostop_fh(f) \
    144   1.9      fvdl 		{ nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \
    145   1.9      fvdl 		*tl++ = nfs_true; \
    146   1.9      fvdl 		*tl++ = txdr_unsigned(NFSX_V3FH); \
    147  1.18     perry 		memcpy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \
    148   1.9      fvdl 		}
    149   1.9      fvdl 
    150   1.9      fvdl #define nfsm_mtofh(d, v, v3, f) \
    151   1.9      fvdl 		{ struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \
    152   1.9      fvdl 		if (v3) { \
    153   1.9      fvdl 			nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    154   1.9      fvdl 			(f) = fxdr_unsigned(int, *tl); \
    155   1.9      fvdl 		} else \
    156   1.9      fvdl 			(f) = 1; \
    157   1.9      fvdl 		if (f) { \
    158   1.9      fvdl 			nfsm_getfh(ttfhp, ttfhsize, (v3)); \
    159   1.9      fvdl 			if ((t1 = nfs_nget((d)->v_mount, ttfhp, ttfhsize, \
    160   1.9      fvdl 				&ttnp)) != 0) { \
    161   1.9      fvdl 				error = t1; \
    162   1.9      fvdl 				m_freem(mrep); \
    163   1.9      fvdl 				goto nfsmout; \
    164   1.9      fvdl 			} \
    165   1.9      fvdl 			(v) = NFSTOV(ttnp); \
    166   1.9      fvdl 		} \
    167   1.9      fvdl 		if (v3) { \
    168   1.9      fvdl 			nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    169   1.9      fvdl 			if (f) \
    170   1.9      fvdl 				(f) = fxdr_unsigned(int, *tl); \
    171   1.9      fvdl 			else if (fxdr_unsigned(int, *tl)) \
    172   1.9      fvdl 				nfsm_adv(NFSX_V3FATTR); \
    173   1.1   mycroft 		} \
    174   1.9      fvdl 		if (f) \
    175  1.22      yamt 			nfsm_loadattr((v), (struct vattr *)0, 0); \
    176   1.1   mycroft 		}
    177   1.1   mycroft 
    178   1.9      fvdl #define nfsm_getfh(f, s, v3) \
    179   1.9      fvdl 		{ if (v3) { \
    180   1.9      fvdl 			nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    181   1.9      fvdl 			if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \
    182   1.9      fvdl 				(s) > NFSX_V3FHMAX) { \
    183   1.9      fvdl 				m_freem(mrep); \
    184   1.9      fvdl 				error = EBADRPC; \
    185   1.9      fvdl 				goto nfsmout; \
    186   1.9      fvdl 			} \
    187   1.9      fvdl 		} else \
    188   1.9      fvdl 			(s) = NFSX_V2FH; \
    189   1.9      fvdl 		nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); }
    190   1.9      fvdl 
    191  1.22      yamt #define	nfsm_loadattr(v, a, flags) \
    192   1.9      fvdl 		{ struct vnode *ttvp = (v); \
    193  1.22      yamt 		if ((t1 = nfsm_loadattrcache(&ttvp, &md, &dpos, (a), (flags))) \
    194  1.22      yamt 		    != 0) { \
    195   1.9      fvdl 			error = t1; \
    196   1.1   mycroft 			m_freem(mrep); \
    197   1.1   mycroft 			goto nfsmout; \
    198   1.1   mycroft 		} \
    199   1.9      fvdl 		(v) = ttvp; }
    200   1.9      fvdl 
    201  1.22      yamt #define	nfsm_postop_attr(v, f, flags) \
    202   1.9      fvdl 		{ struct vnode *ttvp = (v); \
    203   1.9      fvdl 		nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    204   1.9      fvdl 		if (((f) = fxdr_unsigned(int, *tl)) != 0) { \
    205  1.17      fvdl 			if ((t1 = nfsm_loadattrcache(&ttvp, &md, &dpos, \
    206  1.22      yamt 				(struct vattr *)0, (flags))) != 0) { \
    207   1.9      fvdl 				error = t1; \
    208   1.9      fvdl 				(f) = 0; \
    209   1.9      fvdl 				m_freem(mrep); \
    210   1.9      fvdl 				goto nfsmout; \
    211   1.9      fvdl 			} \
    212   1.9      fvdl 			(v) = ttvp; \
    213   1.9      fvdl 		} }
    214   1.9      fvdl 
    215   1.9      fvdl /* Used as (f) for nfsm_wcc_data() */
    216   1.9      fvdl #define NFSV3_WCCRATTR	0
    217   1.9      fvdl #define NFSV3_WCCCHK	1
    218   1.9      fvdl 
    219  1.22      yamt #define	nfsm_wcc_data(v, f, flags) \
    220   1.9      fvdl 		{ int ttattrf, ttretf = 0; \
    221   1.9      fvdl 		nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    222   1.9      fvdl 		if (*tl == nfs_true) { \
    223   1.9      fvdl 			nfsm_dissect(tl, u_int32_t *, 6 * NFSX_UNSIGNED); \
    224   1.9      fvdl 			if (f) \
    225   1.9      fvdl 				ttretf = (VTONFS(v)->n_mtime == \
    226   1.9      fvdl 					fxdr_unsigned(u_int32_t, *(tl + 2))); \
    227   1.9      fvdl 		} \
    228  1.22      yamt 		nfsm_postop_attr((v), ttattrf, (flags)); \
    229   1.9      fvdl 		if (f) { \
    230   1.9      fvdl 			(f) = ttretf; \
    231   1.9      fvdl 		} else { \
    232   1.9      fvdl 			(f) = ttattrf; \
    233   1.9      fvdl 		} }
    234   1.9      fvdl 
    235  1.20      fvdl /* If full is true, set all fields, otherwise just set mode and time fields */
    236  1.20      fvdl #define nfsm_v3attrbuild(a, full)						\
    237  1.20      fvdl 		{ if ((a)->va_mode != (mode_t)VNOVAL) {				\
    238  1.20      fvdl 			nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);		\
    239  1.20      fvdl 			*tl++ = nfs_true;					\
    240  1.20      fvdl 			*tl = txdr_unsigned((a)->va_mode);			\
    241  1.20      fvdl 		} else {							\
    242  1.20      fvdl 			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);		\
    243  1.20      fvdl 			*tl = nfs_false;					\
    244  1.20      fvdl 		}								\
    245  1.20      fvdl 		if ((full) && (a)->va_uid != (uid_t)VNOVAL) {			\
    246  1.20      fvdl 			nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);		\
    247  1.20      fvdl 			*tl++ = nfs_true;					\
    248  1.20      fvdl 			*tl = txdr_unsigned((a)->va_uid);			\
    249  1.20      fvdl 		} else {							\
    250  1.20      fvdl 			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);		\
    251  1.20      fvdl 			*tl = nfs_false;					\
    252  1.20      fvdl 		}								\
    253  1.20      fvdl 		if ((full) && (a)->va_gid != (gid_t)VNOVAL) {			\
    254  1.20      fvdl 			nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);		\
    255  1.20      fvdl 			*tl++ = nfs_true;					\
    256  1.20      fvdl 			*tl = txdr_unsigned((a)->va_gid);			\
    257  1.20      fvdl 		} else {							\
    258  1.20      fvdl 			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);		\
    259  1.20      fvdl 			*tl = nfs_false;					\
    260  1.20      fvdl 		}								\
    261  1.20      fvdl 		if ((full) && (a)->va_size != VNOVAL) {				\
    262  1.20      fvdl 			nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);		\
    263  1.20      fvdl 			*tl++ = nfs_true;					\
    264  1.20      fvdl 			txdr_hyper((a)->va_size, tl);				\
    265  1.20      fvdl 		} else {							\
    266  1.20      fvdl 			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);		\
    267  1.20      fvdl 			*tl = nfs_false;					\
    268  1.20      fvdl 		}								\
    269  1.20      fvdl 		if ((a)->va_atime.tv_sec != VNOVAL) {				\
    270  1.20      fvdl 			if ((a)->va_atime.tv_sec != time.tv_sec) {		\
    271  1.20      fvdl 				nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);	\
    272  1.20      fvdl 				*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);	\
    273  1.20      fvdl 				txdr_nfsv3time(&(a)->va_atime, tl);		\
    274  1.20      fvdl 			} else {						\
    275  1.20      fvdl 				nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);	\
    276  1.20      fvdl 				*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);	\
    277  1.20      fvdl 			}							\
    278  1.20      fvdl 		} else {							\
    279  1.20      fvdl 			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);		\
    280  1.20      fvdl 			*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);		\
    281  1.20      fvdl 		}								\
    282  1.20      fvdl 		if ((a)->va_mtime.tv_sec != VNOVAL) {				\
    283  1.20      fvdl 			if ((a)->va_mtime.tv_sec != time.tv_sec) {		\
    284  1.20      fvdl 				nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);	\
    285  1.20      fvdl 				*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);	\
    286  1.20      fvdl 				txdr_nfsv3time(&(a)->va_mtime, tl);		\
    287  1.20      fvdl 			} else {						\
    288  1.20      fvdl 				nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);	\
    289  1.20      fvdl 				*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);	\
    290  1.20      fvdl 			}							\
    291  1.20      fvdl 		} else {							\
    292  1.20      fvdl 			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);		\
    293  1.20      fvdl 			*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);		\
    294  1.20      fvdl 		}								\
    295   1.9      fvdl 		}
    296  1.20      fvdl 
    297   1.1   mycroft 
    298   1.1   mycroft #define	nfsm_strsiz(s,m) \
    299   1.7       cgd 		{ nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \
    300   1.7       cgd 		if (((s) = fxdr_unsigned(int32_t,*tl)) > (m)) { \
    301   1.1   mycroft 			m_freem(mrep); \
    302   1.1   mycroft 			error = EBADRPC; \
    303   1.1   mycroft 			goto nfsmout; \
    304   1.4   mycroft 		} }
    305   1.1   mycroft 
    306   1.1   mycroft #define	nfsm_srvstrsiz(s,m) \
    307   1.7       cgd 		{ nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \
    308   1.7       cgd 		if (((s) = fxdr_unsigned(int32_t,*tl)) > (m) || (s) <= 0) { \
    309   1.1   mycroft 			error = EBADRPC; \
    310   1.1   mycroft 			nfsm_reply(0); \
    311   1.4   mycroft 		} }
    312   1.1   mycroft 
    313   1.9      fvdl #define	nfsm_srvnamesiz(s) \
    314   1.9      fvdl 		{ nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \
    315   1.9      fvdl 		if (((s) = fxdr_unsigned(int32_t,*tl)) > NFS_MAXNAMLEN) \
    316   1.9      fvdl 			error = NFSERR_NAMETOL; \
    317   1.9      fvdl 		if ((s) <= 0) \
    318   1.9      fvdl 			error = EBADRPC; \
    319   1.9      fvdl 		if (error) \
    320   1.9      fvdl 			nfsm_reply(0); \
    321   1.9      fvdl 		}
    322   1.9      fvdl 
    323   1.1   mycroft #define nfsm_mtouio(p,s) \
    324   1.1   mycroft 		if ((s) > 0 && \
    325   1.9      fvdl 		   (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \
    326   1.9      fvdl 			error = t1; \
    327   1.1   mycroft 			m_freem(mrep); \
    328   1.1   mycroft 			goto nfsmout; \
    329   1.1   mycroft 		}
    330   1.1   mycroft 
    331   1.1   mycroft #define nfsm_uiotom(p,s) \
    332   1.9      fvdl 		if ((t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) != 0) { \
    333   1.9      fvdl 			error = t1; \
    334   1.1   mycroft 			m_freem(mreq); \
    335   1.1   mycroft 			goto nfsmout; \
    336   1.1   mycroft 		}
    337   1.1   mycroft 
    338   1.4   mycroft #define	nfsm_reqhead(v,a,s) \
    339   1.4   mycroft 		mb = mreq = nfsm_reqh((v),(a),(s),&bpos)
    340   1.1   mycroft 
    341   1.1   mycroft #define nfsm_reqdone	m_freem(mrep); \
    342   1.1   mycroft 		nfsmout:
    343   1.1   mycroft 
    344   1.1   mycroft #define nfsm_rndup(a)	(((a)+3)&(~0x3))
    345   1.1   mycroft 
    346   1.4   mycroft #define	nfsm_request(v, t, p, c)	\
    347   1.8  christos 		if ((error = nfs_request((v), mreq, (t), (p), \
    348   1.9      fvdl 		   (c), &mrep, &md, &dpos)) != 0) { \
    349   1.9      fvdl 			if (error & NFSERR_RETERR) \
    350   1.9      fvdl 				error &= ~NFSERR_RETERR; \
    351   1.9      fvdl 			else \
    352   1.9      fvdl 				goto nfsmout; \
    353   1.9      fvdl 		}
    354   1.1   mycroft 
    355   1.1   mycroft #define	nfsm_strtom(a,s,m) \
    356   1.1   mycroft 		if ((s) > (m)) { \
    357   1.1   mycroft 			m_freem(mreq); \
    358   1.1   mycroft 			error = ENAMETOOLONG; \
    359   1.1   mycroft 			goto nfsmout; \
    360   1.1   mycroft 		} \
    361   1.1   mycroft 		t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \
    362   1.4   mycroft 		if (t2 <= M_TRAILINGSPACE(mb)) { \
    363   1.7       cgd 			nfsm_build(tl,u_int32_t *,t2); \
    364   1.1   mycroft 			*tl++ = txdr_unsigned(s); \
    365   1.1   mycroft 			*(tl+((t2>>2)-2)) = 0; \
    366  1.18     perry 			memcpy((caddr_t)tl, (const char *)(a), (s)); \
    367   1.9      fvdl 		} else if ((t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s))) != 0) { \
    368   1.9      fvdl 			error = t2; \
    369   1.1   mycroft 			m_freem(mreq); \
    370   1.1   mycroft 			goto nfsmout; \
    371   1.1   mycroft 		}
    372   1.1   mycroft 
    373   1.1   mycroft #define	nfsm_srvdone \
    374   1.1   mycroft 		nfsmout: \
    375   1.1   mycroft 		return(error)
    376   1.1   mycroft 
    377   1.1   mycroft #define	nfsm_reply(s) \
    378   1.1   mycroft 		{ \
    379   1.4   mycroft 		nfsd->nd_repstat = error; \
    380   1.9      fvdl 		if (error && !(nfsd->nd_flag & ND_NFSV3)) \
    381   1.9      fvdl 		   (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
    382   1.4   mycroft 			mrq, &mb, &bpos); \
    383   1.1   mycroft 		else \
    384   1.9      fvdl 		   (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
    385   1.4   mycroft 			mrq, &mb, &bpos); \
    386  1.10      fvdl 		if (mrep != NULL) { \
    387  1.10      fvdl 			m_freem(mrep); \
    388  1.10      fvdl 			mrep = NULL; \
    389  1.10      fvdl 		} \
    390   1.1   mycroft 		mreq = *mrq; \
    391   1.9      fvdl 		if (error && (!(nfsd->nd_flag & ND_NFSV3) || \
    392   1.9      fvdl 			error == EBADRPC)) \
    393   1.1   mycroft 			return(0); \
    394   1.1   mycroft 		}
    395   1.1   mycroft 
    396   1.9      fvdl #define	nfsm_writereply(s, v3) \
    397   1.9      fvdl 		{ \
    398   1.9      fvdl 		nfsd->nd_repstat = error; \
    399   1.9      fvdl 		if (error && !(v3)) \
    400   1.9      fvdl 		   (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
    401   1.9      fvdl 			&mreq, &mb, &bpos); \
    402   1.9      fvdl 		else \
    403   1.9      fvdl 		   (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
    404   1.9      fvdl 			&mreq, &mb, &bpos); \
    405   1.9      fvdl 		}
    406   1.9      fvdl 
    407   1.1   mycroft #define	nfsm_adv(s) \
    408   1.9      fvdl 		{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
    409   1.1   mycroft 		if (t1 >= (s)) { \
    410   1.1   mycroft 			dpos += (s); \
    411   1.9      fvdl 		} else if ((t1 = nfs_adv(&md, &dpos, (s), t1)) != 0) { \
    412   1.9      fvdl 			error = t1; \
    413   1.1   mycroft 			m_freem(mrep); \
    414   1.1   mycroft 			goto nfsmout; \
    415   1.9      fvdl 		} }
    416   1.1   mycroft 
    417   1.1   mycroft #define nfsm_srvmtofh(f) \
    418  1.16      fvdl 	{ int fhlen = NFSX_V3FH; \
    419  1.16      fvdl 		if (nfsd->nd_flag & ND_NFSV3) { \
    420   1.9      fvdl 			nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    421  1.16      fvdl 			fhlen = fxdr_unsigned(int, *tl); \
    422  1.16      fvdl 			if (fhlen == 0) { \
    423  1.18     perry 				memset((caddr_t)(f), 0, NFSX_V3FH); \
    424  1.16      fvdl 			} else if (fhlen != NFSX_V3FH) { \
    425   1.9      fvdl 				error = EBADRPC; \
    426   1.9      fvdl 				nfsm_reply(0); \
    427   1.9      fvdl 			} \
    428   1.9      fvdl 		} \
    429  1.16      fvdl 		if (fhlen != 0) { \
    430  1.16      fvdl 			nfsm_dissect(tl, u_int32_t *, NFSX_V3FH); \
    431  1.18     perry 			memcpy( (caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \
    432  1.16      fvdl 			if ((nfsd->nd_flag & ND_NFSV3) == 0) \
    433  1.16      fvdl 				nfsm_adv(NFSX_V2FH - NFSX_V3FH); \
    434  1.16      fvdl 		} \
    435  1.16      fvdl 	}
    436   1.1   mycroft 
    437   1.1   mycroft #define	nfsm_clget \
    438   1.1   mycroft 		if (bp >= be) { \
    439   1.4   mycroft 			if (mp == mb) \
    440   1.4   mycroft 				mp->m_len += bp-bpos; \
    441  1.23      matt 			mp = m_get(M_WAIT, MT_DATA); \
    442  1.23      matt 			MCLAIM(mb2, &nfs_mowner); \
    443  1.23      matt 			m_clget(mp, M_WAIT); \
    444   1.1   mycroft 			mp->m_len = NFSMSIZ(mp); \
    445   1.4   mycroft 			mp2->m_next = mp; \
    446   1.4   mycroft 			mp2 = mp; \
    447   1.1   mycroft 			bp = mtod(mp, caddr_t); \
    448   1.1   mycroft 			be = bp+mp->m_len; \
    449   1.1   mycroft 		} \
    450   1.7       cgd 		tl = (u_int32_t *)bp
    451   1.1   mycroft 
    452   1.9      fvdl #define	nfsm_srvfillattr(a, f) \
    453   1.9      fvdl 		nfsm_srvfattr(nfsd, (a), (f))
    454   1.9      fvdl 
    455   1.9      fvdl #define nfsm_srvwcc_data(br, b, ar, a) \
    456   1.9      fvdl 		nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos)
    457   1.9      fvdl 
    458   1.9      fvdl #define nfsm_srvpostop_attr(r, a) \
    459   1.9      fvdl 		nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos)
    460   1.9      fvdl 
    461   1.9      fvdl #define nfsm_srvsattr(a) \
    462   1.9      fvdl 		{ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    463   1.9      fvdl 		if (*tl == nfs_true) { \
    464   1.9      fvdl 			nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    465   1.9      fvdl 			(a)->va_mode = nfstov_mode(*tl); \
    466   1.9      fvdl 		} \
    467   1.9      fvdl 		nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    468   1.9      fvdl 		if (*tl == nfs_true) { \
    469   1.9      fvdl 			nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    470   1.9      fvdl 			(a)->va_uid = fxdr_unsigned(uid_t, *tl); \
    471   1.9      fvdl 		} \
    472   1.9      fvdl 		nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    473   1.9      fvdl 		if (*tl == nfs_true) { \
    474   1.9      fvdl 			nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    475   1.9      fvdl 			(a)->va_gid = fxdr_unsigned(gid_t, *tl); \
    476   1.9      fvdl 		} \
    477   1.9      fvdl 		nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    478   1.9      fvdl 		if (*tl == nfs_true) { \
    479   1.9      fvdl 			nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
    480  1.19      fair 			(a)->va_size = fxdr_hyper(tl); \
    481   1.9      fvdl 		} \
    482   1.9      fvdl 		nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    483   1.9      fvdl 		switch (fxdr_unsigned(int, *tl)) { \
    484   1.9      fvdl 		case NFSV3SATTRTIME_TOCLIENT: \
    485   1.9      fvdl 			nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
    486   1.9      fvdl 			fxdr_nfsv3time(tl, &(a)->va_atime); \
    487   1.9      fvdl 			break; \
    488   1.9      fvdl 		case NFSV3SATTRTIME_TOSERVER: \
    489   1.9      fvdl 			(a)->va_atime.tv_sec = time.tv_sec; \
    490   1.9      fvdl 			(a)->va_atime.tv_nsec = time.tv_usec * 1000; \
    491  1.21  wrstuden 			(a)->va_vaflags |= VA_UTIMES_NULL; \
    492   1.9      fvdl 			break; \
    493   1.9      fvdl 		}; \
    494   1.9      fvdl 		nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
    495   1.9      fvdl 		switch (fxdr_unsigned(int, *tl)) { \
    496   1.9      fvdl 		case NFSV3SATTRTIME_TOCLIENT: \
    497   1.9      fvdl 			nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
    498   1.9      fvdl 			fxdr_nfsv3time(tl, &(a)->va_mtime); \
    499  1.21  wrstuden 			(a)->va_vaflags &= ~VA_UTIMES_NULL; \
    500   1.9      fvdl 			break; \
    501   1.9      fvdl 		case NFSV3SATTRTIME_TOSERVER: \
    502   1.9      fvdl 			(a)->va_mtime.tv_sec = time.tv_sec; \
    503   1.9      fvdl 			(a)->va_mtime.tv_nsec = time.tv_usec * 1000; \
    504  1.21  wrstuden 			(a)->va_vaflags |= VA_UTIMES_NULL; \
    505   1.9      fvdl 			break; \
    506   1.9      fvdl 		}; }
    507   1.1   mycroft 
    508   1.9      fvdl #endif
    509