netbsd32_compat_90.c revision 1.1 1 1.1 christos /* $NetBSD: netbsd32_compat_90.c,v 1.1 2019/09/22 22:59:38 christos Exp $ */
2 1.1 christos
3 1.1 christos /*-
4 1.1 christos * Copyright (c) 2019 The NetBSD Foundation, Inc.
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * This code is derived from software developed for The NetBSD Foundation
8 1.1 christos * by Christos Zoulas.
9 1.1 christos *
10 1.1 christos * Redistribution and use in source and binary forms, with or without
11 1.1 christos * modification, are permitted provided that the following conditions
12 1.1 christos * are met:
13 1.1 christos * 1. Redistributions of source code must retain the above copyright
14 1.1 christos * notice, this list of conditions and the following disclaimer.
15 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 christos * notice, this list of conditions and the following disclaimer in the
17 1.1 christos * documentation and/or other materials provided with the distribution.
18 1.1 christos *
19 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
30 1.1 christos */
31 1.1 christos
32 1.1 christos #include <sys/cdefs.h>
33 1.1 christos __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_90.c,v 1.1 2019/09/22 22:59:38 christos Exp $");
34 1.1 christos
35 1.1 christos #include <sys/param.h>
36 1.1 christos #include <sys/kmem.h>
37 1.1 christos #include <sys/module.h>
38 1.1 christos #include <sys/filedesc.h>
39 1.1 christos #include <sys/statvfs.h>
40 1.1 christos #include <sys/vfs_syscalls.h>
41 1.1 christos #include <sys/syscallvar.h>
42 1.1 christos
43 1.1 christos #include <compat/netbsd32/netbsd32.h>
44 1.1 christos #include <compat/netbsd32/netbsd32_syscall.h>
45 1.1 christos #include <compat/netbsd32/netbsd32_syscallargs.h>
46 1.1 christos #include <compat/netbsd32/netbsd32_conv.h>
47 1.1 christos
48 1.1 christos static int
49 1.1 christos netbsd32_copyout_statvfs90(const void *kp, void *up, size_t len)
50 1.1 christos {
51 1.1 christos struct netbsd32_statvfs90 *sbuf_32;
52 1.1 christos int error;
53 1.1 christos
54 1.1 christos sbuf_32 = kmem_alloc(sizeof(*sbuf_32), KM_SLEEP);
55 1.1 christos netbsd32_from_statvfs90(kp, sbuf_32);
56 1.1 christos error = copyout(sbuf_32, up, sizeof(*sbuf_32));
57 1.1 christos kmem_free(sbuf_32, sizeof(*sbuf_32));
58 1.1 christos
59 1.1 christos return error;
60 1.1 christos }
61 1.1 christos
62 1.1 christos int
63 1.1 christos compat_90_netbsd32_getvfsstat(struct lwp *l,
64 1.1 christos const struct compat_90_netbsd32_getvfsstat_args *uap, register_t *retval)
65 1.1 christos {
66 1.1 christos /* {
67 1.1 christos syscallarg(netbsd32_statvfs90p_t) buf;
68 1.1 christos syscallarg(netbsd32_size_t) bufsize;
69 1.1 christos syscallarg(int) flags;
70 1.1 christos } */
71 1.1 christos
72 1.1 christos return do_sys_getvfsstat(l, SCARG_P32(uap, buf), SCARG(uap, bufsize),
73 1.1 christos SCARG(uap, flags), netbsd32_copyout_statvfs90,
74 1.1 christos sizeof(struct netbsd32_statvfs90), retval);
75 1.1 christos }
76 1.1 christos
77 1.1 christos int
78 1.1 christos compat_90_netbsd32_statvfs1(struct lwp *l,
79 1.1 christos const struct compat_90_netbsd32_statvfs1_args *uap, register_t *retval)
80 1.1 christos {
81 1.1 christos /* {
82 1.1 christos syscallarg(const netbsd32_charp) path;
83 1.1 christos syscallarg(netbsd32_statvfs90p_t) buf;
84 1.1 christos syscallarg(int) flags;
85 1.1 christos } */
86 1.1 christos struct statvfs *sb;
87 1.1 christos int error;
88 1.1 christos
89 1.1 christos sb = STATVFSBUF_GET();
90 1.1 christos error = do_sys_pstatvfs(l, SCARG_P32(uap, path), SCARG(uap, flags), sb);
91 1.1 christos if (error == 0)
92 1.1 christos error = netbsd32_copyout_statvfs90(sb, SCARG_P32(uap, buf),
93 1.1 christos sizeof(struct netbsd32_statvfs90));
94 1.1 christos STATVFSBUF_PUT(sb);
95 1.1 christos return error;
96 1.1 christos }
97 1.1 christos
98 1.1 christos int
99 1.1 christos compat_90_netbsd32_fstatvfs1(struct lwp *l,
100 1.1 christos const struct compat_90_netbsd32_fstatvfs1_args *uap, register_t *retval)
101 1.1 christos {
102 1.1 christos /* {
103 1.1 christos syscallarg(int) fd;
104 1.1 christos syscallarg(netbsd32_statvfs90p_t) buf;
105 1.1 christos syscallarg(int) flags;
106 1.1 christos } */
107 1.1 christos struct statvfs *sb;
108 1.1 christos int error;
109 1.1 christos
110 1.1 christos sb = STATVFSBUF_GET();
111 1.1 christos error = do_sys_fstatvfs(l, SCARG(uap, fd), SCARG(uap, flags), sb);
112 1.1 christos if (error == 0)
113 1.1 christos error = netbsd32_copyout_statvfs90(sb, SCARG_P32(uap, buf), 0);
114 1.1 christos STATVFSBUF_PUT(sb);
115 1.1 christos return error;
116 1.1 christos }
117 1.1 christos
118 1.1 christos
119 1.1 christos int
120 1.1 christos compat_90_netbsd32_fhstatvfs1(struct lwp *l,
121 1.1 christos const struct compat_90_netbsd32_fhstatvfs1_args *uap, register_t *retval)
122 1.1 christos {
123 1.1 christos /* {
124 1.1 christos syscallarg(const netbsd32_pointer_t) fhp;
125 1.1 christos syscallarg(netbsd32_size_t) fh_size;
126 1.1 christos syscallarg(netbsd32_statvfs90p_t) buf;
127 1.1 christos syscallarg(int) flags;
128 1.1 christos } */
129 1.1 christos struct statvfs *sb;
130 1.1 christos int error;
131 1.1 christos
132 1.1 christos sb = STATVFSBUF_GET();
133 1.1 christos error = do_fhstatvfs(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), sb,
134 1.1 christos SCARG(uap, flags));
135 1.1 christos
136 1.1 christos if (error == 0)
137 1.1 christos error = netbsd32_copyout_statvfs90(sb, SCARG_P32(uap, buf), 0);
138 1.1 christos STATVFSBUF_PUT(sb);
139 1.1 christos
140 1.1 christos return error;
141 1.1 christos }
142 1.1 christos
143 1.1 christos static struct syscall_package compat_netbsd32_90_syscalls[] = {
144 1.1 christos { NETBSD32_SYS_compat_90_netbsd32_getvfsstat, 0,
145 1.1 christos (sy_call_t *)compat_90_netbsd32_getvfsstat },
146 1.1 christos { NETBSD32_SYS_compat_90_netbsd32_statvfs1, 0,
147 1.1 christos (sy_call_t *)compat_90_netbsd32_statvfs1 },
148 1.1 christos { NETBSD32_SYS_compat_90_netbsd32_fstatvfs1, 0,
149 1.1 christos (sy_call_t *)compat_90_netbsd32_fstatvfs1 },
150 1.1 christos { NETBSD32_SYS_compat_90_netbsd32_fhstatvfs1, 0,
151 1.1 christos (sy_call_t *)compat_90_netbsd32_fhstatvfs1 },
152 1.1 christos { 0, 0, NULL }
153 1.1 christos };
154 1.1 christos
155 1.1 christos MODULE(MODULE_CLASS_EXEC, compat_netbsd32_90, "compat_netbsd32,compat_90");
156 1.1 christos
157 1.1 christos static int
158 1.1 christos compat_netbsd32_90_modcmd(modcmd_t cmd, void *arg)
159 1.1 christos {
160 1.1 christos
161 1.1 christos switch (cmd) {
162 1.1 christos case MODULE_CMD_INIT:
163 1.1 christos return syscall_establish(&emul_netbsd32,
164 1.1 christos compat_netbsd32_90_syscalls);
165 1.1 christos
166 1.1 christos case MODULE_CMD_FINI:
167 1.1 christos return syscall_disestablish(&emul_netbsd32,
168 1.1 christos compat_netbsd32_90_syscalls);
169 1.1 christos
170 1.1 christos default:
171 1.1 christos return ENOTTY;
172 1.1 christos }
173 1.1 christos }
174