netbsd32_nfssvc.c revision 1.4 1 1.4 pgoyette /* $NetBSD: netbsd32_nfssvc.c,v 1.4 2015/12/01 09:12:23 pgoyette Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 2015 Matthew R. Green
5 1.1 mrg * All rights reserved.
6 1.1 mrg *
7 1.1 mrg * Redistribution and use in source and binary forms, with or without
8 1.1 mrg * modification, are permitted provided that the following conditions
9 1.1 mrg * are met:
10 1.1 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1 mrg * notice, this list of conditions and the following disclaimer.
12 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1 mrg * documentation and/or other materials provided with the distribution.
15 1.1 mrg * 3. The name of the author may not be used to endorse or promote products
16 1.1 mrg * derived from this software without specific prior written permission.
17 1.1 mrg *
18 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 1.1 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.1 mrg * SUCH DAMAGE.
29 1.1 mrg */
30 1.1 mrg
31 1.1 mrg #include <sys/cdefs.h>
32 1.4 pgoyette __KERNEL_RCSID(0, "$NetBSD: netbsd32_nfssvc.c,v 1.4 2015/12/01 09:12:23 pgoyette Exp $");
33 1.1 mrg
34 1.1 mrg #if defined(_KERNEL_OPT)
35 1.1 mrg #include "opt_nfs.h"
36 1.2 dholland #include "opt_nfsserver.h"
37 1.1 mrg #include "opt_compat_netbsd.h"
38 1.1 mrg #endif
39 1.1 mrg
40 1.1 mrg #include <sys/param.h>
41 1.1 mrg #include <sys/vnode.h>
42 1.1 mrg #include <sys/filedesc.h>
43 1.4 pgoyette #include <sys/module.h>
44 1.4 pgoyette #include <sys/syscallvar.h>
45 1.1 mrg
46 1.1 mrg #include <compat/netbsd32/netbsd32.h>
47 1.1 mrg #include <compat/netbsd32/netbsd32_syscall.h>
48 1.1 mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
49 1.1 mrg #include <compat/netbsd32/netbsd32_conv.h>
50 1.1 mrg
51 1.1 mrg #include <nfs/rpcv2.h>
52 1.1 mrg #include <nfs/nfsproto.h>
53 1.1 mrg #include <nfs/nfs.h>
54 1.1 mrg #include <nfs/nfs_var.h>
55 1.1 mrg
56 1.4 pgoyette extern struct emul emul_netbsd32;
57 1.4 pgoyette
58 1.1 mrg static int nfssvc32_addsock_in(struct nfsd_args *, const void *);
59 1.1 mrg static int nfssvc32_setexports_in(struct mountd_exports_list *, const void *);
60 1.1 mrg static int nfssvc32_nsd_in(struct nfsd_srvargs *, const void *);
61 1.1 mrg static int nfssvc32_nsd_out(void *, const struct nfsd_srvargs *);
62 1.1 mrg static int nfssvc32_exp_in(struct export_args *, const void *, size_t);
63 1.1 mrg
64 1.1 mrg static int
65 1.1 mrg nfssvc32_addsock_in(struct nfsd_args *nfsdarg, const void *argp)
66 1.1 mrg {
67 1.1 mrg struct netbsd32_nfsd_args args32;
68 1.1 mrg int error;
69 1.1 mrg
70 1.1 mrg error = copyin(argp, &args32, sizeof args32);
71 1.1 mrg if (!error) {
72 1.1 mrg nfsdarg->sock = args32.sock;
73 1.1 mrg nfsdarg->name = NETBSD32PTR64(args32.name);
74 1.1 mrg nfsdarg->namelen = args32.namelen;
75 1.1 mrg }
76 1.1 mrg
77 1.1 mrg return error;
78 1.1 mrg }
79 1.1 mrg
80 1.1 mrg static int
81 1.1 mrg nfssvc32_setexports_in(struct mountd_exports_list *mel, const void *argp)
82 1.1 mrg {
83 1.1 mrg struct netbsd32_mountd_exports_list args32;
84 1.1 mrg int error;
85 1.1 mrg
86 1.1 mrg error = copyin(argp, &args32, sizeof args32);
87 1.1 mrg if (!error) {
88 1.1 mrg mel->mel_path = NETBSD32PTR64(args32.mel_path);
89 1.1 mrg mel->mel_nexports = args32.mel_nexports;
90 1.1 mrg mel->mel_exports = NETBSD32PTR64(args32.mel_exports);
91 1.1 mrg }
92 1.1 mrg
93 1.1 mrg return error;
94 1.1 mrg }
95 1.1 mrg
96 1.1 mrg static int
97 1.1 mrg nfssvc32_nsd_in(struct nfsd_srvargs *nsd, const void *argp)
98 1.1 mrg {
99 1.1 mrg struct netbsd32_nfsd_srvargs args32;
100 1.1 mrg int error;
101 1.1 mrg
102 1.1 mrg error = copyin(argp, &args32, sizeof args32);
103 1.1 mrg if (!error) {
104 1.1 mrg nsd->nsd_nfsd = NETBSD32PTR64(args32.nsd_nfsd);
105 1.1 mrg nsd->nsd_uid = args32.nsd_uid;
106 1.1 mrg nsd->nsd_haddr = args32.nsd_haddr;
107 1.1 mrg nsd->nsd_cr = args32.nsd_cr;
108 1.1 mrg nsd->nsd_authlen = args32.nsd_authlen;
109 1.1 mrg nsd->nsd_authstr = NETBSD32PTR64(args32.nsd_authstr);
110 1.1 mrg nsd->nsd_verflen = args32.nsd_verflen;
111 1.1 mrg nsd->nsd_uid = args32.nsd_uid;
112 1.1 mrg netbsd32_to_timeval(&args32.nsd_timestamp, &nsd->nsd_timestamp);
113 1.1 mrg nsd->nsd_ttl = args32.nsd_ttl;
114 1.1 mrg nsd->nsd_key[0] = args32.nsd_key[0];
115 1.1 mrg nsd->nsd_key[1] = args32.nsd_key[1];
116 1.1 mrg }
117 1.1 mrg
118 1.1 mrg return error;
119 1.1 mrg }
120 1.1 mrg
121 1.1 mrg static int
122 1.1 mrg nfssvc32_nsd_out(void *argp, const struct nfsd_srvargs *nsd)
123 1.1 mrg {
124 1.1 mrg struct netbsd32_nfsd_srvargs args32;
125 1.1 mrg
126 1.1 mrg NETBSD32PTR32(args32.nsd_nfsd, nsd->nsd_nfsd);
127 1.1 mrg args32.nsd_uid = nsd->nsd_uid;
128 1.1 mrg args32.nsd_haddr = nsd->nsd_haddr;
129 1.1 mrg args32.nsd_cr = nsd->nsd_cr;
130 1.1 mrg args32.nsd_authlen = nsd->nsd_authlen;
131 1.1 mrg NETBSD32PTR32(args32.nsd_authstr, nsd->nsd_authstr);
132 1.1 mrg args32.nsd_verflen = nsd->nsd_verflen;
133 1.1 mrg args32.nsd_uid = nsd->nsd_uid;
134 1.1 mrg netbsd32_from_timeval(&nsd->nsd_timestamp, &args32.nsd_timestamp);
135 1.1 mrg args32.nsd_ttl = nsd->nsd_ttl;
136 1.1 mrg args32.nsd_key[0] = nsd->nsd_key[0];
137 1.1 mrg args32.nsd_key[1] = nsd->nsd_key[1];
138 1.1 mrg
139 1.1 mrg return copyout(nsd, argp, sizeof *nsd);
140 1.1 mrg }
141 1.1 mrg
142 1.1 mrg static int
143 1.1 mrg nfssvc32_exp_in(struct export_args *exp, const void *argp, size_t nexports)
144 1.1 mrg {
145 1.3 mrg struct netbsd32_export_args exp32;
146 1.3 mrg struct netbsd32_export_args const *argp32 = argp;
147 1.1 mrg int error = 0;
148 1.1 mrg
149 1.1 mrg for (size_t i = 0; i < nexports; i++) {
150 1.3 mrg error = copyin(argp32, &exp32, sizeof exp32);
151 1.1 mrg if (error)
152 1.1 mrg break;
153 1.3 mrg exp->ex_flags = exp32.ex_flags;
154 1.3 mrg exp->ex_root = exp32.ex_root;
155 1.3 mrg exp->ex_anon = exp32.ex_anon;
156 1.3 mrg exp->ex_addr = NETBSD32PTR64(exp32.ex_addr);
157 1.3 mrg exp->ex_addrlen = exp32.ex_addrlen;
158 1.3 mrg exp->ex_mask = NETBSD32PTR64(exp32.ex_mask);
159 1.3 mrg exp->ex_masklen = exp32.ex_masklen;
160 1.3 mrg exp->ex_indexfile = NETBSD32PTR64(exp32.ex_indexfile);
161 1.1 mrg exp++;
162 1.3 mrg argp32++;
163 1.1 mrg }
164 1.1 mrg
165 1.1 mrg return error;
166 1.1 mrg }
167 1.1 mrg
168 1.1 mrg /*
169 1.1 mrg * NFS server system calls
170 1.1 mrg */
171 1.1 mrg
172 1.1 mrg static struct nfssvc_copy_ops netbsd32_ops = {
173 1.1 mrg .addsock_in = nfssvc32_addsock_in,
174 1.1 mrg .setexports_in = nfssvc32_setexports_in,
175 1.1 mrg .nsd_in = nfssvc32_nsd_in,
176 1.1 mrg .nsd_out = nfssvc32_nsd_out,
177 1.1 mrg .exp_in = nfssvc32_exp_in,
178 1.1 mrg };
179 1.1 mrg
180 1.1 mrg int
181 1.1 mrg netbsd32_nfssvc(struct lwp *l, const struct netbsd32_nfssvc_args *uap,
182 1.1 mrg register_t *retval)
183 1.1 mrg {
184 1.1 mrg /* {
185 1.1 mrg syscallarg(int) flag;
186 1.1 mrg syscallarg(netbsd32_voidp *) argp;
187 1.1 mrg } */
188 1.1 mrg int flag = SCARG(uap, flag);
189 1.1 mrg void *argp = SCARG_P32(uap, argp);
190 1.1 mrg
191 1.1 mrg return do_nfssvc(&netbsd32_ops, l, flag, argp, retval);
192 1.1 mrg }
193 1.4 pgoyette
194 1.4 pgoyette static const struct syscall_package compat_nfssvc_syscalls[] = {
195 1.4 pgoyette { NETBSD32_SYS_netbsd32_nfssvc, 0, (sy_call_t *)netbsd32_nfssvc },
196 1.4 pgoyette { 0, 0, NULL },
197 1.4 pgoyette };
198 1.4 pgoyette
199 1.4 pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_nfssrv, "nfsserver,compat_netbsd32");
200 1.4 pgoyette
201 1.4 pgoyette static int
202 1.4 pgoyette compat_netbsd32_nfssrv_modcmd(modcmd_t cmd, void *arg)
203 1.4 pgoyette {
204 1.4 pgoyette int error;
205 1.4 pgoyette
206 1.4 pgoyette switch (cmd) {
207 1.4 pgoyette case MODULE_CMD_INIT:
208 1.4 pgoyette error = syscall_establish(&emul_netbsd32,
209 1.4 pgoyette compat_nfssvc_syscalls);
210 1.4 pgoyette break;
211 1.4 pgoyette case MODULE_CMD_FINI:
212 1.4 pgoyette error = syscall_disestablish(&emul_netbsd32,
213 1.4 pgoyette compat_nfssvc_syscalls);
214 1.4 pgoyette break;
215 1.4 pgoyette default:
216 1.4 pgoyette error = ENOTTY;
217 1.4 pgoyette break;
218 1.4 pgoyette }
219 1.4 pgoyette return error;
220 1.4 pgoyette }
221