nfsm_subs.h revision 167665
138451Smsmith/*- 238451Smsmith * Copyright (c) 1989, 1993 338451Smsmith * The Regents of the University of California. All rights reserved. 438451Smsmith * 538451Smsmith * This code is derived from software contributed to Berkeley by 638451Smsmith * Rick Macklem at The University of Guelph. 738451Smsmith * 838451Smsmith * Redistribution and use in source and binary forms, with or without 938451Smsmith * modification, are permitted provided that the following conditions 1038451Smsmith * are met: 1138451Smsmith * 1. Redistributions of source code must retain the above copyright 1238451Smsmith * notice, this list of conditions and the following disclaimer. 1338451Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1438451Smsmith * notice, this list of conditions and the following disclaimer in the 1538451Smsmith * documentation and/or other materials provided with the distribution. 1638451Smsmith * 4. Neither the name of the University nor the names of its contributors 1738451Smsmith * may be used to endorse or promote products derived from this software 1838451Smsmith * without specific prior written permission. 1938451Smsmith * 2038451Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2138451Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2238451Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2338451Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2438451Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2538451Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2638451Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2738451Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2838451Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2938451Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3084221Sdillon * SUCH DAMAGE. 3184221Sdillon * 3284221Sdillon * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 3338451Smsmith * $FreeBSD: head/sys/nfsserver/nfsm_subs.h 167665 2007-03-17 18:18:08Z jeff $ 3438451Smsmith */ 3538451Smsmith 3638451Smsmith#ifndef _NFSSERVER_NFSM_SUBS_H_ 3738451Smsmith#define _NFSSERVER_NFSM_SUBS_H_ 3838451Smsmith 3938451Smsmith#include <nfs/nfs_common.h> 4038451Smsmith 4138451Smsmith#define nfstov_mode(a) (fxdr_unsigned(u_int32_t, (a)) & ALLPERMS) 4238451Smsmith 4338451Smsmith/* 4438451Smsmith * These macros do strange and peculiar things to mbuf chains for 4538451Smsmith * the assistance of the nfs code. To attempt to use them for any 4638451Smsmith * other purpose will be dangerous. (they make weird assumptions) 4738451Smsmith */ 4838451Smsmith 4938451Smsmith/* 5038451Smsmith * First define what the actual subs. return 5138451Smsmith */ 5238451Smsmith 5338451Smsmith#define M_HASCL(m) ((m)->m_flags & M_EXT) 5438451Smsmith#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ 5538451Smsmith (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) 56 57/* 58 * Now for the macros that do the simple stuff and call the functions 59 * for the hard stuff. 60 * These macros use several vars. declared in nfsm_reqhead and these 61 * vars. must not be used elsewhere unless you are careful not to corrupt 62 * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries 63 * that may be used so long as the value is not expected to retained 64 * after a macro. 65 * I know, this is kind of dorkey, but it makes the actual op functions 66 * fairly clean and deals with the mess caused by the xdr discriminating 67 * unions. 68 */ 69 70 71 72/* ************************************* */ 73/* Dissection phase macros */ 74 75int nfsm_srvstrsiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos); 76int nfsm_srvnamesiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos); 77int nfsm_srvnamesiz0_xx(int *s, int m, struct mbuf **md, caddr_t *dpos); 78int nfsm_srvmtofh_xx(fhandle_t *f, struct nfsrv_descript *nfsd, 79 struct mbuf **md, caddr_t *dpos); 80int nfsm_srvsattr_xx(struct vattr *a, struct mbuf **md, caddr_t *dpos); 81 82#define nfsm_srvstrsiz(s, m) \ 83do { \ 84 int t1; \ 85 t1 = nfsm_srvstrsiz_xx(&(s), (m), &md, &dpos); \ 86 if (t1) { \ 87 error = t1; \ 88 nfsm_reply(0); \ 89 } \ 90} while (0) 91 92#define nfsm_srvnamesiz(s) \ 93do { \ 94 int t1; \ 95 t1 = nfsm_srvnamesiz_xx(&(s), NFS_MAXNAMLEN, &md, &dpos); \ 96 if (t1) { \ 97 error = t1; \ 98 nfsm_reply(0); \ 99 } \ 100} while (0) 101 102#define nfsm_srvpathsiz(s) \ 103do { \ 104 int t1; \ 105 t1 = nfsm_srvnamesiz0_xx(&(s), NFS_MAXPATHLEN, &md, &dpos); \ 106 if (t1) { \ 107 error = t1; \ 108 nfsm_reply(0); \ 109 } \ 110} while (0) 111 112#define nfsm_srvmtofh(f) \ 113do { \ 114 int t1; \ 115 t1 = nfsm_srvmtofh_xx((f), nfsd, &md, &dpos); \ 116 if (t1) { \ 117 error = t1; \ 118 nfsm_reply(0); \ 119 } \ 120} while (0) 121 122/* XXX why is this different? */ 123#define nfsm_srvsattr(a) \ 124do { \ 125 int t1; \ 126 t1 = nfsm_srvsattr_xx((a), &md, &dpos); \ 127 if (t1) { \ 128 error = t1; \ 129 m_freem(mrep); \ 130 mrep = NULL; \ 131 goto nfsmout; \ 132 } \ 133} while (0) 134 135/* ************************************* */ 136/* Prepare the reply */ 137 138#define nfsm_reply(s) \ 139do { \ 140 if (mrep != NULL) { \ 141 m_freem(mrep); \ 142 mrep = NULL; \ 143 } \ 144 mreq = nfs_rephead((s), nfsd, error, &mb, &bpos); \ 145 *mrq = mreq; \ 146 if (error == EBADRPC) { \ 147 error = 0; \ 148 goto nfsmout; \ 149 } \ 150} while (0) 151 152#define nfsm_writereply(s) \ 153do { \ 154 mreq = nfs_rephead((s), nfsd, error, &mb, &bpos); \ 155} while(0) 156 157/* ************************************* */ 158/* Reply phase macros - add additional reply info */ 159 160void nfsm_srvfhtom_xx(fhandle_t *f, int v3, struct mbuf **mb, 161 caddr_t *bpos); 162void nfsm_srvpostop_fh_xx(fhandle_t *f, struct mbuf **mb, caddr_t *bpos); 163void nfsm_clget_xx(u_int32_t **tl, struct mbuf *mb, struct mbuf **mp, 164 char **bp, char **be, caddr_t bpos); 165 166#define nfsm_srvfhtom(f, v3) \ 167 nfsm_srvfhtom_xx((f), (v3), &mb, &bpos) 168 169#define nfsm_srvpostop_fh(f) \ 170 nfsm_srvpostop_fh_xx((f), &mb, &bpos) 171 172#define nfsm_srvwcc_data(br, b, ar, a) \ 173 nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos) 174 175#define nfsm_srvpostop_attr(r, a) \ 176 nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos) 177 178#define nfsm_srvfillattr(a, f) \ 179 nfsm_srvfattr(nfsd, (a), (f)) 180 181#define nfsm_clget \ 182 nfsm_clget_xx(&tl, mb, &mp, &bp, &be, bpos) 183 184#endif 185