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 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * from: @(#)nfs_prot_svc.c 8.1 (Berkeley) 6/6/93 35 * $Id: nfs_prot_svc.c,v 1.3 2003/06/02 23:36:52 millert Exp $ 36 * 37 */ 38 39 #include "am.h" 40 41 void nfs_program_2(rqstp, transp) 42 struct svc_req *rqstp; 43 SVCXPRT *transp; 44 { 45 union { 46 nfs_fh nfsproc_getattr_2_arg; 47 sattrargs nfsproc_setattr_2_arg; 48 diropargs nfsproc_lookup_2_arg; 49 nfs_fh nfsproc_readlink_2_arg; 50 readargs nfsproc_read_2_arg; 51 writeargs nfsproc_write_2_arg; 52 createargs nfsproc_create_2_arg; 53 diropargs nfsproc_remove_2_arg; 54 renameargs nfsproc_rename_2_arg; 55 linkargs nfsproc_link_2_arg; 56 symlinkargs nfsproc_symlink_2_arg; 57 createargs nfsproc_mkdir_2_arg; 58 diropargs nfsproc_rmdir_2_arg; 59 readdirargs nfsproc_readdir_2_arg; 60 nfs_fh nfsproc_statfs_2_arg; 61 } argument; 62 char *result; 63 bool_t (*xdr_argument)(), (*xdr_result)(); 64 char *(*local)(); 65 66 switch (rqstp->rq_proc) { 67 case NFSPROC_NULL: 68 xdr_argument = xdr_void; 69 xdr_result = xdr_void; 70 local = (char *(*)()) nfsproc_null_2; 71 break; 72 73 case NFSPROC_GETATTR: 74 xdr_argument = xdr_nfs_fh; 75 xdr_result = xdr_attrstat; 76 local = (char *(*)()) nfsproc_getattr_2; 77 break; 78 79 case NFSPROC_SETATTR: 80 xdr_argument = xdr_sattrargs; 81 xdr_result = xdr_attrstat; 82 local = (char *(*)()) nfsproc_setattr_2; 83 break; 84 85 case NFSPROC_ROOT: 86 xdr_argument = xdr_void; 87 xdr_result = xdr_void; 88 local = (char *(*)()) nfsproc_root_2; 89 break; 90 91 case NFSPROC_LOOKUP: 92 xdr_argument = xdr_diropargs; 93 xdr_result = xdr_diropres; 94 local = (char *(*)()) nfsproc_lookup_2; 95 break; 96 97 case NFSPROC_READLINK: 98 xdr_argument = xdr_nfs_fh; 99 xdr_result = xdr_readlinkres; 100 local = (char *(*)()) nfsproc_readlink_2; 101 break; 102 103 case NFSPROC_READ: 104 xdr_argument = xdr_readargs; 105 xdr_result = xdr_readres; 106 local = (char *(*)()) nfsproc_read_2; 107 break; 108 109 case NFSPROC_WRITECACHE: 110 xdr_argument = xdr_void; 111 xdr_result = xdr_void; 112 local = (char *(*)()) nfsproc_writecache_2; 113 break; 114 115 case NFSPROC_WRITE: 116 xdr_argument = xdr_writeargs; 117 xdr_result = xdr_attrstat; 118 local = (char *(*)()) nfsproc_write_2; 119 break; 120 121 case NFSPROC_CREATE: 122 xdr_argument = xdr_createargs; 123 xdr_result = xdr_diropres; 124 local = (char *(*)()) nfsproc_create_2; 125 break; 126 127 case NFSPROC_REMOVE: 128 xdr_argument = xdr_diropargs; 129 xdr_result = xdr_nfsstat; 130 local = (char *(*)()) nfsproc_remove_2; 131 break; 132 133 case NFSPROC_RENAME: 134 xdr_argument = xdr_renameargs; 135 xdr_result = xdr_nfsstat; 136 local = (char *(*)()) nfsproc_rename_2; 137 break; 138 139 case NFSPROC_LINK: 140 xdr_argument = xdr_linkargs; 141 xdr_result = xdr_nfsstat; 142 local = (char *(*)()) nfsproc_link_2; 143 break; 144 145 case NFSPROC_SYMLINK: 146 xdr_argument = xdr_symlinkargs; 147 xdr_result = xdr_nfsstat; 148 local = (char *(*)()) nfsproc_symlink_2; 149 break; 150 151 case NFSPROC_MKDIR: 152 xdr_argument = xdr_createargs; 153 xdr_result = xdr_diropres; 154 local = (char *(*)()) nfsproc_mkdir_2; 155 break; 156 157 case NFSPROC_RMDIR: 158 xdr_argument = xdr_diropargs; 159 xdr_result = xdr_nfsstat; 160 local = (char *(*)()) nfsproc_rmdir_2; 161 break; 162 163 case NFSPROC_READDIR: 164 xdr_argument = xdr_readdirargs; 165 xdr_result = xdr_readdirres; 166 local = (char *(*)()) nfsproc_readdir_2; 167 break; 168 169 case NFSPROC_STATFS: 170 xdr_argument = xdr_nfs_fh; 171 xdr_result = xdr_statfsres; 172 local = (char *(*)()) nfsproc_statfs_2; 173 break; 174 175 default: 176 svcerr_noproc(transp); 177 return; 178 } 179 bzero((char *)&argument, sizeof(argument)); 180 if (!svc_getargs(transp, xdr_argument, (char *)&argument)) { 181 svcerr_decode(transp); 182 return; 183 } 184 result = (*local)(&argument, rqstp); 185 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) 186 svcerr_systemerr(transp); 187 if (!svc_freeargs(transp, xdr_argument, (char *)&argument)) { 188 plog(XLOG_FATAL, "unable to free rpc arguments in nfs_program_1"); 189 going_down(1); 190 } 191 } 192 193