54 55#define M_HASCL(m) ((m)->m_flags & M_EXT) 56#define NFSMINOFF(m) \ 57 if (M_HASCL(m)) \ 58 (m)->m_data = (m)->m_ext.ext_buf; \ 59 else if ((m)->m_flags & M_PKTHDR) \ 60 (m)->m_data = (m)->m_pktdat; \ 61 else \ 62 (m)->m_data = (m)->m_dat 63#define NFSMADV(m, s) (m)->m_data += (s) 64#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ 65 (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) 66 67/* 68 * Now for the macros that do the simple stuff and call the functions 69 * for the hard stuff. 70 * These macros use several vars. declared in nfsm_reqhead and these 71 * vars. must not be used elsewhere unless you are careful not to corrupt 72 * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries 73 * that may be used so long as the value is not expected to retained 74 * after a macro. 75 * I know, this is kind of dorkey, but it makes the actual op functions 76 * fairly clean and deals with the mess caused by the xdr discriminating 77 * unions. 78 */ 79 80#define nfsm_build(a,c,s) \ 81 { if ((s) > M_TRAILINGSPACE(mb)) { \ 82 MGET(mb2, M_WAIT, MT_DATA); \ 83 if ((s) > MLEN) \ 84 panic("build > MLEN"); \ 85 mb->m_next = mb2; \ 86 mb = mb2; \ 87 mb->m_len = 0; \ 88 bpos = mtod(mb, caddr_t); \ 89 } \ 90 (a) = (c)(bpos); \ 91 mb->m_len += (s); \ 92 bpos += (s); } 93 94#define nfsm_dissect(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 (t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2)) { \ 100 error = t1; \ 101 m_freem(mrep); \ 102 goto nfsmout; \ 103 } else { \ 104 (a) = (c)cp2; \ 105 } } 106 107#define nfsm_fhtom(v, v3) \ 108 { if (v3) { \ 109 t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \ 110 if (t2 <= M_TRAILINGSPACE(mb)) { \ 111 nfsm_build(tl, u_long *, t2); \ 112 *tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \ 113 *(tl + ((t2>>2) - 2)) = 0; \ 114 bcopy((caddr_t)VTONFS(v)->n_fhp,(caddr_t)tl, \ 115 VTONFS(v)->n_fhsize); \ 116 } else if (t2 = nfsm_strtmbuf(&mb, &bpos, \ 117 (caddr_t)VTONFS(v)->n_fhp, VTONFS(v)->n_fhsize)) { \ 118 error = t2; \ 119 m_freem(mreq); \ 120 goto nfsmout; \ 121 } \ 122 } else { \ 123 nfsm_build(cp, caddr_t, NFSX_V2FH); \ 124 bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \ 125 } } 126 127#define nfsm_srvfhtom(f, v3) \ 128 { if (v3) { \ 129 nfsm_build(tl, u_long *, NFSX_UNSIGNED + NFSX_V3FH); \ 130 *tl++ = txdr_unsigned(NFSX_V3FH); \ 131 bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ 132 } else { \ 133 nfsm_build(cp, caddr_t, NFSX_V2FH); \ 134 bcopy((caddr_t)(f), cp, NFSX_V2FH); \ 135 } } 136 137#define nfsm_srvpostop_fh(f) \ 138 { nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \ 139 *tl++ = nfs_true; \ 140 *tl++ = txdr_unsigned(NFSX_V3FH); \ 141 bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ 142 } 143 144#define nfsm_mtofh(d, v, v3, f) \ 145 { struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \ 146 if (v3) { \ 147 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 148 (f) = fxdr_unsigned(int, *tl); \ 149 } else \ 150 (f) = 1; \ 151 if (f) { \ 152 nfsm_getfh(ttfhp, ttfhsize, (v3)); \ 153 if (t1 = nfs_nget((d)->v_mount, ttfhp, ttfhsize, \ 154 &ttnp)) { \ 155 error = t1; \ 156 m_freem(mrep); \ 157 goto nfsmout; \ 158 } \ 159 (v) = NFSTOV(ttnp); \ 160 } \ 161 if (v3) { \ 162 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 163 if (f) \ 164 (f) = fxdr_unsigned(int, *tl); \ 165 else if (fxdr_unsigned(int, *tl)) \ 166 nfsm_adv(NFSX_V3FATTR); \ 167 } \ 168 if (f) \ 169 nfsm_loadattr((v), (struct vattr *)0); \ 170 } 171 172#define nfsm_getfh(f, s, v3) \ 173 { if (v3) { \ 174 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 175 if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \ 176 (s) > NFSX_V3FHMAX) { \ 177 m_freem(mrep); \ 178 error = EBADRPC; \ 179 goto nfsmout; \ 180 } \ 181 } else \ 182 (s) = NFSX_V2FH; \ 183 nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); } 184 185#define nfsm_loadattr(v, a) \ 186 { struct vnode *ttvp = (v); \ 187 if (t1 = nfs_loadattrcache(&ttvp, &md, &dpos, (a))) { \ 188 error = t1; \ 189 m_freem(mrep); \ 190 goto nfsmout; \ 191 } \ 192 (v) = ttvp; } 193 194#define nfsm_postop_attr(v, f) \ 195 { struct vnode *ttvp = (v); \ 196 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 197 if ((f) = fxdr_unsigned(int, *tl)) { \ 198 if (t1 = nfs_loadattrcache(&ttvp, &md, &dpos, \ 199 (struct vattr *)0)) { \ 200 error = t1; \ 201 (f) = 0; \ 202 m_freem(mrep); \ 203 goto nfsmout; \ 204 } \ 205 (v) = ttvp; \ 206 } } 207 208/* Used as (f) for nfsm_wcc_data() */ 209#define NFSV3_WCCRATTR 0 210#define NFSV3_WCCCHK 1 211 212#define nfsm_wcc_data(v, f) \ 213 { int ttattrf, ttretf = 0; \ 214 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 215 if (*tl == nfs_true) { \ 216 nfsm_dissect(tl, u_long *, 6 * NFSX_UNSIGNED); \ 217 if (f) \ 218 ttretf = (VTONFS(v)->n_mtime == \ 219 fxdr_unsigned(u_long, *(tl + 2))); \ 220 } \ 221 nfsm_postop_attr((v), ttattrf); \ 222 if (f) { \ 223 (f) = ttretf; \ 224 } else { \ 225 (f) = ttattrf; \ 226 } } 227 228#define nfsm_v3sattr(s, a, u, g) \ 229 { (s)->sa_modetrue = nfs_true; \ 230 (s)->sa_mode = vtonfsv3_mode((a)->va_mode); \ 231 (s)->sa_uidtrue = nfs_true; \ 232 (s)->sa_uid = txdr_unsigned(u); \ 233 (s)->sa_gidtrue = nfs_true; \ 234 (s)->sa_gid = txdr_unsigned(g); \ 235 (s)->sa_sizefalse = nfs_false; \ 236 (s)->sa_atimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ 237 txdr_nfsv3time(&(a)->va_atime, &(s)->sa_atime); \ 238 (s)->sa_mtimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ 239 txdr_nfsv3time(&(a)->va_mtime, &(s)->sa_mtime); \ 240 } 241 242#define nfsm_strsiz(s,m) \ 243 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \ 244 if (((s) = fxdr_unsigned(long,*tl)) > (m)) { \ 245 m_freem(mrep); \ 246 error = EBADRPC; \ 247 goto nfsmout; \ 248 } } 249 250#define nfsm_srvstrsiz(s,m) \ 251 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \ 252 if (((s) = fxdr_unsigned(long,*tl)) > (m) || (s) <= 0) { \ 253 error = EBADRPC; \ 254 nfsm_reply(0); \ 255 } } 256 257#define nfsm_srvnamesiz(s) \ 258 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \ 259 if (((s) = fxdr_unsigned(long,*tl)) > NFS_MAXNAMLEN) \ 260 error = NFSERR_NAMETOL; \ 261 if ((s) <= 0) \ 262 error = EBADRPC; \ 263 if (error) \ 264 nfsm_reply(0); \ 265 } 266 267#define nfsm_mtouio(p,s) \ 268 if ((s) > 0 && \ 269 (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos))) { \ 270 error = t1; \ 271 m_freem(mrep); \ 272 goto nfsmout; \ 273 } 274 275#define nfsm_uiotom(p,s) \ 276 if (t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) { \ 277 error = t1; \ 278 m_freem(mreq); \ 279 goto nfsmout; \ 280 } 281 282#define nfsm_reqhead(v,a,s) \ 283 mb = mreq = nfsm_reqh((v),(a),(s),&bpos) 284 285#define nfsm_reqdone m_freem(mrep); \ 286 nfsmout: 287 288#define nfsm_rndup(a) (((a)+3)&(~0x3)) 289 290#define nfsm_request(v, t, p, c) \ 291 if (error = nfs_request((v), mreq, (t), (p), \ 292 (c), &mrep, &md, &dpos)) { \ 293 if (error & NFSERR_RETERR) \ 294 error &= ~NFSERR_RETERR; \ 295 else \ 296 goto nfsmout; \ 297 } 298 299#define nfsm_strtom(a,s,m) \ 300 if ((s) > (m)) { \ 301 m_freem(mreq); \ 302 error = ENAMETOOLONG; \ 303 goto nfsmout; \ 304 } \ 305 t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \ 306 if (t2 <= M_TRAILINGSPACE(mb)) { \ 307 nfsm_build(tl,u_long *,t2); \ 308 *tl++ = txdr_unsigned(s); \ 309 *(tl+((t2>>2)-2)) = 0; \ 310 bcopy((caddr_t)(a), (caddr_t)tl, (s)); \ 311 } else if (t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s))) { \ 312 error = t2; \ 313 m_freem(mreq); \ 314 goto nfsmout; \ 315 } 316 317#define nfsm_srvdone \ 318 nfsmout: \ 319 return(error) 320 321#define nfsm_reply(s) \ 322 { \ 323 nfsd->nd_repstat = error; \ 324 if (error && !(nfsd->nd_flag & ND_NFSV3)) \ 325 (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ 326 mrq, &mb, &bpos); \ 327 else \ 328 (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \ 329 mrq, &mb, &bpos); \ 330 m_freem(mrep); \ 331 mreq = *mrq; \ 332 if (error && (!(nfsd->nd_flag & ND_NFSV3) || \ 333 error == EBADRPC)) \ 334 return(0); \ 335 } 336 337#define nfsm_writereply(s, v3) \ 338 { \ 339 nfsd->nd_repstat = error; \ 340 if (error && !(v3)) \ 341 (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ 342 &mreq, &mb, &bpos); \ 343 else \ 344 (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \ 345 &mreq, &mb, &bpos); \ 346 } 347 348#define nfsm_adv(s) \ 349 { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ 350 if (t1 >= (s)) { \ 351 dpos += (s); \ 352 } else if (t1 = nfs_adv(&md, &dpos, (s), t1)) { \ 353 error = t1; \ 354 m_freem(mrep); \ 355 goto nfsmout; \ 356 } } 357 358#define nfsm_srvmtofh(f) \ 359 { if (nfsd->nd_flag & ND_NFSV3) { \ 360 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 361 if (fxdr_unsigned(int, *tl) != NFSX_V3FH) { \ 362 error = EBADRPC; \ 363 nfsm_reply(0); \ 364 } \ 365 } \ 366 nfsm_dissect(tl, u_long *, NFSX_V3FH); \ 367 bcopy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \ 368 if ((nfsd->nd_flag & ND_NFSV3) == 0) \ 369 nfsm_adv(NFSX_V2FH - NFSX_V3FH); \ 370 } 371 372#define nfsm_clget \ 373 if (bp >= be) { \ 374 if (mp == mb) \ 375 mp->m_len += bp-bpos; \ 376 MGET(mp, M_WAIT, MT_DATA); \ 377 MCLGET(mp, M_WAIT); \ 378 mp->m_len = NFSMSIZ(mp); \ 379 mp2->m_next = mp; \ 380 mp2 = mp; \ 381 bp = mtod(mp, caddr_t); \ 382 be = bp+mp->m_len; \ 383 } \ 384 tl = (u_long *)bp 385 386#define nfsm_srvfillattr(a, f) \ 387 nfsm_srvfattr(nfsd, (a), (f)) 388 389#define nfsm_srvwcc_data(br, b, ar, a) \ 390 nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos) 391 392#define nfsm_srvpostop_attr(r, a) \ 393 nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos) 394 395#define nfsm_srvsattr(a) \ 396 { nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 397 if (*tl == nfs_true) { \ 398 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 399 (a)->va_mode = nfstov_mode(*tl); \ 400 } \ 401 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 402 if (*tl == nfs_true) { \ 403 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 404 (a)->va_uid = fxdr_unsigned(uid_t, *tl); \ 405 } \ 406 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 407 if (*tl == nfs_true) { \ 408 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 409 (a)->va_gid = fxdr_unsigned(gid_t, *tl); \ 410 } \ 411 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 412 if (*tl == nfs_true) { \ 413 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \ 414 fxdr_hyper(tl, &(a)->va_size); \ 415 } \ 416 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 417 switch (fxdr_unsigned(int, *tl)) { \ 418 case NFSV3SATTRTIME_TOCLIENT: \ 419 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \ 420 fxdr_nfsv3time(tl, &(a)->va_atime); \ 421 break; \ 422 case NFSV3SATTRTIME_TOSERVER: \ 423 (a)->va_atime.ts_sec = time.tv_sec; \ 424 (a)->va_atime.ts_nsec = time.tv_usec * 1000; \ 425 break; \ 426 }; \ 427 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 428 switch (fxdr_unsigned(int, *tl)) { \ 429 case NFSV3SATTRTIME_TOCLIENT: \ 430 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \ 431 fxdr_nfsv3time(tl, &(a)->va_mtime); \ 432 break; \ 433 case NFSV3SATTRTIME_TOSERVER: \ 434 (a)->va_mtime.ts_sec = time.tv_sec; \ 435 (a)->va_mtime.ts_nsec = time.tv_usec * 1000; \ 436 break; \ 437 }; } 438 439#endif
| 60 61#define M_HASCL(m) ((m)->m_flags & M_EXT) 62#define NFSMINOFF(m) \ 63 if (M_HASCL(m)) \ 64 (m)->m_data = (m)->m_ext.ext_buf; \ 65 else if ((m)->m_flags & M_PKTHDR) \ 66 (m)->m_data = (m)->m_pktdat; \ 67 else \ 68 (m)->m_data = (m)->m_dat 69#define NFSMADV(m, s) (m)->m_data += (s) 70#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ 71 (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) 72 73/* 74 * Now for the macros that do the simple stuff and call the functions 75 * for the hard stuff. 76 * These macros use several vars. declared in nfsm_reqhead and these 77 * vars. must not be used elsewhere unless you are careful not to corrupt 78 * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries 79 * that may be used so long as the value is not expected to retained 80 * after a macro. 81 * I know, this is kind of dorkey, but it makes the actual op functions 82 * fairly clean and deals with the mess caused by the xdr discriminating 83 * unions. 84 */ 85 86#define nfsm_build(a,c,s) \ 87 { if ((s) > M_TRAILINGSPACE(mb)) { \ 88 MGET(mb2, M_WAIT, MT_DATA); \ 89 if ((s) > MLEN) \ 90 panic("build > MLEN"); \ 91 mb->m_next = mb2; \ 92 mb = mb2; \ 93 mb->m_len = 0; \ 94 bpos = mtod(mb, caddr_t); \ 95 } \ 96 (a) = (c)(bpos); \ 97 mb->m_len += (s); \ 98 bpos += (s); } 99 100#define nfsm_dissect(a, c, s) \ 101 { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ 102 if (t1 >= (s)) { \ 103 (a) = (c)(dpos); \ 104 dpos += (s); \ 105 } else if (t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2)) { \ 106 error = t1; \ 107 m_freem(mrep); \ 108 goto nfsmout; \ 109 } else { \ 110 (a) = (c)cp2; \ 111 } } 112 113#define nfsm_fhtom(v, v3) \ 114 { if (v3) { \ 115 t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \ 116 if (t2 <= M_TRAILINGSPACE(mb)) { \ 117 nfsm_build(tl, u_long *, t2); \ 118 *tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \ 119 *(tl + ((t2>>2) - 2)) = 0; \ 120 bcopy((caddr_t)VTONFS(v)->n_fhp,(caddr_t)tl, \ 121 VTONFS(v)->n_fhsize); \ 122 } else if (t2 = nfsm_strtmbuf(&mb, &bpos, \ 123 (caddr_t)VTONFS(v)->n_fhp, VTONFS(v)->n_fhsize)) { \ 124 error = t2; \ 125 m_freem(mreq); \ 126 goto nfsmout; \ 127 } \ 128 } else { \ 129 nfsm_build(cp, caddr_t, NFSX_V2FH); \ 130 bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \ 131 } } 132 133#define nfsm_srvfhtom(f, v3) \ 134 { if (v3) { \ 135 nfsm_build(tl, u_long *, NFSX_UNSIGNED + NFSX_V3FH); \ 136 *tl++ = txdr_unsigned(NFSX_V3FH); \ 137 bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ 138 } else { \ 139 nfsm_build(cp, caddr_t, NFSX_V2FH); \ 140 bcopy((caddr_t)(f), cp, NFSX_V2FH); \ 141 } } 142 143#define nfsm_srvpostop_fh(f) \ 144 { nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \ 145 *tl++ = nfs_true; \ 146 *tl++ = txdr_unsigned(NFSX_V3FH); \ 147 bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ 148 } 149 150#define nfsm_mtofh(d, v, v3, f) \ 151 { struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \ 152 if (v3) { \ 153 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 154 (f) = fxdr_unsigned(int, *tl); \ 155 } else \ 156 (f) = 1; \ 157 if (f) { \ 158 nfsm_getfh(ttfhp, ttfhsize, (v3)); \ 159 if (t1 = nfs_nget((d)->v_mount, ttfhp, ttfhsize, \ 160 &ttnp)) { \ 161 error = t1; \ 162 m_freem(mrep); \ 163 goto nfsmout; \ 164 } \ 165 (v) = NFSTOV(ttnp); \ 166 } \ 167 if (v3) { \ 168 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 169 if (f) \ 170 (f) = fxdr_unsigned(int, *tl); \ 171 else if (fxdr_unsigned(int, *tl)) \ 172 nfsm_adv(NFSX_V3FATTR); \ 173 } \ 174 if (f) \ 175 nfsm_loadattr((v), (struct vattr *)0); \ 176 } 177 178#define nfsm_getfh(f, s, v3) \ 179 { if (v3) { \ 180 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 181 if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \ 182 (s) > NFSX_V3FHMAX) { \ 183 m_freem(mrep); \ 184 error = EBADRPC; \ 185 goto nfsmout; \ 186 } \ 187 } else \ 188 (s) = NFSX_V2FH; \ 189 nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); } 190 191#define nfsm_loadattr(v, a) \ 192 { struct vnode *ttvp = (v); \ 193 if (t1 = nfs_loadattrcache(&ttvp, &md, &dpos, (a))) { \ 194 error = t1; \ 195 m_freem(mrep); \ 196 goto nfsmout; \ 197 } \ 198 (v) = ttvp; } 199 200#define nfsm_postop_attr(v, f) \ 201 { struct vnode *ttvp = (v); \ 202 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 203 if ((f) = fxdr_unsigned(int, *tl)) { \ 204 if (t1 = nfs_loadattrcache(&ttvp, &md, &dpos, \ 205 (struct vattr *)0)) { \ 206 error = t1; \ 207 (f) = 0; \ 208 m_freem(mrep); \ 209 goto nfsmout; \ 210 } \ 211 (v) = ttvp; \ 212 } } 213 214/* Used as (f) for nfsm_wcc_data() */ 215#define NFSV3_WCCRATTR 0 216#define NFSV3_WCCCHK 1 217 218#define nfsm_wcc_data(v, f) \ 219 { int ttattrf, ttretf = 0; \ 220 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 221 if (*tl == nfs_true) { \ 222 nfsm_dissect(tl, u_long *, 6 * NFSX_UNSIGNED); \ 223 if (f) \ 224 ttretf = (VTONFS(v)->n_mtime == \ 225 fxdr_unsigned(u_long, *(tl + 2))); \ 226 } \ 227 nfsm_postop_attr((v), ttattrf); \ 228 if (f) { \ 229 (f) = ttretf; \ 230 } else { \ 231 (f) = ttattrf; \ 232 } } 233 234#define nfsm_v3sattr(s, a, u, g) \ 235 { (s)->sa_modetrue = nfs_true; \ 236 (s)->sa_mode = vtonfsv3_mode((a)->va_mode); \ 237 (s)->sa_uidtrue = nfs_true; \ 238 (s)->sa_uid = txdr_unsigned(u); \ 239 (s)->sa_gidtrue = nfs_true; \ 240 (s)->sa_gid = txdr_unsigned(g); \ 241 (s)->sa_sizefalse = nfs_false; \ 242 (s)->sa_atimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ 243 txdr_nfsv3time(&(a)->va_atime, &(s)->sa_atime); \ 244 (s)->sa_mtimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ 245 txdr_nfsv3time(&(a)->va_mtime, &(s)->sa_mtime); \ 246 } 247 248#define nfsm_strsiz(s,m) \ 249 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \ 250 if (((s) = fxdr_unsigned(long,*tl)) > (m)) { \ 251 m_freem(mrep); \ 252 error = EBADRPC; \ 253 goto nfsmout; \ 254 } } 255 256#define nfsm_srvstrsiz(s,m) \ 257 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \ 258 if (((s) = fxdr_unsigned(long,*tl)) > (m) || (s) <= 0) { \ 259 error = EBADRPC; \ 260 nfsm_reply(0); \ 261 } } 262 263#define nfsm_srvnamesiz(s) \ 264 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \ 265 if (((s) = fxdr_unsigned(long,*tl)) > NFS_MAXNAMLEN) \ 266 error = NFSERR_NAMETOL; \ 267 if ((s) <= 0) \ 268 error = EBADRPC; \ 269 if (error) \ 270 nfsm_reply(0); \ 271 } 272 273#define nfsm_mtouio(p,s) \ 274 if ((s) > 0 && \ 275 (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos))) { \ 276 error = t1; \ 277 m_freem(mrep); \ 278 goto nfsmout; \ 279 } 280 281#define nfsm_uiotom(p,s) \ 282 if (t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) { \ 283 error = t1; \ 284 m_freem(mreq); \ 285 goto nfsmout; \ 286 } 287 288#define nfsm_reqhead(v,a,s) \ 289 mb = mreq = nfsm_reqh((v),(a),(s),&bpos) 290 291#define nfsm_reqdone m_freem(mrep); \ 292 nfsmout: 293 294#define nfsm_rndup(a) (((a)+3)&(~0x3)) 295 296#define nfsm_request(v, t, p, c) \ 297 if (error = nfs_request((v), mreq, (t), (p), \ 298 (c), &mrep, &md, &dpos)) { \ 299 if (error & NFSERR_RETERR) \ 300 error &= ~NFSERR_RETERR; \ 301 else \ 302 goto nfsmout; \ 303 } 304 305#define nfsm_strtom(a,s,m) \ 306 if ((s) > (m)) { \ 307 m_freem(mreq); \ 308 error = ENAMETOOLONG; \ 309 goto nfsmout; \ 310 } \ 311 t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \ 312 if (t2 <= M_TRAILINGSPACE(mb)) { \ 313 nfsm_build(tl,u_long *,t2); \ 314 *tl++ = txdr_unsigned(s); \ 315 *(tl+((t2>>2)-2)) = 0; \ 316 bcopy((caddr_t)(a), (caddr_t)tl, (s)); \ 317 } else if (t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s))) { \ 318 error = t2; \ 319 m_freem(mreq); \ 320 goto nfsmout; \ 321 } 322 323#define nfsm_srvdone \ 324 nfsmout: \ 325 return(error) 326 327#define nfsm_reply(s) \ 328 { \ 329 nfsd->nd_repstat = error; \ 330 if (error && !(nfsd->nd_flag & ND_NFSV3)) \ 331 (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ 332 mrq, &mb, &bpos); \ 333 else \ 334 (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \ 335 mrq, &mb, &bpos); \ 336 m_freem(mrep); \ 337 mreq = *mrq; \ 338 if (error && (!(nfsd->nd_flag & ND_NFSV3) || \ 339 error == EBADRPC)) \ 340 return(0); \ 341 } 342 343#define nfsm_writereply(s, v3) \ 344 { \ 345 nfsd->nd_repstat = error; \ 346 if (error && !(v3)) \ 347 (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ 348 &mreq, &mb, &bpos); \ 349 else \ 350 (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \ 351 &mreq, &mb, &bpos); \ 352 } 353 354#define nfsm_adv(s) \ 355 { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ 356 if (t1 >= (s)) { \ 357 dpos += (s); \ 358 } else if (t1 = nfs_adv(&md, &dpos, (s), t1)) { \ 359 error = t1; \ 360 m_freem(mrep); \ 361 goto nfsmout; \ 362 } } 363 364#define nfsm_srvmtofh(f) \ 365 { if (nfsd->nd_flag & ND_NFSV3) { \ 366 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 367 if (fxdr_unsigned(int, *tl) != NFSX_V3FH) { \ 368 error = EBADRPC; \ 369 nfsm_reply(0); \ 370 } \ 371 } \ 372 nfsm_dissect(tl, u_long *, NFSX_V3FH); \ 373 bcopy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \ 374 if ((nfsd->nd_flag & ND_NFSV3) == 0) \ 375 nfsm_adv(NFSX_V2FH - NFSX_V3FH); \ 376 } 377 378#define nfsm_clget \ 379 if (bp >= be) { \ 380 if (mp == mb) \ 381 mp->m_len += bp-bpos; \ 382 MGET(mp, M_WAIT, MT_DATA); \ 383 MCLGET(mp, M_WAIT); \ 384 mp->m_len = NFSMSIZ(mp); \ 385 mp2->m_next = mp; \ 386 mp2 = mp; \ 387 bp = mtod(mp, caddr_t); \ 388 be = bp+mp->m_len; \ 389 } \ 390 tl = (u_long *)bp 391 392#define nfsm_srvfillattr(a, f) \ 393 nfsm_srvfattr(nfsd, (a), (f)) 394 395#define nfsm_srvwcc_data(br, b, ar, a) \ 396 nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos) 397 398#define nfsm_srvpostop_attr(r, a) \ 399 nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos) 400 401#define nfsm_srvsattr(a) \ 402 { nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 403 if (*tl == nfs_true) { \ 404 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 405 (a)->va_mode = nfstov_mode(*tl); \ 406 } \ 407 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 408 if (*tl == nfs_true) { \ 409 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 410 (a)->va_uid = fxdr_unsigned(uid_t, *tl); \ 411 } \ 412 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 413 if (*tl == nfs_true) { \ 414 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 415 (a)->va_gid = fxdr_unsigned(gid_t, *tl); \ 416 } \ 417 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 418 if (*tl == nfs_true) { \ 419 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \ 420 fxdr_hyper(tl, &(a)->va_size); \ 421 } \ 422 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 423 switch (fxdr_unsigned(int, *tl)) { \ 424 case NFSV3SATTRTIME_TOCLIENT: \ 425 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \ 426 fxdr_nfsv3time(tl, &(a)->va_atime); \ 427 break; \ 428 case NFSV3SATTRTIME_TOSERVER: \ 429 (a)->va_atime.ts_sec = time.tv_sec; \ 430 (a)->va_atime.ts_nsec = time.tv_usec * 1000; \ 431 break; \ 432 }; \ 433 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ 434 switch (fxdr_unsigned(int, *tl)) { \ 435 case NFSV3SATTRTIME_TOCLIENT: \ 436 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \ 437 fxdr_nfsv3time(tl, &(a)->va_mtime); \ 438 break; \ 439 case NFSV3SATTRTIME_TOSERVER: \ 440 (a)->va_mtime.ts_sec = time.tv_sec; \ 441 (a)->va_mtime.ts_nsec = time.tv_usec * 1000; \ 442 break; \ 443 }; } 444 445#endif
|