nfsm_subs.h revision 122698
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/nfsclient/nfsm_subs.h 122698 2003-11-14 20:54:10Z alfred $ 381541Srgrimes */ 391541Srgrimes 4083651Speter#ifndef _NFSCLIENT_NFSM_SUBS_H_ 4183651Speter#define _NFSCLIENT_NFSM_SUBS_H_ 4222521Sdyson 4383651Speter#include <nfs/nfs_common.h> 442175Spaul 4583651Speter#define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_int32_t,(a))&0x7] 4683651Speter 4733054Sbdestruct ucred; 4833054Sbdestruct vnode; 499336Sdfr 501541Srgrimes/* 511541Srgrimes * These macros do strange and peculiar things to mbuf chains for 521541Srgrimes * the assistance of the nfs code. To attempt to use them for any 531541Srgrimes * other purpose will be dangerous. (they make weird assumptions) 541541Srgrimes */ 551541Srgrimes 561541Srgrimes/* 571541Srgrimes * First define what the actual subs. return 581541Srgrimes */ 5983651Speterstruct mbuf *nfsm_reqhead(struct vnode *vp, u_long procid, int hsiz); 6083651Speterstruct mbuf *nfsm_rpchead(struct ucred *cr, int nmflag, int procid, 6183651Speter int auth_type, int auth_len, 6283651Speter struct mbuf *mrest, int mrest_len, 6383651Speter struct mbuf **mbp, u_int32_t *xidp); 641541Srgrimes 651541Srgrimes#define M_HASCL(m) ((m)->m_flags & M_EXT) 661541Srgrimes#define NFSMINOFF(m) \ 6750053Speter do { \ 681541Srgrimes if (M_HASCL(m)) \ 691541Srgrimes (m)->m_data = (m)->m_ext.ext_buf; \ 701541Srgrimes else if ((m)->m_flags & M_PKTHDR) \ 711541Srgrimes (m)->m_data = (m)->m_pktdat; \ 721541Srgrimes else \ 7350053Speter (m)->m_data = (m)->m_dat; \ 7450053Speter } while (0) 751541Srgrimes#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ 761541Srgrimes (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) 771541Srgrimes 781541Srgrimes/* 791541Srgrimes * Now for the macros that do the simple stuff and call the functions 801541Srgrimes * for the hard stuff. 811541Srgrimes * These macros use several vars. declared in nfsm_reqhead and these 821541Srgrimes * vars. must not be used elsewhere unless you are careful not to corrupt 831541Srgrimes * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries 841541Srgrimes * that may be used so long as the value is not expected to retained 851541Srgrimes * after a macro. 861541Srgrimes * I know, this is kind of dorkey, but it makes the actual op functions 871541Srgrimes * fairly clean and deals with the mess caused by the xdr discriminating 881541Srgrimes * unions. 891541Srgrimes */ 901541Srgrimes 9184079Speter 9284079Speter/* *********************************** */ 9384079Speter/* Request generation phase macros */ 9484079Speter 9588091Siedowseint nfsm_fhtom_xx(struct vnode *v, int v3, struct mbuf **mb, 9688091Siedowse caddr_t *bpos); 9788091Siedowsevoid nfsm_v3attrbuild_xx(struct vattr *va, int full, struct mbuf **mb, 9888091Siedowse caddr_t *bpos); 9988091Siedowseint nfsm_strtom_xx(const char *a, int s, int m, struct mbuf **mb, 10088091Siedowse caddr_t *bpos); 1011541Srgrimes 10284079Speter#define nfsm_bcheck(t1, mreq) \ 10383651Speterdo { \ 10483651Speter if (t1) { \ 10583651Speter error = t1; \ 10683651Speter m_freem(mreq); \ 10783651Speter goto nfsmout; \ 10883651Speter } \ 10983651Speter} while (0) 1101541Srgrimes 11184079Speter#define nfsm_fhtom(v, v3) \ 11284079Speterdo { \ 11384079Speter int32_t t1; \ 11488091Siedowse t1 = nfsm_fhtom_xx((v), (v3), &mb, &bpos); \ 11584079Speter nfsm_bcheck(t1, mreq); \ 11684079Speter} while (0) 11784079Speter 11884079Speter/* If full is true, set all fields, otherwise just set mode and time fields */ 11984079Speter#define nfsm_v3attrbuild(a, full) \ 12088091Siedowse nfsm_v3attrbuild_xx(a, full, &mb, &bpos) 12184079Speter 12284079Speter#define nfsm_uiotom(p, s) \ 12384079Speterdo { \ 12484079Speter int t1; \ 12584079Speter t1 = nfsm_uiotombuf((p), &mb, (s), &bpos); \ 12684079Speter nfsm_bcheck(t1, mreq); \ 12784079Speter} while (0) 12884079Speter 12984079Speter#define nfsm_strtom(a, s, m) \ 13084079Speterdo { \ 13184079Speter int t1; \ 13288091Siedowse t1 = nfsm_strtom_xx((a), (s), (m), &mb, &bpos); \ 13384079Speter nfsm_bcheck(t1, mreq); \ 13484079Speter} while (0) 13584079Speter 13684079Speter/* *********************************** */ 13784079Speter/* Send the request */ 13884079Speter 13984079Speter#define nfsm_request(v, t, p, c) \ 14084079Speterdo { \ 14184079Speter error = nfs_request((v), mreq, (t), (p), (c), &mrep, &md, &dpos); \ 14284079Speter if (error != 0) { \ 14384079Speter if (error & NFSERR_RETERR) \ 14484079Speter error &= ~NFSERR_RETERR; \ 14584079Speter else \ 14684079Speter goto nfsmout; \ 14784079Speter } \ 14884079Speter} while (0) 14984079Speter 150122698Salfred#define nfsm_request_mnt(n, t, p, c) \ 151122698Salfreddo { \ 152122698Salfred error = nfs4_request_mnt((n), mreq, (t), (p), (c), &mrep, &md, &dpos); \ 153122698Salfred if (error != 0) { \ 154122698Salfred if (error & NFSERR_RETERR) \ 155122698Salfred error &= ~NFSERR_RETERR; \ 156122698Salfred else \ 157122698Salfred goto nfsmout; \ 158122698Salfred } \ 159122698Salfred} while (0) 160122698Salfred 16184079Speter/* *********************************** */ 16284079Speter/* Reply interpretation phase macros */ 16384079Speter 16484079Speterint nfsm_mtofh_xx(struct vnode *d, struct vnode **v, int v3, int *f, 16584079Speter struct mbuf **md, caddr_t *dpos); 16688091Siedowseint nfsm_getfh_xx(nfsfh_t **f, int *s, int v3, struct mbuf **md, 16788091Siedowse caddr_t *dpos); 16888091Siedowseint nfsm_loadattr_xx(struct vnode **v, struct vattr *va, struct mbuf **md, 16988091Siedowse caddr_t *dpos); 17088091Siedowseint nfsm_postop_attr_xx(struct vnode **v, int *f, struct mbuf **md, 17188091Siedowse caddr_t *dpos); 17288091Siedowseint nfsm_wcc_data_xx(struct vnode **v, int *f, struct mbuf **md, 17388091Siedowse caddr_t *dpos); 17484079Speter 1759336Sdfr#define nfsm_mtofh(d, v, v3, f) \ 17683651Speterdo { \ 17783651Speter int32_t t1; \ 17888091Siedowse t1 = nfsm_mtofh_xx((d), &(v), (v3), &(f), &md, &dpos); \ 17984079Speter nfsm_dcheck(t1, mrep); \ 18083651Speter} while (0) 1811541Srgrimes 1829336Sdfr#define nfsm_getfh(f, s, v3) \ 18383651Speterdo { \ 18483651Speter int32_t t1; \ 18588091Siedowse t1 = nfsm_getfh_xx(&(f), &(s), (v3), &md, &dpos); \ 18684079Speter nfsm_dcheck(t1, mrep); \ 18783651Speter} while (0) 1889336Sdfr 1899336Sdfr#define nfsm_loadattr(v, a) \ 19083651Speterdo { \ 19183651Speter int32_t t1; \ 19288091Siedowse t1 = nfsm_loadattr_xx(&v, a, &md, &dpos); \ 19384079Speter nfsm_dcheck(t1, mrep); \ 19483651Speter} while (0) 1951541Srgrimes 1969336Sdfr#define nfsm_postop_attr(v, f) \ 19783651Speterdo { \ 19883651Speter int32_t t1; \ 19988091Siedowse t1 = nfsm_postop_attr_xx(&v, &f, &md, &dpos); \ 20084079Speter nfsm_dcheck(t1, mrep); \ 20183651Speter} while (0) 2029336Sdfr 2039336Sdfr/* Used as (f) for nfsm_wcc_data() */ 2049336Sdfr#define NFSV3_WCCRATTR 0 2059336Sdfr#define NFSV3_WCCCHK 1 2069336Sdfr 2079336Sdfr#define nfsm_wcc_data(v, f) \ 20883651Speterdo { \ 20983651Speter int32_t t1; \ 21088091Siedowse t1 = nfsm_wcc_data_xx(&v, &f, &md, &dpos); \ 21184079Speter nfsm_dcheck(t1, mrep); \ 21283651Speter} while (0) 2139336Sdfr 2142175Spaul#endif 215