* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Rick Macklem at The University of Guelph.
* %sccs.include.redist.c%
* @(#)nfsm_subs.h 7.14 (Berkeley) %G%
* 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 (error = nfsm_disct(&md, &dpos, (s), t1, TRUE, &cp2)) { \
#define nfsm_dissecton(a,c,s) \
{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
} else if (error = nfsm_disct(&md, &dpos, (s), t1, FALSE, &cp2)) { \
nfsm_build(cp,caddr_t,NFSX_FH); \
bcopy((caddr_t)&(VTONFS(v)->n_fh), cp, NFSX_FH)
#define nfsm_srvfhtom(f) \
nfsm_build(cp,caddr_t,NFSX_FH); \
bcopy((caddr_t)(f), cp, NFSX_FH)
#define nfsm_mtofh(d,v) \
{ struct nfsnode *np; nfsv2fh_t *fhp; \
nfsm_dissect(fhp,nfsv2fh_t *,NFSX_FH); \
if (error = nfs_nget((d)->v_mount, fhp, &np)) { \
nfsm_loadattr(v, (struct vattr *)0); \
#define nfsm_loadattr(v,a) \
{ struct vnode *tvp = (v); \
if (error = nfs_loadattrcache(&tvp, &md, &dpos, (a))) { \
#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_mtouio(p,s) \
(error = nfsm_mbuftouio(&md,(p),(s),&dpos))) { \
#define nfsm_uiotom(p,s) \
if (error = 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)) \
#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 (error = nfsm_strtmbuf(&mb, &bpos, (a), (s))) { \
nfsd->nd_repstat = error; \
(void) nfs_rephead(0, nfsd, error, cache, &frev, \
(void) nfs_rephead((s), nfsd, error, cache, &frev, \
t1 = mtod(md, caddr_t)+md->m_len-dpos; \
} else if (error = nfs_adv(&md, &dpos, (s), t1)) { \
#define nfsm_srvmtofh(f) \
nfsm_dissecton(tl, u_long *, NFSX_FH); \
bcopy((caddr_t)tl, (caddr_t)f, NFSX_FH)
MGET(mp, M_WAIT, MT_DATA); \
mp->m_len = NFSMSIZ(mp); \
bp = mtod(mp, caddr_t); \
#define nfsm_srvfillattr \
fp->fa_type = vtonfs_type(vap->va_type); \
fp->fa_mode = vtonfs_mode(vap->va_type, vap->va_mode); \
fp->fa_nlink = txdr_unsigned(vap->va_nlink); \
fp->fa_uid = txdr_unsigned(vap->va_uid); \
fp->fa_gid = txdr_unsigned(vap->va_gid); \
if (nfsd->nd_nqlflag == NQL_NOVAL) { \
fp->fa_nfsblocksize = txdr_unsigned(vap->va_blocksize); \
if (vap->va_type == VFIFO) \
fp->fa_nfsrdev = 0xffffffff; \
fp->fa_nfsrdev = txdr_unsigned(vap->va_rdev); \
fp->fa_nfsfsid = txdr_unsigned(vap->va_fsid); \
fp->fa_nfsfileid = txdr_unsigned(vap->va_fileid); \
fp->fa_nfssize = txdr_unsigned(vap->va_size); \
fp->fa_nfsblocks = txdr_unsigned(vap->va_bytes / NFS_FABLKSIZE); \
fp->fa_nfsatime.nfs_sec = txdr_unsigned(vap->va_atime.ts_sec); \
fp->fa_nfsatime.nfs_usec = txdr_unsigned(vap->va_flags); \
txdr_nfstime(&vap->va_mtime, &fp->fa_nfsmtime); \
fp->fa_nfsctime.nfs_sec = txdr_unsigned(vap->va_ctime.ts_sec); \
fp->fa_nfsctime.nfs_usec = txdr_unsigned(vap->va_gen); \
fp->fa_nqblocksize = txdr_unsigned(vap->va_blocksize); \
if (vap->va_type == VFIFO) \
fp->fa_nqrdev = 0xffffffff; \
fp->fa_nqrdev = txdr_unsigned(vap->va_rdev); \
fp->fa_nqfsid = txdr_unsigned(vap->va_fsid); \
fp->fa_nqfileid = txdr_unsigned(vap->va_fileid); \
txdr_hyper(&vap->va_size, &fp->fa_nqsize); \
txdr_hyper(&vap->va_bytes, &fp->fa_nqbytes); \
txdr_nqtime(&vap->va_atime, &fp->fa_nqatime); \
txdr_nqtime(&vap->va_mtime, &fp->fa_nqmtime); \
txdr_nqtime(&vap->va_ctime, &fp->fa_nqctime); \
fp->fa_nqflags = txdr_unsigned(vap->va_flags); \
fp->fa_nqgen = txdr_unsigned(vap->va_gen); \
txdr_hyper(&vap->va_filerev, &fp->fa_nqfilerev); \