nfsm_subs.h revision 83651
11541Srgrimes/* 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 * 3. All advertising materials mentioning features or use of this software 171541Srgrimes * must display the following acknowledgement: 181541Srgrimes * This product includes software developed by the University of 191541Srgrimes * California, Berkeley and its contributors. 201541Srgrimes * 4. Neither the name of the University nor the names of its contributors 211541Srgrimes * may be used to endorse or promote products derived from this software 221541Srgrimes * without specific prior written permission. 231541Srgrimes * 241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341541Srgrimes * SUCH DAMAGE. 351541Srgrimes * 3622521Sdyson * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 3750477Speter * $FreeBSD: head/sys/nfsserver/nfsm_subs.h 83651 2001-09-18 23:32:09Z peter $ 381541Srgrimes */ 391541Srgrimes 4083651Speter#ifndef _NFSSERVER_NFSM_SUBS_H_ 4183651Speter#define _NFSSERVER_NFSM_SUBS_H_ 4222521Sdyson 4383651Speter#include <nfs/nfs_common.h> 442175Spaul 4583651Speter#define nfstov_mode(a) (fxdr_unsigned(u_int32_t, (a)) & ALLPERMS) 469336Sdfr 471541Srgrimes/* 481541Srgrimes * These macros do strange and peculiar things to mbuf chains for 491541Srgrimes * the assistance of the nfs code. To attempt to use them for any 501541Srgrimes * other purpose will be dangerous. (they make weird assumptions) 511541Srgrimes */ 521541Srgrimes 531541Srgrimes/* 541541Srgrimes * First define what the actual subs. return 551541Srgrimes */ 561541Srgrimes 571541Srgrimes#define M_HASCL(m) ((m)->m_flags & M_EXT) 5850053Speter#define NFSMADV(m, s) \ 5950053Speter do { \ 6050053Speter (m)->m_data += (s); \ 6150053Speter } while (0) 621541Srgrimes#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ 631541Srgrimes (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) 641541Srgrimes 651541Srgrimes/* 661541Srgrimes * Now for the macros that do the simple stuff and call the functions 671541Srgrimes * for the hard stuff. 681541Srgrimes * These macros use several vars. declared in nfsm_reqhead and these 691541Srgrimes * vars. must not be used elsewhere unless you are careful not to corrupt 701541Srgrimes * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries 711541Srgrimes * that may be used so long as the value is not expected to retained 721541Srgrimes * after a macro. 731541Srgrimes * I know, this is kind of dorkey, but it makes the actual op functions 741541Srgrimes * fairly clean and deals with the mess caused by the xdr discriminating 751541Srgrimes * unions. 761541Srgrimes */ 771541Srgrimes 781541Srgrimes 7983651Speter/* Helpers for macros */ 8083651Spetervoid nfsm_srvfhtom_xx(fhandle_t *f, int v3, u_int32_t **tl, struct mbuf **mb, 8183651Speter caddr_t *bpos); 8283651Spetervoid nfsm_srvpostop_fh_xx(fhandle_t *f, u_int32_t **tl, struct mbuf **mb, 8383651Speter caddr_t *bpos); 8483651Speterint nfsm_srvstrsiz_xx(int *s, int m, u_int32_t **tl, struct mbuf **md, 8583651Speter caddr_t *dpos); 8683651Speterint nfsm_srvnamesiz_xx(int *s, u_int32_t **tl, struct mbuf **md, 8783651Speter caddr_t *dpos); 8883651Spetervoid nfs_rephead_xx(int s, struct nfsrv_descript *nfsd, 8983651Speter struct nfssvc_sock *slp, int error, struct mbuf **mrq, 9083651Speter struct mbuf **mb, struct mbuf **mreq, struct mbuf **mrep, 9183651Speter caddr_t *bpos); 9283651Speterint nfsm_srvmtofh_xx(fhandle_t *f, struct nfsrv_descript *nfsd, 9383651Speter u_int32_t **tl, struct mbuf **md, caddr_t *dpos); 9483651Spetervoid nfsm_clget_xx(u_int32_t **tl, struct mbuf *mb, struct mbuf **mp, 9583651Speter char **bp, char **be, caddr_t bpos); 9683651Speterint nfsm_srvsattr_xx(struct vattr *a, u_int32_t **tl, struct mbuf **md, 9783651Speter caddr_t *dpos); 989336Sdfr 999336Sdfr#define nfsm_srvfhtom(f, v3) \ 10083651Speterdo { \ 10183651Speter nfsm_srvfhtom_xx((f), (v3), &tl, &mb, &bpos); \ 10283651Speter} while (0) 1031541Srgrimes 1049336Sdfr#define nfsm_srvpostop_fh(f) \ 10583651Speterdo { \ 10683651Speter nfsm_srvpostop_fh_xx((f), &tl, &mb, &bpos); \ 10783651Speter} while (0) 1081541Srgrimes 10983651Speter#define nfsm_srvstrsiz(s, m) \ 11083651Speterdo { \ 11183651Speter int t1; \ 11283651Speter t1 = nfsm_srvstrsiz_xx(&(s), (m), &tl, &md, &dpos); \ 11383651Speter if (t1) { \ 11483651Speter error = t1; \ 11583651Speter nfsm_reply(0); \ 11683651Speter } \ 11783651Speter} while (0) 1181541Srgrimes 1199336Sdfr#define nfsm_srvnamesiz(s) \ 12083651Speterdo { \ 12183651Speter int t1; \ 12283651Speter t1 = nfsm_srvnamesiz_xx(&(s), &tl, &md, &dpos); \ 12383651Speter if (t1) { \ 12483651Speter error = t1; \ 12583651Speter nfsm_reply(0); \ 12683651Speter } \ 12783651Speter} while (0) 1289336Sdfr 1291541Srgrimes#define nfsm_reply(s) \ 13083651Speterdo { \ 13183651Speter nfs_rephead_xx((s), nfsd, slp, error, mrq, &mb, &mreq, &mrep, &bpos); \ 13283651Speter if (error && error == EBADRPC) { \ 13383651Speter error = 0; \ 13483651Speter goto nfsmout; \ 13583651Speter } \ 13683651Speter} while (0) 1371541Srgrimes 13883651Speter#define nfsm_writereply(s) \ 13983651Speterdo { \ 14083651Speter nfs_rephead((s), nfsd, slp, error, &mreq, &mb, &bpos); \ 14183651Speter} while (0) 1429336Sdfr 1439336Sdfr#define nfsm_srvmtofh(f) \ 14483651Speterdo { \ 14583651Speter int t1; \ 14683651Speter t1 = nfsm_srvmtofh_xx((f), nfsd, &tl, &md, &dpos); \ 14783651Speter if (t1) { \ 14883651Speter error = t1; \ 14983651Speter nfsm_reply(0); \ 15083651Speter } \ 15183651Speter} while (0) 1521541Srgrimes 15383651Speter#define nfsm_clget \ 15483651Speterdo { \ 15583651Speter nfsm_clget_xx(&tl, mb, &mp, &bp, &be, bpos); \ 15683651Speter} while (0) 1571541Srgrimes 1589336Sdfr#define nfsm_srvfillattr(a, f) \ 15983651Speterdo { \ 16083651Speter nfsm_srvfattr(nfsd, (a), (f)); \ 16183651Speter} while (0) 1621541Srgrimes 1639336Sdfr#define nfsm_srvwcc_data(br, b, ar, a) \ 16483651Speterdo { \ 16583651Speter nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos); \ 16683651Speter} while (0) 1679336Sdfr 1689336Sdfr#define nfsm_srvpostop_attr(r, a) \ 16983651Speterdo { \ 17083651Speter nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos); \ 17183651Speter} while (0) 1729336Sdfr 1739336Sdfr#define nfsm_srvsattr(a) \ 17483651Speterdo { \ 17583651Speter int t1; \ 17683651Speter t1 = nfsm_srvsattr_xx((a), &tl, &md, &dpos); \ 17783651Speter if (t1) { \ 17883651Speter error = t1; \ 17983651Speter m_freem(mrep); \ 18083651Speter mrep = NULL; \ 18183651Speter goto nfsmout; \ 18283651Speter } \ 18383651Speter} while (0) 1849336Sdfr 1852175Spaul#endif 186