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  * %sccs.include.redist.c%
11  *
12  *	@(#)nfs_prot_xdr.c	8.1 (Berkeley) 06/06/93
13  *
14  * $Id: nfs_prot_xdr.c,v 5.2.2.1 1992/02/09 15:09:32 jsp beta $
15  *
16  */
17 
18 #include "am.h"
19 
20 
21 #ifndef xdr_nfsstat
22 bool_t
23 xdr_nfsstat(xdrs, objp)
24 	XDR *xdrs;
25 	nfsstat *objp;
26 {
27 	if (!xdr_enum(xdrs, (enum_t *)objp)) {
28 		return (FALSE);
29 	}
30 	return (TRUE);
31 }
32 #endif /* xdr_nfsstat */
33 
34 
35 
36 #ifndef xdr_ftype
37 static bool_t
38 xdr_ftype(xdrs, objp)
39 	XDR *xdrs;
40 	ftype *objp;
41 {
42 	if (!xdr_enum(xdrs, (enum_t *)objp)) {
43 		return (FALSE);
44 	}
45 	return (TRUE);
46 }
47 #endif /* xdr_ftype */
48 
49 
50 
51 bool_t
52 xdr_nfs_fh(xdrs, objp)
53 	XDR *xdrs;
54 	nfs_fh *objp;
55 {
56 	if (!xdr_opaque(xdrs, objp->data, NFS_FHSIZE)) {
57 		return (FALSE);
58 	}
59 	return (TRUE);
60 }
61 
62 
63 
64 
65 static bool_t
66 xdr_nfstime(xdrs, objp)
67 	XDR *xdrs;
68 	nfstime *objp;
69 {
70 	if (!xdr_u_int(xdrs, &objp->seconds)) {
71 		return (FALSE);
72 	}
73 	if (!xdr_u_int(xdrs, &objp->useconds)) {
74 		return (FALSE);
75 	}
76 	return (TRUE);
77 }
78 
79 
80 
81 
82 static bool_t
83 xdr_fattr(xdrs, objp)
84 	XDR *xdrs;
85 	fattr *objp;
86 {
87 	if (!xdr_ftype(xdrs, &objp->type)) {
88 		return (FALSE);
89 	}
90 	if (!xdr_u_int(xdrs, &objp->mode)) {
91 		return (FALSE);
92 	}
93 	if (!xdr_u_int(xdrs, &objp->nlink)) {
94 		return (FALSE);
95 	}
96 	if (!xdr_u_int(xdrs, &objp->uid)) {
97 		return (FALSE);
98 	}
99 	if (!xdr_u_int(xdrs, &objp->gid)) {
100 		return (FALSE);
101 	}
102 	if (!xdr_u_int(xdrs, &objp->size)) {
103 		return (FALSE);
104 	}
105 	if (!xdr_u_int(xdrs, &objp->blocksize)) {
106 		return (FALSE);
107 	}
108 	if (!xdr_u_int(xdrs, &objp->rdev)) {
109 		return (FALSE);
110 	}
111 	if (!xdr_u_int(xdrs, &objp->blocks)) {
112 		return (FALSE);
113 	}
114 	if (!xdr_u_int(xdrs, &objp->fsid)) {
115 		return (FALSE);
116 	}
117 	if (!xdr_u_int(xdrs, &objp->fileid)) {
118 		return (FALSE);
119 	}
120 	if (!xdr_nfstime(xdrs, &objp->atime)) {
121 		return (FALSE);
122 	}
123 	if (!xdr_nfstime(xdrs, &objp->mtime)) {
124 		return (FALSE);
125 	}
126 	if (!xdr_nfstime(xdrs, &objp->ctime)) {
127 		return (FALSE);
128 	}
129 	return (TRUE);
130 }
131 
132 
133 
134 
135 static bool_t
136 xdr_sattr(xdrs, objp)
137 	XDR *xdrs;
138 	sattr *objp;
139 {
140 	if (!xdr_u_int(xdrs, &objp->mode)) {
141 		return (FALSE);
142 	}
143 	if (!xdr_u_int(xdrs, &objp->uid)) {
144 		return (FALSE);
145 	}
146 	if (!xdr_u_int(xdrs, &objp->gid)) {
147 		return (FALSE);
148 	}
149 	if (!xdr_u_int(xdrs, &objp->size)) {
150 		return (FALSE);
151 	}
152 	if (!xdr_nfstime(xdrs, &objp->atime)) {
153 		return (FALSE);
154 	}
155 	if (!xdr_nfstime(xdrs, &objp->mtime)) {
156 		return (FALSE);
157 	}
158 	return (TRUE);
159 }
160 
161 
162 
163 
164 static bool_t
165 xdr_filename(xdrs, objp)
166 	XDR *xdrs;
167 	filename *objp;
168 {
169 	if (!xdr_string(xdrs, objp, NFS_MAXNAMLEN)) {
170 		return (FALSE);
171 	}
172 	return (TRUE);
173 }
174 
175 
176 
177 
178 bool_t
179 xdr_nfspath(xdrs, objp)
180 	XDR *xdrs;
181 	nfspath *objp;
182 {
183 	if (!xdr_string(xdrs, objp, NFS_MAXPATHLEN)) {
184 		return (FALSE);
185 	}
186 	return (TRUE);
187 }
188 
189 
190 
191 
192 bool_t
193 xdr_attrstat(xdrs, objp)
194 	XDR *xdrs;
195 	attrstat *objp;
196 {
197 	if (!xdr_nfsstat(xdrs, &objp->status)) {
198 		return (FALSE);
199 	}
200 	switch (objp->status) {
201 	case NFS_OK:
202 		if (!xdr_fattr(xdrs, &objp->attrstat_u.attributes)) {
203 			return (FALSE);
204 		}
205 		break;
206 	}
207 	return (TRUE);
208 }
209 
210 
211 
212 
213 bool_t
214 xdr_sattrargs(xdrs, objp)
215 	XDR *xdrs;
216 	sattrargs *objp;
217 {
218 	if (!xdr_nfs_fh(xdrs, &objp->file)) {
219 		return (FALSE);
220 	}
221 	if (!xdr_sattr(xdrs, &objp->attributes)) {
222 		return (FALSE);
223 	}
224 	return (TRUE);
225 }
226 
227 
228 
229 
230 bool_t
231 xdr_diropargs(xdrs, objp)
232 	XDR *xdrs;
233 	diropargs *objp;
234 {
235 	if (!xdr_nfs_fh(xdrs, &objp->dir)) {
236 		return (FALSE);
237 	}
238 	if (!xdr_filename(xdrs, &objp->name)) {
239 		return (FALSE);
240 	}
241 	return (TRUE);
242 }
243 
244 
245 
246 
247 bool_t
248 xdr_diropokres(xdrs, objp)
249 	XDR *xdrs;
250 	diropokres *objp;
251 {
252 	if (!xdr_nfs_fh(xdrs, &objp->file)) {
253 		return (FALSE);
254 	}
255 	if (!xdr_fattr(xdrs, &objp->attributes)) {
256 		return (FALSE);
257 	}
258 	return (TRUE);
259 }
260 
261 
262 
263 
264 bool_t
265 xdr_diropres(xdrs, objp)
266 	XDR *xdrs;
267 	diropres *objp;
268 {
269 	if (!xdr_nfsstat(xdrs, &objp->status)) {
270 		return (FALSE);
271 	}
272 	switch (objp->status) {
273 	case NFS_OK:
274 		if (!xdr_diropokres(xdrs, &objp->diropres_u.diropres)) {
275 			return (FALSE);
276 		}
277 		break;
278 	}
279 	return (TRUE);
280 }
281 
282 
283 
284 
285 bool_t
286 xdr_readlinkres(xdrs, objp)
287 	XDR *xdrs;
288 	readlinkres *objp;
289 {
290 	if (!xdr_nfsstat(xdrs, &objp->status)) {
291 		return (FALSE);
292 	}
293 	switch (objp->status) {
294 	case NFS_OK:
295 		if (!xdr_nfspath(xdrs, &objp->readlinkres_u.data)) {
296 			return (FALSE);
297 		}
298 		break;
299 	}
300 	return (TRUE);
301 }
302 
303 
304 
305 
306 bool_t
307 xdr_readargs(xdrs, objp)
308 	XDR *xdrs;
309 	readargs *objp;
310 {
311 	if (!xdr_nfs_fh(xdrs, &objp->file)) {
312 		return (FALSE);
313 	}
314 	if (!xdr_u_int(xdrs, &objp->offset)) {
315 		return (FALSE);
316 	}
317 	if (!xdr_u_int(xdrs, &objp->count)) {
318 		return (FALSE);
319 	}
320 	if (!xdr_u_int(xdrs, &objp->totalcount)) {
321 		return (FALSE);
322 	}
323 	return (TRUE);
324 }
325 
326 
327 
328 
329 bool_t
330 xdr_readokres(xdrs, objp)
331 	XDR *xdrs;
332 	readokres *objp;
333 {
334 	if (!xdr_fattr(xdrs, &objp->attributes)) {
335 		return (FALSE);
336 	}
337 	if (!xdr_bytes(xdrs, (char **)&objp->data.data_val, (u_int *)&objp->data.data_len, NFS_MAXDATA)) {
338 		return (FALSE);
339 	}
340 	return (TRUE);
341 }
342 
343 
344 
345 
346 bool_t
347 xdr_readres(xdrs, objp)
348 	XDR *xdrs;
349 	readres *objp;
350 {
351 	if (!xdr_nfsstat(xdrs, &objp->status)) {
352 		return (FALSE);
353 	}
354 	switch (objp->status) {
355 	case NFS_OK:
356 		if (!xdr_readokres(xdrs, &objp->readres_u.reply)) {
357 			return (FALSE);
358 		}
359 		break;
360 	}
361 	return (TRUE);
362 }
363 
364 
365 
366 
367 bool_t
368 xdr_writeargs(xdrs, objp)
369 	XDR *xdrs;
370 	writeargs *objp;
371 {
372 	if (!xdr_nfs_fh(xdrs, &objp->file)) {
373 		return (FALSE);
374 	}
375 	if (!xdr_u_int(xdrs, &objp->beginoffset)) {
376 		return (FALSE);
377 	}
378 	if (!xdr_u_int(xdrs, &objp->offset)) {
379 		return (FALSE);
380 	}
381 	if (!xdr_u_int(xdrs, &objp->totalcount)) {
382 		return (FALSE);
383 	}
384 	if (!xdr_bytes(xdrs, (char **)&objp->data.data_val, (u_int *)&objp->data.data_len, NFS_MAXDATA)) {
385 		return (FALSE);
386 	}
387 	return (TRUE);
388 }
389 
390 
391 
392 
393 bool_t
394 xdr_createargs(xdrs, objp)
395 	XDR *xdrs;
396 	createargs *objp;
397 {
398 	if (!xdr_diropargs(xdrs, &objp->where)) {
399 		return (FALSE);
400 	}
401 	if (!xdr_sattr(xdrs, &objp->attributes)) {
402 		return (FALSE);
403 	}
404 	return (TRUE);
405 }
406 
407 
408 
409 
410 bool_t
411 xdr_renameargs(xdrs, objp)
412 	XDR *xdrs;
413 	renameargs *objp;
414 {
415 	if (!xdr_diropargs(xdrs, &objp->from)) {
416 		return (FALSE);
417 	}
418 	if (!xdr_diropargs(xdrs, &objp->to)) {
419 		return (FALSE);
420 	}
421 	return (TRUE);
422 }
423 
424 
425 
426 
427 bool_t
428 xdr_linkargs(xdrs, objp)
429 	XDR *xdrs;
430 	linkargs *objp;
431 {
432 	if (!xdr_nfs_fh(xdrs, &objp->from)) {
433 		return (FALSE);
434 	}
435 	if (!xdr_diropargs(xdrs, &objp->to)) {
436 		return (FALSE);
437 	}
438 	return (TRUE);
439 }
440 
441 
442 
443 
444 bool_t
445 xdr_symlinkargs(xdrs, objp)
446 	XDR *xdrs;
447 	symlinkargs *objp;
448 {
449 	if (!xdr_diropargs(xdrs, &objp->from)) {
450 		return (FALSE);
451 	}
452 	if (!xdr_nfspath(xdrs, &objp->to)) {
453 		return (FALSE);
454 	}
455 	if (!xdr_sattr(xdrs, &objp->attributes)) {
456 		return (FALSE);
457 	}
458 	return (TRUE);
459 }
460 
461 
462 
463 
464 static bool_t
465 xdr_nfscookie(xdrs, objp)
466 	XDR *xdrs;
467 	nfscookie objp;
468 {
469 	if (!xdr_opaque(xdrs, objp, NFS_COOKIESIZE)) {
470 		return (FALSE);
471 	}
472 	return (TRUE);
473 }
474 
475 
476 
477 
478 bool_t
479 xdr_readdirargs(xdrs, objp)
480 	XDR *xdrs;
481 	readdirargs *objp;
482 {
483 	if (!xdr_nfs_fh(xdrs, &objp->dir)) {
484 		return (FALSE);
485 	}
486 	if (!xdr_nfscookie(xdrs, objp->cookie)) {
487 		return (FALSE);
488 	}
489 	if (!xdr_u_int(xdrs, &objp->count)) {
490 		return (FALSE);
491 	}
492 	return (TRUE);
493 }
494 
495 
496 
497 
498 static bool_t
499 xdr_entry(xdrs, objp)
500 	XDR *xdrs;
501 	entry *objp;
502 {
503 	if (!xdr_u_int(xdrs, &objp->fileid)) {
504 		return (FALSE);
505 	}
506 	if (!xdr_filename(xdrs, &objp->name)) {
507 		return (FALSE);
508 	}
509 	if (!xdr_nfscookie(xdrs, objp->cookie)) {
510 		return (FALSE);
511 	}
512 	if (!xdr_pointer(xdrs, (char **)&objp->nextentry, sizeof(entry), xdr_entry)) {
513 		return (FALSE);
514 	}
515 	return (TRUE);
516 }
517 
518 
519 
520 
521 static bool_t
522 xdr_dirlist(xdrs, objp)
523 	XDR *xdrs;
524 	dirlist *objp;
525 {
526 	if (!xdr_pointer(xdrs, (char **)&objp->entries, sizeof(entry), xdr_entry)) {
527 		return (FALSE);
528 	}
529 	if (!xdr_bool(xdrs, &objp->eof)) {
530 		return (FALSE);
531 	}
532 	return (TRUE);
533 }
534 
535 
536 
537 
538 bool_t
539 xdr_readdirres(xdrs, objp)
540 	XDR *xdrs;
541 	readdirres *objp;
542 {
543 	if (!xdr_nfsstat(xdrs, &objp->status)) {
544 		return (FALSE);
545 	}
546 	switch (objp->status) {
547 	case NFS_OK:
548 		if (!xdr_dirlist(xdrs, &objp->readdirres_u.reply)) {
549 			return (FALSE);
550 		}
551 		break;
552 	}
553 	return (TRUE);
554 }
555 
556 
557 
558 
559 bool_t
560 xdr_statfsokres(xdrs, objp)
561 	XDR *xdrs;
562 	statfsokres *objp;
563 {
564 	if (!xdr_u_int(xdrs, &objp->tsize)) {
565 		return (FALSE);
566 	}
567 	if (!xdr_u_int(xdrs, &objp->bsize)) {
568 		return (FALSE);
569 	}
570 	if (!xdr_u_int(xdrs, &objp->blocks)) {
571 		return (FALSE);
572 	}
573 	if (!xdr_u_int(xdrs, &objp->bfree)) {
574 		return (FALSE);
575 	}
576 	if (!xdr_u_int(xdrs, &objp->bavail)) {
577 		return (FALSE);
578 	}
579 	return (TRUE);
580 }
581 
582 
583 
584 
585 bool_t
586 xdr_statfsres(xdrs, objp)
587 	XDR *xdrs;
588 	statfsres *objp;
589 {
590 	if (!xdr_nfsstat(xdrs, &objp->status)) {
591 		return (FALSE);
592 	}
593 	switch (objp->status) {
594 	case NFS_OK:
595 		if (!xdr_statfsokres(xdrs, &objp->statfsres_u.reply)) {
596 			return (FALSE);
597 		}
598 		break;
599 	}
600 	return (TRUE);
601 }
602