38 */ 39 40 41#ifndef _NFS_NFSM_SUBS_H_ 42#define _NFS_NFSM_SUBS_H_ 43 44struct ucred; 45struct vnode; 46 47/* 48 * These macros do strange and peculiar things to mbuf chains for 49 * the assistance of the nfs code. To attempt to use them for any 50 * other purpose will be dangerous. (they make weird assumptions) 51 */ 52 53/* 54 * First define what the actual subs. return 55 */ 56struct mbuf *nfsm_reqh __P((struct vnode *vp, u_long procid, int hsiz, 57 caddr_t *bposp)); 58struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, 59 int auth_type, int auth_len, char *auth_str, 60 int verf_len, char *verf_str, 61 struct mbuf *mrest, int mrest_len, 62 struct mbuf **mbp, u_int32_t *xidp)); 63 64#define M_HASCL(m) ((m)->m_flags & M_EXT) 65#define NFSMINOFF(m) \ 66 if (M_HASCL(m)) \ 67 (m)->m_data = (m)->m_ext.ext_buf; \ 68 else if ((m)->m_flags & M_PKTHDR) \ 69 (m)->m_data = (m)->m_pktdat; \ 70 else \ 71 (m)->m_data = (m)->m_dat 72#define NFSMADV(m, s) (m)->m_data += (s) 73#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ 74 (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) 75 76/* 77 * Now for the macros that do the simple stuff and call the functions 78 * for the hard stuff. 79 * These macros use several vars. declared in nfsm_reqhead and these 80 * vars. must not be used elsewhere unless you are careful not to corrupt 81 * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries 82 * that may be used so long as the value is not expected to retained 83 * after a macro. 84 * I know, this is kind of dorkey, but it makes the actual op functions 85 * fairly clean and deals with the mess caused by the xdr discriminating 86 * unions. 87 */ 88 89#define nfsm_build(a,c,s) \ 90 { if ((s) > M_TRAILINGSPACE(mb)) { \ 91 MGET(mb2, M_WAIT, MT_DATA); \ 92 if ((s) > MLEN) \ 93 panic("build > MLEN"); \ 94 mb->m_next = mb2; \ 95 mb = mb2; \ 96 mb->m_len = 0; \ 97 bpos = mtod(mb, caddr_t); \ 98 } \ 99 (a) = (c)(bpos); \ 100 mb->m_len += (s); \ 101 bpos += (s); } 102 103#define nfsm_dissect(a, c, s) \ 104 { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ 105 if (t1 >= (s)) { \ 106 (a) = (c)(dpos); \ 107 dpos += (s); \ 108 } else if ((t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2)) != 0){ \ 109 error = t1; \ 110 m_freem(mrep); \ 111 goto nfsmout; \ 112 } else { \ 113 (a) = (c)cp2; \ 114 } } 115 116#define nfsm_fhtom(v, v3) \ 117 { if (v3) { \ 118 t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \ 119 if (t2 <= M_TRAILINGSPACE(mb)) { \ 120 nfsm_build(tl, u_int32_t *, t2); \ 121 *tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \ 122 *(tl + ((t2>>2) - 2)) = 0; \ 123 bcopy((caddr_t)VTONFS(v)->n_fhp,(caddr_t)tl, \ 124 VTONFS(v)->n_fhsize); \ 125 } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, \ 126 (caddr_t)VTONFS(v)->n_fhp, \ 127 VTONFS(v)->n_fhsize)) != 0) { \ 128 error = t2; \ 129 m_freem(mreq); \ 130 goto nfsmout; \ 131 } \ 132 } else { \ 133 nfsm_build(cp, caddr_t, NFSX_V2FH); \ 134 bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \ 135 } } 136 137#define nfsm_srvfhtom(f, v3) \ 138 { if (v3) { \ 139 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3FH); \ 140 *tl++ = txdr_unsigned(NFSX_V3FH); \ 141 bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ 142 } else { \ 143 nfsm_build(cp, caddr_t, NFSX_V2FH); \ 144 bcopy((caddr_t)(f), cp, NFSX_V2FH); \ 145 } } 146 147#define nfsm_srvpostop_fh(f) \ 148 { nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \ 149 *tl++ = nfs_true; \ 150 *tl++ = txdr_unsigned(NFSX_V3FH); \ 151 bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ 152 } 153 154#define nfsm_mtofh(d, v, v3, f) \ 155 { struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \ 156 if (v3) { \ 157 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 158 (f) = fxdr_unsigned(int, *tl); \ 159 } else \ 160 (f) = 1; \ 161 if (f) { \ 162 nfsm_getfh(ttfhp, ttfhsize, (v3)); \ 163 if ((t1 = nfs_nget((d)->v_mount, ttfhp, ttfhsize, \ 164 &ttnp)) != 0) { \ 165 error = t1; \ 166 m_freem(mrep); \ 167 goto nfsmout; \ 168 } \ 169 (v) = NFSTOV(ttnp); \ 170 } \ 171 if (v3) { \ 172 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 173 if (f) \ 174 (f) = fxdr_unsigned(int, *tl); \ 175 else if (fxdr_unsigned(int, *tl)) \ 176 nfsm_adv(NFSX_V3FATTR); \ 177 } \ 178 if (f) \ 179 nfsm_loadattr((v), (struct vattr *)0); \ 180 } 181 182#define nfsm_getfh(f, s, v3) \ 183 { if (v3) { \ 184 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 185 if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \ 186 (s) > NFSX_V3FHMAX) { \ 187 m_freem(mrep); \ 188 error = EBADRPC; \ 189 goto nfsmout; \ 190 } \ 191 } else \ 192 (s) = NFSX_V2FH; \ 193 nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); } 194 195#define nfsm_loadattr(v, a) \ 196 { struct vnode *ttvp = (v); \ 197 if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, (a))) != 0) { \ 198 error = t1; \ 199 m_freem(mrep); \ 200 goto nfsmout; \ 201 } \ 202 (v) = ttvp; } 203 204#define nfsm_postop_attr(v, f) \ 205 { struct vnode *ttvp = (v); \ 206 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 207 if (((f) = fxdr_unsigned(int, *tl)) != 0) { \ 208 if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, \ 209 (struct vattr *)0)) != 0) { \ 210 error = t1; \ 211 (f) = 0; \ 212 m_freem(mrep); \ 213 goto nfsmout; \ 214 } \ 215 (v) = ttvp; \ 216 } } 217 218/* Used as (f) for nfsm_wcc_data() */ 219#define NFSV3_WCCRATTR 0 220#define NFSV3_WCCCHK 1 221 222#define nfsm_wcc_data(v, f) \ 223 { int ttattrf, ttretf = 0; \ 224 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 225 if (*tl == nfs_true) { \ 226 nfsm_dissect(tl, u_int32_t *, 6 * NFSX_UNSIGNED); \ 227 if (f) \ 228 ttretf = (VTONFS(v)->n_mtime == \ 229 fxdr_unsigned(u_int32_t, *(tl + 2))); \ 230 } \ 231 nfsm_postop_attr((v), ttattrf); \ 232 if (f) { \ 233 (f) = ttretf; \ 234 } else { \ 235 (f) = ttattrf; \ 236 } } 237 238/* If full is true, set all fields, otherwise just set mode and time fields */ 239#define nfsm_v3attrbuild(a, full) \ 240 { if ((a)->va_mode != (mode_t)VNOVAL) { \ 241 nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 242 *tl++ = nfs_true; \ 243 *tl = txdr_unsigned((a)->va_mode); \ 244 } else { \ 245 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 246 *tl = nfs_false; \ 247 } \ 248 if ((full) && (a)->va_uid != (uid_t)VNOVAL) { \ 249 nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 250 *tl++ = nfs_true; \ 251 *tl = txdr_unsigned((a)->va_uid); \ 252 } else { \ 253 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 254 *tl = nfs_false; \ 255 } \ 256 if ((full) && (a)->va_gid != (gid_t)VNOVAL) { \ 257 nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 258 *tl++ = nfs_true; \ 259 *tl = txdr_unsigned((a)->va_gid); \ 260 } else { \ 261 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 262 *tl = nfs_false; \ 263 } \ 264 if ((full) && (a)->va_size != VNOVAL) { \ 265 nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ 266 *tl++ = nfs_true; \ 267 txdr_hyper((a)->va_size, tl); \ 268 } else { \ 269 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 270 *tl = nfs_false; \ 271 } \ 272 if ((a)->va_atime.tv_sec != VNOVAL) { \ 273 if ((a)->va_atime.tv_sec != time_second) { \ 274 nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ 275 *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ 276 txdr_nfsv3time(&(a)->va_atime, tl); \ 277 } else { \ 278 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 279 *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ 280 } \ 281 } else { \ 282 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 283 *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ 284 } \ 285 if ((a)->va_mtime.tv_sec != VNOVAL) { \ 286 if ((a)->va_mtime.tv_sec != time_second) { \ 287 nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ 288 *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ 289 txdr_nfsv3time(&(a)->va_mtime, tl); \ 290 } else { \ 291 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 292 *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ 293 } \ 294 } else { \ 295 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 296 *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ 297 } \ 298 } 299 300 301#define nfsm_strsiz(s,m) \ 302 { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ 303 if (((s) = fxdr_unsigned(int32_t,*tl)) > (m)) { \ 304 m_freem(mrep); \ 305 error = EBADRPC; \ 306 goto nfsmout; \ 307 } } 308 309#define nfsm_srvstrsiz(s,m) \ 310 { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ 311 if (((s) = fxdr_unsigned(int32_t,*tl)) > (m) || (s) <= 0) { \ 312 error = EBADRPC; \ 313 nfsm_reply(0); \ 314 } } 315 316#define nfsm_srvnamesiz(s) \ 317 { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ 318 if (((s) = fxdr_unsigned(int32_t,*tl)) > NFS_MAXNAMLEN) \ 319 error = NFSERR_NAMETOL; \ 320 if ((s) <= 0) \ 321 error = EBADRPC; \ 322 if (error) \ 323 nfsm_reply(0); \ 324 } 325 326#define nfsm_mtouio(p,s) \ 327 if ((s) > 0 && \ 328 (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \ 329 error = t1; \ 330 m_freem(mrep); \ 331 goto nfsmout; \ 332 } 333 334#define nfsm_uiotom(p,s) \ 335 if ((t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) != 0) { \ 336 error = t1; \ 337 m_freem(mreq); \ 338 goto nfsmout; \ 339 } 340 341#define nfsm_reqhead(v,a,s) \ 342 mb = mreq = nfsm_reqh((v),(a),(s),&bpos) 343 344#define nfsm_reqdone m_freem(mrep); \ 345 nfsmout: 346 347#define nfsm_rndup(a) (((a)+3)&(~0x3)) 348 349#define nfsm_request(v, t, p, c) \ 350 if ((error = nfs_request((v), mreq, (t), (p), \ 351 (c), &mrep, &md, &dpos)) != 0) { \ 352 if (error & NFSERR_RETERR) \ 353 error &= ~NFSERR_RETERR; \ 354 else \ 355 goto nfsmout; \ 356 } 357 358#define nfsm_strtom(a,s,m) \ 359 if ((s) > (m)) { \ 360 m_freem(mreq); \ 361 error = ENAMETOOLONG; \ 362 goto nfsmout; \ 363 } \ 364 t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \ 365 if (t2 <= M_TRAILINGSPACE(mb)) { \ 366 nfsm_build(tl,u_int32_t *,t2); \ 367 *tl++ = txdr_unsigned(s); \ 368 *(tl+((t2>>2)-2)) = 0; \ 369 bcopy((const char *)(a), (caddr_t)tl, (s)); \ 370 } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s))) != 0) { \ 371 error = t2; \ 372 m_freem(mreq); \ 373 goto nfsmout; \ 374 } 375 376#define nfsm_srvdone \ 377 nfsmout: \ 378 return(error) 379 380#define nfsm_reply(s) \ 381 { \ 382 nfsd->nd_repstat = error; \ 383 if (error && !(nfsd->nd_flag & ND_NFSV3)) \ 384 (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ 385 mrq, &mb, &bpos); \ 386 else \ 387 (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \ 388 mrq, &mb, &bpos); \ 389 if (mrep != NULL) { \ 390 m_freem(mrep); \ 391 mrep = NULL; \ 392 } \ 393 mreq = *mrq; \ 394 if (error && (!(nfsd->nd_flag & ND_NFSV3) || \ 395 error == EBADRPC)) { \ 396 error = 0; \ 397 goto nfsmout; \ 398 } } 399 400#define nfsm_writereply(s, v3) \ 401 { \ 402 nfsd->nd_repstat = error; \ 403 if (error && !(v3)) \ 404 (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ 405 &mreq, &mb, &bpos); \ 406 else \ 407 (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \ 408 &mreq, &mb, &bpos); \ 409 } 410 411#define nfsm_adv(s) \ 412 { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ 413 if (t1 >= (s)) { \ 414 dpos += (s); \ 415 } else if ((t1 = nfs_adv(&md, &dpos, (s), t1)) != 0) { \ 416 error = t1; \ 417 m_freem(mrep); \ 418 goto nfsmout; \ 419 } } 420 421#define nfsm_srvmtofh(f) \
| 38 */ 39 40 41#ifndef _NFS_NFSM_SUBS_H_ 42#define _NFS_NFSM_SUBS_H_ 43 44struct ucred; 45struct vnode; 46 47/* 48 * These macros do strange and peculiar things to mbuf chains for 49 * the assistance of the nfs code. To attempt to use them for any 50 * other purpose will be dangerous. (they make weird assumptions) 51 */ 52 53/* 54 * First define what the actual subs. return 55 */ 56struct mbuf *nfsm_reqh __P((struct vnode *vp, u_long procid, int hsiz, 57 caddr_t *bposp)); 58struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, 59 int auth_type, int auth_len, char *auth_str, 60 int verf_len, char *verf_str, 61 struct mbuf *mrest, int mrest_len, 62 struct mbuf **mbp, u_int32_t *xidp)); 63 64#define M_HASCL(m) ((m)->m_flags & M_EXT) 65#define NFSMINOFF(m) \ 66 if (M_HASCL(m)) \ 67 (m)->m_data = (m)->m_ext.ext_buf; \ 68 else if ((m)->m_flags & M_PKTHDR) \ 69 (m)->m_data = (m)->m_pktdat; \ 70 else \ 71 (m)->m_data = (m)->m_dat 72#define NFSMADV(m, s) (m)->m_data += (s) 73#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ 74 (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) 75 76/* 77 * Now for the macros that do the simple stuff and call the functions 78 * for the hard stuff. 79 * These macros use several vars. declared in nfsm_reqhead and these 80 * vars. must not be used elsewhere unless you are careful not to corrupt 81 * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries 82 * that may be used so long as the value is not expected to retained 83 * after a macro. 84 * I know, this is kind of dorkey, but it makes the actual op functions 85 * fairly clean and deals with the mess caused by the xdr discriminating 86 * unions. 87 */ 88 89#define nfsm_build(a,c,s) \ 90 { if ((s) > M_TRAILINGSPACE(mb)) { \ 91 MGET(mb2, M_WAIT, MT_DATA); \ 92 if ((s) > MLEN) \ 93 panic("build > MLEN"); \ 94 mb->m_next = mb2; \ 95 mb = mb2; \ 96 mb->m_len = 0; \ 97 bpos = mtod(mb, caddr_t); \ 98 } \ 99 (a) = (c)(bpos); \ 100 mb->m_len += (s); \ 101 bpos += (s); } 102 103#define nfsm_dissect(a, c, s) \ 104 { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ 105 if (t1 >= (s)) { \ 106 (a) = (c)(dpos); \ 107 dpos += (s); \ 108 } else if ((t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2)) != 0){ \ 109 error = t1; \ 110 m_freem(mrep); \ 111 goto nfsmout; \ 112 } else { \ 113 (a) = (c)cp2; \ 114 } } 115 116#define nfsm_fhtom(v, v3) \ 117 { if (v3) { \ 118 t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \ 119 if (t2 <= M_TRAILINGSPACE(mb)) { \ 120 nfsm_build(tl, u_int32_t *, t2); \ 121 *tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \ 122 *(tl + ((t2>>2) - 2)) = 0; \ 123 bcopy((caddr_t)VTONFS(v)->n_fhp,(caddr_t)tl, \ 124 VTONFS(v)->n_fhsize); \ 125 } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, \ 126 (caddr_t)VTONFS(v)->n_fhp, \ 127 VTONFS(v)->n_fhsize)) != 0) { \ 128 error = t2; \ 129 m_freem(mreq); \ 130 goto nfsmout; \ 131 } \ 132 } else { \ 133 nfsm_build(cp, caddr_t, NFSX_V2FH); \ 134 bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \ 135 } } 136 137#define nfsm_srvfhtom(f, v3) \ 138 { if (v3) { \ 139 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3FH); \ 140 *tl++ = txdr_unsigned(NFSX_V3FH); \ 141 bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ 142 } else { \ 143 nfsm_build(cp, caddr_t, NFSX_V2FH); \ 144 bcopy((caddr_t)(f), cp, NFSX_V2FH); \ 145 } } 146 147#define nfsm_srvpostop_fh(f) \ 148 { nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \ 149 *tl++ = nfs_true; \ 150 *tl++ = txdr_unsigned(NFSX_V3FH); \ 151 bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \ 152 } 153 154#define nfsm_mtofh(d, v, v3, f) \ 155 { struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \ 156 if (v3) { \ 157 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 158 (f) = fxdr_unsigned(int, *tl); \ 159 } else \ 160 (f) = 1; \ 161 if (f) { \ 162 nfsm_getfh(ttfhp, ttfhsize, (v3)); \ 163 if ((t1 = nfs_nget((d)->v_mount, ttfhp, ttfhsize, \ 164 &ttnp)) != 0) { \ 165 error = t1; \ 166 m_freem(mrep); \ 167 goto nfsmout; \ 168 } \ 169 (v) = NFSTOV(ttnp); \ 170 } \ 171 if (v3) { \ 172 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 173 if (f) \ 174 (f) = fxdr_unsigned(int, *tl); \ 175 else if (fxdr_unsigned(int, *tl)) \ 176 nfsm_adv(NFSX_V3FATTR); \ 177 } \ 178 if (f) \ 179 nfsm_loadattr((v), (struct vattr *)0); \ 180 } 181 182#define nfsm_getfh(f, s, v3) \ 183 { if (v3) { \ 184 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 185 if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \ 186 (s) > NFSX_V3FHMAX) { \ 187 m_freem(mrep); \ 188 error = EBADRPC; \ 189 goto nfsmout; \ 190 } \ 191 } else \ 192 (s) = NFSX_V2FH; \ 193 nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); } 194 195#define nfsm_loadattr(v, a) \ 196 { struct vnode *ttvp = (v); \ 197 if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, (a))) != 0) { \ 198 error = t1; \ 199 m_freem(mrep); \ 200 goto nfsmout; \ 201 } \ 202 (v) = ttvp; } 203 204#define nfsm_postop_attr(v, f) \ 205 { struct vnode *ttvp = (v); \ 206 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 207 if (((f) = fxdr_unsigned(int, *tl)) != 0) { \ 208 if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, \ 209 (struct vattr *)0)) != 0) { \ 210 error = t1; \ 211 (f) = 0; \ 212 m_freem(mrep); \ 213 goto nfsmout; \ 214 } \ 215 (v) = ttvp; \ 216 } } 217 218/* Used as (f) for nfsm_wcc_data() */ 219#define NFSV3_WCCRATTR 0 220#define NFSV3_WCCCHK 1 221 222#define nfsm_wcc_data(v, f) \ 223 { int ttattrf, ttretf = 0; \ 224 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 225 if (*tl == nfs_true) { \ 226 nfsm_dissect(tl, u_int32_t *, 6 * NFSX_UNSIGNED); \ 227 if (f) \ 228 ttretf = (VTONFS(v)->n_mtime == \ 229 fxdr_unsigned(u_int32_t, *(tl + 2))); \ 230 } \ 231 nfsm_postop_attr((v), ttattrf); \ 232 if (f) { \ 233 (f) = ttretf; \ 234 } else { \ 235 (f) = ttattrf; \ 236 } } 237 238/* If full is true, set all fields, otherwise just set mode and time fields */ 239#define nfsm_v3attrbuild(a, full) \ 240 { if ((a)->va_mode != (mode_t)VNOVAL) { \ 241 nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 242 *tl++ = nfs_true; \ 243 *tl = txdr_unsigned((a)->va_mode); \ 244 } else { \ 245 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 246 *tl = nfs_false; \ 247 } \ 248 if ((full) && (a)->va_uid != (uid_t)VNOVAL) { \ 249 nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 250 *tl++ = nfs_true; \ 251 *tl = txdr_unsigned((a)->va_uid); \ 252 } else { \ 253 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 254 *tl = nfs_false; \ 255 } \ 256 if ((full) && (a)->va_gid != (gid_t)VNOVAL) { \ 257 nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 258 *tl++ = nfs_true; \ 259 *tl = txdr_unsigned((a)->va_gid); \ 260 } else { \ 261 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 262 *tl = nfs_false; \ 263 } \ 264 if ((full) && (a)->va_size != VNOVAL) { \ 265 nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ 266 *tl++ = nfs_true; \ 267 txdr_hyper((a)->va_size, tl); \ 268 } else { \ 269 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 270 *tl = nfs_false; \ 271 } \ 272 if ((a)->va_atime.tv_sec != VNOVAL) { \ 273 if ((a)->va_atime.tv_sec != time_second) { \ 274 nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ 275 *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ 276 txdr_nfsv3time(&(a)->va_atime, tl); \ 277 } else { \ 278 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 279 *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ 280 } \ 281 } else { \ 282 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 283 *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ 284 } \ 285 if ((a)->va_mtime.tv_sec != VNOVAL) { \ 286 if ((a)->va_mtime.tv_sec != time_second) { \ 287 nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \ 288 *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ 289 txdr_nfsv3time(&(a)->va_mtime, tl); \ 290 } else { \ 291 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 292 *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ 293 } \ 294 } else { \ 295 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \ 296 *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ 297 } \ 298 } 299 300 301#define nfsm_strsiz(s,m) \ 302 { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ 303 if (((s) = fxdr_unsigned(int32_t,*tl)) > (m)) { \ 304 m_freem(mrep); \ 305 error = EBADRPC; \ 306 goto nfsmout; \ 307 } } 308 309#define nfsm_srvstrsiz(s,m) \ 310 { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ 311 if (((s) = fxdr_unsigned(int32_t,*tl)) > (m) || (s) <= 0) { \ 312 error = EBADRPC; \ 313 nfsm_reply(0); \ 314 } } 315 316#define nfsm_srvnamesiz(s) \ 317 { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \ 318 if (((s) = fxdr_unsigned(int32_t,*tl)) > NFS_MAXNAMLEN) \ 319 error = NFSERR_NAMETOL; \ 320 if ((s) <= 0) \ 321 error = EBADRPC; \ 322 if (error) \ 323 nfsm_reply(0); \ 324 } 325 326#define nfsm_mtouio(p,s) \ 327 if ((s) > 0 && \ 328 (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \ 329 error = t1; \ 330 m_freem(mrep); \ 331 goto nfsmout; \ 332 } 333 334#define nfsm_uiotom(p,s) \ 335 if ((t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) != 0) { \ 336 error = t1; \ 337 m_freem(mreq); \ 338 goto nfsmout; \ 339 } 340 341#define nfsm_reqhead(v,a,s) \ 342 mb = mreq = nfsm_reqh((v),(a),(s),&bpos) 343 344#define nfsm_reqdone m_freem(mrep); \ 345 nfsmout: 346 347#define nfsm_rndup(a) (((a)+3)&(~0x3)) 348 349#define nfsm_request(v, t, p, c) \ 350 if ((error = nfs_request((v), mreq, (t), (p), \ 351 (c), &mrep, &md, &dpos)) != 0) { \ 352 if (error & NFSERR_RETERR) \ 353 error &= ~NFSERR_RETERR; \ 354 else \ 355 goto nfsmout; \ 356 } 357 358#define nfsm_strtom(a,s,m) \ 359 if ((s) > (m)) { \ 360 m_freem(mreq); \ 361 error = ENAMETOOLONG; \ 362 goto nfsmout; \ 363 } \ 364 t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \ 365 if (t2 <= M_TRAILINGSPACE(mb)) { \ 366 nfsm_build(tl,u_int32_t *,t2); \ 367 *tl++ = txdr_unsigned(s); \ 368 *(tl+((t2>>2)-2)) = 0; \ 369 bcopy((const char *)(a), (caddr_t)tl, (s)); \ 370 } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s))) != 0) { \ 371 error = t2; \ 372 m_freem(mreq); \ 373 goto nfsmout; \ 374 } 375 376#define nfsm_srvdone \ 377 nfsmout: \ 378 return(error) 379 380#define nfsm_reply(s) \ 381 { \ 382 nfsd->nd_repstat = error; \ 383 if (error && !(nfsd->nd_flag & ND_NFSV3)) \ 384 (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ 385 mrq, &mb, &bpos); \ 386 else \ 387 (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \ 388 mrq, &mb, &bpos); \ 389 if (mrep != NULL) { \ 390 m_freem(mrep); \ 391 mrep = NULL; \ 392 } \ 393 mreq = *mrq; \ 394 if (error && (!(nfsd->nd_flag & ND_NFSV3) || \ 395 error == EBADRPC)) { \ 396 error = 0; \ 397 goto nfsmout; \ 398 } } 399 400#define nfsm_writereply(s, v3) \ 401 { \ 402 nfsd->nd_repstat = error; \ 403 if (error && !(v3)) \ 404 (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \ 405 &mreq, &mb, &bpos); \ 406 else \ 407 (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \ 408 &mreq, &mb, &bpos); \ 409 } 410 411#define nfsm_adv(s) \ 412 { t1 = mtod(md, caddr_t)+md->m_len-dpos; \ 413 if (t1 >= (s)) { \ 414 dpos += (s); \ 415 } else if ((t1 = nfs_adv(&md, &dpos, (s), t1)) != 0) { \ 416 error = t1; \ 417 m_freem(mrep); \ 418 goto nfsmout; \ 419 } } 420 421#define nfsm_srvmtofh(f) \
|
440 441#define nfsm_clget \ 442 if (bp >= be) { \ 443 if (mp == mb) \ 444 mp->m_len += bp-bpos; \ 445 MGET(mp, M_WAIT, MT_DATA); \ 446 MCLGET(mp, M_WAIT); \ 447 mp->m_len = NFSMSIZ(mp); \ 448 mp2->m_next = mp; \ 449 mp2 = mp; \ 450 bp = mtod(mp, caddr_t); \ 451 be = bp+mp->m_len; \ 452 } \ 453 tl = (u_int32_t *)bp 454 455#define nfsm_srvfillattr(a, f) \ 456 nfsm_srvfattr(nfsd, (a), (f)) 457 458#define nfsm_srvwcc_data(br, b, ar, a) \ 459 nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos) 460 461#define nfsm_srvpostop_attr(r, a) \ 462 nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos) 463 464#define nfsm_srvsattr(a) \ 465 { nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 466 if (*tl == nfs_true) { \ 467 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 468 (a)->va_mode = nfstov_mode(*tl); \ 469 } \ 470 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 471 if (*tl == nfs_true) { \ 472 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 473 (a)->va_uid = fxdr_unsigned(uid_t, *tl); \ 474 } \ 475 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 476 if (*tl == nfs_true) { \ 477 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 478 (a)->va_gid = fxdr_unsigned(gid_t, *tl); \ 479 } \ 480 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 481 if (*tl == nfs_true) { \ 482 nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 483 (a)->va_size = fxdr_hyper(tl); \ 484 } \ 485 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 486 switch (fxdr_unsigned(int, *tl)) { \ 487 case NFSV3SATTRTIME_TOCLIENT: \ 488 nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 489 fxdr_nfsv3time(tl, &(a)->va_atime); \ 490 break; \ 491 case NFSV3SATTRTIME_TOSERVER: \ 492 getnanotime(&(a)->va_atime); \ 493 break; \ 494 }; \ 495 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 496 switch (fxdr_unsigned(int, *tl)) { \ 497 case NFSV3SATTRTIME_TOCLIENT: \ 498 nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 499 fxdr_nfsv3time(tl, &(a)->va_mtime); \ 500 break; \ 501 case NFSV3SATTRTIME_TOSERVER: \ 502 getnanotime(&(a)->va_mtime); \ 503 break; \ 504 }; } 505 506#endif
| 441 442#define nfsm_clget \ 443 if (bp >= be) { \ 444 if (mp == mb) \ 445 mp->m_len += bp-bpos; \ 446 MGET(mp, M_WAIT, MT_DATA); \ 447 MCLGET(mp, M_WAIT); \ 448 mp->m_len = NFSMSIZ(mp); \ 449 mp2->m_next = mp; \ 450 mp2 = mp; \ 451 bp = mtod(mp, caddr_t); \ 452 be = bp+mp->m_len; \ 453 } \ 454 tl = (u_int32_t *)bp 455 456#define nfsm_srvfillattr(a, f) \ 457 nfsm_srvfattr(nfsd, (a), (f)) 458 459#define nfsm_srvwcc_data(br, b, ar, a) \ 460 nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos) 461 462#define nfsm_srvpostop_attr(r, a) \ 463 nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos) 464 465#define nfsm_srvsattr(a) \ 466 { nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 467 if (*tl == nfs_true) { \ 468 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 469 (a)->va_mode = nfstov_mode(*tl); \ 470 } \ 471 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 472 if (*tl == nfs_true) { \ 473 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 474 (a)->va_uid = fxdr_unsigned(uid_t, *tl); \ 475 } \ 476 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 477 if (*tl == nfs_true) { \ 478 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 479 (a)->va_gid = fxdr_unsigned(gid_t, *tl); \ 480 } \ 481 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 482 if (*tl == nfs_true) { \ 483 nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 484 (a)->va_size = fxdr_hyper(tl); \ 485 } \ 486 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 487 switch (fxdr_unsigned(int, *tl)) { \ 488 case NFSV3SATTRTIME_TOCLIENT: \ 489 nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 490 fxdr_nfsv3time(tl, &(a)->va_atime); \ 491 break; \ 492 case NFSV3SATTRTIME_TOSERVER: \ 493 getnanotime(&(a)->va_atime); \ 494 break; \ 495 }; \ 496 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ 497 switch (fxdr_unsigned(int, *tl)) { \ 498 case NFSV3SATTRTIME_TOCLIENT: \ 499 nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \ 500 fxdr_nfsv3time(tl, &(a)->va_mtime); \ 501 break; \ 502 case NFSV3SATTRTIME_TOSERVER: \ 503 getnanotime(&(a)->va_mtime); \ 504 break; \ 505 }; } 506 507#endif
|