]>
git.saurik.com Git - apple/xnu.git/blob - bsd/nfs/nfsm_subs.h
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
27 * Copyright (c) 1989, 1993
28 * The Regents of the University of California. All rights reserved.
30 * This code is derived from software contributed to Berkeley by
31 * Rick Macklem at The University of Guelph.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95
62 * FreeBSD-Id: nfsm_subs.h,v 1.13 1997/07/16 09:06:30 dfr Exp $
66 #ifndef _NFS_NFSM_SUBS_H_
67 #define _NFS_NFSM_SUBS_H_
69 #include <sys/appleapiopts.h>
71 #ifdef __APPLE_API_PRIVATE
73 * These macros do strange and peculiar things to mbuf chains for
74 * the assistance of the nfs code. To attempt to use them for any
75 * other purpose will be dangerous. (they make weird assumptions)
79 * First define what the actual subs. return
81 struct mbuf
*nfsm_reqh
__P((struct vnode
*vp
, u_long procid
, int hsiz
,
83 struct mbuf
*nfsm_rpchead
__P((struct ucred
*cr
, int nmflag
, int procid
,
84 int auth_type
, int auth_len
, char *auth_str
,
85 int verf_len
, char *verf_str
,
86 struct mbuf
*mrest
, int mrest_len
,
87 struct mbuf
**mbp
, u_long
*xidp
));
89 #define M_HASCL(m) ((m)->m_flags & M_EXT)
90 #define NFSMINOFF(m) \
92 (m)->m_data = (m)->m_ext.ext_buf; \
93 else if ((m)->m_flags & M_PKTHDR) \
94 (m)->m_data = (m)->m_pktdat; \
96 (m)->m_data = (m)->m_dat
97 #define NFSMADV(m, s) (m)->m_data += (s)
98 #define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \
99 (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN))
102 * Now for the macros that do the simple stuff and call the functions
103 * for the hard stuff.
104 * These macros use several vars. declared in nfsm_reqhead and these
105 * vars. must not be used elsewhere unless you are careful not to corrupt
106 * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
107 * that may be used so long as the value is not expected to retained
109 * I know, this is kind of dorkey, but it makes the actual op functions
110 * fairly clean and deals with the mess caused by the xdr discriminating
114 #define nfsm_build(a,c,s) \
115 { if ((s) > M_TRAILINGSPACE(mb)) { \
116 MGET(mb2, M_WAIT, MT_DATA); \
118 panic("build > MLEN"); \
122 bpos = mtod(mb, caddr_t); \
128 #define nfsm_dissect(a, c, s) \
129 { t1 = mtod(md, caddr_t)+md->m_len-dpos; \
133 } else if ((t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2))) { \
141 #define nfsm_fhtom(v, v3) \
143 t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \
144 if (t2 <= M_TRAILINGSPACE(mb)) { \
145 nfsm_build(tl, u_long *, t2); \
146 *tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \
147 *(tl + ((t2>>2) - 2)) = 0; \
148 bcopy((caddr_t)VTONFS(v)->n_fhp,(caddr_t)tl, \
149 VTONFS(v)->n_fhsize); \
150 } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, \
151 (caddr_t)VTONFS(v)->n_fhp, VTONFS(v)->n_fhsize))) { \
157 nfsm_build(cp, caddr_t, NFSX_V2FH); \
158 bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \
161 #define nfsm_srvfhtom(f, v3) \
163 nfsm_build(tl, u_long *, NFSX_UNSIGNED + NFSX_V3FH); \
164 *tl++ = txdr_unsigned(NFSX_V3FH); \
165 bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \
167 nfsm_build(cp, caddr_t, NFSX_V2FH); \
168 bcopy((caddr_t)(f), cp, NFSX_V2FH); \
171 #define nfsm_srvpostop_fh(f) \
172 { nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \
174 *tl++ = txdr_unsigned(NFSX_V3FH); \
175 bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \
178 #define nfsm_mtofh(d, v, v3, f, x) \
179 { struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \
181 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
182 (f) = fxdr_unsigned(int, *tl); \
186 nfsm_getfh(ttfhp, ttfhsize, (v3)); \
187 if ((t1 = nfs_nget((d)->v_mount, ttfhp, ttfhsize, \
193 (v) = NFSTOV(ttnp); \
196 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
198 (f) = fxdr_unsigned(int, *tl); \
199 else if (fxdr_unsigned(int, *tl)) \
200 nfsm_adv(NFSX_V3FATTR); \
203 nfsm_loadattr((v), (struct vattr *)0, (x)); \
206 #define nfsm_getfh(f, s, v3) \
208 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
209 if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \
210 (s) > NFSX_V3FHMAX) { \
217 nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); }
219 #define nfsm_loadattr(v, a, x) \
220 { struct vnode *ttvp = (v); \
221 if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, (a), 0, \
229 #define nfsm_postop_attr(v, f, x) \
230 { struct vnode *ttvp = (v); \
231 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
232 if (((f) = fxdr_unsigned(int, *tl))) { \
233 if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, \
234 (struct vattr *)0, 1, (x)))) { \
245 /* Used as (f) for nfsm_wcc_data() */
246 #define NFSV3_WCCRATTR 0
247 #define NFSV3_WCCCHK 1
249 #define nfsm_wcc_data(v, f, x) \
250 { int ttattrf, ttretf = 0; \
251 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
252 if (*tl == nfs_true) { \
253 nfsm_dissect(tl, u_long *, 6 * NFSX_UNSIGNED); \
255 ttretf = (VTONFS(v)->n_mtime == \
256 fxdr_unsigned(u_long, *(tl + 2))); \
258 nfsm_postop_attr((v), ttattrf, (x)); \
265 #define nfsm_v3sattr(s, a, u, g) \
266 { (s)->sa_modetrue = nfs_true; \
267 (s)->sa_mode = vtonfsv3_mode((a)->va_mode); \
268 (s)->sa_uidtrue = nfs_true; \
269 (s)->sa_uid = txdr_unsigned(u); \
270 (s)->sa_gidtrue = nfs_true; \
271 (s)->sa_gid = txdr_unsigned(g); \
272 (s)->sa_sizefalse = nfs_false; \
273 (s)->sa_atimetype = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
274 (s)->sa_mtimetype = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
277 #define nfsm_strsiz(s,m) \
278 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \
279 if (((s) = fxdr_unsigned(long,*tl)) > (m)) { \
285 #define nfsm_srvstrsiz(s,m) \
286 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \
287 if (((s) = fxdr_unsigned(long,*tl)) > (m) || (s) <= 0) { \
292 #define nfsm_srvnamesiz(s) \
293 { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \
294 if (((s) = fxdr_unsigned(long,*tl)) > NFS_MAXNAMLEN) \
295 error = NFSERR_NAMETOL; \
302 #define nfsm_mtouio(p,s) \
304 (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos))) { \
310 #define nfsm_uiotom(p,s) \
311 if ((t1 = nfsm_uiotombuf((p),&mb,(s),&bpos))) { \
317 #define nfsm_reqhead(v,a,s) \
318 mb = mreq = nfsm_reqh((v),(a),(s),&bpos)
320 #define nfsm_reqdone m_freem(mrep); \
323 #define nfsm_rndup(a) (((a)+3)&(~0x3))
326 * We seem to see cases mainly on shutdown where the vnode got recycled
327 * on use while waiting on server. Maybe nfs vnode locking will help if
328 * we implement that, but for now, check for bad vnodes and return an
329 * error. This call spot should catch most of them. Note that NFSv2
330 * just goes to nfsmout here, while nfsV3 goes back to caller's next
331 * line for post-processing. It will do a nfsm_reqdone also making
332 * m_freem(mrep). Wondering if some of our freeing problems could be
333 * due to nfsv3 calling nfsm_reqdone unlike nfsv2. Separate problem.
335 #define nfsm_request(v, t, p, c, x) \
337 int nfsv3 = (VFSTONFS((v)->v_mount))->nm_flag & NFSMNT_NFSV3; \
338 if ((error = nfs_request((v), mreq, (t), (p), \
339 (c), &mrep, &md, &dpos, (x)))) { \
340 if (error & NFSERR_RETERR) \
341 error &= ~NFSERR_RETERR; \
345 else if ((v)->v_type==VBAD) { \
352 #define nfsm_strtom(a,s,m) \
355 error = ENAMETOOLONG; \
358 t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \
359 if (t2 <= M_TRAILINGSPACE(mb)) { \
360 nfsm_build(tl,u_long *,t2); \
361 *tl++ = txdr_unsigned(s); \
362 *(tl+((t2>>2)-2)) = 0; \
363 bcopy((caddr_t)(a), (caddr_t)tl, (s)); \
364 } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s)))) { \
370 #define nfsm_srvdone \
374 #define nfsm_reply(s) \
376 nfsd->nd_repstat = error; \
377 if (error && !(nfsd->nd_flag & ND_NFSV3)) \
378 (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
381 (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
385 if (error && (!(nfsd->nd_flag & ND_NFSV3) || \
390 #define nfsm_writereply(s, v3) \
392 nfsd->nd_repstat = error; \
393 if (error && !(v3)) \
394 (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
395 &mreq, &mb, &bpos); \
397 (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
398 &mreq, &mb, &bpos); \
401 #define nfsm_adv(s) \
402 { t1 = mtod(md, caddr_t)+md->m_len-dpos; \
405 } else if ((t1 = nfs_adv(&md, &dpos, (s), t1))) { \
411 #define nfsm_srvmtofh(f) \
412 { if (nfsd->nd_flag & ND_NFSV3) { \
413 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
414 if (fxdr_unsigned(int, *tl) != NFSX_V3FH) { \
419 nfsm_dissect(tl, u_long *, NFSX_V3FH); \
420 bcopy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \
421 if ((nfsd->nd_flag & ND_NFSV3) == 0) \
422 nfsm_adv(NFSX_V2FH - NFSX_V3FH); \
428 mp->m_len += bp-bpos; \
429 MGET(mp, M_WAIT, MT_DATA); \
430 MCLGET(mp, M_WAIT); \
431 mp->m_len = NFSMSIZ(mp); \
434 bp = mtod(mp, caddr_t); \
439 #define nfsm_srvfillattr(a, f) \
440 nfsm_srvfattr(nfsd, (a), (f))
442 #define nfsm_srvwcc_data(br, b, ar, a) \
443 nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos)
445 #define nfsm_srvpostop_attr(r, a) \
446 nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos)
448 #define nfsm_srvsattr(a) \
449 { nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
450 if (*tl == nfs_true) { \
451 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
452 (a)->va_mode = nfstov_mode(*tl); \
454 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
455 if (*tl == nfs_true) { \
456 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
457 (a)->va_uid = fxdr_unsigned(uid_t, *tl); \
459 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
460 if (*tl == nfs_true) { \
461 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
462 (a)->va_gid = fxdr_unsigned(gid_t, *tl); \
464 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
465 if (*tl == nfs_true) { \
466 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
467 fxdr_hyper(tl, &(a)->va_size); \
469 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
470 switch (fxdr_unsigned(int, *tl)) { \
471 case NFSV3SATTRTIME_TOCLIENT: \
472 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
473 fxdr_nfsv3time(tl, &(a)->va_atime); \
475 case NFSV3SATTRTIME_TOSERVER: \
476 (a)->va_atime.tv_sec = time.tv_sec; \
477 (a)->va_atime.tv_nsec = time.tv_usec * 1000; \
480 nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
481 switch (fxdr_unsigned(int, *tl)) { \
482 case NFSV3SATTRTIME_TOCLIENT: \
483 nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
484 fxdr_nfsv3time(tl, &(a)->va_mtime); \
486 case NFSV3SATTRTIME_TOSERVER: \
487 (a)->va_mtime.tv_sec = time.tv_sec; \
488 (a)->va_mtime.tv_nsec = time.tv_usec * 1000; \
492 #endif /* __APPLE_API_PRIVATE */
493 #endif /* _NFS_NFSM_SUBS_H_ */