Annotation of 43BSDReno/sys/nfs/nfsm_subs.h, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1989 The Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * This code is derived from software contributed to Berkeley by
        !             6:  * Rick Macklem at The University of Guelph.
        !             7:  *
        !             8:  * Redistribution is only permitted until one year after the first shipment
        !             9:  * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
        !            10:  * binary forms are permitted provided that: (1) source distributions retain
        !            11:  * this entire copyright notice and comment, and (2) distributions including
        !            12:  * binaries display the following acknowledgement:  This product includes
        !            13:  * software developed by the University of California, Berkeley and its
        !            14:  * contributors'' in the documentation or other materials provided with the
        !            15:  * distribution and in all advertising materials mentioning features or use
        !            16:  * of this software.  Neither the name of the University nor the names of
        !            17:  * its contributors may be used to endorse or promote products derived from
        !            18:  * this software without specific prior written permission.
        !            19:  * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            20:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            21:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            22:  *
        !            23:  *     @(#)nfsm_subs.h 7.10 (Berkeley) 6/28/90
        !            24:  */
        !            25: 
        !            26: /*
        !            27:  * These macros do strange and peculiar things to mbuf chains for
        !            28:  * the assistance of the nfs code. To attempt to use them for any
        !            29:  * other purpose will be dangerous. (they make weird assumptions)
        !            30:  */
        !            31: 
        !            32: /*
        !            33:  * First define what the actual subs. return
        !            34:  */
        !            35: extern struct mbuf *nfsm_reqh();
        !            36: 
        !            37: #define        M_HASCL(m)      ((m)->m_flags & M_EXT)
        !            38: #define        NFSMGETHDR(m) \
        !            39:                MGETHDR(m, M_WAIT, MT_DATA); \
        !            40:                (m)->m_pkthdr.len = 0; \
        !            41:                (m)->m_pkthdr.rcvif = (struct ifnet *)0
        !            42: #define        NFSMINOFF(m) \
        !            43:                if (M_HASCL(m)) \
        !            44:                        (m)->m_data = (m)->m_ext.ext_buf; \
        !            45:                else \
        !            46:                        (m)->m_data = (m)->m_dat
        !            47: #define        NFSMADV(m, s)   (m)->m_data += (s)
        !            48: #define        NFSMSIZ(m)      ((M_HASCL(m))?MCLBYTES: \
        !            49:                                (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN))
        !            50: 
        !            51: /*
        !            52:  * Now for the macros that do the simple stuff and call the functions
        !            53:  * for the hard stuff.
        !            54:  * These macros use several vars. declared in nfsm_reqhead and these
        !            55:  * vars. must not be used elsewhere unless you are careful not to corrupt
        !            56:  * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
        !            57:  * that may be used so long as the value is not expected to retained
        !            58:  * after a macro.
        !            59:  * I know, this is kind of dorkey, but it makes the actual op functions
        !            60:  * fairly clean and deals with the mess caused by the xdr discriminating
        !            61:  * unions.
        !            62:  */
        !            63: 
        !            64: #ifndef lint
        !            65: #define        nfsm_build(a,c,s) \
        !            66:                t1 = NFSMSIZ(mb); \
        !            67:                if ((s) > (t1-mb->m_len)) { \
        !            68:                        MGET(mb2, M_WAIT, MT_DATA); \
        !            69:                        if ((s) > MLEN) \
        !            70:                                panic("build > MLEN"); \
        !            71:                        mb->m_next = mb2; \
        !            72:                        mb = mb2; \
        !            73:                        mb->m_len = 0; \
        !            74:                        bpos = mtod(mb, caddr_t); \
        !            75:                } \
        !            76:                (a) = (c)(bpos); \
        !            77:                mb->m_len += (s); \
        !            78:                bpos += (s)
        !            79: #else /* lint */
        !            80: #define        nfsm_build(a,c,s) \
        !            81:                t1 = NFSMSIZ(mb); \
        !            82:                if ((s) > (t1-mb->m_len)) { \
        !            83:                        MGET(mb2, M_WAIT, MT_DATA); \
        !            84:                        mb->m_next = mb2; \
        !            85:                        mb = mb2; \
        !            86:                        mb->m_len = 0; \
        !            87:                        bpos = mtod(mb, caddr_t); \
        !            88:                } \
        !            89:                (a) = (c)(bpos); \
        !            90:                mb->m_len += (s); \
        !            91:                bpos += (s)
        !            92: #endif /* lint */
        !            93: 
        !            94: #define        nfsm_disect(a,c,s) \
        !            95:                t1 = mtod(md, caddr_t)+md->m_len-dpos; \
        !            96:                if (t1 >= (s)) { \
        !            97:                        (a) = (c)(dpos); \
        !            98:                        dpos += (s); \
        !            99:                } else if (error = nfsm_disct(&md, &dpos, (s), t1, TRUE, &cp2)) { \
        !           100:                        m_freem(mrep); \
        !           101:                        goto nfsmout; \
        !           102:                } else { \
        !           103:                        (a) = (c)cp2; \
        !           104:                }
        !           105: 
        !           106: #define        nfsm_disecton(a,c,s) \
        !           107:                t1 = mtod(md, caddr_t)+md->m_len-dpos; \
        !           108:                if (t1 >= (s)) { \
        !           109:                        (a) = (c)(dpos); \
        !           110:                        dpos += (s); \
        !           111:                } else if (error = nfsm_disct(&md, &dpos, (s), t1, FALSE, &cp2)) { \
        !           112:                        m_freem(mrep); \
        !           113:                        goto nfsmout; \
        !           114:                } else { \
        !           115:                        (a) = (c)cp2; \
        !           116:                }
        !           117: 
        !           118: #define nfsm_fhtom(v) \
        !           119:                nfsm_build(cp,caddr_t,NFSX_FH); \
        !           120:                bcopy((caddr_t)&(VTONFS(v)->n_fh), cp, NFSX_FH)
        !           121: 
        !           122: #define nfsm_srvfhtom(f) \
        !           123:                nfsm_build(cp,caddr_t,NFSX_FH); \
        !           124:                bcopy((caddr_t)(f), cp, NFSX_FH)
        !           125: 
        !           126: #define nfsm_mtofh(d,v) \
        !           127:                { struct nfsnode *np; nfsv2fh_t *fhp; \
        !           128:                nfsm_disect(fhp,nfsv2fh_t *,NFSX_FH); \
        !           129:                if (error = nfs_nget((d)->v_mount, fhp, &np)) { \
        !           130:                        m_freem(mrep); \
        !           131:                        goto nfsmout; \
        !           132:                } \
        !           133:                (v) = NFSTOV(np); \
        !           134:                nfsm_loadattr(v, (struct vattr *)0); \
        !           135:                }
        !           136: 
        !           137: #define        nfsm_loadattr(v,a) \
        !           138:                { struct vnode *tvp = (v); \
        !           139:                if (error = nfs_loadattrcache(&tvp, &md, &dpos, (a))) { \
        !           140:                        m_freem(mrep); \
        !           141:                        goto nfsmout; \
        !           142:                } \
        !           143:                (v) = tvp; }
        !           144: 
        !           145: #define        nfsm_strsiz(s,m) \
        !           146:                nfsm_disect(p,u_long *,NFSX_UNSIGNED); \
        !           147:                if (((s) = fxdr_unsigned(long,*p)) > (m)) { \
        !           148:                        m_freem(mrep); \
        !           149:                        error = EBADRPC; \
        !           150:                        goto nfsmout; \
        !           151:                }
        !           152: 
        !           153: #define        nfsm_srvstrsiz(s,m) \
        !           154:                nfsm_disect(p,u_long *,NFSX_UNSIGNED); \
        !           155:                if (((s) = fxdr_unsigned(long,*p)) > (m) || (s) <= 0) { \
        !           156:                        error = EBADRPC; \
        !           157:                        nfsm_reply(0); \
        !           158:                }
        !           159: 
        !           160: #define nfsm_mtouio(p,s) \
        !           161:                if ((s) > 0 && \
        !           162:                   (error = nfsm_mbuftouio(&md,(p),(s),&dpos))) { \
        !           163:                        m_freem(mrep); \
        !           164:                        goto nfsmout; \
        !           165:                }
        !           166: 
        !           167: #define nfsm_uiotom(p,s) \
        !           168:                if (error = nfsm_uiotombuf((p),&mb,(s),&bpos)) { \
        !           169:                        m_freem(mreq); \
        !           170:                        goto nfsmout; \
        !           171:                }
        !           172: 
        !           173: #define        nfsm_reqhead(a,c,s) \
        !           174:                if ((mreq = nfsm_reqh(nfs_prog,nfs_vers,(a),(c),(s),&bpos,&mb,&xid)) == NULL) { \
        !           175:                        error = ENOBUFS; \
        !           176:                        goto nfsmout; \
        !           177:                }
        !           178: 
        !           179: #define nfsm_reqdone   m_freem(mrep); \
        !           180:                nfsmout: 
        !           181: 
        !           182: #define nfsm_rndup(a)  (((a)+3)&(~0x3))
        !           183: 
        !           184: #define        nfsm_request(v, t, p, h)        \
        !           185:                if (error = nfs_request((v), mreq, xid, (t), (p), (h), \
        !           186:                   (v)->v_mount, &mrep, &md, &dpos)) \
        !           187:                        goto nfsmout
        !           188: 
        !           189: #define        nfsm_strtom(a,s,m) \
        !           190:                if ((s) > (m)) { \
        !           191:                        m_freem(mreq); \
        !           192:                        error = ENAMETOOLONG; \
        !           193:                        goto nfsmout; \
        !           194:                } \
        !           195:                t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \
        !           196:                if(t2<=(NFSMSIZ(mb)-mb->m_len)){ \
        !           197:                        nfsm_build(p,u_long *,t2); \
        !           198:                        *p++ = txdr_unsigned(s); \
        !           199:                        *(p+((t2>>2)-2)) = 0; \
        !           200:                        bcopy((caddr_t)(a), (caddr_t)p, (s)); \
        !           201:                } else if (error = nfsm_strtmbuf(&mb, &bpos, (a), (s))) { \
        !           202:                        m_freem(mreq); \
        !           203:                        goto nfsmout; \
        !           204:                }
        !           205: 
        !           206: #define        nfsm_srvdone \
        !           207:                nfsmout: \
        !           208:                return(error)
        !           209: 
        !           210: #ifndef lint
        !           211: #define        nfsm_reply(s) \
        !           212:                { \
        !           213:                *repstat = error; \
        !           214:                if (error) \
        !           215:                        nfs_rephead(0, xid, error, mrq, &mb, &bpos); \
        !           216:                else \
        !           217:                        nfs_rephead((s), xid, error, mrq, &mb, &bpos); \
        !           218:                m_freem(mrep); \
        !           219:                mreq = *mrq; \
        !           220:                if (error) \
        !           221:                        return(0); \
        !           222:                }
        !           223: #else  /* lint */
        !           224: #define        nfsm_reply(s) \
        !           225:                { \
        !           226:                *repstat = error; \
        !           227:                if (error) \
        !           228:                        nfs_rephead(0, xid, error, mrq, &mb, &bpos); \
        !           229:                else \
        !           230:                        nfs_rephead((s), xid, error, mrq, &mb, &bpos); \
        !           231:                m_freem(mrep); \
        !           232:                mreq = *mrq; \
        !           233:                mrep = mreq; \
        !           234:                if (error) \
        !           235:                        return(0); \
        !           236:                }
        !           237: #endif /* lint */
        !           238: 
        !           239: #define        nfsm_adv(s) \
        !           240:                t1 = mtod(md, caddr_t)+md->m_len-dpos; \
        !           241:                if (t1 >= (s)) { \
        !           242:                        dpos += (s); \
        !           243:                } else if (error = nfs_adv(&md, &dpos, (s), t1)) { \
        !           244:                        m_freem(mrep); \
        !           245:                        goto nfsmout; \
        !           246:                }
        !           247: 
        !           248: #define nfsm_srvmtofh(f) \
        !           249:                nfsm_disecton(p, u_long *, NFSX_FH); \
        !           250:                bcopy((caddr_t)p, (caddr_t)f, NFSX_FH)
        !           251: 
        !           252: #define        nfsm_clget \
        !           253:                if (bp >= be) { \
        !           254:                        MGET(mp, M_WAIT, MT_DATA); \
        !           255:                        MCLGET(mp, M_WAIT); \
        !           256:                        mp->m_len = NFSMSIZ(mp); \
        !           257:                        if (mp3 == NULL) \
        !           258:                                mp3 = mp2 = mp; \
        !           259:                        else { \
        !           260:                                mp2->m_next = mp; \
        !           261:                                mp2 = mp; \
        !           262:                        } \
        !           263:                        bp = mtod(mp, caddr_t); \
        !           264:                        be = bp+mp->m_len; \
        !           265:                } \
        !           266:                p = (u_long *)bp
        !           267: 
        !           268: #define        nfsm_srvfillattr \
        !           269:        fp->fa_type = vtonfs_type(vap->va_type); \
        !           270:        fp->fa_mode = vtonfs_mode(vap->va_type, vap->va_mode); \
        !           271:        fp->fa_nlink = txdr_unsigned(vap->va_nlink); \
        !           272:        fp->fa_uid = txdr_unsigned(vap->va_uid); \
        !           273:        fp->fa_gid = txdr_unsigned(vap->va_gid); \
        !           274:        fp->fa_size = txdr_unsigned(vap->va_size); \
        !           275:        fp->fa_blocksize = txdr_unsigned(vap->va_blocksize); \
        !           276:        if (vap->va_type == VFIFO) \
        !           277:                fp->fa_rdev = 0xffffffff; \
        !           278:        else \
        !           279:                fp->fa_rdev = txdr_unsigned(vap->va_rdev); \
        !           280:        fp->fa_blocks = txdr_unsigned(vap->va_bytes / NFS_FABLKSIZE); \
        !           281:        fp->fa_fsid = txdr_unsigned(vap->va_fsid); \
        !           282:        fp->fa_fileid = txdr_unsigned(vap->va_fileid); \
        !           283:        fp->fa_atime.tv_sec = txdr_unsigned(vap->va_atime.tv_sec); \
        !           284:        fp->fa_atime.tv_usec = txdr_unsigned(vap->va_flags); \
        !           285:        txdr_time(&vap->va_mtime, &fp->fa_mtime); \
        !           286:        fp->fa_ctime.tv_sec = txdr_unsigned(vap->va_ctime.tv_sec); \
        !           287:        fp->fa_ctime.tv_usec = txdr_unsigned(vap->va_gen)
        !           288: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.