* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
* This code is derived from software contributed to Berkeley by
* Rick Macklem at The University of Guelph.
* %sccs.include.redist.c%
* @(#)nfsm_subs.h 8.2 (Berkeley) %G%
#ifndef _NFS_NFSM_SUBS_H_
#define _NFS_NFSM_SUBS_H_
* These macros do strange and peculiar things to mbuf chains for
* the assistance of the nfs code. To attempt to use them for any
* other purpose will be dangerous. (they make weird assumptions)
* First define what the actual subs. return
extern struct mbuf
*nfsm_reqh();
#define M_HASCL(m) ((m)->m_flags & M_EXT)
(m)->m_data = (m)->m_ext.ext_buf; \
else if ((m)->m_flags & M_PKTHDR) \
(m)->m_data = (m)->m_pktdat; \
#define NFSMADV(m, s) (m)->m_data += (s)
#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \
(((m)->m_flags & M_PKTHDR)?MHLEN:MLEN))
* Now for the macros that do the simple stuff and call the functions
* These macros use several vars. declared in nfsm_reqhead and these
* vars. must not be used elsewhere unless you are careful not to corrupt
* them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
* that may be used so long as the value is not expected to retained
* I know, this is kind of dorkey, but it makes the actual op functions
* fairly clean and deals with the mess caused by the xdr discriminating
#define nfsm_build(a,c,s) \
{ if ((s) > M_TRAILINGSPACE(mb)) { \
MGET(mb2, M_WAIT, MT_DATA); \
bpos = mtod(mb, caddr_t); \
#define nfsm_dissect(a, c, s) \
{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
} else if (t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2)) { \
#define nfsm_fhtom(v, v3) \
t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \
if (t2 <= M_TRAILINGSPACE(mb)) { \
nfsm_build(tl, u_long *, t2); \
*tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \
*(tl + ((t2>>2) - 2)) = 0; \
bcopy((caddr_t)VTONFS(v)->n_fhp,(caddr_t)tl, \
} else if (t2 = nfsm_strtmbuf(&mb, &bpos, \
(caddr_t)VTONFS(v)->n_fhp, VTONFS(v)->n_fhsize)) { \
nfsm_build(cp, caddr_t, NFSX_V2FH); \
bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \
#define nfsm_srvfhtom(f, v3) \
nfsm_build(tl, u_long *, NFSX_UNSIGNED + NFSX_V3FH); \
*tl++ = txdr_unsigned(NFSX_V3FH); \
bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \
nfsm_build(cp, caddr_t, NFSX_V2FH); \
bcopy((caddr_t)(f), cp, NFSX_V2FH); \
#define nfsm_srvpostop_fh(f) \
{ nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \
*tl++ = txdr_unsigned(NFSX_V3FH); \
bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \
#define nfsm_mtofh(d, v, v3, f) \
{ struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
(f) = fxdr_unsigned(int, *tl); \
nfsm_getfh(ttfhp, ttfhsize, (v3)); \
if (t1 = nfs_nget((d)->v_mount, ttfhp, ttfhsize, \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
(f) = fxdr_unsigned(int, *tl); \
else if (fxdr_unsigned(int, *tl)) \
nfsm_adv(NFSX_V3FATTR); \
nfsm_loadattr((v), (struct vattr *)0); \
#define nfsm_getfh(f, s, v3) \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \
nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); }
#define nfsm_loadattr(v, a) \
{ struct vnode *ttvp = (v); \
if (t1 = nfs_loadattrcache(&ttvp, &md, &dpos, (a))) { \
#define nfsm_postop_attr(v, f) \
{ struct vnode *ttvp = (v); \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
if ((f) = fxdr_unsigned(int, *tl)) { \
if (t1 = nfs_loadattrcache(&ttvp, &md, &dpos, \
/* Used as (f) for nfsm_wcc_data() */
#define nfsm_wcc_data(v, f) \
{ int ttattrf, ttretf = 0; \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
nfsm_dissect(tl, u_long *, 6 * NFSX_UNSIGNED); \
ttretf = (VTONFS(v)->n_mtime == \
fxdr_unsigned(u_long, *(tl + 2))); \
nfsm_postop_attr((v), ttattrf); \
#define nfsm_v3sattr(s, a, u, g) \
{ (s)->sa_modetrue = nfs_true; \
(s)->sa_mode = vtonfsv3_mode((a)->va_mode); \
(s)->sa_uidtrue = nfs_true; \
(s)->sa_uid = txdr_unsigned(u); \
(s)->sa_gidtrue = nfs_true; \
(s)->sa_gid = txdr_unsigned(g); \
(s)->sa_sizefalse = nfs_false; \
(s)->sa_atimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
txdr_nfsv3time(&(a)->va_atime, &(s)->sa_atime); \
(s)->sa_mtimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
txdr_nfsv3time(&(a)->va_mtime, &(s)->sa_mtime); \
#define nfsm_strsiz(s,m) \
{ nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \
if (((s) = fxdr_unsigned(long,*tl)) > (m)) { \
#define nfsm_srvstrsiz(s,m) \
{ nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \
if (((s) = fxdr_unsigned(long,*tl)) > (m) || (s) <= 0) { \
#define nfsm_srvnamesiz(s) \
{ nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \
if (((s) = fxdr_unsigned(long,*tl)) > NFS_MAXNAMLEN) \
error = NFSERR_NAMETOL; \
#define nfsm_mtouio(p,s) \
(t1 = nfsm_mbuftouio(&md,(p),(s),&dpos))) { \
#define nfsm_uiotom(p,s) \
if (t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) { \
#define nfsm_reqhead(v,a,s) \
mb = mreq = nfsm_reqh((v),(a),(s),&bpos)
#define nfsm_reqdone m_freem(mrep); \
#define nfsm_rndup(a) (((a)+3)&(~0x3))
#define nfsm_request(v, t, p, c) \
if (error = nfs_request((v), mreq, (t), (p), \
(c), &mrep, &md, &dpos)) { \
if (error & NFSERR_RETERR) \
error &= ~NFSERR_RETERR; \
#define nfsm_strtom(a,s,m) \
t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \
if (t2 <= M_TRAILINGSPACE(mb)) { \
nfsm_build(tl,u_long *,t2); \
*tl++ = txdr_unsigned(s); \
bcopy((caddr_t)(a), (caddr_t)tl, (s)); \
} else if (t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s))) { \
nfsd->nd_repstat = error; \
if (error && !(nfsd->nd_flag & ND_NFSV3)) \
(void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
(void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
if (error && (!(nfsd->nd_flag & ND_NFSV3) || \
#define nfsm_writereply(s, v3) \
nfsd->nd_repstat = error; \
(void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
(void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
} else if (t1 = nfs_adv(&md, &dpos, (s), t1)) { \
#define nfsm_srvmtofh(f) \
{ if (nfsd->nd_flag & ND_NFSV3) { \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
if (fxdr_unsigned(int, *tl) != NFSX_V3FH) { \
nfsm_dissect(tl, u_long *, NFSX_V3FH); \
bcopy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \
if ((nfsd->nd_flag & ND_NFSV3) == 0) \
nfsm_adv(NFSX_V2FH - NFSX_V3FH); \
MGET(mp, M_WAIT, MT_DATA); \
mp->m_len = NFSMSIZ(mp); \
bp = mtod(mp, caddr_t); \
#define nfsm_srvfillattr(a, f) \
nfsm_srvfattr(nfsd, (a), (f))
#define nfsm_srvwcc_data(br, b, ar, a) \
nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos)
#define nfsm_srvpostop_attr(r, a) \
nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos)
#define nfsm_srvsattr(a) \
{ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
(a)->va_mode = nfstov_mode(*tl); \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
(a)->va_uid = fxdr_unsigned(uid_t, *tl); \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
(a)->va_gid = fxdr_unsigned(gid_t, *tl); \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
fxdr_hyper(tl, &(a)->va_size); \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
switch (fxdr_unsigned(int, *tl)) { \
case NFSV3SATTRTIME_TOCLIENT: \
nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
fxdr_nfsv3time(tl, &(a)->va_atime); \
case NFSV3SATTRTIME_TOSERVER: \
(a)->va_atime.ts_sec = time.tv_sec; \
(a)->va_atime.ts_nsec = time.tv_usec * 1000; \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
switch (fxdr_unsigned(int, *tl)) { \
case NFSV3SATTRTIME_TOCLIENT: \
nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
fxdr_nfsv3time(tl, &(a)->va_mtime); \
case NFSV3SATTRTIME_TOSERVER: \
(a)->va_mtime.ts_sec = time.tv_sec; \
(a)->va_mtime.ts_nsec = time.tv_usec * 1000; \