From d4c0c0bd4aa267c169eeebee5cb975271791f325 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 19 Aug 1999 14:50:12 +0000 Subject: Convert all the nfs macros to do { blah } while (0) to ensure it works correctly in if/else etc. egcs had probably picked up most of the problems here before with "ambiguous braces" etc, but this should increase the robustness a bit. Based on an idea from Eivind Eklund. --- sys/nfs/nfs_common.h | 279 +++++++++++++++++++++++++++++++-------------------- sys/nfs/nfsm_subs.h | 279 +++++++++++++++++++++++++++++++-------------------- sys/nfs/xdr_subs.h | 27 +++-- 3 files changed, 352 insertions(+), 233 deletions(-) (limited to 'sys/nfs') diff --git a/sys/nfs/nfs_common.h b/sys/nfs/nfs_common.h index f70645f..8533d52 100644 --- a/sys/nfs/nfs_common.h +++ b/sys/nfs/nfs_common.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 - * $Id: nfsm_subs.h,v 1.24 1999/06/23 04:44:14 julian Exp $ + * $Id: nfsm_subs.h,v 1.25 1999/08/04 14:41:39 peter Exp $ */ @@ -63,13 +63,18 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, #define M_HASCL(m) ((m)->m_flags & M_EXT) #define NFSMINOFF(m) \ + do { \ if (M_HASCL(m)) \ (m)->m_data = (m)->m_ext.ext_buf; \ else if ((m)->m_flags & M_PKTHDR) \ (m)->m_data = (m)->m_pktdat; \ else \ - (m)->m_data = (m)->m_dat -#define NFSMADV(m, s) (m)->m_data += (s) + (m)->m_data = (m)->m_dat; \ + } while (0) +#define NFSMADV(m, s) \ + do { \ + (m)->m_data += (s); \ + } while (0) #define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) @@ -87,7 +92,8 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, */ #define nfsm_build(a,c,s) \ - { if ((s) > M_TRAILINGSPACE(mb)) { \ + do { \ + if ((s) > M_TRAILINGSPACE(mb)) { \ MGET(mb2, M_WAIT, MT_DATA); \ if ((s) > MLEN) \ panic("build > MLEN"); \ @@ -98,10 +104,12 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } \ (a) = (c)(bpos); \ mb->m_len += (s); \ - bpos += (s); } + bpos += (s); \ + } while (0) #define nfsm_dissect(a, c, s) \ - { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ + do { \ + t1 = mtod(md, caddr_t)+md->m_len-dpos; \ if (t1 >= (s)) { \ (a) = (c)(dpos); \ dpos += (s); \ @@ -111,10 +119,12 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, goto nfsmout; \ } else { \ (a) = (c)cp2; \ - } } + } \ + } while (0) #define nfsm_fhtom(v, v3) \ - { if (v3) { \ + do { \ + if (v3) { \ t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \ if (t2 <= M_TRAILINGSPACE(mb)) { \ nfsm_build(tl, u_int32_t *, t2); \ @@ -132,27 +142,32 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } else { \ nfsm_build(cp, caddr_t, NFSX_V2FH); \ bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \ - } } + } \ + } while (0) #define nfsm_srvfhtom(f, v3) \ - { if (v3) { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3FH); \ + do { \ + if (v3) { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3FH);\ *tl++ = txdr_unsigned(NFSX_V3FH); \ bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ } else { \ nfsm_build(cp, caddr_t, NFSX_V2FH); \ bcopy((caddr_t)(f), cp, NFSX_V2FH); \ - } } + } \ + } while (0) #define nfsm_srvpostop_fh(f) \ - { nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \ + do { \ + nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \ *tl++ = nfs_true; \ *tl++ = txdr_unsigned(NFSX_V3FH); \ bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ - } + } while (0) #define nfsm_mtofh(d, v, v3, f) \ - { struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \ + do { \ + struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \ if (v3) { \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ (f) = fxdr_unsigned(int, *tl); \ @@ -177,10 +192,11 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } \ if (f) \ nfsm_loadattr((v), (struct vattr *)0); \ - } + } while (0) #define nfsm_getfh(f, s, v3) \ - { if (v3) { \ + do { \ + if (v3) { \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \ (s) > NFSX_V3FHMAX) { \ @@ -190,19 +206,23 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } \ } else \ (s) = NFSX_V2FH; \ - nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); } + nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); \ + } while (0) #define nfsm_loadattr(v, a) \ - { struct vnode *ttvp = (v); \ + do { \ + struct vnode *ttvp = (v); \ if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, (a))) != 0) { \ error = t1; \ m_freem(mrep); \ goto nfsmout; \ } \ - (v) = ttvp; } + (v) = ttvp; \ + } while (0) #define nfsm_postop_attr(v, f) \ - { struct vnode *ttvp = (v); \ + do { \ + struct vnode *ttvp = (v); \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ if (((f) = fxdr_unsigned(int, *tl)) != 0) { \ if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, \ @@ -213,14 +233,16 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, goto nfsmout; \ } \ (v) = ttvp; \ - } } + } \ + } while (0) /* Used as (f) for nfsm_wcc_data() */ #define NFSV3_WCCRATTR 0 #define NFSV3_WCCCHK 1 #define nfsm_wcc_data(v, f) \ - { int ttattrf, ttretf = 0; \ + do { \ + int ttattrf, ttretf = 0; \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ if (*tl == nfs_true) { \ nfsm_dissect(tl, u_int32_t *, 6 * NFSX_UNSIGNED); \ @@ -233,129 +255,148 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, (f) = ttretf; \ } else { \ (f) = ttattrf; \ - } } + } \ + } while (0) /* If full is true, set all fields, otherwise just set mode and time fields */ -#define nfsm_v3attrbuild(a, full) \ - { if ((a)->va_mode != (mode_t)VNOVAL) { \ - nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ - *tl++ = nfs_true; \ - *tl = txdr_unsigned((a)->va_mode); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = nfs_false; \ - } \ - if ((full) && (a)->va_uid != (uid_t)VNOVAL) { \ - nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ - *tl++ = nfs_true; \ - *tl = txdr_unsigned((a)->va_uid); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = nfs_false; \ - } \ - if ((full) && (a)->va_gid != (gid_t)VNOVAL) { \ - nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ - *tl++ = nfs_true; \ - *tl = txdr_unsigned((a)->va_gid); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = nfs_false; \ - } \ - if ((full) && (a)->va_size != VNOVAL) { \ - nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ - *tl++ = nfs_true; \ - txdr_hyper((a)->va_size, tl); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = nfs_false; \ - } \ - if ((a)->va_atime.tv_sec != VNOVAL) { \ - if ((a)->va_atime.tv_sec != time_second) { \ - nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ - *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ - txdr_nfsv3time(&(a)->va_atime, tl); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ - } \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ - } \ - if ((a)->va_mtime.tv_sec != VNOVAL) { \ - if ((a)->va_mtime.tv_sec != time_second) { \ - nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ - *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ - txdr_nfsv3time(&(a)->va_mtime, tl); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ - } \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ - } \ - } +#define nfsm_v3attrbuild(a, full) \ + do { \ + if ((a)->va_mode != (mode_t)VNOVAL) { \ + nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ + *tl++ = nfs_true; \ + *tl = txdr_unsigned((a)->va_mode); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = nfs_false; \ + } \ + if ((full) && (a)->va_uid != (uid_t)VNOVAL) { \ + nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ + *tl++ = nfs_true; \ + *tl = txdr_unsigned((a)->va_uid); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = nfs_false; \ + } \ + if ((full) && (a)->va_gid != (gid_t)VNOVAL) { \ + nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ + *tl++ = nfs_true; \ + *tl = txdr_unsigned((a)->va_gid); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = nfs_false; \ + } \ + if ((full) && (a)->va_size != VNOVAL) { \ + nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ + *tl++ = nfs_true; \ + txdr_hyper((a)->va_size, tl); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = nfs_false; \ + } \ + if ((a)->va_atime.tv_sec != VNOVAL) { \ + if ((a)->va_atime.tv_sec != time_second) { \ + nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);\ + *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);\ + txdr_nfsv3time(&(a)->va_atime, tl); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ + } \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ + } \ + if ((a)->va_mtime.tv_sec != VNOVAL) { \ + if ((a)->va_mtime.tv_sec != time_second) { \ + nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);\ + *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);\ + txdr_nfsv3time(&(a)->va_mtime, tl); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ + } \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ + } \ + } while (0) #define nfsm_strsiz(s,m) \ - { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ + do { \ + nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ if (((s) = fxdr_unsigned(int32_t,*tl)) > (m)) { \ m_freem(mrep); \ error = EBADRPC; \ goto nfsmout; \ - } } + } \ + } while (0) #define nfsm_srvstrsiz(s,m) \ - { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ + do { \ + nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ if (((s) = fxdr_unsigned(int32_t,*tl)) > (m) || (s) <= 0) { \ error = EBADRPC; \ nfsm_reply(0); \ - } } + } \ + } while (0) #define nfsm_srvnamesiz(s) \ - { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ + do { \ + nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ if (((s) = fxdr_unsigned(int32_t,*tl)) > NFS_MAXNAMLEN) \ error = NFSERR_NAMETOL; \ if ((s) <= 0) \ error = EBADRPC; \ if (error) \ nfsm_reply(0); \ - } + } while (0) #define nfsm_mtouio(p,s) \ + do {\ if ((s) > 0 && \ (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \ error = t1; \ m_freem(mrep); \ goto nfsmout; \ - } + } \ + } while (0) #define nfsm_uiotom(p,s) \ + do { \ if ((t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) != 0) { \ error = t1; \ m_freem(mreq); \ goto nfsmout; \ - } + } \ + } while (0) #define nfsm_reqhead(v,a,s) \ - mb = mreq = nfsm_reqh((v),(a),(s),&bpos) + do { \ + mb = mreq = nfsm_reqh((v),(a),(s),&bpos); \ + } while (0) -#define nfsm_reqdone m_freem(mrep); \ - nfsmout: +#define nfsm_reqdone \ + do { \ + m_freem(mrep); \ + nfsmout: \ + } while (0) #define nfsm_rndup(a) (((a)+3)&(~0x3)) -#define nfsm_request(v, t, p, c) \ +#define nfsm_request(v, t, p, c) \ + do { \ if ((error = nfs_request((v), mreq, (t), (p), \ (c), &mrep, &md, &dpos)) != 0) { \ if (error & NFSERR_RETERR) \ error &= ~NFSERR_RETERR; \ else \ goto nfsmout; \ - } + } \ + } while (0) #define nfsm_strtom(a,s,m) \ + do {\ if ((s) > (m)) { \ m_freem(mreq); \ error = ENAMETOOLONG; \ @@ -371,14 +412,17 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, error = t2; \ m_freem(mreq); \ goto nfsmout; \ - } + } \ + } while (0) #define nfsm_srvdone \ + do { \ nfsmout: \ - return(error) + return (error); \ + } while (0) #define nfsm_reply(s) \ - { \ + do { \ nfsd->nd_repstat = error; \ if (error && !(nfsd->nd_flag & ND_NFSV3)) \ (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ @@ -395,10 +439,11 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, error == EBADRPC)) { \ error = 0; \ goto nfsmout; \ - } } + } \ + } while (0) #define nfsm_writereply(s, v3) \ - { \ + do { \ nfsd->nd_repstat = error; \ if (error && !(v3)) \ (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ @@ -406,17 +451,19 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, else \ (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \ &mreq, &mb, &bpos); \ - } + } while (0) #define nfsm_adv(s) \ - { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ + do { \ + t1 = mtod(md, caddr_t)+md->m_len-dpos; \ if (t1 >= (s)) { \ dpos += (s); \ } else if ((t1 = nfs_adv(&md, &dpos, (s), t1)) != 0) { \ error = t1; \ m_freem(mrep); \ goto nfsmout; \ - } } + } \ + } while (0) #define nfsm_srvmtofh(f) \ do { \ @@ -440,6 +487,7 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } while (0) #define nfsm_clget \ + do { \ if (bp >= be) { \ if (mp == mb) \ mp->m_len += bp-bpos; \ @@ -451,19 +499,27 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, bp = mtod(mp, caddr_t); \ be = bp+mp->m_len; \ } \ - tl = (u_int32_t *)bp + tl = (u_int32_t *)bp; \ + } while (0) #define nfsm_srvfillattr(a, f) \ - nfsm_srvfattr(nfsd, (a), (f)) + do { \ + nfsm_srvfattr(nfsd, (a), (f)); \ + } while (0) #define nfsm_srvwcc_data(br, b, ar, a) \ - nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos) + do { \ + nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos); \ + } while (0) #define nfsm_srvpostop_attr(r, a) \ - nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos) + do { \ + nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos); \ + } while (0) #define nfsm_srvsattr(a) \ - { nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ + do { \ + nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ if (*tl == nfs_true) { \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ (a)->va_mode = nfstov_mode(*tl); \ @@ -502,6 +558,7 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, case NFSV3SATTRTIME_TOSERVER: \ getnanotime(&(a)->va_mtime); \ break; \ - }; } + } \ + } while (0) #endif diff --git a/sys/nfs/nfsm_subs.h b/sys/nfs/nfsm_subs.h index f70645f..8533d52 100644 --- a/sys/nfs/nfsm_subs.h +++ b/sys/nfs/nfsm_subs.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 - * $Id: nfsm_subs.h,v 1.24 1999/06/23 04:44:14 julian Exp $ + * $Id: nfsm_subs.h,v 1.25 1999/08/04 14:41:39 peter Exp $ */ @@ -63,13 +63,18 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, #define M_HASCL(m) ((m)->m_flags & M_EXT) #define NFSMINOFF(m) \ + do { \ if (M_HASCL(m)) \ (m)->m_data = (m)->m_ext.ext_buf; \ else if ((m)->m_flags & M_PKTHDR) \ (m)->m_data = (m)->m_pktdat; \ else \ - (m)->m_data = (m)->m_dat -#define NFSMADV(m, s) (m)->m_data += (s) + (m)->m_data = (m)->m_dat; \ + } while (0) +#define NFSMADV(m, s) \ + do { \ + (m)->m_data += (s); \ + } while (0) #define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) @@ -87,7 +92,8 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, */ #define nfsm_build(a,c,s) \ - { if ((s) > M_TRAILINGSPACE(mb)) { \ + do { \ + if ((s) > M_TRAILINGSPACE(mb)) { \ MGET(mb2, M_WAIT, MT_DATA); \ if ((s) > MLEN) \ panic("build > MLEN"); \ @@ -98,10 +104,12 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } \ (a) = (c)(bpos); \ mb->m_len += (s); \ - bpos += (s); } + bpos += (s); \ + } while (0) #define nfsm_dissect(a, c, s) \ - { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ + do { \ + t1 = mtod(md, caddr_t)+md->m_len-dpos; \ if (t1 >= (s)) { \ (a) = (c)(dpos); \ dpos += (s); \ @@ -111,10 +119,12 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, goto nfsmout; \ } else { \ (a) = (c)cp2; \ - } } + } \ + } while (0) #define nfsm_fhtom(v, v3) \ - { if (v3) { \ + do { \ + if (v3) { \ t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \ if (t2 <= M_TRAILINGSPACE(mb)) { \ nfsm_build(tl, u_int32_t *, t2); \ @@ -132,27 +142,32 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } else { \ nfsm_build(cp, caddr_t, NFSX_V2FH); \ bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \ - } } + } \ + } while (0) #define nfsm_srvfhtom(f, v3) \ - { if (v3) { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3FH); \ + do { \ + if (v3) { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3FH);\ *tl++ = txdr_unsigned(NFSX_V3FH); \ bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ } else { \ nfsm_build(cp, caddr_t, NFSX_V2FH); \ bcopy((caddr_t)(f), cp, NFSX_V2FH); \ - } } + } \ + } while (0) #define nfsm_srvpostop_fh(f) \ - { nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \ + do { \ + nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \ *tl++ = nfs_true; \ *tl++ = txdr_unsigned(NFSX_V3FH); \ bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ - } + } while (0) #define nfsm_mtofh(d, v, v3, f) \ - { struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \ + do { \ + struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \ if (v3) { \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ (f) = fxdr_unsigned(int, *tl); \ @@ -177,10 +192,11 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } \ if (f) \ nfsm_loadattr((v), (struct vattr *)0); \ - } + } while (0) #define nfsm_getfh(f, s, v3) \ - { if (v3) { \ + do { \ + if (v3) { \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \ (s) > NFSX_V3FHMAX) { \ @@ -190,19 +206,23 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } \ } else \ (s) = NFSX_V2FH; \ - nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); } + nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); \ + } while (0) #define nfsm_loadattr(v, a) \ - { struct vnode *ttvp = (v); \ + do { \ + struct vnode *ttvp = (v); \ if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, (a))) != 0) { \ error = t1; \ m_freem(mrep); \ goto nfsmout; \ } \ - (v) = ttvp; } + (v) = ttvp; \ + } while (0) #define nfsm_postop_attr(v, f) \ - { struct vnode *ttvp = (v); \ + do { \ + struct vnode *ttvp = (v); \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ if (((f) = fxdr_unsigned(int, *tl)) != 0) { \ if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, \ @@ -213,14 +233,16 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, goto nfsmout; \ } \ (v) = ttvp; \ - } } + } \ + } while (0) /* Used as (f) for nfsm_wcc_data() */ #define NFSV3_WCCRATTR 0 #define NFSV3_WCCCHK 1 #define nfsm_wcc_data(v, f) \ - { int ttattrf, ttretf = 0; \ + do { \ + int ttattrf, ttretf = 0; \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ if (*tl == nfs_true) { \ nfsm_dissect(tl, u_int32_t *, 6 * NFSX_UNSIGNED); \ @@ -233,129 +255,148 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, (f) = ttretf; \ } else { \ (f) = ttattrf; \ - } } + } \ + } while (0) /* If full is true, set all fields, otherwise just set mode and time fields */ -#define nfsm_v3attrbuild(a, full) \ - { if ((a)->va_mode != (mode_t)VNOVAL) { \ - nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ - *tl++ = nfs_true; \ - *tl = txdr_unsigned((a)->va_mode); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = nfs_false; \ - } \ - if ((full) && (a)->va_uid != (uid_t)VNOVAL) { \ - nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ - *tl++ = nfs_true; \ - *tl = txdr_unsigned((a)->va_uid); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = nfs_false; \ - } \ - if ((full) && (a)->va_gid != (gid_t)VNOVAL) { \ - nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ - *tl++ = nfs_true; \ - *tl = txdr_unsigned((a)->va_gid); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = nfs_false; \ - } \ - if ((full) && (a)->va_size != VNOVAL) { \ - nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ - *tl++ = nfs_true; \ - txdr_hyper((a)->va_size, tl); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = nfs_false; \ - } \ - if ((a)->va_atime.tv_sec != VNOVAL) { \ - if ((a)->va_atime.tv_sec != time_second) { \ - nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ - *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ - txdr_nfsv3time(&(a)->va_atime, tl); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ - } \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ - } \ - if ((a)->va_mtime.tv_sec != VNOVAL) { \ - if ((a)->va_mtime.tv_sec != time_second) { \ - nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ - *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ - txdr_nfsv3time(&(a)->va_mtime, tl); \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ - } \ - } else { \ - nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ - *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ - } \ - } +#define nfsm_v3attrbuild(a, full) \ + do { \ + if ((a)->va_mode != (mode_t)VNOVAL) { \ + nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ + *tl++ = nfs_true; \ + *tl = txdr_unsigned((a)->va_mode); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = nfs_false; \ + } \ + if ((full) && (a)->va_uid != (uid_t)VNOVAL) { \ + nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ + *tl++ = nfs_true; \ + *tl = txdr_unsigned((a)->va_uid); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = nfs_false; \ + } \ + if ((full) && (a)->va_gid != (gid_t)VNOVAL) { \ + nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ + *tl++ = nfs_true; \ + *tl = txdr_unsigned((a)->va_gid); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = nfs_false; \ + } \ + if ((full) && (a)->va_size != VNOVAL) { \ + nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ + *tl++ = nfs_true; \ + txdr_hyper((a)->va_size, tl); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = nfs_false; \ + } \ + if ((a)->va_atime.tv_sec != VNOVAL) { \ + if ((a)->va_atime.tv_sec != time_second) { \ + nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);\ + *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);\ + txdr_nfsv3time(&(a)->va_atime, tl); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ + } \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ + } \ + if ((a)->va_mtime.tv_sec != VNOVAL) { \ + if ((a)->va_mtime.tv_sec != time_second) { \ + nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);\ + *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);\ + txdr_nfsv3time(&(a)->va_mtime, tl); \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ + } \ + } else { \ + nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ + *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ + } \ + } while (0) #define nfsm_strsiz(s,m) \ - { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ + do { \ + nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ if (((s) = fxdr_unsigned(int32_t,*tl)) > (m)) { \ m_freem(mrep); \ error = EBADRPC; \ goto nfsmout; \ - } } + } \ + } while (0) #define nfsm_srvstrsiz(s,m) \ - { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ + do { \ + nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ if (((s) = fxdr_unsigned(int32_t,*tl)) > (m) || (s) <= 0) { \ error = EBADRPC; \ nfsm_reply(0); \ - } } + } \ + } while (0) #define nfsm_srvnamesiz(s) \ - { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ + do { \ + nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ if (((s) = fxdr_unsigned(int32_t,*tl)) > NFS_MAXNAMLEN) \ error = NFSERR_NAMETOL; \ if ((s) <= 0) \ error = EBADRPC; \ if (error) \ nfsm_reply(0); \ - } + } while (0) #define nfsm_mtouio(p,s) \ + do {\ if ((s) > 0 && \ (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \ error = t1; \ m_freem(mrep); \ goto nfsmout; \ - } + } \ + } while (0) #define nfsm_uiotom(p,s) \ + do { \ if ((t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) != 0) { \ error = t1; \ m_freem(mreq); \ goto nfsmout; \ - } + } \ + } while (0) #define nfsm_reqhead(v,a,s) \ - mb = mreq = nfsm_reqh((v),(a),(s),&bpos) + do { \ + mb = mreq = nfsm_reqh((v),(a),(s),&bpos); \ + } while (0) -#define nfsm_reqdone m_freem(mrep); \ - nfsmout: +#define nfsm_reqdone \ + do { \ + m_freem(mrep); \ + nfsmout: \ + } while (0) #define nfsm_rndup(a) (((a)+3)&(~0x3)) -#define nfsm_request(v, t, p, c) \ +#define nfsm_request(v, t, p, c) \ + do { \ if ((error = nfs_request((v), mreq, (t), (p), \ (c), &mrep, &md, &dpos)) != 0) { \ if (error & NFSERR_RETERR) \ error &= ~NFSERR_RETERR; \ else \ goto nfsmout; \ - } + } \ + } while (0) #define nfsm_strtom(a,s,m) \ + do {\ if ((s) > (m)) { \ m_freem(mreq); \ error = ENAMETOOLONG; \ @@ -371,14 +412,17 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, error = t2; \ m_freem(mreq); \ goto nfsmout; \ - } + } \ + } while (0) #define nfsm_srvdone \ + do { \ nfsmout: \ - return(error) + return (error); \ + } while (0) #define nfsm_reply(s) \ - { \ + do { \ nfsd->nd_repstat = error; \ if (error && !(nfsd->nd_flag & ND_NFSV3)) \ (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ @@ -395,10 +439,11 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, error == EBADRPC)) { \ error = 0; \ goto nfsmout; \ - } } + } \ + } while (0) #define nfsm_writereply(s, v3) \ - { \ + do { \ nfsd->nd_repstat = error; \ if (error && !(v3)) \ (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ @@ -406,17 +451,19 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, else \ (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \ &mreq, &mb, &bpos); \ - } + } while (0) #define nfsm_adv(s) \ - { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ + do { \ + t1 = mtod(md, caddr_t)+md->m_len-dpos; \ if (t1 >= (s)) { \ dpos += (s); \ } else if ((t1 = nfs_adv(&md, &dpos, (s), t1)) != 0) { \ error = t1; \ m_freem(mrep); \ goto nfsmout; \ - } } + } \ + } while (0) #define nfsm_srvmtofh(f) \ do { \ @@ -440,6 +487,7 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } while (0) #define nfsm_clget \ + do { \ if (bp >= be) { \ if (mp == mb) \ mp->m_len += bp-bpos; \ @@ -451,19 +499,27 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, bp = mtod(mp, caddr_t); \ be = bp+mp->m_len; \ } \ - tl = (u_int32_t *)bp + tl = (u_int32_t *)bp; \ + } while (0) #define nfsm_srvfillattr(a, f) \ - nfsm_srvfattr(nfsd, (a), (f)) + do { \ + nfsm_srvfattr(nfsd, (a), (f)); \ + } while (0) #define nfsm_srvwcc_data(br, b, ar, a) \ - nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos) + do { \ + nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos); \ + } while (0) #define nfsm_srvpostop_attr(r, a) \ - nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos) + do { \ + nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos); \ + } while (0) #define nfsm_srvsattr(a) \ - { nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ + do { \ + nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ if (*tl == nfs_true) { \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ (a)->va_mode = nfstov_mode(*tl); \ @@ -502,6 +558,7 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, case NFSV3SATTRTIME_TOSERVER: \ getnanotime(&(a)->va_mtime); \ break; \ - }; } + } \ + } while (0) #endif diff --git a/sys/nfs/xdr_subs.h b/sys/nfs/xdr_subs.h index a77e5cf..bb60dd0 100644 --- a/sys/nfs/xdr_subs.h +++ b/sys/nfs/xdr_subs.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)xdr_subs.h 8.3 (Berkeley) 3/30/95 - * $Id: xdr_subs.h,v 1.10 1998/05/31 20:09:01 peter Exp $ + * $Id: xdr_subs.h,v 1.11 1999/06/05 05:35:03 peter Exp $ */ @@ -55,36 +55,41 @@ #define fxdr_unsigned(t, v) ((t)ntohl((int32_t)(v))) #define txdr_unsigned(v) (htonl((int32_t)(v))) -#define fxdr_nfsv2time(f, t) { \ +#define fxdr_nfsv2time(f, t) \ +do { \ (t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \ if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \ (t)->tv_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \ else \ (t)->tv_nsec = 0; \ -} -#define txdr_nfsv2time(f, t) { \ +} while (0) +#define txdr_nfsv2time(f, t) \ +do { \ ((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->tv_sec); \ if ((f)->tv_nsec != -1) \ ((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->tv_nsec / 1000); \ else \ ((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \ -} +} while (0) -#define fxdr_nfsv3time(f, t) { \ +#define fxdr_nfsv3time(f, t) \ +do { \ (t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \ (t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \ -} -#define txdr_nfsv3time(f, t) { \ +} while (0) +#define txdr_nfsv3time(f, t) \ +do { \ ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \ ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \ -} +} while (0) #define fxdr_hyper(f) \ ((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) | \ (u_quad_t)(ntohl(((u_int32_t *)(f))[1]))) -#define txdr_hyper(f, t) { \ +#define txdr_hyper(f, t) \ +do { \ ((u_int32_t *)(t))[0] = htonl((u_int32_t)((f) >> 32)); \ ((u_int32_t *)(t))[1] = htonl((u_int32_t)((f) & 0xffffffff)); \ -} +} while (0) #endif -- cgit v1.1