home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume21 / amd / part06 / nfs_prot_xdr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-10  |  9.1 KB  |  612 lines

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