home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Utilities / vmount-0.6a-I / src / nfs / nfs_prot_sstub.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-14  |  5.7 KB  |  225 lines

  1. #include <stdio.h>
  2. #include <rpc/rpc.h>
  3. #include "nfs_prot.h"
  4. /*
  5.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  6.  * unrestricted use provided that this legend is included on all tape
  7.  * media and as a part of the software program in whole or part.  Users
  8.  * may copy or modify Sun RPC without charge, but are not authorized
  9.  * to license or distribute it to anyone else except as part of a product or
  10.  * program developed by the user or with the express written consent of
  11.  * Sun Microsystems, Inc.
  12.  *
  13.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  14.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  16.  *
  17.  * Sun RPC is provided with no support and without any obligation on the
  18.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  19.  * modification or enhancement.
  20.  *
  21.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  22.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  23.  * OR ANY PART THEREOF.
  24.  *
  25.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  26.  * or profits or other special, indirect and consequential damages, even if
  27.  * Sun has been advised of the possibility of such damages.
  28.  *
  29.  * Sun Microsystems, Inc.
  30.  * 2550 Garcia Avenue
  31.  * Mountain View, California  94043
  32.  */
  33. /*
  34.  * Copyright (c) 1987, 1990 by Sun Microsystems, Inc.
  35.  */
  36.  
  37. /* from @(#)nfs_prot.x    1.3 91/03/11 TIRPC 1.0 */
  38.  
  39.  void nfs_program_2();
  40.  
  41. int nfsd_main()
  42. {
  43.     SVCXPRT *transp;
  44.  
  45.     (void)pmap_unset(NFS_PROGRAM, NFS_VERSION);
  46.  
  47.     transp = svcudp_create(RPC_ANYSOCK);
  48.     if (transp == NULL) {
  49.         (void)fprintf(stderr, "cannot create udp service.\n");
  50.         exit(1);
  51.     }
  52.     if (!svc_register(transp, NFS_PROGRAM, NFS_VERSION, nfs_program_2, IPPROTO_UDP)) {
  53.         (void)fprintf(stderr, "unable to register (NFS_PROGRAM, NFS_VERSION, udp).\n");
  54.         exit(1);
  55.     }
  56.  
  57.     transp = svctcp_create(RPC_ANYSOCK, 0, 0);
  58.     if (transp == NULL) {
  59.         (void)fprintf(stderr, "cannot create tcp service.\n");
  60.         exit(1);
  61.     }
  62.     if (!svc_register(transp, NFS_PROGRAM, NFS_VERSION, nfs_program_2, IPPROTO_TCP)) {
  63.         (void)fprintf(stderr, "unable to register (NFS_PROGRAM, NFS_VERSION, tcp).\n");
  64.         exit(1);
  65.     }
  66.     svc_run();
  67.     (void)fprintf(stderr, "svc_run returned\n");
  68.     exit(1);
  69. }
  70.  
  71.  void
  72. nfs_program_2(rqstp, transp)
  73.     struct svc_req *rqstp;
  74.     SVCXPRT *transp;
  75. {
  76.     union {
  77.         nfs_fh nfsproc_getattr_2_arg;
  78.         sattrargs nfsproc_setattr_2_arg;
  79.         diropargs nfsproc_lookup_2_arg;
  80.         nfs_fh nfsproc_readlink_2_arg;
  81.         readargs nfsproc_read_2_arg;
  82.         writeargs nfsproc_write_2_arg;
  83.         createargs nfsproc_create_2_arg;
  84.         diropargs nfsproc_remove_2_arg;
  85.         renameargs nfsproc_rename_2_arg;
  86.         linkargs nfsproc_link_2_arg;
  87.         symlinkargs nfsproc_symlink_2_arg;
  88.         createargs nfsproc_mkdir_2_arg;
  89.         diropargs nfsproc_rmdir_2_arg;
  90.         readdirargs nfsproc_readdir_2_arg;
  91.         nfs_fh nfsproc_statfs_2_arg;
  92.     } argument;
  93.     char *result;
  94.     bool_t (*xdr_argument)(), (*xdr_result)();
  95.     char *(*local)();
  96.  
  97.     switch (rqstp->rq_proc) {
  98.     case NFSPROC_NULL:
  99.         xdr_argument = xdr_void;
  100.         xdr_result = xdr_void;
  101.         local = (char *(*)()) nfsproc_null_2;
  102.         break;
  103.  
  104.     case NFSPROC_GETATTR:
  105.         xdr_argument = xdr_nfs_fh;
  106.         xdr_result = xdr_attrstat;
  107.         local = (char *(*)()) nfsproc_getattr_2;
  108.         break;
  109.  
  110.     case NFSPROC_SETATTR:
  111.         xdr_argument = xdr_sattrargs;
  112.         xdr_result = xdr_attrstat;
  113.         local = (char *(*)()) nfsproc_setattr_2;
  114.         break;
  115.  
  116.     case NFSPROC_ROOT:
  117.         xdr_argument = xdr_void;
  118.         xdr_result = xdr_void;
  119.         local = (char *(*)()) nfsproc_root_2;
  120.         break;
  121.  
  122.     case NFSPROC_LOOKUP:
  123.         xdr_argument = xdr_diropargs;
  124.         xdr_result = xdr_diropres;
  125.         local = (char *(*)()) nfsproc_lookup_2;
  126.         break;
  127.  
  128.     case NFSPROC_READLINK:
  129.         xdr_argument = xdr_nfs_fh;
  130.         xdr_result = xdr_readlinkres;
  131.         local = (char *(*)()) nfsproc_readlink_2;
  132.         break;
  133.  
  134.     case NFSPROC_READ:
  135.         xdr_argument = xdr_readargs;
  136.         xdr_result = xdr_readres;
  137.         local = (char *(*)()) nfsproc_read_2;
  138.         break;
  139.  
  140.     case NFSPROC_WRITECACHE:
  141.         xdr_argument = xdr_void;
  142.         xdr_result = xdr_void;
  143.         local = (char *(*)()) nfsproc_writecache_2;
  144.         break;
  145.  
  146.     case NFSPROC_WRITE:
  147.         xdr_argument = xdr_writeargs;
  148.         xdr_result = xdr_attrstat;
  149.         local = (char *(*)()) nfsproc_write_2;
  150.         break;
  151.  
  152.     case NFSPROC_CREATE:
  153.         xdr_argument = xdr_createargs;
  154.         xdr_result = xdr_diropres;
  155.         local = (char *(*)()) nfsproc_create_2;
  156.         break;
  157.  
  158.     case NFSPROC_REMOVE:
  159.         xdr_argument = xdr_diropargs;
  160.         xdr_result = xdr_nfsstat;
  161.         local = (char *(*)()) nfsproc_remove_2;
  162.         break;
  163.  
  164.     case NFSPROC_RENAME:
  165.         xdr_argument = xdr_renameargs;
  166.         xdr_result = xdr_nfsstat;
  167.         local = (char *(*)()) nfsproc_rename_2;
  168.         break;
  169.  
  170.     case NFSPROC_LINK:
  171.         xdr_argument = xdr_linkargs;
  172.         xdr_result = xdr_nfsstat;
  173.         local = (char *(*)()) nfsproc_link_2;
  174.         break;
  175.  
  176.     case NFSPROC_SYMLINK:
  177.         xdr_argument = xdr_symlinkargs;
  178.         xdr_result = xdr_nfsstat;
  179.         local = (char *(*)()) nfsproc_symlink_2;
  180.         break;
  181.  
  182.     case NFSPROC_MKDIR:
  183.         xdr_argument = xdr_createargs;
  184.         xdr_result = xdr_diropres;
  185.         local = (char *(*)()) nfsproc_mkdir_2;
  186.         break;
  187.  
  188.     case NFSPROC_RMDIR:
  189.         xdr_argument = xdr_diropargs;
  190.         xdr_result = xdr_nfsstat;
  191.         local = (char *(*)()) nfsproc_rmdir_2;
  192.         break;
  193.  
  194.     case NFSPROC_READDIR:
  195.         xdr_argument = xdr_readdirargs;
  196.         xdr_result = xdr_readdirres;
  197.         local = (char *(*)()) nfsproc_readdir_2;
  198.         break;
  199.  
  200.     case NFSPROC_STATFS:
  201.         xdr_argument = xdr_nfs_fh;
  202.         xdr_result = xdr_statfsres;
  203.         local = (char *(*)()) nfsproc_statfs_2;
  204.         break;
  205.  
  206.     default:
  207.         svcerr_noproc(transp);
  208.         return;
  209.     }
  210.     bzero((char *)&argument, sizeof(argument));
  211.     if (!svc_getargs(transp, xdr_argument, &argument)) {
  212.         svcerr_decode(transp);
  213.         return;
  214.     }
  215.     result = (*local)(&argument, rqstp);
  216.     if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
  217.         svcerr_systemerr(transp);
  218.     }
  219.     if (!svc_freeargs(transp, xdr_argument, &argument)) {
  220.         (void)fprintf(stderr, "unable to free arguments\n");
  221.         exit(1);
  222.     }
  223. }
  224.  
  225.