2013-09-15 01:48:49 +04:00
|
|
|
/* $NetBSD: nfsm_subs.h,v 1.52 2013/09/14 21:48:49 martin Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-04-20 15:20:47 +04:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Copyright (c) 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-20 15:20:47 +04:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Rick Macklem at The University of Guelph.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-04-20 15:20:47 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1996-02-18 14:53:36 +03:00
|
|
|
* @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95
|
1993-04-20 15:20:47 +04:00
|
|
|
*/
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
|
|
|
|
#ifndef _NFS_NFSM_SUBS_H_
|
|
|
|
#define _NFS_NFSM_SUBS_H_
|
|
|
|
|
|
|
|
|
1993-04-20 15:20:47 +04:00
|
|
|
/*
|
|
|
|
* These macros do strange and peculiar things to mbuf chains for
|
|
|
|
* the assistance of the nfs code. To attempt to use them for any
|
|
|
|
* other purpose will be dangerous. (they make weird assumptions)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First define what the actual subs. return
|
|
|
|
*/
|
1996-02-18 14:53:36 +03:00
|
|
|
|
1993-04-20 15:20:47 +04:00
|
|
|
#define M_HASCL(m) ((m)->m_flags & M_EXT)
|
|
|
|
#define NFSMADV(m, s) (m)->m_data += (s)
|
1997-03-27 23:45:27 +03:00
|
|
|
#define NFSMSIZ(m) ((M_HASCL(m)) ? (m)->m_ext.ext_size : \
|
|
|
|
(((m)->m_flags & M_PKTHDR) ? MHLEN : MLEN))
|
1993-04-20 15:20:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now for the macros that do the simple stuff and call the functions
|
|
|
|
* for the hard stuff.
|
|
|
|
* These macros use several vars. declared in nfsm_reqhead and these
|
|
|
|
* vars. must not be used elsewhere unless you are careful not to corrupt
|
|
|
|
* them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
|
|
|
|
* that may be used so long as the value is not expected to retained
|
|
|
|
* after a macro.
|
|
|
|
* I know, this is kind of dorkey, but it makes the actual op functions
|
|
|
|
* fairly clean and deals with the mess caused by the xdr discriminating
|
|
|
|
* unions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define nfsm_build(a,c,s) \
|
1994-06-08 15:33:09 +04:00
|
|
|
{ if ((s) > M_TRAILINGSPACE(mb)) { \
|
2003-02-26 09:31:08 +03:00
|
|
|
struct mbuf *mb2; \
|
|
|
|
mb2 = m_get(M_WAIT, MT_DATA); \
|
|
|
|
MCLAIM(mb2, &nfs_mowner); \
|
1993-04-20 15:20:47 +04:00
|
|
|
if ((s) > MLEN) \
|
|
|
|
panic("build > MLEN"); \
|
|
|
|
mb->m_next = mb2; \
|
|
|
|
mb = mb2; \
|
|
|
|
mb->m_len = 0; \
|
2007-03-04 08:59:00 +03:00
|
|
|
bpos = mtod(mb, char *); \
|
1993-04-20 15:20:47 +04:00
|
|
|
} \
|
|
|
|
(a) = (c)(bpos); \
|
|
|
|
mb->m_len += (s); \
|
1994-06-08 15:33:09 +04:00
|
|
|
bpos += (s); }
|
1993-04-20 15:20:47 +04:00
|
|
|
|
1997-02-25 02:26:20 +03:00
|
|
|
#define nfsm_aligned(p) ALIGNED_POINTER(p,u_int32_t)
|
1997-02-22 06:11:12 +03:00
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
#define nfsm_dissect(a, c, s) \
|
2007-03-04 08:59:00 +03:00
|
|
|
{ t1 = mtod(md, char *) + md->m_len-dpos; \
|
1997-02-22 06:11:12 +03:00
|
|
|
if (t1 >= (s) && nfsm_aligned(dpos)) { \
|
1993-04-20 15:20:47 +04:00
|
|
|
(a) = (c)(dpos); \
|
|
|
|
dpos += (s); \
|
1996-02-18 14:53:36 +03:00
|
|
|
} else if ((t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2)) != 0){ \
|
|
|
|
error = t1; \
|
1993-04-20 15:20:47 +04:00
|
|
|
m_freem(mrep); \
|
|
|
|
goto nfsmout; \
|
|
|
|
} else { \
|
|
|
|
(a) = (c)cp2; \
|
1994-06-08 15:33:09 +04:00
|
|
|
} }
|
1993-04-20 15:20:47 +04:00
|
|
|
|
2003-04-25 01:21:04 +04:00
|
|
|
#define nfsm_fhtom(n, v3) \
|
1996-02-18 14:53:36 +03:00
|
|
|
{ if (v3) { \
|
2003-04-25 01:21:04 +04:00
|
|
|
t2 = nfsm_rndup((n)->n_fhsize) + NFSX_UNSIGNED; \
|
1996-02-18 14:53:36 +03:00
|
|
|
if (t2 <= M_TRAILINGSPACE(mb)) { \
|
|
|
|
nfsm_build(tl, u_int32_t *, t2); \
|
2003-04-25 01:21:04 +04:00
|
|
|
*tl++ = txdr_unsigned((n)->n_fhsize); \
|
1996-02-18 14:53:36 +03:00
|
|
|
*(tl + ((t2>>2) - 2)) = 0; \
|
2007-03-04 08:59:00 +03:00
|
|
|
memcpy(tl,(n)->n_fhp, (n)->n_fhsize); \
|
1996-02-18 14:53:36 +03:00
|
|
|
} else if ((t2 = nfsm_strtmbuf(&mb, &bpos, \
|
2007-03-04 08:59:00 +03:00
|
|
|
(void *)(n)->n_fhp, (n)->n_fhsize)) != 0) { \
|
1996-02-18 14:53:36 +03:00
|
|
|
error = t2; \
|
|
|
|
m_freem(mreq); \
|
|
|
|
goto nfsmout; \
|
|
|
|
} \
|
|
|
|
} else { \
|
2007-03-04 08:59:00 +03:00
|
|
|
nfsm_build(cp, void *, NFSX_V2FH); \
|
|
|
|
memcpy(cp, (n)->n_fhp, NFSX_V2FH); \
|
1996-02-18 14:53:36 +03:00
|
|
|
} }
|
1993-04-20 15:20:47 +04:00
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
#define nfsm_srvfhtom(f, v3) \
|
|
|
|
{ if (v3) { \
|
2006-09-02 16:40:36 +04:00
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + \
|
|
|
|
NFSRVFH_SIZE(f)); \
|
|
|
|
*tl++ = txdr_unsigned(NFSRVFH_SIZE(f)); \
|
|
|
|
memcpy(tl, NFSRVFH_DATA(f), NFSRVFH_SIZE(f)); \
|
1996-02-18 14:53:36 +03:00
|
|
|
} else { \
|
2006-09-02 16:40:36 +04:00
|
|
|
KASSERT(NFSRVFH_SIZE(f) == NFSX_V2FH); \
|
2007-03-04 08:59:00 +03:00
|
|
|
nfsm_build(cp, void *, NFSX_V2FH); \
|
2006-09-02 16:40:36 +04:00
|
|
|
memcpy(cp, NFSRVFH_DATA(f), NFSX_V2FH); \
|
1996-02-18 14:53:36 +03:00
|
|
|
} }
|
1993-04-20 15:20:47 +04:00
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
#define nfsm_srvpostop_fh(f) \
|
2006-09-02 16:40:36 +04:00
|
|
|
{ nfsm_build(tl, u_int32_t *, \
|
|
|
|
2 * NFSX_UNSIGNED + NFSRVFH_SIZE(f)); \
|
1996-02-18 14:53:36 +03:00
|
|
|
*tl++ = nfs_true; \
|
2006-09-02 16:40:36 +04:00
|
|
|
*tl++ = txdr_unsigned(NFSRVFH_SIZE(f)); \
|
|
|
|
memcpy(tl, NFSRVFH_DATA(f), NFSRVFH_SIZE(f)); \
|
1996-02-18 14:53:36 +03:00
|
|
|
}
|
|
|
|
|
2004-03-19 16:52:07 +03:00
|
|
|
/*
|
|
|
|
* nfsm_mtofh: dissect a "resulted obj" part of create-like operations
|
|
|
|
* like mkdir.
|
|
|
|
*
|
|
|
|
* for nfsv3, dissect post_op_fh3 and following post_op_attr.
|
|
|
|
* for nfsv2, dissect fhandle and following fattr.
|
|
|
|
*
|
|
|
|
* d: (IN) the vnode of the parent directry.
|
|
|
|
* v: (OUT) the corresponding vnode (we allocate one if needed)
|
|
|
|
* v3: (IN) true for nfsv3.
|
|
|
|
* f: (OUT) true if we got valid filehandle. always true for nfsv2.
|
|
|
|
*/
|
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
#define nfsm_mtofh(d, v, v3, f) \
|
1996-02-18 14:53:36 +03:00
|
|
|
{ struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \
|
2004-04-05 14:41:45 +04:00
|
|
|
int hasattr = 0; \
|
1996-02-18 14:53:36 +03:00
|
|
|
if (v3) { \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
(f) = fxdr_unsigned(int, *tl); \
|
2004-04-05 14:41:45 +04:00
|
|
|
} else { \
|
1996-02-18 14:53:36 +03:00
|
|
|
(f) = 1; \
|
2004-04-05 14:41:45 +04:00
|
|
|
hasattr = 1; \
|
|
|
|
} \
|
1996-02-18 14:53:36 +03:00
|
|
|
if (f) { \
|
|
|
|
nfsm_getfh(ttfhp, ttfhsize, (v3)); \
|
|
|
|
if ((t1 = nfs_nget((d)->v_mount, ttfhp, ttfhsize, \
|
2003-06-30 02:28:00 +04:00
|
|
|
&ttnp)) != 0) { \
|
1996-02-18 14:53:36 +03:00
|
|
|
error = t1; \
|
|
|
|
m_freem(mrep); \
|
|
|
|
goto nfsmout; \
|
|
|
|
} \
|
|
|
|
(v) = NFSTOV(ttnp); \
|
|
|
|
} \
|
|
|
|
if (v3) { \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
if (f) \
|
2004-04-05 14:41:45 +04:00
|
|
|
hasattr = fxdr_unsigned(int, *tl); \
|
1996-02-18 14:53:36 +03:00
|
|
|
else if (fxdr_unsigned(int, *tl)) \
|
|
|
|
nfsm_adv(NFSX_V3FATTR); \
|
1993-04-20 15:20:47 +04:00
|
|
|
} \
|
2004-04-05 14:41:45 +04:00
|
|
|
if (f && hasattr) \
|
2002-10-21 16:52:32 +04:00
|
|
|
nfsm_loadattr((v), (struct vattr *)0, 0); \
|
1993-04-20 15:20:47 +04:00
|
|
|
}
|
|
|
|
|
2004-03-19 16:52:07 +03:00
|
|
|
/*
|
|
|
|
* nfsm_getfh: dissect a filehandle.
|
|
|
|
*
|
|
|
|
* f: (OUT) a filehandle.
|
|
|
|
* s: (OUT) size of the filehandle in bytes.
|
|
|
|
* v3: (IN) true if nfsv3.
|
|
|
|
*/
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
#define nfsm_getfh(f, s, v3) \
|
|
|
|
{ if (v3) { \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \
|
|
|
|
(s) > NFSX_V3FHMAX) { \
|
|
|
|
m_freem(mrep); \
|
|
|
|
error = EBADRPC; \
|
|
|
|
goto nfsmout; \
|
|
|
|
} \
|
|
|
|
} else \
|
|
|
|
(s) = NFSX_V2FH; \
|
|
|
|
nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); }
|
|
|
|
|
2002-10-21 16:52:32 +04:00
|
|
|
#define nfsm_loadattr(v, a, flags) \
|
1996-02-18 14:53:36 +03:00
|
|
|
{ struct vnode *ttvp = (v); \
|
2002-10-21 16:52:32 +04:00
|
|
|
if ((t1 = nfsm_loadattrcache(&ttvp, &md, &dpos, (a), (flags))) \
|
|
|
|
!= 0) { \
|
1996-02-18 14:53:36 +03:00
|
|
|
error = t1; \
|
1993-04-20 15:20:47 +04:00
|
|
|
m_freem(mrep); \
|
|
|
|
goto nfsmout; \
|
|
|
|
} \
|
1996-02-18 14:53:36 +03:00
|
|
|
(v) = ttvp; }
|
|
|
|
|
2004-03-15 14:47:52 +03:00
|
|
|
/*
|
|
|
|
* nfsm_postop_attr: process nfsv3 post_op_attr
|
|
|
|
*
|
|
|
|
* dissect post_op_attr. if we got a one,
|
|
|
|
* call nfsm_loadattrcache to update attribute cache.
|
|
|
|
*
|
|
|
|
* v: (IN/OUT) the corresponding vnode
|
|
|
|
* f: (OUT) true if we got valid attribute
|
|
|
|
* flags: (IN) flags for nfsm_loadattrcache
|
|
|
|
*/
|
|
|
|
|
2002-10-21 16:52:32 +04:00
|
|
|
#define nfsm_postop_attr(v, f, flags) \
|
1996-02-18 14:53:36 +03:00
|
|
|
{ struct vnode *ttvp = (v); \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
if (((f) = fxdr_unsigned(int, *tl)) != 0) { \
|
1997-07-15 00:46:20 +04:00
|
|
|
if ((t1 = nfsm_loadattrcache(&ttvp, &md, &dpos, \
|
2002-10-21 16:52:32 +04:00
|
|
|
(struct vattr *)0, (flags))) != 0) { \
|
1996-02-18 14:53:36 +03:00
|
|
|
error = t1; \
|
|
|
|
(f) = 0; \
|
|
|
|
m_freem(mrep); \
|
|
|
|
goto nfsmout; \
|
|
|
|
} \
|
|
|
|
(v) = ttvp; \
|
|
|
|
} }
|
|
|
|
|
2004-03-15 14:47:52 +03:00
|
|
|
/*
|
|
|
|
* nfsm_wcc_data: process nfsv3 wcc_data
|
|
|
|
*
|
|
|
|
* dissect pre_op_attr and then let nfsm_postop_attr dissect post_op_attr.
|
|
|
|
*
|
|
|
|
* v: (IN/OUT) the corresponding vnode
|
|
|
|
* f: (IN/OUT)
|
|
|
|
* NFSV3_WCCRATTR return true if we got valid post_op_attr.
|
|
|
|
* NFSV3_WCCCHK return true if pre_op_attr's mtime is the same
|
|
|
|
* as our n_mtime. (ie. our cache isn't stale.)
|
|
|
|
* flags: (IN) flags for nfsm_loadattrcache
|
2007-02-22 09:05:00 +03:00
|
|
|
* docheck: (IN) true if timestamp change is expected
|
2004-03-15 14:47:52 +03:00
|
|
|
*/
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
/* Used as (f) for nfsm_wcc_data() */
|
|
|
|
#define NFSV3_WCCRATTR 0
|
|
|
|
#define NFSV3_WCCCHK 1
|
|
|
|
|
2013-09-15 01:48:49 +04:00
|
|
|
#if __GNUC_PREREQ__(4, 8)
|
|
|
|
/*
|
|
|
|
* With all the macros in here, it is hard to track set-but-not-used cases
|
|
|
|
* and avoid them without cluttering the code.
|
|
|
|
*/
|
|
|
|
_Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"")
|
|
|
|
#endif
|
|
|
|
|
2005-01-19 19:22:19 +03:00
|
|
|
#define nfsm_wcc_data(v, f, flags, docheck) \
|
2004-04-05 14:28:23 +04:00
|
|
|
{ int ttattrf, ttretf = 0, renewctime = 0, renewnctime = 0; \
|
2005-01-19 19:22:19 +03:00
|
|
|
struct timespec ctime, mtime; \
|
2005-05-30 00:58:13 +04:00
|
|
|
struct nfsnode *nfsp = VTONFS(v); \
|
2007-02-22 09:05:00 +03:00
|
|
|
bool haspreopattr = false; \
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
if (*tl == nfs_true) { \
|
2007-02-22 09:05:00 +03:00
|
|
|
haspreopattr = true; \
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsm_dissect(tl, u_int32_t *, 6 * NFSX_UNSIGNED); \
|
2005-01-19 19:22:19 +03:00
|
|
|
fxdr_nfsv3time(tl + 2, &mtime); \
|
2004-04-05 14:28:23 +04:00
|
|
|
fxdr_nfsv3time(tl + 4, &ctime); \
|
2005-05-30 00:58:13 +04:00
|
|
|
if (nfsp->n_ctime == ctime.tv_sec) \
|
2004-04-05 14:28:23 +04:00
|
|
|
renewctime = 1; \
|
|
|
|
if ((v)->v_type == VDIR) { \
|
2005-05-30 00:58:13 +04:00
|
|
|
if (timespeccmp(&nfsp->n_nctime, &ctime, ==)) \
|
2004-04-05 14:28:23 +04:00
|
|
|
renewnctime = 1; \
|
|
|
|
} \
|
2003-09-26 15:51:53 +04:00
|
|
|
if (f) { \
|
2005-05-30 00:58:13 +04:00
|
|
|
ttretf = timespeccmp(&nfsp->n_mtime, &mtime, ==);\
|
2003-09-26 15:51:53 +04:00
|
|
|
} \
|
1996-02-18 14:53:36 +03:00
|
|
|
} \
|
2002-10-21 16:52:32 +04:00
|
|
|
nfsm_postop_attr((v), ttattrf, (flags)); \
|
2005-05-30 00:58:13 +04:00
|
|
|
nfsp = VTONFS(v); \
|
2005-01-19 19:22:19 +03:00
|
|
|
if (ttattrf) { \
|
|
|
|
if (haspreopattr && \
|
2005-05-30 00:58:13 +04:00
|
|
|
nfs_check_wccdata(nfsp, &ctime, &mtime, (docheck))) \
|
2005-01-19 19:22:19 +03:00
|
|
|
renewctime = renewnctime = ttretf = 0; \
|
|
|
|
if (renewctime) \
|
2005-05-30 00:58:13 +04:00
|
|
|
nfsp->n_ctime = nfsp->n_vattr->va_ctime.tv_sec; \
|
2005-01-19 19:22:19 +03:00
|
|
|
if (renewnctime) \
|
2005-05-30 00:58:13 +04:00
|
|
|
nfsp->n_nctime = nfsp->n_vattr->va_ctime; \
|
2005-01-19 19:22:19 +03:00
|
|
|
} \
|
1996-02-18 14:53:36 +03:00
|
|
|
if (f) { \
|
|
|
|
(f) = ttretf; \
|
|
|
|
} else { \
|
|
|
|
(f) = ttattrf; \
|
|
|
|
} }
|
|
|
|
|
1999-05-29 05:22:03 +04:00
|
|
|
/* If full is true, set all fields, otherwise just set mode and time fields */
|
|
|
|
#define nfsm_v3attrbuild(a, full) \
|
|
|
|
{ if ((a)->va_mode != (mode_t)VNOVAL) { \
|
|
|
|
nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
|
|
|
|
*tl++ = nfs_true; \
|
|
|
|
*tl = txdr_unsigned((a)->va_mode); \
|
|
|
|
} else { \
|
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
*tl = nfs_false; \
|
|
|
|
} \
|
|
|
|
if ((full) && (a)->va_uid != (uid_t)VNOVAL) { \
|
|
|
|
nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
|
|
|
|
*tl++ = nfs_true; \
|
|
|
|
*tl = txdr_unsigned((a)->va_uid); \
|
|
|
|
} else { \
|
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
*tl = nfs_false; \
|
|
|
|
} \
|
|
|
|
if ((full) && (a)->va_gid != (gid_t)VNOVAL) { \
|
|
|
|
nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
|
|
|
|
*tl++ = nfs_true; \
|
|
|
|
*tl = txdr_unsigned((a)->va_gid); \
|
|
|
|
} else { \
|
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
*tl = nfs_false; \
|
|
|
|
} \
|
|
|
|
if ((full) && (a)->va_size != VNOVAL) { \
|
|
|
|
nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \
|
|
|
|
*tl++ = nfs_true; \
|
|
|
|
txdr_hyper((a)->va_size, tl); \
|
|
|
|
} else { \
|
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
*tl = nfs_false; \
|
|
|
|
} \
|
|
|
|
if ((a)->va_atime.tv_sec != VNOVAL) { \
|
2006-06-08 02:33:33 +04:00
|
|
|
if ((a)->va_atime.tv_sec != time_second) { \
|
1999-05-29 05:22:03 +04:00
|
|
|
nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \
|
|
|
|
*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
|
|
|
|
txdr_nfsv3time(&(a)->va_atime, tl); \
|
|
|
|
} else { \
|
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \
|
|
|
|
} \
|
|
|
|
if ((a)->va_mtime.tv_sec != VNOVAL) { \
|
2006-06-08 02:33:33 +04:00
|
|
|
if ((a)->va_mtime.tv_sec != time_second) { \
|
1999-05-29 05:22:03 +04:00
|
|
|
nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \
|
|
|
|
*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
|
|
|
|
txdr_nfsv3time(&(a)->va_mtime, tl); \
|
|
|
|
} else { \
|
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \
|
|
|
|
} \
|
1996-02-18 14:53:36 +03:00
|
|
|
}
|
2005-02-27 01:31:44 +03:00
|
|
|
|
1993-04-20 15:20:47 +04:00
|
|
|
|
|
|
|
#define nfsm_strsiz(s,m) \
|
2003-03-28 16:05:47 +03:00
|
|
|
{ nfsm_dissect(tl,uint32_t *,NFSX_UNSIGNED); \
|
|
|
|
if (((s) = fxdr_unsigned(uint32_t,*tl)) > (m)) { \
|
1993-04-20 15:20:47 +04:00
|
|
|
m_freem(mrep); \
|
|
|
|
error = EBADRPC; \
|
|
|
|
goto nfsmout; \
|
1994-06-08 15:33:09 +04:00
|
|
|
} }
|
1993-04-20 15:20:47 +04:00
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
#define nfsm_srvnamesiz(s) \
|
2003-03-28 16:05:47 +03:00
|
|
|
{ nfsm_dissect(tl,uint32_t *,NFSX_UNSIGNED); \
|
|
|
|
if (((s) = fxdr_unsigned(uint32_t,*tl)) > NFS_MAXNAMLEN) \
|
1996-02-18 14:53:36 +03:00
|
|
|
error = NFSERR_NAMETOL; \
|
|
|
|
if (error) \
|
|
|
|
nfsm_reply(0); \
|
|
|
|
}
|
|
|
|
|
1993-04-20 15:20:47 +04:00
|
|
|
#define nfsm_mtouio(p,s) \
|
|
|
|
if ((s) > 0 && \
|
1996-02-18 14:53:36 +03:00
|
|
|
(t1 = nfsm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \
|
|
|
|
error = t1; \
|
1993-04-20 15:20:47 +04:00
|
|
|
m_freem(mrep); \
|
|
|
|
goto nfsmout; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define nfsm_uiotom(p,s) \
|
1996-02-18 14:53:36 +03:00
|
|
|
if ((t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) != 0) { \
|
|
|
|
error = t1; \
|
1993-04-20 15:20:47 +04:00
|
|
|
m_freem(mreq); \
|
|
|
|
goto nfsmout; \
|
|
|
|
}
|
|
|
|
|
2003-04-25 01:21:04 +04:00
|
|
|
#define nfsm_reqhead(n,a,s) \
|
|
|
|
mb = mreq = nfsm_reqh((n),(a),(s),&bpos)
|
1993-04-20 15:20:47 +04:00
|
|
|
|
|
|
|
#define nfsm_reqdone m_freem(mrep); \
|
2005-02-27 01:31:44 +03:00
|
|
|
nfsmout:
|
1993-04-20 15:20:47 +04:00
|
|
|
|
|
|
|
#define nfsm_rndup(a) (((a)+3)&(~0x3))
|
2003-06-09 17:10:31 +04:00
|
|
|
#define nfsm_padlen(a) (nfsm_rndup(a) - (a))
|
1993-04-20 15:20:47 +04:00
|
|
|
|
2004-05-10 14:40:42 +04:00
|
|
|
#define nfsm_request1(v, t, p, c, rexmitp) \
|
1996-02-10 00:48:19 +03:00
|
|
|
if ((error = nfs_request((v), mreq, (t), (p), \
|
2004-05-10 14:40:42 +04:00
|
|
|
(c), &mrep, &md, &dpos, (rexmitp))) != 0) { \
|
1996-02-18 14:53:36 +03:00
|
|
|
if (error & NFSERR_RETERR) \
|
|
|
|
error &= ~NFSERR_RETERR; \
|
|
|
|
else \
|
|
|
|
goto nfsmout; \
|
|
|
|
}
|
1993-04-20 15:20:47 +04:00
|
|
|
|
2004-05-10 14:40:42 +04:00
|
|
|
#define nfsm_request(v, t, p, c) nfsm_request1((v), (t), (p), (c), NULL)
|
|
|
|
|
1993-04-20 15:20:47 +04:00
|
|
|
#define nfsm_strtom(a,s,m) \
|
|
|
|
if ((s) > (m)) { \
|
|
|
|
m_freem(mreq); \
|
|
|
|
error = ENAMETOOLONG; \
|
|
|
|
goto nfsmout; \
|
|
|
|
} \
|
|
|
|
t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \
|
1994-06-08 15:33:09 +04:00
|
|
|
if (t2 <= M_TRAILINGSPACE(mb)) { \
|
1995-12-20 02:07:11 +03:00
|
|
|
nfsm_build(tl,u_int32_t *,t2); \
|
1993-04-20 15:20:47 +04:00
|
|
|
*tl++ = txdr_unsigned(s); \
|
|
|
|
*(tl+((t2>>2)-2)) = 0; \
|
2007-03-04 08:59:00 +03:00
|
|
|
memcpy(tl, (const char *)(a), (s)); \
|
1996-02-18 14:53:36 +03:00
|
|
|
} else if ((t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s))) != 0) { \
|
|
|
|
error = t2; \
|
1993-04-20 15:20:47 +04:00
|
|
|
m_freem(mreq); \
|
|
|
|
goto nfsmout; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define nfsm_srvdone \
|
|
|
|
nfsmout: \
|
|
|
|
return(error)
|
|
|
|
|
|
|
|
#define nfsm_reply(s) \
|
|
|
|
{ \
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsd->nd_repstat = error; \
|
1996-02-18 14:53:36 +03:00
|
|
|
if (error && !(nfsd->nd_flag & ND_NFSV3)) \
|
|
|
|
(void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
|
1994-06-08 15:33:09 +04:00
|
|
|
mrq, &mb, &bpos); \
|
1993-04-20 15:20:47 +04:00
|
|
|
else \
|
1996-02-18 14:53:36 +03:00
|
|
|
(void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
|
1994-06-08 15:33:09 +04:00
|
|
|
mrq, &mb, &bpos); \
|
1996-03-21 00:59:56 +03:00
|
|
|
if (mrep != NULL) { \
|
|
|
|
m_freem(mrep); \
|
|
|
|
mrep = NULL; \
|
|
|
|
} \
|
1993-04-20 15:20:47 +04:00
|
|
|
mreq = *mrq; \
|
1996-02-18 14:53:36 +03:00
|
|
|
if (error && (!(nfsd->nd_flag & ND_NFSV3) || \
|
2009-04-10 22:58:50 +04:00
|
|
|
error == EBADRPC)) {\
|
|
|
|
error = 0; \
|
|
|
|
goto nfsmout; \
|
|
|
|
} \
|
1993-04-20 15:20:47 +04:00
|
|
|
}
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
#define nfsm_writereply(s, v3) \
|
|
|
|
{ \
|
|
|
|
nfsd->nd_repstat = error; \
|
|
|
|
if (error && !(v3)) \
|
|
|
|
(void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
|
|
|
|
&mreq, &mb, &bpos); \
|
|
|
|
else \
|
|
|
|
(void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
|
|
|
|
&mreq, &mb, &bpos); \
|
|
|
|
}
|
|
|
|
|
1993-04-20 15:20:47 +04:00
|
|
|
#define nfsm_adv(s) \
|
2007-03-04 08:59:00 +03:00
|
|
|
{ t1 = mtod(md, char *) + md->m_len - dpos; \
|
1993-04-20 15:20:47 +04:00
|
|
|
if (t1 >= (s)) { \
|
|
|
|
dpos += (s); \
|
1996-02-18 14:53:36 +03:00
|
|
|
} else if ((t1 = nfs_adv(&md, &dpos, (s), t1)) != 0) { \
|
|
|
|
error = t1; \
|
1993-04-20 15:20:47 +04:00
|
|
|
m_freem(mrep); \
|
|
|
|
goto nfsmout; \
|
1996-02-18 14:53:36 +03:00
|
|
|
} }
|
1993-04-20 15:20:47 +04:00
|
|
|
|
2006-09-02 16:40:36 +04:00
|
|
|
#define nfsm_srvmtofh(nsfh) \
|
1997-06-25 03:40:43 +04:00
|
|
|
{ int fhlen = NFSX_V3FH; \
|
|
|
|
if (nfsd->nd_flag & ND_NFSV3) { \
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
1997-06-25 03:40:43 +04:00
|
|
|
fhlen = fxdr_unsigned(int, *tl); \
|
2006-09-02 16:40:36 +04:00
|
|
|
if (fhlen > NFSX_V3FHMAX || \
|
|
|
|
(fhlen < FHANDLE_SIZE_MIN && fhlen > 0)) { \
|
1996-02-18 14:53:36 +03:00
|
|
|
error = EBADRPC; \
|
|
|
|
nfsm_reply(0); \
|
|
|
|
} \
|
2006-09-02 16:40:36 +04:00
|
|
|
} else { \
|
|
|
|
fhlen = NFSX_V2FH; \
|
1996-02-18 14:53:36 +03:00
|
|
|
} \
|
2006-09-02 16:40:36 +04:00
|
|
|
(nsfh)->nsfh_size = fhlen; \
|
1997-06-25 03:40:43 +04:00
|
|
|
if (fhlen != 0) { \
|
2006-09-02 16:40:36 +04:00
|
|
|
nfsm_dissect(tl, u_int32_t *, fhlen); \
|
|
|
|
memcpy(NFSRVFH_DATA(nsfh), tl, fhlen); \
|
1997-06-25 03:40:43 +04:00
|
|
|
} \
|
|
|
|
}
|
1993-04-20 15:20:47 +04:00
|
|
|
|
|
|
|
#define nfsm_clget \
|
|
|
|
if (bp >= be) { \
|
1994-06-08 15:33:09 +04:00
|
|
|
if (mp == mb) \
|
|
|
|
mp->m_len += bp-bpos; \
|
2003-02-26 09:31:08 +03:00
|
|
|
mp = m_get(M_WAIT, MT_DATA); \
|
2003-02-26 10:33:57 +03:00
|
|
|
MCLAIM(mp, &nfs_mowner); \
|
2003-02-26 09:31:08 +03:00
|
|
|
m_clget(mp, M_WAIT); \
|
1993-04-20 15:20:47 +04:00
|
|
|
mp->m_len = NFSMSIZ(mp); \
|
1994-06-08 15:33:09 +04:00
|
|
|
mp2->m_next = mp; \
|
|
|
|
mp2 = mp; \
|
2007-03-04 08:59:00 +03:00
|
|
|
bp = mtod(mp, char *); \
|
1993-04-20 15:20:47 +04:00
|
|
|
be = bp+mp->m_len; \
|
|
|
|
} \
|
1995-12-20 02:07:11 +03:00
|
|
|
tl = (u_int32_t *)bp
|
1993-04-20 15:20:47 +04:00
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
#define nfsm_srvfillattr(a, f) \
|
|
|
|
nfsm_srvfattr(nfsd, (a), (f))
|
|
|
|
|
|
|
|
#define nfsm_srvwcc_data(br, b, ar, a) \
|
|
|
|
nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos)
|
|
|
|
|
|
|
|
#define nfsm_srvpostop_attr(r, a) \
|
|
|
|
nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos)
|
|
|
|
|
|
|
|
#define nfsm_srvsattr(a) \
|
2005-10-01 10:13:55 +04:00
|
|
|
{ \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
1996-02-18 14:53:36 +03:00
|
|
|
if (*tl == nfs_true) { \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
(a)->va_mode = nfstov_mode(*tl); \
|
|
|
|
} \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
if (*tl == nfs_true) { \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
(a)->va_uid = fxdr_unsigned(uid_t, *tl); \
|
|
|
|
} \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
if (*tl == nfs_true) { \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
(a)->va_gid = fxdr_unsigned(gid_t, *tl); \
|
|
|
|
} \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
if (*tl == nfs_true) { \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
|
1999-03-06 08:34:40 +03:00
|
|
|
(a)->va_size = fxdr_hyper(tl); \
|
1996-02-18 14:53:36 +03:00
|
|
|
} \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
switch (fxdr_unsigned(int, *tl)) { \
|
|
|
|
case NFSV3SATTRTIME_TOCLIENT: \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
|
|
|
|
fxdr_nfsv3time(tl, &(a)->va_atime); \
|
|
|
|
break; \
|
|
|
|
case NFSV3SATTRTIME_TOSERVER: \
|
2006-06-08 02:33:33 +04:00
|
|
|
getnanotime(&(a)->va_atime); \
|
2002-04-03 04:20:15 +04:00
|
|
|
(a)->va_vaflags |= VA_UTIMES_NULL; \
|
1996-02-18 14:53:36 +03:00
|
|
|
break; \
|
|
|
|
}; \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
|
|
|
|
switch (fxdr_unsigned(int, *tl)) { \
|
|
|
|
case NFSV3SATTRTIME_TOCLIENT: \
|
|
|
|
nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
|
|
|
|
fxdr_nfsv3time(tl, &(a)->va_mtime); \
|
2002-04-03 04:20:15 +04:00
|
|
|
(a)->va_vaflags &= ~VA_UTIMES_NULL; \
|
1996-02-18 14:53:36 +03:00
|
|
|
break; \
|
|
|
|
case NFSV3SATTRTIME_TOSERVER: \
|
2006-06-08 02:33:33 +04:00
|
|
|
getnanotime(&(a)->va_mtime); \
|
2002-04-03 04:20:15 +04:00
|
|
|
(a)->va_vaflags |= VA_UTIMES_NULL; \
|
1996-02-18 14:53:36 +03:00
|
|
|
break; \
|
|
|
|
}; }
|
1993-04-20 15:20:47 +04:00
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
#endif
|