1139823Simp/*- 21541Srgrimes * Copyright (c) 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * This code is derived from software contributed to Berkeley by 61541Srgrimes * Rick Macklem at The University of Guelph. 71541Srgrimes * 81541Srgrimes * Redistribution and use in source and binary forms, with or without 91541Srgrimes * modification, are permitted provided that the following conditions 101541Srgrimes * are met: 111541Srgrimes * 1. Redistributions of source code must retain the above copyright 121541Srgrimes * notice, this list of conditions and the following disclaimer. 131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer in the 151541Srgrimes * documentation and/or other materials provided with the distribution. 161541Srgrimes * 4. Neither the name of the University nor the names of its contributors 171541Srgrimes * may be used to endorse or promote products derived from this software 181541Srgrimes * without specific prior written permission. 191541Srgrimes * 201541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301541Srgrimes * SUCH DAMAGE. 311541Srgrimes * 3222521Sdyson * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 3350477Speter * $FreeBSD$ 341541Srgrimes */ 351541Srgrimes 3683651Speter#ifndef _NFSSERVER_NFSM_SUBS_H_ 3783651Speter#define _NFSSERVER_NFSM_SUBS_H_ 3822521Sdyson 3983651Speter#include <nfs/nfs_common.h> 402175Spaul 4183651Speter#define nfstov_mode(a) (fxdr_unsigned(u_int32_t, (a)) & ALLPERMS) 429336Sdfr 431541Srgrimes/* 441541Srgrimes * These macros do strange and peculiar things to mbuf chains for 451541Srgrimes * the assistance of the nfs code. To attempt to use them for any 461541Srgrimes * other purpose will be dangerous. (they make weird assumptions) 471541Srgrimes */ 481541Srgrimes 491541Srgrimes/* 501541Srgrimes * First define what the actual subs. return 511541Srgrimes */ 521541Srgrimes 531541Srgrimes#define M_HASCL(m) ((m)->m_flags & M_EXT) 541541Srgrimes#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ 551541Srgrimes (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) 561541Srgrimes 571541Srgrimes/* 581541Srgrimes * Now for the macros that do the simple stuff and call the functions 591541Srgrimes * for the hard stuff. 601541Srgrimes * These macros use several vars. declared in nfsm_reqhead and these 611541Srgrimes * vars. must not be used elsewhere unless you are careful not to corrupt 621541Srgrimes * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries 631541Srgrimes * that may be used so long as the value is not expected to retained 641541Srgrimes * after a macro. 651541Srgrimes * I know, this is kind of dorkey, but it makes the actual op functions 661541Srgrimes * fairly clean and deals with the mess caused by the xdr discriminating 671541Srgrimes * unions. 681541Srgrimes */ 691541Srgrimes 701541Srgrimes 7184079Speter 7284079Speter/* ************************************* */ 7384079Speter/* Dissection phase macros */ 7484079Speter 7588091Siedowseint nfsm_srvstrsiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos); 76106264Sjeffint nfsm_srvnamesiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos); 77165739Shrsint nfsm_srvnamesiz0_xx(int *s, int m, struct mbuf **md, caddr_t *dpos); 78184588Sdfrint nfsm_srvmtofh_xx(fhandle_t *f, int v3, struct mbuf **md, caddr_t *dpos); 7988091Siedowseint nfsm_srvsattr_xx(struct vattr *a, struct mbuf **md, caddr_t *dpos); 809336Sdfr 8183651Speter#define nfsm_srvstrsiz(s, m) \ 8283651Speterdo { \ 8383651Speter int t1; \ 8488091Siedowse t1 = nfsm_srvstrsiz_xx(&(s), (m), &md, &dpos); \ 8583651Speter if (t1) { \ 8683651Speter error = t1; \ 8783651Speter nfsm_reply(0); \ 8883651Speter } \ 8983651Speter} while (0) 901541Srgrimes 919336Sdfr#define nfsm_srvnamesiz(s) \ 9283651Speterdo { \ 9383651Speter int t1; \ 94106264Sjeff t1 = nfsm_srvnamesiz_xx(&(s), NFS_MAXNAMLEN, &md, &dpos); \ 9583651Speter if (t1) { \ 9683651Speter error = t1; \ 9783651Speter nfsm_reply(0); \ 9883651Speter } \ 9983651Speter} while (0) 1009336Sdfr 101106264Sjeff#define nfsm_srvpathsiz(s) \ 102106264Sjeffdo { \ 103106264Sjeff int t1; \ 104165739Shrs t1 = nfsm_srvnamesiz0_xx(&(s), NFS_MAXPATHLEN, &md, &dpos); \ 105106264Sjeff if (t1) { \ 106106264Sjeff error = t1; \ 107106264Sjeff nfsm_reply(0); \ 108106264Sjeff } \ 109106264Sjeff} while (0) 110106264Sjeff 1119336Sdfr#define nfsm_srvmtofh(f) \ 11283651Speterdo { \ 11383651Speter int t1; \ 114184588Sdfr t1 = nfsm_srvmtofh_xx((f), nfsd->nd_flag & ND_NFSV3, &md, &dpos); \ 11583651Speter if (t1) { \ 11683651Speter error = t1; \ 11783651Speter nfsm_reply(0); \ 11883651Speter } \ 11983651Speter} while (0) 1201541Srgrimes 12184079Speter/* XXX why is this different? */ 1229336Sdfr#define nfsm_srvsattr(a) \ 12383651Speterdo { \ 12483651Speter int t1; \ 12588091Siedowse t1 = nfsm_srvsattr_xx((a), &md, &dpos); \ 12683651Speter if (t1) { \ 12783651Speter error = t1; \ 12883651Speter m_freem(mrep); \ 12983651Speter mrep = NULL; \ 13083651Speter goto nfsmout; \ 13183651Speter } \ 13283651Speter} while (0) 1339336Sdfr 13484079Speter/* ************************************* */ 13584079Speter/* Prepare the reply */ 13684079Speter 13784079Speter#define nfsm_reply(s) \ 13884079Speterdo { \ 13984079Speter if (mrep != NULL) { \ 14084079Speter m_freem(mrep); \ 14184079Speter mrep = NULL; \ 14284079Speter } \ 14389272Siedowse mreq = nfs_rephead((s), nfsd, error, &mb, &bpos); \ 14489272Siedowse *mrq = mreq; \ 14584079Speter if (error == EBADRPC) { \ 14684079Speter error = 0; \ 14784079Speter goto nfsmout; \ 14884079Speter } \ 14984079Speter} while (0) 15084079Speter 15184079Speter#define nfsm_writereply(s) \ 15284079Speterdo { \ 15384079Speter mreq = nfs_rephead((s), nfsd, error, &mb, &bpos); \ 15484079Speter} while(0) 15584079Speter 15684079Speter/* ************************************* */ 15784079Speter/* Reply phase macros - add additional reply info */ 15884079Speter 15988091Siedowsevoid nfsm_srvfhtom_xx(fhandle_t *f, int v3, struct mbuf **mb, 16084079Speter caddr_t *bpos); 16188091Siedowsevoid nfsm_srvpostop_fh_xx(fhandle_t *f, struct mbuf **mb, caddr_t *bpos); 16284079Spetervoid nfsm_clget_xx(u_int32_t **tl, struct mbuf *mb, struct mbuf **mp, 163167665Sjeff char **bp, char **be, caddr_t bpos); 16484079Speter 16584079Speter#define nfsm_srvfhtom(f, v3) \ 16688091Siedowse nfsm_srvfhtom_xx((f), (v3), &mb, &bpos) 16784079Speter 16884079Speter#define nfsm_srvpostop_fh(f) \ 16988091Siedowse nfsm_srvpostop_fh_xx((f), &mb, &bpos) 17084079Speter 17184079Speter#define nfsm_srvwcc_data(br, b, ar, a) \ 17284079Speter nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos) 17384079Speter 17484079Speter#define nfsm_srvpostop_attr(r, a) \ 17584079Speter nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos) 17684079Speter 17784079Speter#define nfsm_srvfillattr(a, f) \ 17884079Speter nfsm_srvfattr(nfsd, (a), (f)) 17984079Speter 18084079Speter#define nfsm_clget \ 181167665Sjeff nfsm_clget_xx(&tl, mb, &mp, &bp, &be, bpos) 18284079Speter 1832175Spaul#endif 184