xref: /openbsd-src/usr.sbin/amd/rpcx/nfs_prot_xdr.c (revision 898184e3e61f9129feb5978fad5a8c6865f00b92)
1 /*
2  * Copyright (c) 1989 Jan-Simon Pendry
3  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
4  * Copyright (c) 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Jan-Simon Pendry at Imperial College, London.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	from: @(#)nfs_prot_xdr.c	8.1 (Berkeley) 6/6/93
35  *	$Id: nfs_prot_xdr.c,v 1.3 2003/06/02 23:36:52 millert Exp $
36  *
37  */
38 
39 #include "am.h"
40 
41 
42 #ifndef xdr_nfsstat
43 bool_t
44 xdr_nfsstat(xdrs, objp)
45 	XDR *xdrs;
46 	nfsstat *objp;
47 {
48 	if (!xdr_enum(xdrs, (enum_t *)objp)) {
49 		return (FALSE);
50 	}
51 	return (TRUE);
52 }
53 #endif /* xdr_nfsstat */
54 
55 
56 
57 #ifndef xdr_ftype
58 static bool_t
59 xdr_ftype(xdrs, objp)
60 	XDR *xdrs;
61 	ftype *objp;
62 {
63 	if (!xdr_enum(xdrs, (enum_t *)objp)) {
64 		return (FALSE);
65 	}
66 	return (TRUE);
67 }
68 #endif /* xdr_ftype */
69 
70 
71 
72 bool_t
73 xdr_nfs_fh(xdrs, objp)
74 	XDR *xdrs;
75 	nfs_fh *objp;
76 {
77 	if (!xdr_opaque(xdrs, objp->data, NFS_FHSIZE)) {
78 		return (FALSE);
79 	}
80 	return (TRUE);
81 }
82 
83 
84 
85 
86 static bool_t
87 xdr_nfstime(xdrs, objp)
88 	XDR *xdrs;
89 	nfstime *objp;
90 {
91 	if (!xdr_u_int(xdrs, &objp->seconds)) {
92 		return (FALSE);
93 	}
94 	if (!xdr_u_int(xdrs, &objp->useconds)) {
95 		return (FALSE);
96 	}
97 	return (TRUE);
98 }
99 
100 
101 
102 
103 static bool_t
104 xdr_fattr(xdrs, objp)
105 	XDR *xdrs;
106 	fattr *objp;
107 {
108 	if (!xdr_ftype(xdrs, (enum_t *) &objp->type)) {
109 		return (FALSE);
110 	}
111 	if (!xdr_u_int(xdrs, &objp->mode)) {
112 		return (FALSE);
113 	}
114 	if (!xdr_u_int(xdrs, &objp->nlink)) {
115 		return (FALSE);
116 	}
117 	if (!xdr_u_int(xdrs, &objp->uid)) {
118 		return (FALSE);
119 	}
120 	if (!xdr_u_int(xdrs, &objp->gid)) {
121 		return (FALSE);
122 	}
123 	if (!xdr_u_int(xdrs, &objp->size)) {
124 		return (FALSE);
125 	}
126 	if (!xdr_u_int(xdrs, &objp->blocksize)) {
127 		return (FALSE);
128 	}
129 	if (!xdr_u_int(xdrs, &objp->rdev)) {
130 		return (FALSE);
131 	}
132 	if (!xdr_u_int(xdrs, &objp->blocks)) {
133 		return (FALSE);
134 	}
135 	if (!xdr_u_int(xdrs, &objp->fsid)) {
136 		return (FALSE);
137 	}
138 	if (!xdr_u_int(xdrs, &objp->fileid)) {
139 		return (FALSE);
140 	}
141 	if (!xdr_nfstime(xdrs, &objp->atime)) {
142 		return (FALSE);
143 	}
144 	if (!xdr_nfstime(xdrs, &objp->mtime)) {
145 		return (FALSE);
146 	}
147 	if (!xdr_nfstime(xdrs, &objp->ctime)) {
148 		return (FALSE);
149 	}
150 	return (TRUE);
151 }
152 
153 
154 
155 
156 static bool_t
157 xdr_sattr(xdrs, objp)
158 	XDR *xdrs;
159 	sattr *objp;
160 {
161 	if (!xdr_u_int(xdrs, &objp->mode)) {
162 		return (FALSE);
163 	}
164 	if (!xdr_u_int(xdrs, &objp->uid)) {
165 		return (FALSE);
166 	}
167 	if (!xdr_u_int(xdrs, &objp->gid)) {
168 		return (FALSE);
169 	}
170 	if (!xdr_u_int(xdrs, &objp->size)) {
171 		return (FALSE);
172 	}
173 	if (!xdr_nfstime(xdrs, &objp->atime)) {
174 		return (FALSE);
175 	}
176 	if (!xdr_nfstime(xdrs, &objp->mtime)) {
177 		return (FALSE);
178 	}
179 	return (TRUE);
180 }
181 
182 
183 
184 
185 static bool_t
186 xdr_filename(xdrs, objp)
187 	XDR *xdrs;
188 	filename *objp;
189 {
190 	if (!xdr_string(xdrs, objp, NFS_MAXNAMLEN)) {
191 		return (FALSE);
192 	}
193 	return (TRUE);
194 }
195 
196 
197 
198 
199 bool_t
200 xdr_nfspath(xdrs, objp)
201 	XDR *xdrs;
202 	nfspath *objp;
203 {
204 	if (!xdr_string(xdrs, objp, NFS_MAXPATHLEN)) {
205 		return (FALSE);
206 	}
207 	return (TRUE);
208 }
209 
210 
211 
212 
213 bool_t
214 xdr_attrstat(xdrs, objp)
215 	XDR *xdrs;
216 	attrstat *objp;
217 {
218 	if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) {
219 		return (FALSE);
220 	}
221 	switch (objp->status) {
222 	case NFS_OK:
223 		if (!xdr_fattr(xdrs, &objp->attrstat_u.attributes)) {
224 			return (FALSE);
225 		}
226 		break;
227 	}
228 	return (TRUE);
229 }
230 
231 
232 
233 
234 bool_t
235 xdr_sattrargs(xdrs, objp)
236 	XDR *xdrs;
237 	sattrargs *objp;
238 {
239 	if (!xdr_nfs_fh(xdrs, &objp->file)) {
240 		return (FALSE);
241 	}
242 	if (!xdr_sattr(xdrs, &objp->attributes)) {
243 		return (FALSE);
244 	}
245 	return (TRUE);
246 }
247 
248 
249 
250 
251 bool_t
252 xdr_diropargs(xdrs, objp)
253 	XDR *xdrs;
254 	diropargs *objp;
255 {
256 	if (!xdr_nfs_fh(xdrs, &objp->dir)) {
257 		return (FALSE);
258 	}
259 	if (!xdr_filename(xdrs, &objp->name)) {
260 		return (FALSE);
261 	}
262 	return (TRUE);
263 }
264 
265 
266 
267 
268 bool_t
269 xdr_diropokres(xdrs, objp)
270 	XDR *xdrs;
271 	diropokres *objp;
272 {
273 	if (!xdr_nfs_fh(xdrs, &objp->file)) {
274 		return (FALSE);
275 	}
276 	if (!xdr_fattr(xdrs, &objp->attributes)) {
277 		return (FALSE);
278 	}
279 	return (TRUE);
280 }
281 
282 
283 
284 
285 bool_t
286 xdr_diropres(xdrs, objp)
287 	XDR *xdrs;
288 	diropres *objp;
289 {
290 	if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) {
291 		return (FALSE);
292 	}
293 	switch (objp->status) {
294 	case NFS_OK:
295 		if (!xdr_diropokres(xdrs, &objp->diropres_u.diropres)) {
296 			return (FALSE);
297 		}
298 		break;
299 	}
300 	return (TRUE);
301 }
302 
303 
304 
305 
306 bool_t
307 xdr_readlinkres(xdrs, objp)
308 	XDR *xdrs;
309 	readlinkres *objp;
310 {
311 	if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) {
312 		return (FALSE);
313 	}
314 	switch (objp->status) {
315 	case NFS_OK:
316 		if (!xdr_nfspath(xdrs, &objp->readlinkres_u.data)) {
317 			return (FALSE);
318 		}
319 		break;
320 	}
321 	return (TRUE);
322 }
323 
324 
325 
326 
327 bool_t
328 xdr_readargs(xdrs, objp)
329 	XDR *xdrs;
330 	readargs *objp;
331 {
332 	if (!xdr_nfs_fh(xdrs, &objp->file)) {
333 		return (FALSE);
334 	}
335 	if (!xdr_u_int(xdrs, &objp->offset)) {
336 		return (FALSE);
337 	}
338 	if (!xdr_u_int(xdrs, &objp->count)) {
339 		return (FALSE);
340 	}
341 	if (!xdr_u_int(xdrs, &objp->totalcount)) {
342 		return (FALSE);
343 	}
344 	return (TRUE);
345 }
346 
347 
348 
349 
350 bool_t
351 xdr_readokres(xdrs, objp)
352 	XDR *xdrs;
353 	readokres *objp;
354 {
355 	if (!xdr_fattr(xdrs, &objp->attributes)) {
356 		return (FALSE);
357 	}
358 	if (!xdr_bytes(xdrs, (char **)&objp->data.data_val,
359 	    (u_int *)&objp->data.data_len, NFS_MAXDATA)) {
360 		return (FALSE);
361 	}
362 	return (TRUE);
363 }
364 
365 
366 
367 
368 bool_t
369 xdr_readres(xdrs, objp)
370 	XDR *xdrs;
371 	readres *objp;
372 {
373 	if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) {
374 		return (FALSE);
375 	}
376 	switch (objp->status) {
377 	case NFS_OK:
378 		if (!xdr_readokres(xdrs, &objp->readres_u.reply)) {
379 			return (FALSE);
380 		}
381 		break;
382 	}
383 	return (TRUE);
384 }
385 
386 
387 
388 
389 bool_t
390 xdr_writeargs(xdrs, objp)
391 	XDR *xdrs;
392 	writeargs *objp;
393 {
394 	if (!xdr_nfs_fh(xdrs, &objp->file)) {
395 		return (FALSE);
396 	}
397 	if (!xdr_u_int(xdrs, &objp->beginoffset)) {
398 		return (FALSE);
399 	}
400 	if (!xdr_u_int(xdrs, &objp->offset)) {
401 		return (FALSE);
402 	}
403 	if (!xdr_u_int(xdrs, &objp->totalcount)) {
404 		return (FALSE);
405 	}
406 	if (!xdr_bytes(xdrs, (char **)&objp->data.data_val,
407 	    (u_int *)&objp->data.data_len, NFS_MAXDATA)) {
408 		return (FALSE);
409 	}
410 	return (TRUE);
411 }
412 
413 
414 
415 
416 bool_t
417 xdr_createargs(xdrs, objp)
418 	XDR *xdrs;
419 	createargs *objp;
420 {
421 	if (!xdr_diropargs(xdrs, &objp->where)) {
422 		return (FALSE);
423 	}
424 	if (!xdr_sattr(xdrs, &objp->attributes)) {
425 		return (FALSE);
426 	}
427 	return (TRUE);
428 }
429 
430 
431 
432 
433 bool_t
434 xdr_renameargs(xdrs, objp)
435 	XDR *xdrs;
436 	renameargs *objp;
437 {
438 	if (!xdr_diropargs(xdrs, &objp->from)) {
439 		return (FALSE);
440 	}
441 	if (!xdr_diropargs(xdrs, &objp->to)) {
442 		return (FALSE);
443 	}
444 	return (TRUE);
445 }
446 
447 
448 
449 
450 bool_t
451 xdr_linkargs(xdrs, objp)
452 	XDR *xdrs;
453 	linkargs *objp;
454 {
455 	if (!xdr_nfs_fh(xdrs, &objp->from)) {
456 		return (FALSE);
457 	}
458 	if (!xdr_diropargs(xdrs, &objp->to)) {
459 		return (FALSE);
460 	}
461 	return (TRUE);
462 }
463 
464 
465 
466 
467 bool_t
468 xdr_symlinkargs(xdrs, objp)
469 	XDR *xdrs;
470 	symlinkargs *objp;
471 {
472 	if (!xdr_diropargs(xdrs, &objp->from)) {
473 		return (FALSE);
474 	}
475 	if (!xdr_nfspath(xdrs, &objp->to)) {
476 		return (FALSE);
477 	}
478 	if (!xdr_sattr(xdrs, &objp->attributes)) {
479 		return (FALSE);
480 	}
481 	return (TRUE);
482 }
483 
484 
485 
486 
487 static bool_t
488 xdr_nfscookie(xdrs, objp)
489 	XDR *xdrs;
490 	nfscookie objp;
491 {
492 	if (!xdr_opaque(xdrs, objp, NFS_COOKIESIZE)) {
493 		return (FALSE);
494 	}
495 	return (TRUE);
496 }
497 
498 
499 
500 
501 bool_t
502 xdr_readdirargs(xdrs, objp)
503 	XDR *xdrs;
504 	readdirargs *objp;
505 {
506 	if (!xdr_nfs_fh(xdrs, &objp->dir)) {
507 		return (FALSE);
508 	}
509 	if (!xdr_nfscookie(xdrs, objp->cookie)) {
510 		return (FALSE);
511 	}
512 	if (!xdr_u_int(xdrs, &objp->count)) {
513 		return (FALSE);
514 	}
515 	return (TRUE);
516 }
517 
518 
519 
520 
521 static bool_t
522 xdr_entry(xdrs, objp)
523 	XDR *xdrs;
524 	entry *objp;
525 {
526 	if (!xdr_u_int(xdrs, &objp->fileid)) {
527 		return (FALSE);
528 	}
529 	if (!xdr_filename(xdrs, &objp->name)) {
530 		return (FALSE);
531 	}
532 	if (!xdr_nfscookie(xdrs, objp->cookie)) {
533 		return (FALSE);
534 	}
535 	if (!xdr_pointer(xdrs, (char **)&objp->nextentry,
536 	    sizeof(entry), xdr_entry)) {
537 		return (FALSE);
538 	}
539 	return (TRUE);
540 }
541 
542 
543 
544 
545 static bool_t
546 xdr_dirlist(xdrs, objp)
547 	XDR *xdrs;
548 	dirlist *objp;
549 {
550 	if (!xdr_pointer(xdrs, (char **)&objp->entries,
551 	    sizeof(entry), xdr_entry)) {
552 		return (FALSE);
553 	}
554 	if (!xdr_bool(xdrs, &objp->eof)) {
555 		return (FALSE);
556 	}
557 	return (TRUE);
558 }
559 
560 
561 
562 
563 bool_t
564 xdr_readdirres(xdrs, objp)
565 	XDR *xdrs;
566 	readdirres *objp;
567 {
568 	if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) {
569 		return (FALSE);
570 	}
571 	switch (objp->status) {
572 	case NFS_OK:
573 		if (!xdr_dirlist(xdrs, &objp->readdirres_u.reply)) {
574 			return (FALSE);
575 		}
576 		break;
577 	}
578 	return (TRUE);
579 }
580 
581 
582 
583 
584 bool_t
585 xdr_statfsokres(xdrs, objp)
586 	XDR *xdrs;
587 	statfsokres *objp;
588 {
589 	if (!xdr_u_int(xdrs, &objp->tsize)) {
590 		return (FALSE);
591 	}
592 	if (!xdr_u_int(xdrs, &objp->bsize)) {
593 		return (FALSE);
594 	}
595 	if (!xdr_u_int(xdrs, &objp->blocks)) {
596 		return (FALSE);
597 	}
598 	if (!xdr_u_int(xdrs, &objp->bfree)) {
599 		return (FALSE);
600 	}
601 	if (!xdr_u_int(xdrs, &objp->bavail)) {
602 		return (FALSE);
603 	}
604 	return (TRUE);
605 }
606 
607 
608 
609 
610 bool_t
611 xdr_statfsres(xdrs, objp)
612 	XDR *xdrs;
613 	statfsres *objp;
614 {
615 	if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) {
616 		return (FALSE);
617 	}
618 	switch (objp->status) {
619 	case NFS_OK:
620 		if (!xdr_statfsokres(xdrs, &objp->statfsres_u.reply)) {
621 			return (FALSE);
622 		}
623 		break;
624 	}
625 	return (TRUE);
626 }
627