netbsd32_nfssvc.c revision 1.1 1 1.1 mrg /* $NetBSD: netbsd32_nfssvc.c,v 1.1 2015/06/22 10:35:00 mrg 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.1 mrg __KERNEL_RCSID(0, "$NetBSD: netbsd32_nfssvc.c,v 1.1 2015/06/22 10:35:00 mrg Exp $");
33 1.1 mrg
34 1.1 mrg #if defined(_KERNEL_OPT)
35 1.1 mrg #include "opt_nfs.h"
36 1.1 mrg #include "opt_compat_netbsd.h"
37 1.1 mrg #endif
38 1.1 mrg
39 1.1 mrg #include <sys/param.h>
40 1.1 mrg #include <sys/vnode.h>
41 1.1 mrg #include <sys/filedesc.h>
42 1.1 mrg
43 1.1 mrg #include <compat/netbsd32/netbsd32.h>
44 1.1 mrg #include <compat/netbsd32/netbsd32_syscall.h>
45 1.1 mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
46 1.1 mrg #include <compat/netbsd32/netbsd32_conv.h>
47 1.1 mrg
48 1.1 mrg #include <nfs/rpcv2.h>
49 1.1 mrg #include <nfs/nfsproto.h>
50 1.1 mrg #include <nfs/nfs.h>
51 1.1 mrg #include <nfs/nfs_var.h>
52 1.1 mrg
53 1.1 mrg static int nfssvc32_addsock_in(struct nfsd_args *, const void *);
54 1.1 mrg static int nfssvc32_setexports_in(struct mountd_exports_list *, const void *);
55 1.1 mrg static int nfssvc32_nsd_in(struct nfsd_srvargs *, const void *);
56 1.1 mrg static int nfssvc32_nsd_out(void *, const struct nfsd_srvargs *);
57 1.1 mrg static int nfssvc32_exp_in(struct export_args *, const void *, size_t);
58 1.1 mrg
59 1.1 mrg static int
60 1.1 mrg nfssvc32_addsock_in(struct nfsd_args *nfsdarg, const void *argp)
61 1.1 mrg {
62 1.1 mrg struct netbsd32_nfsd_args args32;
63 1.1 mrg int error;
64 1.1 mrg
65 1.1 mrg error = copyin(argp, &args32, sizeof args32);
66 1.1 mrg if (!error) {
67 1.1 mrg nfsdarg->sock = args32.sock;
68 1.1 mrg nfsdarg->name = NETBSD32PTR64(args32.name);
69 1.1 mrg nfsdarg->namelen = args32.namelen;
70 1.1 mrg }
71 1.1 mrg
72 1.1 mrg return error;
73 1.1 mrg }
74 1.1 mrg
75 1.1 mrg static int
76 1.1 mrg nfssvc32_setexports_in(struct mountd_exports_list *mel, const void *argp)
77 1.1 mrg {
78 1.1 mrg struct netbsd32_mountd_exports_list args32;
79 1.1 mrg int error;
80 1.1 mrg
81 1.1 mrg error = copyin(argp, &args32, sizeof args32);
82 1.1 mrg if (!error) {
83 1.1 mrg mel->mel_path = NETBSD32PTR64(args32.mel_path);
84 1.1 mrg mel->mel_nexports = args32.mel_nexports;
85 1.1 mrg mel->mel_exports = NETBSD32PTR64(args32.mel_exports);
86 1.1 mrg }
87 1.1 mrg
88 1.1 mrg return error;
89 1.1 mrg }
90 1.1 mrg
91 1.1 mrg static int
92 1.1 mrg nfssvc32_nsd_in(struct nfsd_srvargs *nsd, const void *argp)
93 1.1 mrg {
94 1.1 mrg struct netbsd32_nfsd_srvargs args32;
95 1.1 mrg int error;
96 1.1 mrg
97 1.1 mrg error = copyin(argp, &args32, sizeof args32);
98 1.1 mrg if (!error) {
99 1.1 mrg nsd->nsd_nfsd = NETBSD32PTR64(args32.nsd_nfsd);
100 1.1 mrg nsd->nsd_uid = args32.nsd_uid;
101 1.1 mrg nsd->nsd_haddr = args32.nsd_haddr;
102 1.1 mrg nsd->nsd_cr = args32.nsd_cr;
103 1.1 mrg nsd->nsd_authlen = args32.nsd_authlen;
104 1.1 mrg nsd->nsd_authstr = NETBSD32PTR64(args32.nsd_authstr);
105 1.1 mrg nsd->nsd_verflen = args32.nsd_verflen;
106 1.1 mrg nsd->nsd_uid = args32.nsd_uid;
107 1.1 mrg netbsd32_to_timeval(&args32.nsd_timestamp, &nsd->nsd_timestamp);
108 1.1 mrg nsd->nsd_ttl = args32.nsd_ttl;
109 1.1 mrg nsd->nsd_key[0] = args32.nsd_key[0];
110 1.1 mrg nsd->nsd_key[1] = args32.nsd_key[1];
111 1.1 mrg }
112 1.1 mrg
113 1.1 mrg return error;
114 1.1 mrg }
115 1.1 mrg
116 1.1 mrg static int
117 1.1 mrg nfssvc32_nsd_out(void *argp, const struct nfsd_srvargs *nsd)
118 1.1 mrg {
119 1.1 mrg struct netbsd32_nfsd_srvargs args32;
120 1.1 mrg
121 1.1 mrg NETBSD32PTR32(args32.nsd_nfsd, nsd->nsd_nfsd);
122 1.1 mrg args32.nsd_uid = nsd->nsd_uid;
123 1.1 mrg args32.nsd_haddr = nsd->nsd_haddr;
124 1.1 mrg args32.nsd_cr = nsd->nsd_cr;
125 1.1 mrg args32.nsd_authlen = nsd->nsd_authlen;
126 1.1 mrg NETBSD32PTR32(args32.nsd_authstr, nsd->nsd_authstr);
127 1.1 mrg args32.nsd_verflen = nsd->nsd_verflen;
128 1.1 mrg args32.nsd_uid = nsd->nsd_uid;
129 1.1 mrg netbsd32_from_timeval(&nsd->nsd_timestamp, &args32.nsd_timestamp);
130 1.1 mrg args32.nsd_ttl = nsd->nsd_ttl;
131 1.1 mrg args32.nsd_key[0] = nsd->nsd_key[0];
132 1.1 mrg args32.nsd_key[1] = nsd->nsd_key[1];
133 1.1 mrg
134 1.1 mrg return copyout(nsd, argp, sizeof *nsd);
135 1.1 mrg }
136 1.1 mrg
137 1.1 mrg static int
138 1.1 mrg nfssvc32_exp_in(struct export_args *exp, const void *argp, size_t nexports)
139 1.1 mrg {
140 1.1 mrg struct netbsd32_export_args args32;
141 1.1 mrg int error = 0;
142 1.1 mrg
143 1.1 mrg for (size_t i = 0; i < nexports; i++) {
144 1.1 mrg error = copyin(argp, &args32, sizeof args32);
145 1.1 mrg if (error)
146 1.1 mrg break;
147 1.1 mrg exp->ex_flags = args32.ex_flags;
148 1.1 mrg exp->ex_root = args32.ex_root;
149 1.1 mrg exp->ex_anon = args32.ex_anon;
150 1.1 mrg exp->ex_addr = NETBSD32PTR64(args32.ex_addr);
151 1.1 mrg exp->ex_addrlen = args32.ex_addrlen;
152 1.1 mrg exp->ex_mask = NETBSD32PTR64(args32.ex_mask);
153 1.1 mrg exp->ex_masklen = args32.ex_masklen;
154 1.1 mrg exp->ex_indexfile = NETBSD32PTR64(args32.ex_indexfile);
155 1.1 mrg exp++;
156 1.1 mrg }
157 1.1 mrg
158 1.1 mrg return error;
159 1.1 mrg }
160 1.1 mrg
161 1.1 mrg /*
162 1.1 mrg * NFS server system calls
163 1.1 mrg */
164 1.1 mrg
165 1.1 mrg static struct nfssvc_copy_ops netbsd32_ops = {
166 1.1 mrg .addsock_in = nfssvc32_addsock_in,
167 1.1 mrg .setexports_in = nfssvc32_setexports_in,
168 1.1 mrg .nsd_in = nfssvc32_nsd_in,
169 1.1 mrg .nsd_out = nfssvc32_nsd_out,
170 1.1 mrg .exp_in = nfssvc32_exp_in,
171 1.1 mrg };
172 1.1 mrg
173 1.1 mrg int
174 1.1 mrg netbsd32_nfssvc(struct lwp *l, const struct netbsd32_nfssvc_args *uap,
175 1.1 mrg register_t *retval)
176 1.1 mrg {
177 1.1 mrg /* {
178 1.1 mrg syscallarg(int) flag;
179 1.1 mrg syscallarg(netbsd32_voidp *) argp;
180 1.1 mrg } */
181 1.1 mrg int flag = SCARG(uap, flag);
182 1.1 mrg void *argp = SCARG_P32(uap, argp);
183 1.1 mrg
184 1.1 mrg return do_nfssvc(&netbsd32_ops, l, flag, argp, retval);
185 1.1 mrg }
186