home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / lan / soss.arj / SRC / MNT_XDR.C < prev    next >
C/C++ Source or Header  |  1991-02-22  |  5KB  |  208 lines

  1. /* @(#)unfs_mountxdr.c    1.1 86/06/30 UNFSSRC */
  2.  
  3. /*
  4.  * Copyright (c) 1986 Sun Microsystems, Inc.
  5.  */
  6.  
  7. #include "common.h"
  8.  
  9. #define xdr_dev_t xdr_short
  10.  
  11. xdr_fhstatus(xdrs, fhsp)
  12.     XDR *xdrs;
  13.     struct fhstatus *fhsp;
  14. {
  15.     if (!xdr_int(xdrs, &fhsp->fhs_status))
  16.         return FALSE;
  17.     if (fhsp->fhs_status == 0) {
  18.         if (!xdr_fhandle(xdrs, &fhsp->fhs_fh))
  19.             return FALSE;
  20.     }
  21. }
  22.  
  23. xdr_fhandle(xdrs, fhp)
  24.     XDR *xdrs;
  25.     fhandle_t *fhp;
  26. {
  27.     if (xdr_opaque(xdrs, fhp, NFS_FHSIZE)) {
  28.         return (TRUE);
  29.     }
  30.     return (FALSE);
  31. }
  32.  
  33. bool_t
  34. xdr_path(xdrs, pathp)
  35.     XDR *xdrs;
  36.     char **pathp;
  37. {
  38.     if (xdr_string(xdrs, pathp, 1024)) {
  39.         return(TRUE);
  40.     }
  41.     return(FALSE);
  42. }
  43.  
  44. /* 
  45.  * body of a mountlist
  46.  */
  47. bool_t
  48. xdr_mountbody(xdrs, mlp)
  49.     XDR *xdrs;
  50.     struct mountlist *mlp;
  51. {
  52.     if (!xdr_path(xdrs, &mlp->ml_name))
  53.         return FALSE;
  54.     if (!xdr_path(xdrs, &mlp->ml_path))
  55.         return FALSE;
  56.     return(TRUE);
  57. }
  58.  
  59. bool_t
  60. xdr_mountlist(xdrs, mlp)
  61.     register XDR *xdrs;
  62.     register struct mountlist **mlp;
  63. {
  64.     /*
  65.      * more_elements is pre-computed in case the direction is
  66.      * XDR_ENCODE or XDR_FREE.  more_elements is overwritten by
  67.      * xdr_bool when the direction is XDR_DECODE.
  68.      */
  69.     int more_elements;
  70.     register int freeing = (xdrs->x_op == XDR_FREE);
  71.     register struct mountlist **nxt;
  72.  
  73.     while (TRUE) {
  74.         more_elements = (*mlp != NULL);
  75.         if (! xdr_bool(xdrs, &more_elements))
  76.             return (FALSE);
  77.         if (! more_elements)
  78.             return (TRUE);  /* we are done */
  79.         /*
  80.          * the unfortunate side effect of non-recursion is that in
  81.          * the case of freeing we must remember the nxt object
  82.          * before we free the current object ...
  83.          */
  84.         if (freeing)
  85.             nxt = &((*mlp)->ml_nxt); 
  86.         if (! xdr_reference(xdrs, mlp, sizeof(struct mountlist),
  87.             xdr_mountbody))
  88.             return (FALSE);
  89.         mlp = (freeing) ? nxt : &((*mlp)->ml_nxt);
  90.     }
  91. }
  92.  
  93. /*
  94.  * Strange but true: the boolean that tells if another element
  95.  * in the list is present has already been checked.  We handle the
  96.  * body of this element then check on the next element.  YUK.
  97.  */
  98. bool_t
  99. xdr_groups(xdrs, gr)
  100.     register XDR *xdrs;
  101.     register struct groups *gr;
  102. {
  103.     /*
  104.      * more_elements is pre-computed in case the direction is
  105.      * XDR_ENCODE or XDR_FREE.  more_elements is overwritten by
  106.      * xdr_bool when the direction is XDR_DECODE.
  107.      */
  108.     int more_elements;
  109.     register int freeing = (xdrs->x_op == XDR_FREE);
  110.     register struct groups *nxt;
  111.  
  112.     while (TRUE) {
  113.         /*
  114.          * the unfortunate side effect of non-recursion is that in
  115.          * the case of freeing we must remember the nxt object
  116.          * before we free the current object ...
  117.          */
  118.         if (freeing)
  119.             nxt = gr->g_next; 
  120.         if (! xdr_path(xdrs, &(gr->g_name)))
  121.             return (FALSE);
  122.         more_elements = (gr->g_next != NULL);
  123.         if (! xdr_bool(xdrs, &more_elements))
  124.             return (FALSE);
  125.         if (! more_elements) {
  126.             gr->g_next = NULL;
  127.             return (TRUE);  /* we are done */
  128.         }
  129.         if (! xdr_reference(xdrs, &(gr->g_next), sizeof(struct groups),
  130.             xdr_groups))
  131.             return (FALSE);
  132.         gr = (freeing) ? nxt : gr->g_next;
  133.     }
  134. }
  135.  
  136. /* 
  137.  * body of a exportlist
  138.  */
  139. bool_t
  140. xdr_exportbody(xdrs, ex)
  141.     XDR *xdrs;
  142.     struct exports *ex;
  143. {
  144.     int more_elements;
  145.  
  146.     if (!xdr_path(xdrs, &ex->ex_name))
  147.         return FALSE;
  148.     more_elements = (ex->ex_groups != NULL);
  149.     if (! xdr_bool(xdrs, &more_elements))
  150.         return (FALSE);
  151.     if (! more_elements) {
  152.         ex->ex_groups = NULL;
  153.         return (TRUE);  /* we are done */
  154.     }
  155.     if (! xdr_reference(xdrs, &(ex->ex_groups), sizeof(struct groups),
  156.         xdr_groups))
  157.         return (FALSE);
  158.     return(TRUE);
  159. }
  160.  
  161.  
  162. /*
  163.  * Encodes the export list structure "exports" on the
  164.  * wire as:
  165.  * bool_t eol;
  166.  * if (!eol) {
  167.  *     char *name;
  168.  *    struct groups *groups;
  169.  * }
  170.  * where groups look like:
  171.  * if (!eog) {
  172.  *    char *gname;
  173.  * }
  174.  */
  175. bool_t
  176. xdr_exports(xdrs, exp)
  177.     register XDR *xdrs;
  178.     register struct exports **exp;
  179. {
  180.     /*
  181.      * more_elements is pre-computed in case the direction is
  182.      * XDR_ENCODE or XDR_FREE.  more_elements is overwritten by
  183.      * xdr_bool when the direction is XDR_DECODE.
  184.      */
  185.     int more_elements;
  186.     register int freeing = (xdrs->x_op == XDR_FREE);
  187.     register struct exports **nxt;
  188.  
  189.     while (TRUE) {
  190.         more_elements = (*exp != NULL);
  191.         if (! xdr_bool(xdrs, &more_elements))
  192.             return (FALSE);
  193.         if (! more_elements)
  194.             return (TRUE);  /* we are done */
  195.         /*
  196.          * the unfortunate side effect of non-recursion is that in
  197.          * the case of freeing we must remember the nxt object
  198.          * before we free the current object ...
  199.          */
  200.         if (freeing)
  201.             nxt = &((*exp)->ex_next); 
  202.         if (! xdr_reference(xdrs, exp, sizeof(struct exports),
  203.             xdr_exportbody))
  204.             return (FALSE);
  205.         exp = (freeing) ? nxt : &((*exp)->ex_next);
  206.     }
  207. }
  208.