nfs_prot_svc.c revision 51292
1177633Sdfr/* 2177633Sdfr * Copyright (c) 1997-1999 Erez Zadok 3177633Sdfr * Copyright (c) 1989 Jan-Simon Pendry 4177633Sdfr * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 5177633Sdfr * Copyright (c) 1989 The Regents of the University of California. 6177633Sdfr * All rights reserved. 7177633Sdfr * 8177633Sdfr * This code is derived from software contributed to Berkeley by 9177633Sdfr * Jan-Simon Pendry at Imperial College, London. 10177633Sdfr * 11177633Sdfr * Redistribution and use in source and binary forms, with or without 12177633Sdfr * modification, are permitted provided that the following conditions 13177633Sdfr * are met: 14177633Sdfr * 1. Redistributions of source code must retain the above copyright 15177633Sdfr * notice, this list of conditions and the following disclaimer. 16177633Sdfr * 2. Redistributions in binary form must reproduce the above copyright 17177633Sdfr * notice, this list of conditions and the following disclaimer in the 18177633Sdfr * documentation and/or other materials provided with the distribution. 19177633Sdfr * 3. All advertising materials mentioning features or use of this software 20177633Sdfr * must display the following acknowledgment: 21177633Sdfr * This product includes software developed by the University of 22177633Sdfr * California, Berkeley and its contributors. 23177633Sdfr * 4. Neither the name of the University nor the names of its contributors 24177633Sdfr * may be used to endorse or promote products derived from this software 25177633Sdfr * without specific prior written permission. 26177633Sdfr * 27177633Sdfr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28177633Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29177633Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30177633Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31177633Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32177633Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33177633Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34177633Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35177633Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36177633Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37177633Sdfr * SUCH DAMAGE. 38177633Sdfr * 39177633Sdfr * %W% (Berkeley) %G% 40177633Sdfr * 41177633Sdfr * $Id: nfs_prot_svc.c,v 1.3 1999/01/13 23:31:19 ezk Exp $ 42177633Sdfr * 43177633Sdfr */ 44177633Sdfr 45177633Sdfr#ifdef HAVE_CONFIG_H 46177633Sdfr# include <config.h> 47177633Sdfr#endif /* HAVE_CONFIG_H */ 48177633Sdfr#include <am_defs.h> 49177633Sdfr#include <hlfsd.h> 50177633Sdfr 51177633Sdfr/* EXTERNAL FUNCTIONS */ 52177633Sdfrextern voidp nfsproc_null_2_svc(voidp, struct svc_req *); 53177633Sdfrextern nfsattrstat * nfsproc_getattr_2_svc(am_nfs_fh *, struct svc_req *); 54177633Sdfrextern nfsattrstat * nfsproc_setattr_2_svc(nfssattrargs *, struct svc_req *); 55177633Sdfrextern voidp nfsproc_root_2_svc(voidp, struct svc_req *); 56177633Sdfrextern nfsdiropres * nfsproc_lookup_2_svc(nfsdiropargs *, struct svc_req *); 57177633Sdfrextern nfsreadlinkres * nfsproc_readlink_2_svc(am_nfs_fh *, struct svc_req *); 58177633Sdfrextern nfsreadres * nfsproc_read_2_svc(nfsreadargs *, struct svc_req *); 59177633Sdfrextern voidp nfsproc_writecache_2_svc(voidp, struct svc_req *); 60177633Sdfrextern nfsattrstat * nfsproc_write_2_svc(nfswriteargs *, struct svc_req *); 61177633Sdfrextern nfsdiropres * nfsproc_create_2_svc(nfscreateargs *, struct svc_req *); 62177633Sdfrextern nfsstat * nfsproc_remove_2_svc(nfsdiropargs *, struct svc_req *); 63177633Sdfrextern nfsstat * nfsproc_rename_2_svc(nfsrenameargs *, struct svc_req *); 64177633Sdfrextern nfsstat * nfsproc_link_2_svc(nfslinkargs *, struct svc_req *); 65177633Sdfrextern nfsstat * nfsproc_symlink_2_svc(nfssymlinkargs *, struct svc_req *); 66177633Sdfrextern nfsdiropres * nfsproc_mkdir_2_svc(nfscreateargs *, struct svc_req *); 67177633Sdfrextern nfsstat * nfsproc_rmdir_2_svc(nfsdiropargs *, struct svc_req *); 68177633Sdfrextern nfsreaddirres * nfsproc_readdir_2_svc(nfsreaddirargs *, struct svc_req *); 69177633Sdfrextern nfsstatfsres * nfsproc_statfs_2_svc(am_nfs_fh *, struct svc_req *); 70177633Sdfr 71177633Sdfr/* GLOBALS */ 72177633SdfrSVCXPRT *nfs_program_2_transp; 73177633Sdfr 74177633Sdfr/* TYPEDEFS */ 75177633Sdfrtypedef char *(*nfssvcproc_t)(voidp, struct svc_req *); 76177633Sdfr 77177633Sdfr 78177633Sdfrvoid 79177633Sdfrnfs_program_2(struct svc_req *rqstp, SVCXPRT *transp) 80177633Sdfr{ 81177633Sdfr union { 82177633Sdfr am_nfs_fh nfsproc_getattr_2_arg; 83177633Sdfr nfssattrargs nfsproc_setattr_2_arg; 84 nfsdiropargs nfsproc_lookup_2_arg; 85 am_nfs_fh nfsproc_readlink_2_arg; 86 nfsreadargs nfsproc_read_2_arg; 87 nfswriteargs nfsproc_write_2_arg; 88 nfscreateargs nfsproc_create_2_arg; 89 nfsdiropargs nfsproc_remove_2_arg; 90 nfsrenameargs nfsproc_rename_2_arg; 91 nfslinkargs nfsproc_link_2_arg; 92 nfssymlinkargs nfsproc_symlink_2_arg; 93 nfscreateargs nfsproc_mkdir_2_arg; 94 nfsdiropargs nfsproc_rmdir_2_arg; 95 nfsreaddirargs nfsproc_readdir_2_arg; 96 am_nfs_fh nfsproc_statfs_2_arg; 97 } argument; 98 char *result; 99 xdrproc_t xdr_argument, xdr_result; 100 nfssvcproc_t local; 101 102 nfs_program_2_transp = NULL; 103 104 switch (rqstp->rq_proc) { 105 106 case NFSPROC_NULL: 107 xdr_argument = (xdrproc_t) xdr_void; 108 xdr_result = (xdrproc_t) xdr_void; 109 local = (nfssvcproc_t) nfsproc_null_2_svc; 110 break; 111 112 case NFSPROC_GETATTR: 113 xdr_argument = (xdrproc_t) xdr_nfs_fh; 114 xdr_result = (xdrproc_t) xdr_attrstat; 115 local = (nfssvcproc_t) nfsproc_getattr_2_svc; 116 break; 117 118 case NFSPROC_SETATTR: 119 xdr_argument = (xdrproc_t) xdr_sattrargs; 120 xdr_result = (xdrproc_t) xdr_attrstat; 121 local = (nfssvcproc_t) nfsproc_setattr_2_svc; 122 break; 123 124 case NFSPROC_ROOT: 125 xdr_argument = (xdrproc_t) xdr_void; 126 xdr_result = (xdrproc_t) xdr_void; 127 local = (nfssvcproc_t) nfsproc_root_2_svc; 128 break; 129 130 case NFSPROC_LOOKUP: 131 xdr_argument = (xdrproc_t) xdr_diropargs; 132 xdr_result = (xdrproc_t) xdr_diropres; 133 local = (nfssvcproc_t) nfsproc_lookup_2_svc; 134 /* 135 * Cheap way to pass transp down to afs_lookuppn so it can 136 * be stored in the am_node structure and later used for 137 * quick_reply(). 138 */ 139 nfs_program_2_transp = transp; 140 break; 141 142 case NFSPROC_READLINK: 143 xdr_argument = (xdrproc_t) xdr_nfs_fh; 144 xdr_result = (xdrproc_t) xdr_readlinkres; 145 local = (nfssvcproc_t) nfsproc_readlink_2_svc; 146 break; 147 148 case NFSPROC_READ: 149 xdr_argument = (xdrproc_t) xdr_readargs; 150 xdr_result = (xdrproc_t) xdr_readres; 151 local = (nfssvcproc_t) nfsproc_read_2_svc; 152 break; 153 154 case NFSPROC_WRITECACHE: 155 xdr_argument = (xdrproc_t) xdr_void; 156 xdr_result = (xdrproc_t) xdr_void; 157 local = (nfssvcproc_t) nfsproc_writecache_2_svc; 158 break; 159 160 case NFSPROC_WRITE: 161 xdr_argument = (xdrproc_t) xdr_writeargs; 162 xdr_result = (xdrproc_t) xdr_attrstat; 163 local = (nfssvcproc_t) nfsproc_write_2_svc; 164 break; 165 166 case NFSPROC_CREATE: 167 xdr_argument = (xdrproc_t) xdr_createargs; 168 xdr_result = (xdrproc_t) xdr_diropres; 169 local = (nfssvcproc_t) nfsproc_create_2_svc; 170 break; 171 172 case NFSPROC_REMOVE: 173 xdr_argument = (xdrproc_t) xdr_diropargs; 174 xdr_result = (xdrproc_t) xdr_nfsstat; 175 local = (nfssvcproc_t) nfsproc_remove_2_svc; 176 break; 177 178 case NFSPROC_RENAME: 179 xdr_argument = (xdrproc_t) xdr_renameargs; 180 xdr_result = (xdrproc_t) xdr_nfsstat; 181 local = (nfssvcproc_t) nfsproc_rename_2_svc; 182 break; 183 184 case NFSPROC_LINK: 185 xdr_argument = (xdrproc_t) xdr_linkargs; 186 xdr_result = (xdrproc_t) xdr_nfsstat; 187 local = (nfssvcproc_t) nfsproc_link_2_svc; 188 break; 189 190 case NFSPROC_SYMLINK: 191 xdr_argument = (xdrproc_t) xdr_symlinkargs; 192 xdr_result = (xdrproc_t) xdr_nfsstat; 193 local = (nfssvcproc_t) nfsproc_symlink_2_svc; 194 break; 195 196 case NFSPROC_MKDIR: 197 xdr_argument = (xdrproc_t) xdr_createargs; 198 xdr_result = (xdrproc_t) xdr_diropres; 199 local = (nfssvcproc_t) nfsproc_mkdir_2_svc; 200 break; 201 202 case NFSPROC_RMDIR: 203 xdr_argument = (xdrproc_t) xdr_diropargs; 204 xdr_result = (xdrproc_t) xdr_nfsstat; 205 local = (nfssvcproc_t) nfsproc_rmdir_2_svc; 206 break; 207 208 case NFSPROC_READDIR: 209 xdr_argument = (xdrproc_t) xdr_readdirargs; 210 xdr_result = (xdrproc_t) xdr_readdirres; 211 local = (nfssvcproc_t) nfsproc_readdir_2_svc; 212 break; 213 214 case NFSPROC_STATFS: 215 xdr_argument = (xdrproc_t) xdr_nfs_fh; 216 xdr_result = (xdrproc_t) xdr_statfsres; 217 local = (nfssvcproc_t) nfsproc_statfs_2_svc; 218 break; 219 220 default: 221 svcerr_noproc(transp); 222 return; 223 } 224 225 memset((char *) &argument, 0, sizeof(argument)); 226 if (!svc_getargs(transp, 227 (XDRPROC_T_TYPE) xdr_argument, 228 (SVC_IN_ARG_TYPE) &argument)) { 229 plog(XLOG_ERROR, 230 "NFS xdr decode failed for %d %d %d", 231 (int) rqstp->rq_prog, (int) rqstp->rq_vers, (int) rqstp->rq_proc); 232 svcerr_decode(transp); 233 return; 234 } 235 result = (*local) (&argument, rqstp); 236 237 nfs_program_2_transp = NULL; 238 239 if (result != NULL && !svc_sendreply(transp, 240 (XDRPROC_T_TYPE) xdr_result, 241 result)) { 242 svcerr_systemerr(transp); 243 } 244 if (!svc_freeargs(transp, 245 (XDRPROC_T_TYPE) xdr_argument, 246 (SVC_IN_ARG_TYPE) & argument)) { 247 plog(XLOG_FATAL, "unable to free rpc arguments in nfs_program_2"); 248 going_down(1); 249 } 250} 251