2 static char sfs_c_xdrSid[] = "@(#)sfs_2_xdr.c 2.1 97/10/23";
6 * Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
8 * Standard Performance Evaluation Corporation (SPEC)
9 * 6585 Merchant Place, Suite 100
12 * This product contains benchmarks acquired from several sources who
13 * understand and agree with SPEC's goal of creating fair and objective
14 * benchmarks to measure computer performance.
16 * This copyright notice is placed here only to protect SPEC in the
17 * event the source is misused in any manner that is contrary to the
18 * spirit, the goals and the intent of SPEC.
20 * The source code is provided to the user or company under the license
21 * agreement for the SPEC Benchmark Suite for this product.
25 * -------------------------- sfs_c_xdr.c --------------------------
27 * XDR routines for the nfs protocol.
30 * bool_t xdr_fhstatus(XDR *, struct fhstatus *)
31 * bool_t xdr_path(XDR *, char **)
32 * bool_t xdr_fattr(XDR *, fattr *)
33 * bool_t xdr_sattr(XDR *, sattr *)
34 * bool_t xdr_null(void)
35 * bool_t xdr_getattr(XDR *, char *)
36 * bool_t xdr_setattr(XDR *, char *)
37 * bool_t xdr_root(void)
38 * bool_t xdr_lookup(XDR *, char *)
39 * bool_t xdr_readlink(XDR *, char *)
40 * bool_t xdr_read(XDR *, char *)
41 * bool_t xdr_write(XDR *, char *)
42 * bool_t xdr_create(XDR *, char *)
43 * bool_t xdr_remove(XDR *, char *)
44 * bool_t xdr_rename(XDR *, char *)
45 * bool_t xdr_link(XDR *, char *)
46 * bool_t xdr_symlink(XDR *, char *)
47 * bool_t xdr_mkdir(XDR *, char *)
48 * bool_t xdr_rmdir(XDR *, char *)
49 * bool_t xdr_readdir(XDR *, char *)
50 * bool_t xdr_statfs(XDR *, char *)
53 * bool_t xdr_timeval(XDR *, nfstime *)
54 * bool_t xdr_nfsstat(XDR *, nfsstat *)
55 * bool_t xdr_ftype(XDR *, ftype *)
56 * bool_t xdr_diropargs(XDR *, diropargs *)
57 * bool_t xdr_diropres(XDR *, diropres *)
58 * bool_t xdr_attrstat(XDR *, attrstat *)
61 * 28-NOv-91 Teelucksingh ANSI C
62 * 25-Jun-91 Santa Wiryaman Changed return values to TRUE when
63 * status != NFS_OK. This way we can
64 * decode NFS error messages.
65 * 17-May-90 Richard Bean Created.
70 * ------------------------- Include Files -------------------------
81 #include <sys/types.h>
84 #include "sfs_c_def.h"
87 * ----------------------- Forward Definitions -----------------------
90 static bool_t xdr_f_handle(XDR *, fhandle_t *);
91 static bool_t xdr_fattr(XDR *, fattr *);
92 static bool_t xdr_sattr(XDR *, sattr *);
93 static bool_t xdr_timeval(XDR *, nfstime *);
94 static bool_t xdr_nfsstat(XDR *, nfsstat *);
95 static bool_t xdr_ftype(XDR *, ftype *);
96 static bool_t xdr_diropargs(XDR *, diropargs *);
97 static bool_t xdr_diropres(XDR *, diropres *);
98 static bool_t xdr_attrstat(XDR *, attrstat *);
101 * ----------------------- SFS XDR Routines -------------------------
108 fhandle_t * fhandle_ptr)
110 return(xdr_opaque(xdrs, (char *)fhandle_ptr, NFS_FHSIZE));
117 nfstime * timeval_ptr)
119 return(xdr_int32_t(xdrs, (int32_t *) &timeval_ptr->seconds) &&
120 xdr_int32_t(xdrs, (int32_t *) &timeval_ptr->useconds));
127 nfsstat * nfsstat_ptr)
129 return(xdr_enum(xdrs, (enum_t *) nfsstat_ptr));
138 return(xdr_enum(xdrs, (enum_t *) ftype_ptr));
145 struct fhstatus * fhsp)
147 if (!xdr_nfsstat(xdrs, (nfsstat *) &fhsp->fhs_status)) {
150 if (fhsp->fhs_status != (int)NFS_OK) {
153 return(xdr_f_handle(xdrs, &fhsp->fhs_fh));
162 return(xdr_string(xdrs, pathp, NFS_MAXPATHLEN));
171 return(xdr_ftype(xdrs, &fattr_ptr->type) &&
172 xdr_u_int(xdrs, &fattr_ptr->mode) &&
173 xdr_u_int(xdrs, &fattr_ptr->nlink) &&
174 xdr_u_int(xdrs, &fattr_ptr->uid) &&
175 xdr_u_int(xdrs, &fattr_ptr->gid) &&
176 xdr_u_int(xdrs, &fattr_ptr->size) &&
177 xdr_u_int(xdrs, &fattr_ptr->blocksize) &&
178 xdr_u_int(xdrs, &fattr_ptr->rdev) &&
179 xdr_u_int(xdrs, &fattr_ptr->blocks) &&
180 xdr_u_int(xdrs, &fattr_ptr->fsid) &&
181 xdr_u_int(xdrs, &fattr_ptr->fileid) &&
182 xdr_timeval(xdrs, &fattr_ptr->atime) &&
183 xdr_timeval(xdrs, &fattr_ptr->mtime) &&
184 xdr_timeval(xdrs, &fattr_ptr->ctime));
193 return(xdr_u_int(xdrs, &sattr_ptr->mode) &&
194 xdr_u_int(xdrs, &sattr_ptr->uid) &&
195 xdr_u_int(xdrs, &sattr_ptr->gid) &&
196 xdr_u_int(xdrs, &sattr_ptr->size) &&
197 xdr_timeval(xdrs, &sattr_ptr->atime) &&
198 xdr_timeval(xdrs, &sattr_ptr->mtime));
205 diropargs * dir_args_ptr)
207 return(xdr_f_handle(xdrs, &dir_args_ptr->dir) &&
208 xdr_path(xdrs, &dir_args_ptr->name));
215 diropres * dir_res_ptr)
217 if (!xdr_nfsstat(xdrs, &dir_res_ptr->status)) {
221 if (dir_res_ptr->status == NFS_OK) {
222 return(xdr_f_handle(xdrs, &dir_res_ptr->diropres_u.diropres.file) &&
223 xdr_fattr(xdrs, &dir_res_ptr->diropres_u.diropres.attributes));
232 attrstat * attrstat_ptr)
234 if (!xdr_nfsstat(xdrs, &attrstat_ptr->status)) {
238 if (attrstat_ptr->status == NFS_OK) {
239 return(xdr_fattr(xdrs, &attrstat_ptr->attrstat_u.attributes));
250 fhandle_t * fhandle_ptr;
251 attrstat * attrstat_ptr;
253 switch (xdrs->x_op) {
255 fhandle_ptr = (fhandle_t *) params_ptr;
256 return(xdr_f_handle(xdrs, fhandle_ptr));
259 /* LINTED pointer cast */
260 attrstat_ptr = (attrstat *) params_ptr;
261 return(xdr_attrstat(xdrs, attrstat_ptr));
265 } /* switch on operation */
274 sattrargs * sattrargs_ptr;
275 attrstat * attrstat_ptr;
277 switch (xdrs->x_op) {
279 /* LINTED pointer cast */
280 sattrargs_ptr = (sattrargs *) params_ptr;
281 return(xdr_f_handle(xdrs, &sattrargs_ptr->file) &&
282 xdr_sattr(xdrs, &sattrargs_ptr->attributes));
285 /* LINTED pointer cast */
286 attrstat_ptr = (attrstat *) params_ptr;
287 return(xdr_attrstat(xdrs, attrstat_ptr));
291 } /* switch on operation */
300 diropargs * diropargs_ptr;
301 diropres * diropres_ptr;
306 /* LINTED pointer cast */
307 diropargs_ptr = (diropargs *) params_ptr;
308 return(xdr_f_handle(xdrs, &diropargs_ptr->dir) &&
309 xdr_path(xdrs, &diropargs_ptr->name));
312 /* LINTED pointer cast */
313 diropres_ptr = (diropres *) params_ptr;
314 return(xdr_diropres(xdrs, diropres_ptr));
318 } /* switch on operation */
326 fhandle_t * fhandle_ptr;
327 readlinkres * readlinkres_ptr;
331 fhandle_ptr = (fhandle_t *) params_ptr;
332 return(xdr_f_handle(xdrs, fhandle_ptr));
335 /* LINTED pointer cast */
336 readlinkres_ptr = (readlinkres *) params_ptr;
337 if (!xdr_nfsstat(xdrs, &readlinkres_ptr->status)) {
340 if (readlinkres_ptr->status != NFS_OK) {
343 return(xdr_bytes(xdrs, &readlinkres_ptr->readlinkres_u.data,
345 &readlinkres_ptr->readlinkres_u.len,
346 (unsigned int) NFS_MAXPATHLEN));
350 } /* switch on operation */
359 readargs * readargs_ptr;
360 readres * readres_ptr;
363 switch (xdrs->x_op) {
365 /* LINTED pointer cast */
366 readargs_ptr = (readargs *) params_ptr;
367 return(xdr_f_handle(xdrs, &readargs_ptr->file) &&
368 xdr_u_int(xdrs, &readargs_ptr->offset) &&
369 xdr_u_int(xdrs, &readargs_ptr->count) &&
370 xdr_u_int(xdrs, &readargs_ptr->totalcount));
373 /* LINTED pointer cast */
374 readres_ptr = (readres *) params_ptr;
375 if (!xdr_nfsstat(xdrs, &readres_ptr->status)) {
378 if (readres_ptr->status != NFS_OK) {
381 return(xdr_fattr(xdrs, &readres_ptr->readres_u.reply.attributes) &&
382 xdr_bytes(xdrs, &readres_ptr->readres_u.reply.data.data_val,
383 &readres_ptr->readres_u.reply.data.data_len,
384 (unsigned int) NFS_MAXDATA));
388 } /* switch on operation */
396 writeargs * writeargs_ptr;
397 attrstat * attrstat_ptr;
400 switch (xdrs->x_op) {
402 /* LINTED pointer cast */
403 writeargs_ptr = (writeargs *) params_ptr;
404 return(xdr_f_handle(xdrs, &writeargs_ptr->file) &&
405 xdr_u_int(xdrs, &writeargs_ptr->beginoffset) &&
406 xdr_u_int(xdrs, &writeargs_ptr->offset) &&
407 xdr_u_int(xdrs, &writeargs_ptr->totalcount) &&
408 xdr_bytes(xdrs, &writeargs_ptr->data.data_val,
409 &writeargs_ptr->data.data_len,
410 (unsigned int) NFS_MAXDATA));
413 /* LINTED pointer cast */
414 attrstat_ptr = (attrstat *) params_ptr;
415 return(xdr_attrstat(xdrs, attrstat_ptr));
419 } /* switch on operation */
428 createargs * createargs_ptr;
429 diropres * diropres_ptr;
432 switch (xdrs->x_op) {
434 /* LINTED pointer cast */
435 createargs_ptr = (createargs *) params_ptr;
436 return(xdr_diropargs(xdrs, &createargs_ptr->where) &&
437 xdr_sattr(xdrs, &createargs_ptr->attributes));
440 /* LINTED pointer cast */
441 diropres_ptr = (diropres *) params_ptr;
442 return(xdr_diropres(xdrs, diropres_ptr));
446 } /* switch on operation */
455 diropargs * diropargs_ptr;
456 nfsstat * nfsstat_ptr;
459 switch (xdrs->x_op) {
461 /* LINTED pointer cast */
462 diropargs_ptr = (diropargs *) params_ptr;
463 return(xdr_diropargs (xdrs, diropargs_ptr));
466 /* LINTED pointer cast */
467 nfsstat_ptr = (nfsstat *) params_ptr;
468 return(xdr_nfsstat(xdrs, nfsstat_ptr));
472 } /* switch on operation */
481 renameargs * renameargs_ptr;
482 nfsstat * nfsstat_ptr;
485 switch (xdrs->x_op) {
487 /* LINTED pointer cast */
488 renameargs_ptr = (renameargs *) params_ptr;
489 return(xdr_diropargs(xdrs, &renameargs_ptr->from) &&
490 xdr_diropargs(xdrs, &renameargs_ptr->to));
493 /* LINTED pointer cast */
494 nfsstat_ptr = (nfsstat *) params_ptr;
495 return(xdr_nfsstat(xdrs, nfsstat_ptr));
499 } /* switch on operation */
508 linkargs * linkargs_ptr;
509 nfsstat * nfsstat_ptr;
512 switch (xdrs->x_op) {
514 /* LINTED pointer cast */
515 linkargs_ptr = (linkargs *) params_ptr;
516 return(xdr_f_handle(xdrs, &linkargs_ptr->from) &&
517 xdr_diropargs(xdrs, &linkargs_ptr->to));
520 /* LINTED pointer cast */
521 nfsstat_ptr = (nfsstat *) params_ptr;
522 return(xdr_nfsstat(xdrs, nfsstat_ptr));
526 } /* switch on operation */
535 symlinkargs * symlinkargs_ptr;
536 nfsstat * nfsstat_ptr;
539 switch (xdrs->x_op) {
541 /* LINTED pointer cast */
542 symlinkargs_ptr = (symlinkargs *) params_ptr;
543 return(xdr_diropargs(xdrs, &symlinkargs_ptr->from) &&
544 xdr_path(xdrs, &symlinkargs_ptr->to) &&
545 xdr_sattr(xdrs, &symlinkargs_ptr->attributes));
548 /* LINTED pointer cast */
549 nfsstat_ptr = (nfsstat *) params_ptr;
550 return(xdr_nfsstat(xdrs, nfsstat_ptr));
554 } /* switch on operation */
563 mkdirargs * mkdirargs_ptr;
564 diropres * diropres_ptr;
567 switch (xdrs->x_op) {
569 /* LINTED pointer cast */
570 mkdirargs_ptr = (mkdirargs *) params_ptr;
571 return(xdr_diropargs(xdrs, &mkdirargs_ptr->where) &&
572 xdr_sattr(xdrs, &mkdirargs_ptr->attributes));
575 /* LINTED pointer cast */
576 diropres_ptr = (diropres *) params_ptr;
577 return(xdr_diropres(xdrs, diropres_ptr));
581 } /* switch on operation */
590 diropargs * diropargs_ptr;
591 nfsstat * nfsstat_ptr;
594 switch (xdrs->x_op) {
596 /* LINTED pointer cast */
597 diropargs_ptr = (diropargs *) params_ptr;
598 return(xdr_diropargs(xdrs, diropargs_ptr));
601 /* LINTED pointer cast */
602 nfsstat_ptr = (nfsstat *) params_ptr;
603 return(xdr_nfsstat(xdrs, nfsstat_ptr));
607 } /* switch on operation */
616 readdirargs * readdirargs_ptr;
617 readdirres * readdirres_ptr;
619 int n; /* entry ctr */
622 switch (xdrs->x_op) {
624 /* LINTED pointer cast */
625 readdirargs_ptr = (readdirargs *) params_ptr;
626 return(xdr_f_handle(xdrs, &readdirargs_ptr->dir) &&
627 xdr_opaque(xdrs, (char *) readdirargs_ptr->cookie,
629 xdr_u_int(xdrs, &readdirargs_ptr->count));
632 /* LINTED pointer cast */
633 readdirres_ptr = (readdirres *) params_ptr;
634 if (!xdr_nfsstat(xdrs, &readdirres_ptr->status)) {
637 if (readdirres_ptr->status != NFS_OK) {
642 * go thru the stream of entries until hit an invalid one
643 * or have gotten all the user asked for.
645 * max_entries is read to obtain a maximum. it is written
646 * to return how many entries were decoded.
648 entry_ptr = readdirres_ptr->readdirres_u.reply.entries;
651 while (n < readdirres_ptr->readdirres_u.reply.max_entries) {
652 if (!xdr_bool(xdrs, &entry_ptr->valid)) {
656 if (!entry_ptr->valid) {
660 if (!xdr_u_int(xdrs, &entry_ptr->fileid)) {
664 if (!xdr_uint16_t(xdrs, &entry_ptr->name_len)) {
668 if (!xdr_opaque(xdrs, entry_ptr->name, entry_ptr->name_len)) {
672 if (!xdr_opaque(xdrs, entry_ptr->cookie, NFS_COOKIESIZE)) {
678 } /* while extracting entries */
680 /* If we are at the user's data buffer limit, stop right now. */
681 if (n == readdirres_ptr->readdirres_u.reply.max_entries) {
685 /* Return how many entries were gotten for the dirlist */
686 readdirres_ptr->readdirres_u.reply.max_entries = n;
688 /* check the EOF flag for the dirlist */
689 if(!xdr_bool(xdrs, &readdirres_ptr->readdirres_u.reply.eof)) {
697 } /* switch on operation */
705 fhandle_t * fhandle_ptr;
706 statfsres * statfsres_ptr;
709 switch (xdrs->x_op) {
711 fhandle_ptr = (fhandle_t *) params_ptr;
712 return(xdr_f_handle(xdrs, fhandle_ptr));
715 /* LINTED pointer cast */
716 statfsres_ptr = (statfsres *) params_ptr;
717 if (!xdr_nfsstat(xdrs, &statfsres_ptr->status)) {
720 if (statfsres_ptr->status != NFS_OK) {
723 return(xdr_u_int(xdrs, &statfsres_ptr->statfsres_u.reply.tsize) &&
724 xdr_u_int(xdrs, &statfsres_ptr->statfsres_u.reply.bsize) &&
725 xdr_u_int(xdrs, &statfsres_ptr->statfsres_u.reply.blocks) &&
726 xdr_u_int(xdrs, &statfsres_ptr->statfsres_u.reply.bfree) &&
727 xdr_u_int(xdrs, &statfsres_ptr->statfsres_u.reply.bavail));
731 } /* switch on operation */