1 /* $NetBSD: netbsd32_quota.c,v 1.3 2020/03/12 15:02:29 pgoyette Exp $ */
2
3 /*
4 * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * from: NetBSD: netbsd32_netbsd.c,v 1.218 2018/08/10 21:44:58 pgoyette Exp
29 */
30
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: netbsd32_quota.c,v 1.3 2020/03/12 15:02:29 pgoyette Exp $");
33
34 #ifdef _KERNEL_OPT
35 #include "opt_quota.h"
36 #endif
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/quotactl.h>
41 #include <sys/module.h>
42 #include <sys/vfs_syscalls.h>
43 #include <sys/syscallvar.h>
44
45 #include <compat/netbsd32/netbsd32.h>
46 #include <compat/netbsd32/netbsd32_syscall.h>
47 #include <compat/netbsd32/netbsd32_syscallargs.h>
48
49 #ifdef QUOTA
50 int
netbsd32___quotactl(struct lwp * l,const struct netbsd32___quotactl_args * uap,register_t * retval)51 netbsd32___quotactl(struct lwp *l, const struct netbsd32___quotactl_args *uap, register_t *retval)
52 {
53 /* {
54 syscallarg(const netbsd32_charp) path;
55 syscallarg(netbsd32_voidp) args;
56 } */
57 struct netbsd32_quotactlargs args32;
58 struct quotactl_args args;
59 int error;
60
61 error = copyin(SCARG_P32(uap, args), &args32, sizeof(args32));
62 if (error) {
63 return error;
64 }
65
66 args.qc_op = args32.qc_op;
67 switch (args.qc_op) {
68 case QUOTACTL_STAT:
69 args.u.stat.qc_info = NETBSD32PTR64(args32.u.stat.qc_info);
70 break;
71 case QUOTACTL_IDTYPESTAT:
72 args.u.idtypestat.qc_idtype = args32.u.idtypestat.qc_idtype;
73 args.u.idtypestat.qc_info =
74 NETBSD32PTR64(args32.u.idtypestat.qc_info);
75 break;
76 case QUOTACTL_OBJTYPESTAT:
77 args.u.objtypestat.qc_objtype =
78 args32.u.objtypestat.qc_objtype;
79 args.u.objtypestat.qc_info =
80 NETBSD32PTR64(args32.u.objtypestat.qc_info);
81 break;
82 case QUOTACTL_GET:
83 args.u.get.qc_key = NETBSD32PTR64(args32.u.get.qc_key);
84 args.u.get.qc_val = NETBSD32PTR64(args32.u.get.qc_val);
85 break;
86 case QUOTACTL_PUT:
87 args.u.put.qc_key = NETBSD32PTR64(args32.u.put.qc_key);
88 args.u.put.qc_val = NETBSD32PTR64(args32.u.put.qc_val);
89 break;
90 case QUOTACTL_DEL:
91 args.u.del.qc_key = NETBSD32PTR64(args32.u.del.qc_key);
92 break;
93 case QUOTACTL_CURSOROPEN:
94 args.u.cursoropen.qc_cursor =
95 NETBSD32PTR64(args32.u.cursoropen.qc_cursor);
96 break;
97 case QUOTACTL_CURSORCLOSE:
98 args.u.cursorclose.qc_cursor =
99 NETBSD32PTR64(args32.u.cursorclose.qc_cursor);
100 break;
101 case QUOTACTL_CURSORSKIPIDTYPE:
102 args.u.cursorskipidtype.qc_cursor =
103 NETBSD32PTR64(args32.u.cursorskipidtype.qc_cursor);
104 args.u.cursorskipidtype.qc_idtype =
105 args32.u.cursorskipidtype.qc_idtype;
106 break;
107 case QUOTACTL_CURSORGET:
108 args.u.cursorget.qc_cursor =
109 NETBSD32PTR64(args32.u.cursorget.qc_cursor);
110 args.u.cursorget.qc_keys =
111 NETBSD32PTR64(args32.u.cursorget.qc_keys);
112 args.u.cursorget.qc_vals =
113 NETBSD32PTR64(args32.u.cursorget.qc_vals);
114 args.u.cursorget.qc_maxnum =
115 args32.u.cursorget.qc_maxnum;
116 args.u.cursorget.qc_ret =
117 NETBSD32PTR64(args32.u.cursorget.qc_ret);
118 break;
119 case QUOTACTL_CURSORATEND:
120 args.u.cursoratend.qc_cursor =
121 NETBSD32PTR64(args32.u.cursoratend.qc_cursor);
122 args.u.cursoratend.qc_ret =
123 NETBSD32PTR64(args32.u.cursoratend.qc_ret);
124 break;
125 case QUOTACTL_CURSORREWIND:
126 args.u.cursorrewind.qc_cursor =
127 NETBSD32PTR64(args32.u.cursorrewind.qc_cursor);
128 break;
129 case QUOTACTL_QUOTAON:
130 args.u.quotaon.qc_idtype = args32.u.quotaon.qc_idtype;
131 args.u.quotaon.qc_quotafile =
132 NETBSD32PTR64(args32.u.quotaon.qc_quotafile);
133 break;
134 case QUOTACTL_QUOTAOFF:
135 args.u.quotaoff.qc_idtype = args32.u.quotaoff.qc_idtype;
136 break;
137 default:
138 return EINVAL;
139 }
140
141 return do_sys_quotactl(SCARG_P32(uap, path), &args);
142 }
143 static struct syscall_package compat_netbsd32_quota_syscalls[] = {
144 { NETBSD32_SYS_netbsd32___quotactl, 0,
145 (sy_call_t *)netbsd32___quotactl },
146 { 0, 0, NULL }
147 };
148
149 MODULE(MODULE_CLASS_EXEC, compat_netbsd32_quota, "compat_netbsd32");
150
151 static int
compat_netbsd32_quota_modcmd(modcmd_t cmd,void * arg)152 compat_netbsd32_quota_modcmd(modcmd_t cmd, void *arg)
153 {
154 int ret;
155
156 switch (cmd) {
157 case MODULE_CMD_INIT:
158 ret = syscall_establish(&emul_netbsd32,
159 compat_netbsd32_quota_syscalls);
160 return ret;
161 case MODULE_CMD_FINI:
162 ret = syscall_disestablish(&emul_netbsd32,
163 compat_netbsd32_quota_syscalls);
164 return ret;
165 default:
166 return ENOTTY;
167 }
168 }
169 #endif
170