nfsm_subs.h revision 192578
1/*- 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rick Macklem at The University of Guelph. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 4. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 33 * $FreeBSD: head/sys/nfsclient/nfsm_subs.h 192578 2009-05-22 12:35:12Z rwatson $ 34 */ 35 36#ifndef _NFSCLIENT_NFSM_SUBS_H_ 37#define _NFSCLIENT_NFSM_SUBS_H_ 38 39#include <nfs/nfs_common.h> 40 41#define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_int32_t,(a))&0x7] 42 43struct ucred; 44struct vnode; 45 46/* 47 * These macros do strange and peculiar things to mbuf chains for 48 * the assistance of the nfs code. To attempt to use them for any 49 * other purpose will be dangerous. (they make weird assumptions) 50 */ 51 52/* 53 * First define what the actual subs. return 54 */ 55u_int32_t nfs_xid_gen(void); 56struct mbuf *nfsm_reqhead(struct vnode *vp, u_long procid, int hsiz); 57struct mbuf *nfsm_rpchead(struct ucred *cr, int nmflag, int procid, 58 int auth_type, int auth_len, 59 struct mbuf *mrest, int mrest_len, 60 struct mbuf **mbp, u_int32_t **xidpp); 61 62#define M_HASCL(m) ((m)->m_flags & M_EXT) 63#define NFSMINOFF(m) \ 64 do { \ 65 if (M_HASCL(m)) \ 66 (m)->m_data = (m)->m_ext.ext_buf; \ 67 else if ((m)->m_flags & M_PKTHDR) \ 68 (m)->m_data = (m)->m_pktdat; \ 69 else \ 70 (m)->m_data = (m)->m_dat; \ 71 } while (0) 72#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \ 73 (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN)) 74 75/* 76 * Now for the macros that do the simple stuff and call the functions 77 * for the hard stuff. 78 * These macros use several vars. declared in nfsm_reqhead and these 79 * vars. must not be used elsewhere unless you are careful not to corrupt 80 * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries 81 * that may be used so long as the value is not expected to retained 82 * after a macro. 83 * I know, this is kind of dorkey, but it makes the actual op functions 84 * fairly clean and deals with the mess caused by the xdr discriminating 85 * unions. 86 */ 87 88 89/* *********************************** */ 90/* Request generation phase macros */ 91 92int nfsm_fhtom_xx(struct vnode *v, int v3, struct mbuf **mb, 93 caddr_t *bpos); 94void nfsm_v3attrbuild_xx(struct vattr *va, int full, struct mbuf **mb, 95 caddr_t *bpos); 96int nfsm_strtom_xx(const char *a, int s, int m, struct mbuf **mb, 97 caddr_t *bpos); 98 99#define nfsm_bcheck(t1, mreq) \ 100do { \ 101 if (t1) { \ 102 error = t1; \ 103 m_freem(mreq); \ 104 goto nfsmout; \ 105 } \ 106} while (0) 107 108#define nfsm_fhtom(v, v3) \ 109do { \ 110 int32_t t1; \ 111 t1 = nfsm_fhtom_xx((v), (v3), &mb, &bpos); \ 112 nfsm_bcheck(t1, mreq); \ 113} while (0) 114 115/* If full is true, set all fields, otherwise just set mode and time fields */ 116#define nfsm_v3attrbuild(a, full) \ 117 nfsm_v3attrbuild_xx(a, full, &mb, &bpos) 118 119#define nfsm_uiotom(p, s) \ 120do { \ 121 int t1; \ 122 t1 = nfsm_uiotombuf((p), &mb, (s), &bpos); \ 123 nfsm_bcheck(t1, mreq); \ 124} while (0) 125 126#define nfsm_strtom(a, s, m) \ 127do { \ 128 int t1; \ 129 t1 = nfsm_strtom_xx((a), (s), (m), &mb, &bpos); \ 130 nfsm_bcheck(t1, mreq); \ 131} while (0) 132 133/* *********************************** */ 134/* Send the request */ 135 136#define nfsm_request(v, t, p, c) \ 137do { \ 138 sigset_t oldset; \ 139 nfs_set_sigmask(p, &oldset); \ 140 error = nfs_request((v), mreq, (t), (p), (c), &mrep, &md, &dpos); \ 141 nfs_restore_sigmask(p, &oldset); \ 142 if (error != 0) { \ 143 if (error & NFSERR_RETERR) \ 144 error &= ~NFSERR_RETERR; \ 145 else \ 146 goto nfsmout; \ 147 } \ 148} while (0) 149 150/* *********************************** */ 151/* Reply interpretation phase macros */ 152 153int nfsm_mtofh_xx(struct vnode *d, struct vnode **v, int v3, int *f, 154 struct mbuf **md, caddr_t *dpos); 155int nfsm_getfh_xx(nfsfh_t **f, int *s, int v3, struct mbuf **md, 156 caddr_t *dpos); 157int nfsm_loadattr_xx(struct vnode **v, struct vattr *va, struct mbuf **md, 158 caddr_t *dpos); 159int nfsm_postop_attr_xx(struct vnode **v, int *f, struct mbuf **md, 160 caddr_t *dpos); 161int nfsm_wcc_data_xx(struct vnode **v, int *f, struct mbuf **md, 162 caddr_t *dpos); 163 164#define nfsm_mtofh(d, v, v3, f) \ 165do { \ 166 int32_t t1; \ 167 t1 = nfsm_mtofh_xx((d), &(v), (v3), &(f), &md, &dpos); \ 168 nfsm_dcheck(t1, mrep); \ 169} while (0) 170 171#define nfsm_getfh(f, s, v3) \ 172do { \ 173 int32_t t1; \ 174 t1 = nfsm_getfh_xx(&(f), &(s), (v3), &md, &dpos); \ 175 nfsm_dcheck(t1, mrep); \ 176} while (0) 177 178#define nfsm_loadattr(v, a) \ 179do { \ 180 int32_t t1; \ 181 t1 = nfsm_loadattr_xx(&v, a, &md, &dpos); \ 182 nfsm_dcheck(t1, mrep); \ 183} while (0) 184 185#define nfsm_postop_attr(v, f) \ 186do { \ 187 int32_t t1; \ 188 t1 = nfsm_postop_attr_xx(&v, &f, &md, &dpos); \ 189 nfsm_dcheck(t1, mrep); \ 190} while (0) 191 192/* Used as (f) for nfsm_wcc_data() */ 193#define NFSV3_WCCRATTR 0 194#define NFSV3_WCCCHK 1 195 196#define nfsm_wcc_data(v, f) \ 197do { \ 198 int32_t t1; \ 199 t1 = nfsm_wcc_data_xx(&v, &f, &md, &dpos); \ 200 nfsm_dcheck(t1, mrep); \ 201} while (0) 202 203#endif 204