nfsm_subs.h revision 1.3
1/* $OpenBSD: nfsm_subs.h,v 1.3 1996/02/29 09:25:02 niklas Exp $ */ 2/* $NetBSD: nfsm_subs.h,v 1.8 1996/02/09 21:48:43 christos Exp $ */ 3 4/* 5 * Copyright (c) 1989, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Rick Macklem at The University of Guelph. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)nfsm_subs.h 8.1 (Berkeley) 6/16/93 40 */ 41 42/* 43 * These macros do strange and peculiar things to mbuf chains for 44 * the assistance of the nfs code. To attempt to use them for any 45 * other purpose will be dangerous. (they make weird assumptions) 46 */ 47 48/* 49 * First define what the actual subs. return 50 */ 51#define M_HASCL(m) ((m)->m_flags & M_EXT) 52#define NFSMINOFF(m) \ 53 if (M_HASCL(m)) \ 54 (m)->m_data = (m)->m_ext.ext_buf; \ 55 else if ((m)->m_flags & M_PKTHDR) \ 56 (m)->m_data = (m)->m_pktdat; \ 57 else \ 58 (m)->m_data = (m)->m_dat 59#define NFSMADV(m, s) (m)->m_data += (s) 60#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ 61 (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) 62 63/* 64 * Now for the macros that do the simple stuff and call the functions 65 * for the hard stuff. 66 * These macros use several vars. declared in nfsm_reqhead and these 67 * vars. must not be used elsewhere unless you are careful not to corrupt 68 * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries 69 * that may be used so long as the value is not expected to retained 70 * after a macro. 71 * I know, this is kind of dorkey, but it makes the actual op functions 72 * fairly clean and deals with the mess caused by the xdr discriminating 73 * unions. 74 */ 75 76#define nfsm_build(a,c,s) \ 77 { if ((s) > M_TRAILINGSPACE(mb)) { \ 78 MGET(mb2, M_WAIT, MT_DATA); \ 79 if ((s) > MLEN) \ 80 panic("build > MLEN"); \ 81 mb->m_next = mb2; \ 82 mb = mb2; \ 83 mb->m_len = 0; \ 84 bpos = mtod(mb, caddr_t); \ 85 } \ 86 (a) = (c)(bpos); \ 87 mb->m_len += (s); \ 88 bpos += (s); } 89 90#define nfsm_dissect(a,c,s) \ 91 { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ 92 if (t1 >= (s)) { \ 93 (a) = (c)(dpos); \ 94 dpos += (s); \ 95 } else if ((error = nfsm_disct(&md, &dpos, \ 96 (s), t1, &cp2)) != 0) { \ 97 m_freem(mrep); \ 98 goto nfsmout; \ 99 } else { \ 100 (a) = (c)cp2; \ 101 } } 102 103#define nfsm_fhtom(v) \ 104 nfsm_build(cp,caddr_t,NFSX_FH); \ 105 bcopy((caddr_t)&(VTONFS(v)->n_fh), cp, NFSX_FH) 106 107#define nfsm_srvfhtom(f) \ 108 nfsm_build(cp,caddr_t,NFSX_FH); \ 109 bcopy((caddr_t)(f), cp, NFSX_FH) 110 111#define nfsm_mtofh(d,v) \ 112 { struct nfsnode *np; nfsv2fh_t *fhp; \ 113 nfsm_dissect(fhp,nfsv2fh_t *,NFSX_FH); \ 114 if ((error = nfs_nget((d)->v_mount, fhp, &np)) != 0) { \ 115 m_freem(mrep); \ 116 goto nfsmout; \ 117 } \ 118 (v) = NFSTOV(np); \ 119 nfsm_loadattr(v, (struct vattr *)0); \ 120 } 121 122#define nfsm_loadattr(v,a) \ 123 { struct vnode *tvp = (v); \ 124 if ((error = nfs_loadattrcache(&tvp, &md, &dpos, (a))) != 0) { \ 125 m_freem(mrep); \ 126 goto nfsmout; \ 127 } \ 128 (v) = tvp; } 129 130#define nfsm_strsiz(s,m) \ 131 { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ 132 if (((s) = fxdr_unsigned(int32_t,*tl)) > (m)) { \ 133 m_freem(mrep); \ 134 error = EBADRPC; \ 135 goto nfsmout; \ 136 } } 137 138#define nfsm_srvstrsiz(s,m) \ 139 { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ 140 if (((s) = fxdr_unsigned(int32_t,*tl)) > (m) || (s) <= 0) { \ 141 error = EBADRPC; \ 142 nfsm_reply(0); \ 143 } } 144 145#define nfsm_mtouio(p,s) \ 146 if ((s) > 0 && \ 147 (error = nfsm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \ 148 m_freem(mrep); \ 149 goto nfsmout; \ 150 } 151 152#define nfsm_uiotom(p,s) \ 153 if ((error = nfsm_uiotombuf((p),&mb,(s),&bpos)) != 0) { \ 154 m_freem(mreq); \ 155 goto nfsmout; \ 156 } 157 158#define nfsm_reqhead(v,a,s) \ 159 mb = mreq = nfsm_reqh((v),(a),(s),&bpos) 160 161#define nfsm_reqdone m_freem(mrep); \ 162 nfsmout: 163 164#define nfsm_rndup(a) (((a)+3)&(~0x3)) 165 166#define nfsm_request(v, t, p, c) \ 167 if ((error = nfs_request((v), mreq, (t), (p), \ 168 (c), &mrep, &md, &dpos)) != 0) \ 169 goto nfsmout 170 171#define nfsm_strtom(a,s,m) \ 172 if ((s) > (m)) { \ 173 m_freem(mreq); \ 174 error = ENAMETOOLONG; \ 175 goto nfsmout; \ 176 } \ 177 t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \ 178 if (t2 <= M_TRAILINGSPACE(mb)) { \ 179 nfsm_build(tl,u_int32_t *,t2); \ 180 *tl++ = txdr_unsigned(s); \ 181 *(tl+((t2>>2)-2)) = 0; \ 182 bcopy((caddr_t)(a), (caddr_t)tl, (s)); \ 183 } else if ((error = nfsm_strtmbuf(&mb, &bpos, \ 184 (a), (s))) != 0) { \ 185 m_freem(mreq); \ 186 goto nfsmout; \ 187 } 188 189#define nfsm_srvdone \ 190 nfsmout: \ 191 return(error) 192 193#define nfsm_reply(s) \ 194 { \ 195 nfsd->nd_repstat = error; \ 196 if (error) \ 197 (void) nfs_rephead(0, nfsd, error, cache, &frev, \ 198 mrq, &mb, &bpos); \ 199 else \ 200 (void) nfs_rephead((s), nfsd, error, cache, &frev, \ 201 mrq, &mb, &bpos); \ 202 m_freem(mrep); \ 203 mreq = *mrq; \ 204 if (error) \ 205 return(0); \ 206 } 207 208#define nfsm_adv(s) \ 209 t1 = mtod(md, caddr_t)+md->m_len-dpos; \ 210 if (t1 >= (s)) { \ 211 dpos += (s); \ 212 } else if ((error = nfs_adv(&md, &dpos, (s), t1)) != 0) { \ 213 m_freem(mrep); \ 214 goto nfsmout; \ 215 } 216 217#define nfsm_srvmtofh(f) \ 218 nfsm_dissect(tl, u_int32_t *, NFSX_FH); \ 219 bcopy((caddr_t)tl, (caddr_t)f, NFSX_FH) 220 221#define nfsm_clget \ 222 if (bp >= be) { \ 223 if (mp == mb) \ 224 mp->m_len += bp-bpos; \ 225 MGET(mp, M_WAIT, MT_DATA); \ 226 MCLGET(mp, M_WAIT); \ 227 mp->m_len = NFSMSIZ(mp); \ 228 mp2->m_next = mp; \ 229 mp2 = mp; \ 230 bp = mtod(mp, caddr_t); \ 231 be = bp+mp->m_len; \ 232 } \ 233 tl = (u_int32_t *)bp 234 235#define nfsm_srvfillattr \ 236 fp->fa_type = vtonfs_type(va.va_type); \ 237 fp->fa_mode = vtonfs_mode(va.va_type, va.va_mode); \ 238 fp->fa_nlink = txdr_unsigned(va.va_nlink); \ 239 fp->fa_uid = txdr_unsigned(va.va_uid); \ 240 fp->fa_gid = txdr_unsigned(va.va_gid); \ 241 if (nfsd->nd_nqlflag == NQL_NOVAL) { \ 242 fp->fa_nfsblocksize = txdr_unsigned(va.va_blocksize); \ 243 if (va.va_type == VFIFO) \ 244 fp->fa_nfsrdev = 0xffffffff; \ 245 else \ 246 fp->fa_nfsrdev = txdr_unsigned(va.va_rdev); \ 247 fp->fa_nfsfsid = txdr_unsigned(va.va_fsid); \ 248 fp->fa_nfsfileid = txdr_unsigned(va.va_fileid); \ 249 fp->fa_nfssize = txdr_unsigned(va.va_size); \ 250 fp->fa_nfsblocks = txdr_unsigned(va.va_bytes / NFS_FABLKSIZE); \ 251 txdr_nfstime(&va.va_atime, &fp->fa_nfsatime); \ 252 txdr_nfstime(&va.va_mtime, &fp->fa_nfsmtime); \ 253 txdr_nfstime(&va.va_ctime, &fp->fa_nfsctime); \ 254 } else { \ 255 fp->fa_nqblocksize = txdr_unsigned(va.va_blocksize); \ 256 if (va.va_type == VFIFO) \ 257 fp->fa_nqrdev = 0xffffffff; \ 258 else \ 259 fp->fa_nqrdev = txdr_unsigned(va.va_rdev); \ 260 fp->fa_nqfsid = txdr_unsigned(va.va_fsid); \ 261 fp->fa_nqfileid = txdr_unsigned(va.va_fileid); \ 262 txdr_hyper(&va.va_size, &fp->fa_nqsize); \ 263 txdr_hyper(&va.va_bytes, &fp->fa_nqbytes); \ 264 txdr_nqtime(&va.va_atime, &fp->fa_nqatime); \ 265 txdr_nqtime(&va.va_mtime, &fp->fa_nqmtime); \ 266 txdr_nqtime(&va.va_ctime, &fp->fa_nqctime); \ 267 fp->fa_nqflags = txdr_unsigned(va.va_flags); \ 268 fp->fa_nqgen = txdr_unsigned(va.va_gen); \ 269 txdr_hyper(&va.va_filerev, &fp->fa_nqfilerev); \ 270 } 271 272