nfsm_subs.h revision 256281
1303231Sdim/*-
2303231Sdim * Copyright (c) 1989, 1993
3353358Sdim *	The Regents of the University of California.  All rights reserved.
4353358Sdim *
5353358Sdim * This code is derived from software contributed to Berkeley by
6303231Sdim * Rick Macklem at The University of Guelph.
7303231Sdim *
8303231Sdim * Redistribution and use in source and binary forms, with or without
9303231Sdim * modification, are permitted provided that the following conditions
10303231Sdim * are met:
11303231Sdim * 1. Redistributions of source code must retain the above copyright
12303231Sdim *    notice, this list of conditions and the following disclaimer.
13303231Sdim * 2. Redistributions in binary form must reproduce the above copyright
14303231Sdim *    notice, this list of conditions and the following disclaimer in the
15303231Sdim *    documentation and/or other materials provided with the distribution.
16303231Sdim * 4. Neither the name of the University nor the names of its contributors
17321369Sdim *    may be used to endorse or promote products derived from this software
18327952Sdim *    without specific prior written permission.
19327952Sdim *
20327952Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21360784Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22303231Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23303231Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24303231Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25303231Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26303231Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27303231Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28303231Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29303231Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30303231Sdim * SUCH DAMAGE.
31303231Sdim *
32303231Sdim *	@(#)nfsm_subs.h	8.2 (Berkeley) 3/30/95
33303231Sdim * $FreeBSD: stable/10/sys/nfsserver/nfsm_subs.h 184588 2008-11-03 10:38:00Z dfr $
34303231Sdim */
35314564Sdim
36303231Sdim#ifndef _NFSSERVER_NFSM_SUBS_H_
37303231Sdim#define _NFSSERVER_NFSM_SUBS_H_
38303231Sdim
39303231Sdim#include <nfs/nfs_common.h>
40303231Sdim
41303231Sdim#define	nfstov_mode(a)	(fxdr_unsigned(u_int32_t, (a)) & ALLPERMS)
42303231Sdim
43303231Sdim/*
44303231Sdim * These macros do strange and peculiar things to mbuf chains for
45303231Sdim * the assistance of the nfs code. To attempt to use them for any
46303231Sdim * other purpose will be dangerous. (they make weird assumptions)
47303231Sdim */
48303231Sdim
49303231Sdim/*
50303231Sdim * First define what the actual subs. return
51303231Sdim */
52341825Sdim
53303231Sdim#define	M_HASCL(m)	((m)->m_flags & M_EXT)
54303231Sdim#define	NFSMSIZ(m)	((M_HASCL(m))?MCLBYTES: \
55303231Sdim				(((m)->m_flags & M_PKTHDR)?MHLEN:MLEN))
56303231Sdim
57303231Sdim/*
58360784Sdim * Now for the macros that do the simple stuff and call the functions
59360784Sdim * for the hard stuff.
60360784Sdim * These macros use several vars. declared in nfsm_reqhead and these
61360784Sdim * vars. must not be used elsewhere unless you are careful not to corrupt
62360784Sdim * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
63360784Sdim * that may be used so long as the value is not expected to retained
64360784Sdim * after a macro.
65360784Sdim * I know, this is kind of dorkey, but it makes the actual op functions
66360784Sdim * fairly clean and deals with the mess caused by the xdr discriminating
67360784Sdim * unions.
68360784Sdim */
69360784Sdim
70360784Sdim
71360784Sdim
72327952Sdim/* ************************************* */
73303231Sdim/* Dissection phase macros */
74303231Sdim
75303231Sdimint	nfsm_srvstrsiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos);
76327952Sdimint	nfsm_srvnamesiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos);
77303231Sdimint	nfsm_srvnamesiz0_xx(int *s, int m, struct mbuf **md, caddr_t *dpos);
78303231Sdimint	nfsm_srvmtofh_xx(fhandle_t *f, int v3, struct mbuf **md, caddr_t *dpos);
79303231Sdimint	nfsm_srvsattr_xx(struct vattr *a, struct mbuf **md, caddr_t *dpos);
80303231Sdim
81303231Sdim#define	nfsm_srvstrsiz(s, m) \
82303231Sdimdo { \
83303231Sdim	int t1; \
84303231Sdim	t1 = nfsm_srvstrsiz_xx(&(s), (m), &md, &dpos); \
85303231Sdim	if (t1) { \
86303231Sdim		error = t1; \
87303231Sdim		nfsm_reply(0); \
88303231Sdim	} \
89303231Sdim} while (0)
90303231Sdim
91303231Sdim#define	nfsm_srvnamesiz(s) \
92303231Sdimdo { \
93321369Sdim	int t1; \
94303231Sdim	t1 = nfsm_srvnamesiz_xx(&(s), NFS_MAXNAMLEN, &md, &dpos); \
95303231Sdim	if (t1) { \
96360784Sdim		error = t1; \
97303231Sdim		nfsm_reply(0); \
98303231Sdim	} \
99303231Sdim} while (0)
100303231Sdim
101303231Sdim#define	nfsm_srvpathsiz(s) \
102303231Sdimdo { \
103303231Sdim	int t1; \
104	t1 = nfsm_srvnamesiz0_xx(&(s), NFS_MAXPATHLEN, &md, &dpos); \
105	if (t1) { \
106		error = t1; \
107		nfsm_reply(0); \
108	} \
109} while (0)
110
111#define nfsm_srvmtofh(f) \
112do { \
113	int t1; \
114	t1 = nfsm_srvmtofh_xx((f), nfsd->nd_flag & ND_NFSV3, &md, &dpos); \
115	if (t1) { \
116		error = t1; \
117		nfsm_reply(0); \
118	} \
119} while (0)
120
121/* XXX why is this different? */
122#define nfsm_srvsattr(a) \
123do { \
124	int t1; \
125	t1 = nfsm_srvsattr_xx((a), &md, &dpos); \
126	if (t1) { \
127		error = t1; \
128		m_freem(mrep); \
129		mrep = NULL; \
130		goto nfsmout; \
131	} \
132} while (0)
133
134/* ************************************* */
135/* Prepare the reply */
136
137#define	nfsm_reply(s) \
138do { \
139	if (mrep != NULL) { \
140		m_freem(mrep); \
141		mrep = NULL; \
142	} \
143	mreq = nfs_rephead((s), nfsd, error, &mb, &bpos); \
144	*mrq = mreq; \
145	if (error == EBADRPC) { \
146		error = 0; \
147		goto nfsmout; \
148	} \
149} while (0)
150
151#define	nfsm_writereply(s) \
152do { \
153	mreq = nfs_rephead((s), nfsd, error, &mb, &bpos); \
154} while(0)
155
156/* ************************************* */
157/* Reply phase macros - add additional reply info */
158
159void	nfsm_srvfhtom_xx(fhandle_t *f, int v3, struct mbuf **mb,
160	    caddr_t *bpos);
161void	nfsm_srvpostop_fh_xx(fhandle_t *f, struct mbuf **mb, caddr_t *bpos);
162void	nfsm_clget_xx(u_int32_t **tl, struct mbuf *mb, struct mbuf **mp,
163	    char **bp, char **be, caddr_t bpos);
164
165#define nfsm_srvfhtom(f, v3) \
166	nfsm_srvfhtom_xx((f), (v3), &mb, &bpos)
167
168#define nfsm_srvpostop_fh(f) \
169	nfsm_srvpostop_fh_xx((f), &mb, &bpos)
170
171#define nfsm_srvwcc_data(br, b, ar, a) \
172	nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos)
173
174#define nfsm_srvpostop_attr(r, a) \
175	nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos)
176
177#define	nfsm_srvfillattr(a, f) \
178	nfsm_srvfattr(nfsd, (a), (f))
179
180#define nfsm_clget \
181	nfsm_clget_xx(&tl, mb, &mp, &bp, &be, bpos)
182
183#endif
184