]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
29 | /* | |
30 | * Copyright (c) 1989, 1993 | |
31 | * The Regents of the University of California. All rights reserved. | |
32 | * | |
33 | * This code is derived from software contributed to Berkeley by | |
34 | * Rick Macklem at The University of Guelph. | |
35 | * | |
36 | * Redistribution and use in source and binary forms, with or without | |
37 | * modification, are permitted provided that the following conditions | |
38 | * are met: | |
39 | * 1. Redistributions of source code must retain the above copyright | |
40 | * notice, this list of conditions and the following disclaimer. | |
41 | * 2. Redistributions in binary form must reproduce the above copyright | |
42 | * notice, this list of conditions and the following disclaimer in the | |
43 | * documentation and/or other materials provided with the distribution. | |
44 | * 3. All advertising materials mentioning features or use of this software | |
45 | * must display the following acknowledgement: | |
46 | * This product includes software developed by the University of | |
47 | * California, Berkeley and its contributors. | |
48 | * 4. Neither the name of the University nor the names of its contributors | |
49 | * may be used to endorse or promote products derived from this software | |
50 | * without specific prior written permission. | |
51 | * | |
52 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
53 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
54 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
55 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
56 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
57 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
58 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
59 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
60 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
61 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
62 | * SUCH DAMAGE. | |
63 | * | |
64 | * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 | |
65 | * FreeBSD-Id: nfsm_subs.h,v 1.13 1997/07/16 09:06:30 dfr Exp $ | |
66 | */ | |
67 | ||
68 | ||
69 | #ifndef _NFS_NFSM_SUBS_H_ | |
70 | #define _NFS_NFSM_SUBS_H_ | |
71 | ||
72 | #include <sys/appleapiopts.h> | |
73 | ||
74 | #ifdef __APPLE_API_PRIVATE | |
75 | /* | |
76 | * These macros do strange and peculiar things to mbuf chains for | |
77 | * the assistance of the nfs code. To attempt to use them for any | |
78 | * other purpose will be dangerous. (they make weird assumptions) | |
79 | */ | |
80 | ||
81 | /* | |
82 | * First define what the actual subs. return | |
83 | */ | |
84 | int nfsm_reqh(int hsiz, caddr_t *bposp, mbuf_t *mbp); | |
85 | int nfsm_rpchead(struct ucred *cr, int nmflag, int procid, | |
86 | int auth_type, int auth_len, char *auth_str, | |
87 | int verf_len, char *verf_str, | |
88 | mbuf_t mrest, int mrest_len, | |
89 | mbuf_t *mbp, u_long *xidp, mbuf_t *mreqp); | |
90 | ||
91 | /* | |
92 | * Now for the macros that do the simple stuff and call the functions | |
93 | * for the hard stuff. | |
94 | * These macros use several vars. declared in nfsm_reqhead and these | |
95 | * vars. must not be used elsewhere unless you are careful not to corrupt | |
96 | * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries | |
97 | * that may be used so long as the value is not expected to retained | |
98 | * after a macro. | |
99 | * I know, this is kind of dorkey, but it makes the actual op functions | |
100 | * fairly clean and deals with the mess caused by the xdr discriminating | |
101 | * unions. | |
102 | */ | |
103 | ||
104 | #define nfsm_build(a,c,s) \ | |
105 | { if ((s) > mbuf_trailingspace(mb)) { \ | |
106 | int __nfsm_error; \ | |
107 | __nfsm_error = mbuf_get(MBUF_WAITOK, MBUF_TYPE_DATA, &mb2); \ | |
108 | if (__nfsm_error) \ | |
109 | panic("nfsm_build mbuf_get error %d", __nfsm_error); \ | |
110 | if ((s) > mbuf_maxlen(mb2)) \ | |
111 | panic("nfsm_build size error"); \ | |
112 | __nfsm_error = mbuf_setnext(mb, mb2); \ | |
113 | if (__nfsm_error) \ | |
114 | panic("nfsm_build mbuf_setnext error %d", __nfsm_error); \ | |
115 | mb = mb2; \ | |
116 | bpos = mbuf_data(mb); \ | |
117 | } \ | |
118 | (a) = (c)(bpos); \ | |
119 | mbuf_setlen(mb, (mbuf_len(mb) + (s))); \ | |
120 | bpos += (s); } | |
121 | ||
122 | #define nfsm_dissect(a, c, s) \ | |
123 | { t1 = ((caddr_t)mbuf_data(md)) + mbuf_len(md) - dpos; \ | |
124 | if (t1 >= (s)) { \ | |
125 | (a) = (c)(dpos); \ | |
126 | dpos += (s); \ | |
127 | } else if ((t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2))) { \ | |
128 | error = t1; \ | |
129 | mbuf_freem(mrep); \ | |
130 | goto nfsmout; \ | |
131 | } else { \ | |
132 | (a) = (c)cp2; \ | |
133 | } } | |
134 | ||
135 | #define nfsm_fhtom(v, v3) \ | |
136 | { if (v3) { \ | |
137 | t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \ | |
138 | if (t2 <= mbuf_trailingspace(mb)) { \ | |
139 | nfsm_build(tl, u_long *, t2); \ | |
140 | *tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \ | |
141 | *(tl + ((t2>>2) - 2)) = 0; \ | |
142 | bcopy((caddr_t)VTONFS(v)->n_fhp,(caddr_t)tl, \ | |
143 | VTONFS(v)->n_fhsize); \ | |
144 | } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, \ | |
145 | (caddr_t)VTONFS(v)->n_fhp, VTONFS(v)->n_fhsize))) { \ | |
146 | error = t2; \ | |
147 | mbuf_freem(mreq); \ | |
148 | goto nfsmout; \ | |
149 | } \ | |
150 | } else { \ | |
151 | nfsm_build(cp, caddr_t, NFSX_V2FH); \ | |
152 | bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \ | |
153 | } } | |
154 | ||
155 | #define nfsm_srvfhtom(f, v3) \ | |
156 | { if (v3) { \ | |
157 | nfsm_build(tl, u_long *, NFSX_UNSIGNED + (unsigned)(f)->nfh_len); \ | |
158 | *tl++ = txdr_unsigned((f)->nfh_len); \ | |
159 | bcopy((caddr_t)&(f)->nfh_xh, (caddr_t)tl, (f)->nfh_len); \ | |
160 | } else { \ | |
161 | nfsm_build(cp, caddr_t, NFSX_V2FH); \ | |
162 | bcopy((caddr_t)&(f)->nfh_xh, cp, NFSX_V2FH); \ | |
163 | } } | |
164 | ||
165 | #define nfsm_srvpostop_fh(f) \ | |
166 | { nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED + (unsigned)(f)->nfh_len); \ | |
167 | *tl++ = nfs_true; \ | |
168 | *tl++ = txdr_unsigned((f)->nfh_len); \ | |
169 | bcopy((caddr_t)&(f)->nfh_xh, (caddr_t)tl, (f)->nfh_len); \ | |
170 | } | |
171 | ||
172 | #define nfsm_mtofh(d, cnp, v, v3, xp, f) \ | |
173 | { \ | |
174 | struct nfsnode *ttnp; u_char *ttfhp = NULL; \ | |
175 | int ttfhsize = 0, ttgotfh = 1, ttgotattr = 1, ttgotnode = 0; \ | |
176 | struct nfs_vattr ttvattr; \ | |
177 | (v) = NULL; \ | |
178 | /* XXX would be nice to not bail to nfsmout on error */ \ | |
179 | if (v3) { /* check for file handle */ \ | |
180 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
181 | ttgotfh = fxdr_unsigned(int, *tl); \ | |
182 | } \ | |
183 | if (ttgotfh) { \ | |
184 | /* get file handle */ \ | |
185 | nfsm_getfh(ttfhp, ttfhsize, (v3)); \ | |
186 | } \ | |
187 | if (v3) { /* check for attributes */ \ | |
188 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
189 | ttgotattr = fxdr_unsigned(int, *tl); \ | |
190 | } \ | |
191 | /* get attributes */ \ | |
192 | if (ttgotattr) { \ | |
193 | if (!ttgotfh) { \ | |
194 | nfsm_adv(NFSX_V3FATTR); \ | |
195 | } else { \ | |
196 | nfsm_attr_get(v3, &ttvattr); \ | |
197 | } \ | |
198 | } else if (ttgotfh) { \ | |
199 | /* We need valid attributes in order */ \ | |
200 | /* to call nfs_nget/vnode_create(). */ \ | |
201 | t1 = nfs_getattr_no_vnode(vnode_mount(d), \ | |
202 | ttfhp, ttfhsize, cred, p, &ttvattr, xp); \ | |
203 | if (t1) \ | |
204 | ttgotattr = 0; \ | |
205 | } \ | |
206 | if (ttgotfh && ttgotattr) { \ | |
207 | int ttngflags = NG_MAKEENTRY; \ | |
208 | if ((t1 = nfs_nget(vnode_mount(d), d, cnp, ttfhp, ttfhsize, \ | |
209 | &ttvattr, xp, ttngflags, &ttnp))) { \ | |
210 | error = t1; \ | |
211 | ttgotnode = 0; \ | |
212 | } else { \ | |
213 | ttgotnode = 1; \ | |
214 | (v) = NFSTOV(ttnp); \ | |
215 | } \ | |
216 | } \ | |
217 | (f) = ttgotnode; \ | |
218 | } | |
219 | ||
220 | #define nfsm_getfh(f, s, v3) \ | |
221 | { if (v3) { \ | |
222 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
223 | if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \ | |
224 | (s) > NFSX_V3FHMAX) { \ | |
225 | mbuf_freem(mrep); \ | |
226 | error = EBADRPC; \ | |
227 | goto nfsmout; \ | |
228 | } \ | |
229 | } else { \ | |
230 | (s) = NFSX_V2FH; \ | |
231 | } \ | |
232 | nfsm_dissect((f), u_char *, nfsm_rndup(s)); } | |
233 | ||
234 | #define nfsm_loadattr(v, v3, a, x) \ | |
235 | { struct nfs_vattr ttvattr; \ | |
236 | if ((t1 = nfs_parsefattr(&md, &dpos, v3, &ttvattr))) { \ | |
237 | error = t1; \ | |
238 | mbuf_freem(mrep); \ | |
239 | goto nfsmout; \ | |
240 | } \ | |
241 | if ((t1 = nfs_loadattrcache(VTONFS(v), &ttvattr, (x), 0))) { \ | |
242 | error = t1; \ | |
243 | mbuf_freem(mrep); \ | |
244 | goto nfsmout; \ | |
245 | } \ | |
246 | if (a) { \ | |
247 | bcopy(&ttvattr, (a), sizeof(ttvattr)); \ | |
248 | } \ | |
249 | } | |
250 | ||
251 | #define nfsm_attr_get(v3, vap) \ | |
252 | { \ | |
253 | if ((t1 = nfs_parsefattr(&md, &dpos, v3, vap))) { \ | |
254 | error = t1; \ | |
255 | mbuf_freem(mrep); \ | |
256 | goto nfsmout; \ | |
257 | } \ | |
258 | } | |
259 | ||
260 | #define nfsm_postop_attr_get(v3, f, vap) \ | |
261 | { \ | |
262 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
263 | if (((f) = fxdr_unsigned(int, *tl))) { \ | |
264 | if ((t1 = nfs_parsefattr(&md, &dpos, v3, vap))) { \ | |
265 | error = t1; \ | |
266 | (f) = 0; \ | |
267 | mbuf_freem(mrep); \ | |
268 | goto nfsmout; \ | |
269 | } \ | |
270 | } } | |
271 | ||
272 | #define nfsm_postop_attr_update(v, v3, f, x) \ | |
273 | { \ | |
274 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
275 | if (((f) = fxdr_unsigned(int, *tl))) { \ | |
276 | struct nfs_vattr ttvattr; \ | |
277 | if ((t1 = nfs_parsefattr(&md, &dpos, v3, &ttvattr))) { \ | |
278 | error = t1; \ | |
279 | (f) = 0; \ | |
280 | mbuf_freem(mrep); \ | |
281 | goto nfsmout; \ | |
282 | } \ | |
283 | if ((t1 = nfs_loadattrcache(VTONFS(v), &ttvattr, (x), 1))) { \ | |
284 | error = t1; \ | |
285 | (f) = 0; \ | |
286 | mbuf_freem(mrep); \ | |
287 | goto nfsmout; \ | |
288 | } \ | |
289 | if (*(x) == 0) \ | |
290 | (f) = 0; \ | |
291 | } } | |
292 | ||
293 | #define nfsm_wcc_data(v, premtime, newpostattr, x) \ | |
294 | { \ | |
295 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
296 | if (*tl == nfs_true) { \ | |
297 | nfsm_dissect(tl, u_long *, 6 * NFSX_UNSIGNED); \ | |
298 | (premtime)->tv_sec = fxdr_unsigned(time_t, *(tl + 2)); \ | |
299 | (premtime)->tv_nsec = fxdr_unsigned(time_t, *(tl + 3)); \ | |
300 | } else { \ | |
301 | (premtime)->tv_sec = 0; \ | |
302 | (premtime)->tv_nsec = 0; \ | |
303 | } \ | |
304 | nfsm_postop_attr_update((v), 1, (newpostattr), (x)); \ | |
305 | } | |
306 | ||
307 | #define nfsm_v3sattr(vap) \ | |
308 | {\ | |
309 | struct timeval now; \ | |
310 | if (VATTR_IS_ACTIVE(vap, va_mode)) { \ | |
311 | nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED); \ | |
312 | *tl++ = nfs_true; \ | |
313 | *tl = txdr_unsigned(vap->va_mode); \ | |
314 | } else { \ | |
315 | nfsm_build(tl, u_long *, NFSX_UNSIGNED); \ | |
316 | *tl = nfs_false; \ | |
317 | } \ | |
318 | if (VATTR_IS_ACTIVE(vap, va_uid)) { \ | |
319 | nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED); \ | |
320 | *tl++ = nfs_true; \ | |
321 | *tl = txdr_unsigned(vap->va_uid); \ | |
322 | } else { \ | |
323 | nfsm_build(tl, u_long *, NFSX_UNSIGNED); \ | |
324 | *tl = nfs_false; \ | |
325 | } \ | |
326 | if (VATTR_IS_ACTIVE(vap, va_gid)) { \ | |
327 | nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED); \ | |
328 | *tl++ = nfs_true; \ | |
329 | *tl = txdr_unsigned(vap->va_gid); \ | |
330 | } else { \ | |
331 | nfsm_build(tl, u_long *, NFSX_UNSIGNED); \ | |
332 | *tl = nfs_false; \ | |
333 | } \ | |
334 | if (VATTR_IS_ACTIVE(vap, va_data_size)) { \ | |
335 | nfsm_build(tl, u_long *, 3 * NFSX_UNSIGNED); \ | |
336 | *tl++ = nfs_true; \ | |
337 | txdr_hyper(&vap->va_data_size, tl); \ | |
338 | } else { \ | |
339 | nfsm_build(tl, u_long *, NFSX_UNSIGNED); \ | |
340 | *tl = nfs_false; \ | |
341 | } \ | |
342 | microtime(&now); \ | |
343 | if (VATTR_IS_ACTIVE(vap, va_access_time)) { \ | |
344 | if (vap->va_access_time.tv_sec != now.tv_sec) { \ | |
345 | nfsm_build(tl, u_long *, 3 * NFSX_UNSIGNED); \ | |
346 | *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ | |
347 | txdr_nfsv3time(&vap->va_access_time, tl); \ | |
348 | } else { \ | |
349 | nfsm_build(tl, u_long *, NFSX_UNSIGNED); \ | |
350 | *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ | |
351 | } \ | |
352 | } else { \ | |
353 | nfsm_build(tl, u_long *, NFSX_UNSIGNED); \ | |
354 | *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ | |
355 | } \ | |
356 | if (VATTR_IS_ACTIVE(vap, va_modify_time)) { \ | |
357 | if (vap->va_modify_time.tv_sec != now.tv_sec) { \ | |
358 | nfsm_build(tl, u_long *, 3 * NFSX_UNSIGNED); \ | |
359 | *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \ | |
360 | txdr_nfsv3time(&vap->va_modify_time, tl); \ | |
361 | } else { \ | |
362 | nfsm_build(tl, u_long *, NFSX_UNSIGNED); \ | |
363 | *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \ | |
364 | } \ | |
365 | } else { \ | |
366 | nfsm_build(tl, u_long *, NFSX_UNSIGNED); \ | |
367 | *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \ | |
368 | } \ | |
369 | } | |
370 | ||
371 | #define nfsm_strsiz(s,m,v3) \ | |
372 | { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \ | |
373 | (s) = fxdr_unsigned(long,*tl); \ | |
374 | if (!(v3) && ((s) > (m))) { \ | |
375 | mbuf_freem(mrep); \ | |
376 | error = EBADRPC; \ | |
377 | goto nfsmout; \ | |
378 | } } | |
379 | ||
380 | #define nfsm_srvstrsiz(s,m) \ | |
381 | { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \ | |
382 | if (((s) = fxdr_unsigned(long,*tl)) > (m) || (s) <= 0) { \ | |
383 | error = EBADRPC; \ | |
384 | nfsm_reply(0); \ | |
385 | } } | |
386 | ||
387 | #define nfsm_srvnamesiz(s,v3) \ | |
388 | { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \ | |
389 | (s) = fxdr_unsigned(long,*tl); \ | |
390 | if (!(v3) && ((s) > NFS_MAXNAMLEN)) \ | |
391 | error = NFSERR_NAMETOL; \ | |
392 | if ((s) <= 0) \ | |
393 | error = EBADRPC; \ | |
394 | if (error) \ | |
395 | nfsm_reply(0); \ | |
396 | } | |
397 | ||
398 | #define nfsm_mtouio(p,s) \ | |
399 | if ((s) > 0 && \ | |
400 | (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos))) { \ | |
401 | error = t1; \ | |
402 | mbuf_freem(mrep); \ | |
403 | goto nfsmout; \ | |
404 | } | |
405 | ||
406 | #define nfsm_uiotom(p,s) \ | |
407 | if ((t1 = nfsm_uiotombuf((p),&mb,(s),&bpos))) { \ | |
408 | error = t1; \ | |
409 | mbuf_freem(mreq); \ | |
410 | goto nfsmout; \ | |
411 | } | |
412 | ||
413 | #define nfsm_reqhead(s) \ | |
414 | error = nfsm_reqh((s), &bpos, &mreq); \ | |
415 | mb = mreq; | |
416 | ||
417 | #define nfsm_reqdone mbuf_freem(mrep); \ | |
418 | nfsmout: | |
419 | ||
420 | #define nfsm_rndup(a) (((a)+3)&(~0x3)) | |
421 | ||
422 | #define nfsm_request(v, t, p, c, x) \ | |
423 | if ((error = nfs_request((v), vnode_mount(v), mreq, (t), (p), \ | |
424 | (c), &mrep, &md, &dpos, (x)))) { \ | |
425 | if (error & NFSERR_RETERR) \ | |
426 | error &= ~NFSERR_RETERR; \ | |
427 | else \ | |
428 | goto nfsmout; \ | |
429 | } | |
430 | ||
431 | #define nfsm_strtom(a,s,m,v3) \ | |
432 | if (!(v3) && ((s) > (m))) { \ | |
433 | mbuf_freem(mreq); \ | |
434 | error = ENAMETOOLONG; \ | |
435 | goto nfsmout; \ | |
436 | } \ | |
437 | t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \ | |
438 | if (t2 <= mbuf_trailingspace(mb)) { \ | |
439 | nfsm_build(tl,u_long *,t2); \ | |
440 | *tl++ = txdr_unsigned(s); \ | |
441 | *(tl+((t2>>2)-2)) = 0; \ | |
442 | bcopy((caddr_t)(a), (caddr_t)tl, (s)); \ | |
443 | } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s)))) { \ | |
444 | error = t2; \ | |
445 | mbuf_freem(mreq); \ | |
446 | goto nfsmout; \ | |
447 | } | |
448 | ||
449 | #define nfsm_srvdone \ | |
450 | nfsmout: \ | |
451 | return(error) | |
452 | ||
453 | #define nfsm_reply(s) \ | |
454 | { \ | |
455 | nfsd->nd_repstat = error; \ | |
456 | if (error && !(nfsd->nd_flag & ND_NFSV3)) \ | |
457 | nfs_rephead(0, nfsd, slp, error, mrq, &mb, &bpos); \ | |
458 | else \ | |
459 | nfs_rephead((s), nfsd, slp, error, mrq, &mb, &bpos); \ | |
460 | mbuf_freem(mrep); \ | |
461 | mrep = NULL; \ | |
462 | mreq = *mrq; \ | |
463 | if (error && (!(nfsd->nd_flag & ND_NFSV3) || \ | |
464 | error == EBADRPC)) { \ | |
465 | error = 0; \ | |
466 | goto nfsmout; \ | |
467 | } \ | |
468 | } | |
469 | ||
470 | #define nfsm_writereply(s, v3) \ | |
471 | { \ | |
472 | nfsd->nd_repstat = error; \ | |
473 | if (error && !(v3)) \ | |
474 | nfs_rephead(0, nfsd, slp, error, &mreq, &mb, &bpos); \ | |
475 | else \ | |
476 | nfs_rephead((s), nfsd, slp, error, &mreq, &mb, &bpos); \ | |
477 | } | |
478 | ||
479 | #define nfsm_adv(s) \ | |
480 | { t1 = ((caddr_t)mbuf_data(md)) + mbuf_len(md) - dpos; \ | |
481 | if (t1 >= (s)) { \ | |
482 | dpos += (s); \ | |
483 | } else if ((t1 = nfs_adv(&md, &dpos, (s), t1))) { \ | |
484 | error = t1; \ | |
485 | mbuf_freem(mrep); \ | |
486 | goto nfsmout; \ | |
487 | } } | |
488 | ||
489 | #define nfsm_srvmtofh(f) \ | |
490 | { \ | |
491 | if (nfsd->nd_flag & ND_NFSV3) { \ | |
492 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
493 | (f)->nfh_len = fxdr_unsigned(int, *tl); \ | |
494 | if (((f)->nfh_len < (int)sizeof(struct nfs_exphandle)) || \ | |
495 | ((f)->nfh_len > NFSX_V3FHMAX)) { \ | |
496 | error = EBADRPC; \ | |
497 | nfsm_reply(0); \ | |
498 | } \ | |
499 | } else { \ | |
500 | (f)->nfh_len = NFSX_V2FH; \ | |
501 | } \ | |
502 | nfsm_dissect(tl, u_long *, (f)->nfh_len); \ | |
503 | bcopy((caddr_t)tl, (caddr_t)&(f)->nfh_xh, (f)->nfh_len); \ | |
504 | } | |
505 | ||
506 | #define nfsm_clget \ | |
507 | if (bp >= be) { \ | |
508 | int __nfsm_error, __nfsm_len; \ | |
509 | if (mp == mb) \ | |
510 | mbuf_setlen(mp, mbuf_len(mp) + bp - bpos); \ | |
511 | mp = NULL; \ | |
512 | __nfsm_error = mbuf_mclget(MBUF_WAITOK, MBUF_TYPE_DATA, &mp); \ | |
513 | if (__nfsm_error) \ | |
514 | panic("nfsm_clget: mbuf_mclget error %d", __nfsm_error); \ | |
515 | __nfsm_len = mbuf_maxlen(mp); \ | |
516 | mbuf_setlen(mp, __nfsm_len); \ | |
517 | __nfsm_error = mbuf_setnext(mp2, mp); \ | |
518 | if (__nfsm_error) \ | |
519 | panic("nfsm_clget: mbuf_setnext error %d", __nfsm_error); \ | |
520 | mp2 = mp; \ | |
521 | bp = mbuf_data(mp); \ | |
522 | be = bp + __nfsm_len; \ | |
523 | } \ | |
524 | tl = (u_long *)bp | |
525 | ||
526 | #define nfsm_srv_vattr_init(vap, v3) \ | |
527 | { \ | |
528 | VATTR_INIT(vap); \ | |
529 | VATTR_WANTED((vap), va_type); \ | |
530 | VATTR_WANTED((vap), va_mode); \ | |
531 | VATTR_WANTED((vap), va_nlink); \ | |
532 | VATTR_WANTED((vap), va_uid); \ | |
533 | VATTR_WANTED((vap), va_gid); \ | |
534 | VATTR_WANTED((vap), va_data_size); \ | |
535 | VATTR_WANTED((vap), va_data_alloc); \ | |
536 | VATTR_WANTED((vap), va_rdev); \ | |
537 | VATTR_WANTED((vap), va_fsid); \ | |
538 | VATTR_WANTED((vap), va_fileid); \ | |
539 | VATTR_WANTED((vap), va_access_time); \ | |
540 | VATTR_WANTED((vap), va_modify_time); \ | |
541 | VATTR_WANTED((vap), va_change_time); \ | |
542 | if (!v3) VATTR_WANTED((vap), va_iosize); \ | |
543 | } | |
544 | ||
545 | #define nfsm_srv_pre_vattr_init(vap, v3) \ | |
546 | { \ | |
547 | VATTR_INIT(vap); \ | |
548 | VATTR_WANTED((vap), va_data_size); \ | |
549 | VATTR_WANTED((vap), va_modify_time); \ | |
550 | VATTR_WANTED((vap), va_change_time); \ | |
551 | } | |
552 | ||
553 | #define nfsm_srvfillattr(a, f) \ | |
554 | nfsm_srvfattr(nfsd, (a), (f)) | |
555 | ||
556 | #define nfsm_srvwcc_data(br, b, ar, a) \ | |
557 | nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos) | |
558 | ||
559 | #define nfsm_srvpostop_attr(r, a) \ | |
560 | nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos) | |
561 | ||
562 | #define nfsm_srvsattr(a) \ | |
563 | { \ | |
564 | struct timespec now; \ | |
565 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
566 | if (*tl == nfs_true) { \ | |
567 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
568 | VATTR_SET(a, va_mode, nfstov_mode(*tl)); \ | |
569 | } \ | |
570 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
571 | if (*tl == nfs_true) { \ | |
572 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
573 | VATTR_SET(a, va_uid, fxdr_unsigned(uid_t, *tl)); \ | |
574 | } \ | |
575 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
576 | if (*tl == nfs_true) { \ | |
577 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
578 | VATTR_SET(a, va_gid, fxdr_unsigned(gid_t, *tl)); \ | |
579 | } \ | |
580 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
581 | if (*tl == nfs_true) { \ | |
582 | nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \ | |
583 | fxdr_hyper(tl, &(a)->va_data_size); \ | |
584 | VATTR_SET_ACTIVE(a, va_data_size); \ | |
585 | } \ | |
586 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
587 | nanotime(&now); \ | |
588 | switch (fxdr_unsigned(int, *tl)) { \ | |
589 | case NFSV3SATTRTIME_TOCLIENT: \ | |
590 | nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \ | |
591 | fxdr_nfsv3time(tl, &(a)->va_access_time); \ | |
592 | VATTR_SET_ACTIVE(a, va_access_time); \ | |
593 | break; \ | |
594 | case NFSV3SATTRTIME_TOSERVER: \ | |
595 | VATTR_SET(a, va_access_time, now); \ | |
596 | break; \ | |
597 | }; \ | |
598 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \ | |
599 | switch (fxdr_unsigned(int, *tl)) { \ | |
600 | case NFSV3SATTRTIME_TOCLIENT: \ | |
601 | nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \ | |
602 | fxdr_nfsv3time(tl, &(a)->va_modify_time); \ | |
603 | VATTR_SET_ACTIVE(a, va_modify_time); \ | |
604 | break; \ | |
605 | case NFSV3SATTRTIME_TOSERVER: \ | |
606 | VATTR_SET(a, va_modify_time, now); \ | |
607 | break; \ | |
608 | }; } | |
609 | ||
610 | #endif /* __APPLE_API_PRIVATE */ | |
611 | #endif /* _NFS_NFSM_SUBS_H_ */ |