xref: /minix3/sys/fs/puffs/puffs_compat.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: puffs_compat.c,v 1.2 2010/07/11 11:17:27 pooka Exp $	*/
2*84d9c625SLionel Sambuc 
3*84d9c625SLionel Sambuc /*
4*84d9c625SLionel Sambuc  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
5*84d9c625SLionel Sambuc  *
6*84d9c625SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
7*84d9c625SLionel Sambuc  * modification, are permitted provided that the following conditions
8*84d9c625SLionel Sambuc  * are met:
9*84d9c625SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
10*84d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
11*84d9c625SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
12*84d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
13*84d9c625SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
14*84d9c625SLionel Sambuc  *
15*84d9c625SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16*84d9c625SLionel Sambuc  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17*84d9c625SLionel Sambuc  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18*84d9c625SLionel Sambuc  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*84d9c625SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*84d9c625SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21*84d9c625SLionel Sambuc  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*84d9c625SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*84d9c625SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*84d9c625SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*84d9c625SLionel Sambuc  * SUCH DAMAGE.
26*84d9c625SLionel Sambuc  */
27*84d9c625SLionel Sambuc 
28*84d9c625SLionel Sambuc /*
29*84d9c625SLionel Sambuc  * This file handles puffs PDUs so that they are compatible between
30*84d9c625SLionel Sambuc  * 32bit<->64bit time_t/dev_t.  It enables running a -current kernel
31*84d9c625SLionel Sambuc  * against a 5.0 userland (assuming the protocol otherwise matches!).
32*84d9c625SLionel Sambuc  */
33*84d9c625SLionel Sambuc 
34*84d9c625SLionel Sambuc #include <sys/cdefs.h>
35*84d9c625SLionel Sambuc __KERNEL_RCSID(0, "$NetBSD: puffs_compat.c,v 1.2 2010/07/11 11:17:27 pooka Exp $");
36*84d9c625SLionel Sambuc 
37*84d9c625SLionel Sambuc #include <sys/param.h>
38*84d9c625SLionel Sambuc #include <sys/atomic.h>
39*84d9c625SLionel Sambuc #include <sys/kmem.h>
40*84d9c625SLionel Sambuc #include <sys/kthread.h>
41*84d9c625SLionel Sambuc #include <sys/lock.h>
42*84d9c625SLionel Sambuc #include <sys/malloc.h>
43*84d9c625SLionel Sambuc #include <sys/mount.h>
44*84d9c625SLionel Sambuc #include <sys/namei.h>
45*84d9c625SLionel Sambuc #include <sys/proc.h>
46*84d9c625SLionel Sambuc #include <sys/vnode.h>
47*84d9c625SLionel Sambuc #include <sys/atomic.h>
48*84d9c625SLionel Sambuc 
49*84d9c625SLionel Sambuc #include <dev/putter/putter_sys.h>
50*84d9c625SLionel Sambuc 
51*84d9c625SLionel Sambuc #include <fs/puffs/puffs_msgif.h>
52*84d9c625SLionel Sambuc #include <fs/puffs/puffs_sys.h>
53*84d9c625SLionel Sambuc 
54*84d9c625SLionel Sambuc #include <compat/sys/time.h>
55*84d9c625SLionel Sambuc 
56*84d9c625SLionel Sambuc /*
57*84d9c625SLionel Sambuc  * compat types
58*84d9c625SLionel Sambuc  */
59*84d9c625SLionel Sambuc struct vattr50 {
60*84d9c625SLionel Sambuc 	enum vtype		va_type;
61*84d9c625SLionel Sambuc 	mode_t			va_mode;
62*84d9c625SLionel Sambuc 	nlink_t			va_nlink;
63*84d9c625SLionel Sambuc 	uid_t			va_uid;
64*84d9c625SLionel Sambuc 	gid_t			va_gid;
65*84d9c625SLionel Sambuc 	uint32_t		va_fsid;
66*84d9c625SLionel Sambuc 	ino_t			va_fileid;
67*84d9c625SLionel Sambuc 	u_quad_t		va_size;
68*84d9c625SLionel Sambuc 	long			va_blocksize;
69*84d9c625SLionel Sambuc 	struct timespec50	va_atime;
70*84d9c625SLionel Sambuc 	struct timespec50	va_mtime;
71*84d9c625SLionel Sambuc 	struct timespec50	va_ctime;
72*84d9c625SLionel Sambuc 	struct timespec50	va_birthtime;
73*84d9c625SLionel Sambuc 	u_long			va_gen;
74*84d9c625SLionel Sambuc 	u_long			va_flags;
75*84d9c625SLionel Sambuc 	uint32_t		va_rdev;
76*84d9c625SLionel Sambuc 	u_quad_t		va_bytes;
77*84d9c625SLionel Sambuc 	u_quad_t		va_filerev;
78*84d9c625SLionel Sambuc 	u_int			va_vaflags;
79*84d9c625SLionel Sambuc 	long			va_spare;
80*84d9c625SLionel Sambuc };
81*84d9c625SLionel Sambuc 
82*84d9c625SLionel Sambuc struct puffs50_vfsmsg_fhtonode {
83*84d9c625SLionel Sambuc 	struct puffs_req	pvfsr_pr;
84*84d9c625SLionel Sambuc 
85*84d9c625SLionel Sambuc 	void			*pvfsr_fhcookie;	/* IN   */
86*84d9c625SLionel Sambuc 	enum vtype		pvfsr_vtype;		/* IN   */
87*84d9c625SLionel Sambuc 	voff_t			pvfsr_size;		/* IN   */
88*84d9c625SLionel Sambuc 	uint32_t		pvfsr_rdev;		/* IN   */
89*84d9c625SLionel Sambuc 
90*84d9c625SLionel Sambuc 	size_t			pvfsr_dsize;		/* OUT */
91*84d9c625SLionel Sambuc 	uint8_t			pvfsr_data[0]		/* OUT, XXX */
92*84d9c625SLionel Sambuc 					__aligned(ALIGNBYTES+1);
93*84d9c625SLionel Sambuc };
94*84d9c625SLionel Sambuc 
95*84d9c625SLionel Sambuc struct puffs50_vnmsg_lookup {
96*84d9c625SLionel Sambuc 	struct puffs_req	pvn_pr;
97*84d9c625SLionel Sambuc 
98*84d9c625SLionel Sambuc 	struct puffs_kcn	pvnr_cn;		/* OUT	*/
99*84d9c625SLionel Sambuc 	struct puffs_kcred	pvnr_cn_cred;		/* OUT	*/
100*84d9c625SLionel Sambuc 
101*84d9c625SLionel Sambuc 	puffs_cookie_t		pvnr_newnode;		/* IN	*/
102*84d9c625SLionel Sambuc 	enum vtype		pvnr_vtype;		/* IN	*/
103*84d9c625SLionel Sambuc 	voff_t			pvnr_size;		/* IN	*/
104*84d9c625SLionel Sambuc 	uint32_t		pvnr_rdev;		/* IN	*/
105*84d9c625SLionel Sambuc };
106*84d9c625SLionel Sambuc 
107*84d9c625SLionel Sambuc struct puffs50_vnmsg_create {
108*84d9c625SLionel Sambuc 	struct puffs_req	pvn_pr;
109*84d9c625SLionel Sambuc 
110*84d9c625SLionel Sambuc 	struct puffs_kcn	pvnr_cn;		/* OUT	*/
111*84d9c625SLionel Sambuc 	struct puffs_kcred	pvnr_cn_cred;		/* OUT	*/
112*84d9c625SLionel Sambuc 
113*84d9c625SLionel Sambuc 	struct vattr50		pvnr_va;		/* OUT	*/
114*84d9c625SLionel Sambuc 	puffs_cookie_t		pvnr_newnode;		/* IN	*/
115*84d9c625SLionel Sambuc };
116*84d9c625SLionel Sambuc 
117*84d9c625SLionel Sambuc struct puffs50_vnmsg_mknod {
118*84d9c625SLionel Sambuc 	struct puffs_req	pvn_pr;
119*84d9c625SLionel Sambuc 
120*84d9c625SLionel Sambuc 	struct puffs_kcn	pvnr_cn;		/* OUT	*/
121*84d9c625SLionel Sambuc 	struct puffs_kcred	pvnr_cn_cred;		/* OUT	*/
122*84d9c625SLionel Sambuc 
123*84d9c625SLionel Sambuc 	struct vattr50		pvnr_va;		/* OUT	*/
124*84d9c625SLionel Sambuc 	puffs_cookie_t		pvnr_newnode;		/* IN	*/
125*84d9c625SLionel Sambuc };
126*84d9c625SLionel Sambuc 
127*84d9c625SLionel Sambuc #define puffs50_vnmsg_setattr puffs50_vnmsg_setgetattr
128*84d9c625SLionel Sambuc #define puffs50_vnmsg_getattr puffs50_vnmsg_setgetattr
129*84d9c625SLionel Sambuc struct puffs50_vnmsg_setgetattr {
130*84d9c625SLionel Sambuc 	struct puffs_req	pvn_pr;
131*84d9c625SLionel Sambuc 
132*84d9c625SLionel Sambuc 	struct puffs_kcred	pvnr_cred;		/* OUT	*/
133*84d9c625SLionel Sambuc 	struct vattr50		pvnr_va;		/* IN/OUT (op depend) */
134*84d9c625SLionel Sambuc };
135*84d9c625SLionel Sambuc 
136*84d9c625SLionel Sambuc struct puffs50_vnmsg_mkdir {
137*84d9c625SLionel Sambuc 	struct puffs_req	pvn_pr;
138*84d9c625SLionel Sambuc 
139*84d9c625SLionel Sambuc 	struct puffs_kcn	pvnr_cn;		/* OUT	*/
140*84d9c625SLionel Sambuc 	struct puffs_kcred	pvnr_cn_cred;		/* OUT	*/
141*84d9c625SLionel Sambuc 
142*84d9c625SLionel Sambuc 	struct vattr50		pvnr_va;		/* OUT	*/
143*84d9c625SLionel Sambuc 	puffs_cookie_t		pvnr_newnode;		/* IN	*/
144*84d9c625SLionel Sambuc };
145*84d9c625SLionel Sambuc 
146*84d9c625SLionel Sambuc struct puffs50_vnmsg_symlink {
147*84d9c625SLionel Sambuc 	struct puffs_req	pvn_pr;
148*84d9c625SLionel Sambuc 
149*84d9c625SLionel Sambuc 	struct puffs_kcn	pvnr_cn;		/* OUT	*/
150*84d9c625SLionel Sambuc 	struct puffs_kcred	pvnr_cn_cred;		/* OUT	*/
151*84d9c625SLionel Sambuc 
152*84d9c625SLionel Sambuc 	struct vattr50		pvnr_va;		/* OUT	*/
153*84d9c625SLionel Sambuc 	puffs_cookie_t		pvnr_newnode;		/* IN	*/
154*84d9c625SLionel Sambuc 	char			pvnr_link[MAXPATHLEN];	/* OUT	*/
155*84d9c625SLionel Sambuc };
156*84d9c625SLionel Sambuc 
157*84d9c625SLionel Sambuc /*
158*84d9c625SLionel Sambuc  * vattr translation routines
159*84d9c625SLionel Sambuc  */
160*84d9c625SLionel Sambuc 
161*84d9c625SLionel Sambuc static void
162*84d9c625SLionel Sambuc vattr_to_50(const struct vattr *va, struct vattr50 *va50)
163*84d9c625SLionel Sambuc {
164*84d9c625SLionel Sambuc 
165*84d9c625SLionel Sambuc 	va50->va_type = va->va_type;
166*84d9c625SLionel Sambuc 	va50->va_mode = va->va_mode;
167*84d9c625SLionel Sambuc 	va50->va_nlink = va->va_nlink;
168*84d9c625SLionel Sambuc 	va50->va_uid = va->va_uid;
169*84d9c625SLionel Sambuc 	va50->va_gid = va->va_gid;
170*84d9c625SLionel Sambuc 	va50->va_fsid = (uint64_t)va->va_fsid;
171*84d9c625SLionel Sambuc 	va50->va_fileid = va->va_fileid;
172*84d9c625SLionel Sambuc 	va50->va_size = va->va_size;
173*84d9c625SLionel Sambuc 	va50->va_blocksize = va->va_blocksize;
174*84d9c625SLionel Sambuc 	timespec_to_timespec50(&va->va_atime, &va50->va_atime);
175*84d9c625SLionel Sambuc 	timespec_to_timespec50(&va->va_ctime, &va50->va_ctime);
176*84d9c625SLionel Sambuc 	timespec_to_timespec50(&va->va_mtime, &va50->va_mtime);
177*84d9c625SLionel Sambuc 	timespec_to_timespec50(&va->va_birthtime, &va50->va_birthtime);
178*84d9c625SLionel Sambuc 	va50->va_gen = va->va_gen;
179*84d9c625SLionel Sambuc 	va50->va_flags = va->va_flags;
180*84d9c625SLionel Sambuc 	va50->va_rdev = (int32_t)va->va_rdev;
181*84d9c625SLionel Sambuc 	va50->va_bytes = va->va_bytes;
182*84d9c625SLionel Sambuc 	va50->va_filerev = va->va_filerev;
183*84d9c625SLionel Sambuc 	va50->va_vaflags = va->va_flags;
184*84d9c625SLionel Sambuc }
185*84d9c625SLionel Sambuc 
186*84d9c625SLionel Sambuc static void
187*84d9c625SLionel Sambuc vattr_from_50(const struct vattr50 *va50, struct vattr *va)
188*84d9c625SLionel Sambuc {
189*84d9c625SLionel Sambuc 
190*84d9c625SLionel Sambuc 	va->va_type = va50->va_type;
191*84d9c625SLionel Sambuc 	va->va_mode = va50->va_mode;
192*84d9c625SLionel Sambuc 	va->va_nlink = va50->va_nlink;
193*84d9c625SLionel Sambuc 	va->va_uid = va50->va_uid;
194*84d9c625SLionel Sambuc 	va->va_gid = va50->va_gid;
195*84d9c625SLionel Sambuc 	va->va_fsid = (uint32_t)va50->va_fsid;
196*84d9c625SLionel Sambuc 	va->va_fileid = va50->va_fileid;
197*84d9c625SLionel Sambuc 	va->va_size = va50->va_size;
198*84d9c625SLionel Sambuc 	va->va_blocksize = va50->va_blocksize;
199*84d9c625SLionel Sambuc 	timespec50_to_timespec(&va50->va_atime, &va->va_atime);
200*84d9c625SLionel Sambuc 	timespec50_to_timespec(&va50->va_ctime, &va->va_ctime);
201*84d9c625SLionel Sambuc 	timespec50_to_timespec(&va50->va_mtime, &va->va_mtime);
202*84d9c625SLionel Sambuc 	timespec50_to_timespec(&va50->va_birthtime, &va->va_birthtime);
203*84d9c625SLionel Sambuc 	va->va_gen = va50->va_gen;
204*84d9c625SLionel Sambuc 	va->va_flags = va50->va_flags;
205*84d9c625SLionel Sambuc 	va->va_rdev = (uint32_t)va50->va_rdev;
206*84d9c625SLionel Sambuc 	va->va_bytes = va50->va_bytes;
207*84d9c625SLionel Sambuc 	va->va_filerev = va50->va_filerev;
208*84d9c625SLionel Sambuc 	va->va_vaflags = va50->va_flags;
209*84d9c625SLionel Sambuc }
210*84d9c625SLionel Sambuc 
211*84d9c625SLionel Sambuc /*
212*84d9c625SLionel Sambuc  * XXX: cannot assert that sleeping is possible
213*84d9c625SLionel Sambuc  * (this always a valid assumption for now)
214*84d9c625SLionel Sambuc  */
215*84d9c625SLionel Sambuc #define INIT(name, extra)						\
216*84d9c625SLionel Sambuc 	struct puffs50_##name *cmsg;					\
217*84d9c625SLionel Sambuc 	struct puffs_##name *omsg;					\
218*84d9c625SLionel Sambuc 	creq =kmem_zalloc(sizeof(struct puffs50_##name)+extra,KM_SLEEP);\
219*84d9c625SLionel Sambuc 	cmsg = (struct puffs50_##name *)creq;				\
220*84d9c625SLionel Sambuc 	omsg = (struct puffs_##name *)oreq;				\
221*84d9c625SLionel Sambuc 	delta = sizeof(struct puffs50_##name)-sizeof(struct puffs_##name);
222*84d9c625SLionel Sambuc #define ASSIGN(field)							\
223*84d9c625SLionel Sambuc 	cmsg->field = omsg->field;
224*84d9c625SLionel Sambuc 
225*84d9c625SLionel Sambuc bool
226*84d9c625SLionel Sambuc puffs_compat_outgoing(struct puffs_req *oreq,
227*84d9c625SLionel Sambuc 	struct puffs_req **creqp, ssize_t *deltap)
228*84d9c625SLionel Sambuc {
229*84d9c625SLionel Sambuc 	struct puffs_req *creq = NULL;
230*84d9c625SLionel Sambuc 	ssize_t delta = 0;
231*84d9c625SLionel Sambuc 	bool rv = false;
232*84d9c625SLionel Sambuc 
233*84d9c625SLionel Sambuc 	if (PUFFSOP_OPCLASS(oreq->preq_opclass) == PUFFSOP_VFS
234*84d9c625SLionel Sambuc 	    && oreq->preq_optype == PUFFS_VFS_FHTOVP) {
235*84d9c625SLionel Sambuc 		INIT(vfsmsg_fhtonode,
236*84d9c625SLionel Sambuc 		    ((struct puffs_vfsmsg_fhtonode *)oreq)->pvfsr_dsize);
237*84d9c625SLionel Sambuc 
238*84d9c625SLionel Sambuc 		ASSIGN(pvfsr_pr);
239*84d9c625SLionel Sambuc 		ASSIGN(pvfsr_dsize);
240*84d9c625SLionel Sambuc 		memcpy(cmsg->pvfsr_data, omsg->pvfsr_data, cmsg->pvfsr_dsize);
241*84d9c625SLionel Sambuc 	} else if (PUFFSOP_OPCLASS(oreq->preq_opclass) == PUFFSOP_VN) {
242*84d9c625SLionel Sambuc 		switch (oreq->preq_optype) {
243*84d9c625SLionel Sambuc 		case PUFFS_VN_LOOKUP:
244*84d9c625SLionel Sambuc 		{
245*84d9c625SLionel Sambuc 			INIT(vnmsg_lookup, 0);
246*84d9c625SLionel Sambuc 
247*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
248*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cn);
249*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cn_cred);
250*84d9c625SLionel Sambuc 
251*84d9c625SLionel Sambuc 			break;
252*84d9c625SLionel Sambuc 		}
253*84d9c625SLionel Sambuc 
254*84d9c625SLionel Sambuc 		case PUFFS_VN_CREATE:
255*84d9c625SLionel Sambuc 		{
256*84d9c625SLionel Sambuc 			INIT(vnmsg_create, 0);
257*84d9c625SLionel Sambuc 
258*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
259*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cn);
260*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cn_cred);
261*84d9c625SLionel Sambuc 			vattr_to_50(&omsg->pvnr_va, &cmsg->pvnr_va);
262*84d9c625SLionel Sambuc 
263*84d9c625SLionel Sambuc 			break;
264*84d9c625SLionel Sambuc 		}
265*84d9c625SLionel Sambuc 
266*84d9c625SLionel Sambuc 		case PUFFS_VN_MKNOD:
267*84d9c625SLionel Sambuc 		{
268*84d9c625SLionel Sambuc 			INIT(vnmsg_mknod, 0);
269*84d9c625SLionel Sambuc 
270*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
271*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cn);
272*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cn_cred);
273*84d9c625SLionel Sambuc 			vattr_to_50(&omsg->pvnr_va, &cmsg->pvnr_va);
274*84d9c625SLionel Sambuc 
275*84d9c625SLionel Sambuc 			break;
276*84d9c625SLionel Sambuc 		}
277*84d9c625SLionel Sambuc 
278*84d9c625SLionel Sambuc 		case PUFFS_VN_MKDIR:
279*84d9c625SLionel Sambuc 		{
280*84d9c625SLionel Sambuc 			INIT(vnmsg_mkdir, 0);
281*84d9c625SLionel Sambuc 
282*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
283*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cn);
284*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cn_cred);
285*84d9c625SLionel Sambuc 			vattr_to_50(&omsg->pvnr_va, &cmsg->pvnr_va);
286*84d9c625SLionel Sambuc 
287*84d9c625SLionel Sambuc 			break;
288*84d9c625SLionel Sambuc 		}
289*84d9c625SLionel Sambuc 
290*84d9c625SLionel Sambuc 		case PUFFS_VN_SYMLINK:
291*84d9c625SLionel Sambuc 		{
292*84d9c625SLionel Sambuc 			INIT(vnmsg_symlink, 0);
293*84d9c625SLionel Sambuc 
294*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
295*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cn);
296*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cn_cred);
297*84d9c625SLionel Sambuc 			vattr_to_50(&omsg->pvnr_va, &cmsg->pvnr_va);
298*84d9c625SLionel Sambuc 			memcpy(cmsg->pvnr_link, omsg->pvnr_link,
299*84d9c625SLionel Sambuc 			    sizeof(cmsg->pvnr_link));
300*84d9c625SLionel Sambuc 
301*84d9c625SLionel Sambuc 			break;
302*84d9c625SLionel Sambuc 		}
303*84d9c625SLionel Sambuc 
304*84d9c625SLionel Sambuc 		case PUFFS_VN_SETATTR:
305*84d9c625SLionel Sambuc 		{
306*84d9c625SLionel Sambuc 			INIT(vnmsg_setattr, 0);
307*84d9c625SLionel Sambuc 
308*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
309*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cred);
310*84d9c625SLionel Sambuc 			vattr_to_50(&omsg->pvnr_va, &cmsg->pvnr_va);
311*84d9c625SLionel Sambuc 
312*84d9c625SLionel Sambuc 			break;
313*84d9c625SLionel Sambuc 		}
314*84d9c625SLionel Sambuc 		case PUFFS_VN_GETATTR:
315*84d9c625SLionel Sambuc 		{
316*84d9c625SLionel Sambuc 			INIT(vnmsg_getattr, 0);
317*84d9c625SLionel Sambuc 
318*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
319*84d9c625SLionel Sambuc 			ASSIGN(pvnr_cred);
320*84d9c625SLionel Sambuc 
321*84d9c625SLionel Sambuc 			break;
322*84d9c625SLionel Sambuc 		}
323*84d9c625SLionel Sambuc 
324*84d9c625SLionel Sambuc 		default:
325*84d9c625SLionel Sambuc 			break;
326*84d9c625SLionel Sambuc 		}
327*84d9c625SLionel Sambuc 	}
328*84d9c625SLionel Sambuc 
329*84d9c625SLionel Sambuc 	if (creq) {
330*84d9c625SLionel Sambuc 		*creqp = creq;
331*84d9c625SLionel Sambuc 		*deltap = delta;
332*84d9c625SLionel Sambuc 		rv = true;
333*84d9c625SLionel Sambuc 	}
334*84d9c625SLionel Sambuc 
335*84d9c625SLionel Sambuc 	return rv;
336*84d9c625SLionel Sambuc }
337*84d9c625SLionel Sambuc #undef INIT
338*84d9c625SLionel Sambuc #undef ASSIGN
339*84d9c625SLionel Sambuc 
340*84d9c625SLionel Sambuc #define INIT(name)							\
341*84d9c625SLionel Sambuc 	struct puffs50_##name *cmsg = (void *)preq;			\
342*84d9c625SLionel Sambuc 	struct puffs_##name *omsg = (void *)creq;
343*84d9c625SLionel Sambuc #define ASSIGN(field)							\
344*84d9c625SLionel Sambuc 	omsg->field = cmsg->field;
345*84d9c625SLionel Sambuc 
346*84d9c625SLionel Sambuc void
347*84d9c625SLionel Sambuc puffs_compat_incoming(struct puffs_req *preq, struct puffs_req *creq)
348*84d9c625SLionel Sambuc {
349*84d9c625SLionel Sambuc 
350*84d9c625SLionel Sambuc 	if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS
351*84d9c625SLionel Sambuc 	    && preq->preq_optype == PUFFS_VFS_FHTOVP) {
352*84d9c625SLionel Sambuc 		INIT(vfsmsg_fhtonode);
353*84d9c625SLionel Sambuc 
354*84d9c625SLionel Sambuc 		ASSIGN(pvfsr_pr);
355*84d9c625SLionel Sambuc 
356*84d9c625SLionel Sambuc 		ASSIGN(pvfsr_fhcookie);
357*84d9c625SLionel Sambuc 		ASSIGN(pvfsr_vtype);
358*84d9c625SLionel Sambuc 		ASSIGN(pvfsr_size);
359*84d9c625SLionel Sambuc 		ASSIGN(pvfsr_rdev);
360*84d9c625SLionel Sambuc 	} else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) {
361*84d9c625SLionel Sambuc 		switch (preq->preq_optype) {
362*84d9c625SLionel Sambuc 		case PUFFS_VN_LOOKUP:
363*84d9c625SLionel Sambuc 		{
364*84d9c625SLionel Sambuc 			INIT(vnmsg_lookup);
365*84d9c625SLionel Sambuc 
366*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
367*84d9c625SLionel Sambuc 			ASSIGN(pvnr_newnode);
368*84d9c625SLionel Sambuc 			ASSIGN(pvnr_vtype);
369*84d9c625SLionel Sambuc 			ASSIGN(pvnr_size);
370*84d9c625SLionel Sambuc 			ASSIGN(pvnr_rdev);
371*84d9c625SLionel Sambuc 
372*84d9c625SLionel Sambuc 			break;
373*84d9c625SLionel Sambuc 		}
374*84d9c625SLionel Sambuc 
375*84d9c625SLionel Sambuc 		case PUFFS_VN_CREATE:
376*84d9c625SLionel Sambuc 		{
377*84d9c625SLionel Sambuc 			INIT(vnmsg_create);
378*84d9c625SLionel Sambuc 
379*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
380*84d9c625SLionel Sambuc 			ASSIGN(pvnr_newnode);
381*84d9c625SLionel Sambuc 
382*84d9c625SLionel Sambuc 			break;
383*84d9c625SLionel Sambuc 		}
384*84d9c625SLionel Sambuc 
385*84d9c625SLionel Sambuc 		case PUFFS_VN_MKNOD:
386*84d9c625SLionel Sambuc 		{
387*84d9c625SLionel Sambuc 			INIT(vnmsg_mknod);
388*84d9c625SLionel Sambuc 
389*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
390*84d9c625SLionel Sambuc 			ASSIGN(pvnr_newnode);
391*84d9c625SLionel Sambuc 
392*84d9c625SLionel Sambuc 			break;
393*84d9c625SLionel Sambuc 		}
394*84d9c625SLionel Sambuc 
395*84d9c625SLionel Sambuc 		case PUFFS_VN_MKDIR:
396*84d9c625SLionel Sambuc 		{
397*84d9c625SLionel Sambuc 			INIT(vnmsg_mkdir);
398*84d9c625SLionel Sambuc 
399*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
400*84d9c625SLionel Sambuc 			ASSIGN(pvnr_newnode);
401*84d9c625SLionel Sambuc 
402*84d9c625SLionel Sambuc 			break;
403*84d9c625SLionel Sambuc 		}
404*84d9c625SLionel Sambuc 
405*84d9c625SLionel Sambuc 		case PUFFS_VN_SYMLINK:
406*84d9c625SLionel Sambuc 		{
407*84d9c625SLionel Sambuc 			INIT(vnmsg_symlink);
408*84d9c625SLionel Sambuc 
409*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
410*84d9c625SLionel Sambuc 			ASSIGN(pvnr_newnode);
411*84d9c625SLionel Sambuc 
412*84d9c625SLionel Sambuc 			break;
413*84d9c625SLionel Sambuc 		}
414*84d9c625SLionel Sambuc 
415*84d9c625SLionel Sambuc 		case PUFFS_VN_SETATTR:
416*84d9c625SLionel Sambuc 		{
417*84d9c625SLionel Sambuc 			INIT(vnmsg_setattr);
418*84d9c625SLionel Sambuc 
419*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
420*84d9c625SLionel Sambuc 
421*84d9c625SLionel Sambuc 			break;
422*84d9c625SLionel Sambuc 		}
423*84d9c625SLionel Sambuc 		case PUFFS_VN_GETATTR:
424*84d9c625SLionel Sambuc 		{
425*84d9c625SLionel Sambuc 			INIT(vnmsg_getattr);
426*84d9c625SLionel Sambuc 
427*84d9c625SLionel Sambuc 			ASSIGN(pvn_pr);
428*84d9c625SLionel Sambuc 			vattr_from_50(&cmsg->pvnr_va, &omsg->pvnr_va);
429*84d9c625SLionel Sambuc 
430*84d9c625SLionel Sambuc 			break;
431*84d9c625SLionel Sambuc 		}
432*84d9c625SLionel Sambuc 
433*84d9c625SLionel Sambuc 		default:
434*84d9c625SLionel Sambuc 			panic("puffs compat ops come in pairs");
435*84d9c625SLionel Sambuc 		}
436*84d9c625SLionel Sambuc 	}
437*84d9c625SLionel Sambuc }
438