xref: /netbsd-src/sys/compat/netbsd32/netbsd32_quota.c (revision 4b5fc12da6e91290951ae2640fcfd7b4b0d46630)
1*4b5fc12dSpgoyette /*	$NetBSD: netbsd32_quota.c,v 1.3 2020/03/12 15:02:29 pgoyette Exp $	*/
280c61288Smrg 
380c61288Smrg /*
480c61288Smrg  * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green
580c61288Smrg  * All rights reserved.
680c61288Smrg  *
780c61288Smrg  * Redistribution and use in source and binary forms, with or without
880c61288Smrg  * modification, are permitted provided that the following conditions
980c61288Smrg  * are met:
1080c61288Smrg  * 1. Redistributions of source code must retain the above copyright
1180c61288Smrg  *    notice, this list of conditions and the following disclaimer.
1280c61288Smrg  * 2. Redistributions in binary form must reproduce the above copyright
1380c61288Smrg  *    notice, this list of conditions and the following disclaimer in the
1480c61288Smrg  *    documentation and/or other materials provided with the distribution.
1580c61288Smrg  *
1680c61288Smrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1780c61288Smrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1880c61288Smrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1980c61288Smrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2080c61288Smrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2180c61288Smrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2280c61288Smrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2380c61288Smrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2480c61288Smrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2580c61288Smrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2680c61288Smrg  * SUCH DAMAGE.
2780c61288Smrg  *
2880c61288Smrg  * from: NetBSD: netbsd32_netbsd.c,v 1.218 2018/08/10 21:44:58 pgoyette Exp
2980c61288Smrg  */
3080c61288Smrg 
3180c61288Smrg #include <sys/cdefs.h>
32*4b5fc12dSpgoyette __KERNEL_RCSID(0, "$NetBSD: netbsd32_quota.c,v 1.3 2020/03/12 15:02:29 pgoyette Exp $");
339ab1edd4Schristos 
349ab1edd4Schristos #ifdef _KERNEL_OPT
359ab1edd4Schristos #include "opt_quota.h"
369ab1edd4Schristos #endif
3780c61288Smrg 
3880c61288Smrg #include <sys/param.h>
3980c61288Smrg #include <sys/systm.h>
4080c61288Smrg #include <sys/quotactl.h>
41*4b5fc12dSpgoyette #include <sys/module.h>
4280c61288Smrg #include <sys/vfs_syscalls.h>
43*4b5fc12dSpgoyette #include <sys/syscallvar.h>
4480c61288Smrg 
4580c61288Smrg #include <compat/netbsd32/netbsd32.h>
4680c61288Smrg #include <compat/netbsd32/netbsd32_syscall.h>
4780c61288Smrg #include <compat/netbsd32/netbsd32_syscallargs.h>
4880c61288Smrg 
499ab1edd4Schristos #ifdef QUOTA
5080c61288Smrg int
netbsd32___quotactl(struct lwp * l,const struct netbsd32___quotactl_args * uap,register_t * retval)5180c61288Smrg netbsd32___quotactl(struct lwp *l, const struct netbsd32___quotactl_args *uap, register_t *retval)
5280c61288Smrg {
5380c61288Smrg 	/* {
5480c61288Smrg 		syscallarg(const netbsd32_charp) path;
5580c61288Smrg 		syscallarg(netbsd32_voidp) args;
5680c61288Smrg 	} */
5780c61288Smrg 	struct netbsd32_quotactlargs args32;
5880c61288Smrg 	struct quotactl_args args;
5980c61288Smrg 	int error;
6080c61288Smrg 
6180c61288Smrg 	error = copyin(SCARG_P32(uap, args), &args32, sizeof(args32));
6280c61288Smrg 	if (error) {
6380c61288Smrg 		return error;
6480c61288Smrg 	}
6580c61288Smrg 
6680c61288Smrg 	args.qc_op = args32.qc_op;
6780c61288Smrg 	switch (args.qc_op) {
6880c61288Smrg 	    case QUOTACTL_STAT:
6980c61288Smrg 		args.u.stat.qc_info = NETBSD32PTR64(args32.u.stat.qc_info);
7080c61288Smrg 		break;
7180c61288Smrg 	    case QUOTACTL_IDTYPESTAT:
7280c61288Smrg 		args.u.idtypestat.qc_idtype = args32.u.idtypestat.qc_idtype;
7380c61288Smrg 		args.u.idtypestat.qc_info =
7480c61288Smrg 			NETBSD32PTR64(args32.u.idtypestat.qc_info);
7580c61288Smrg 		break;
7680c61288Smrg 	    case QUOTACTL_OBJTYPESTAT:
7780c61288Smrg 		args.u.objtypestat.qc_objtype =
7880c61288Smrg 			args32.u.objtypestat.qc_objtype;
7980c61288Smrg 		args.u.objtypestat.qc_info =
8080c61288Smrg 			NETBSD32PTR64(args32.u.objtypestat.qc_info);
8180c61288Smrg 		break;
8280c61288Smrg 	    case QUOTACTL_GET:
8380c61288Smrg 		args.u.get.qc_key = NETBSD32PTR64(args32.u.get.qc_key);
8480c61288Smrg 		args.u.get.qc_val = NETBSD32PTR64(args32.u.get.qc_val);
8580c61288Smrg 		break;
8680c61288Smrg 	    case QUOTACTL_PUT:
8780c61288Smrg 		args.u.put.qc_key = NETBSD32PTR64(args32.u.put.qc_key);
8880c61288Smrg 		args.u.put.qc_val = NETBSD32PTR64(args32.u.put.qc_val);
8980c61288Smrg 		break;
9080c61288Smrg 	    case QUOTACTL_DEL:
9180c61288Smrg 		args.u.del.qc_key = NETBSD32PTR64(args32.u.del.qc_key);
9280c61288Smrg 		break;
9380c61288Smrg 	    case QUOTACTL_CURSOROPEN:
9480c61288Smrg 		args.u.cursoropen.qc_cursor =
9580c61288Smrg 			NETBSD32PTR64(args32.u.cursoropen.qc_cursor);
9680c61288Smrg 		break;
9780c61288Smrg 	    case QUOTACTL_CURSORCLOSE:
9880c61288Smrg 		args.u.cursorclose.qc_cursor =
9980c61288Smrg 			NETBSD32PTR64(args32.u.cursorclose.qc_cursor);
10080c61288Smrg 		break;
10180c61288Smrg 	    case QUOTACTL_CURSORSKIPIDTYPE:
10280c61288Smrg 		args.u.cursorskipidtype.qc_cursor =
10380c61288Smrg 			NETBSD32PTR64(args32.u.cursorskipidtype.qc_cursor);
10480c61288Smrg 		args.u.cursorskipidtype.qc_idtype =
10580c61288Smrg 			args32.u.cursorskipidtype.qc_idtype;
10680c61288Smrg 		break;
10780c61288Smrg 	    case QUOTACTL_CURSORGET:
10880c61288Smrg 		args.u.cursorget.qc_cursor =
10980c61288Smrg 			NETBSD32PTR64(args32.u.cursorget.qc_cursor);
11080c61288Smrg 		args.u.cursorget.qc_keys =
11180c61288Smrg 			NETBSD32PTR64(args32.u.cursorget.qc_keys);
11280c61288Smrg 		args.u.cursorget.qc_vals =
11380c61288Smrg 			NETBSD32PTR64(args32.u.cursorget.qc_vals);
11480c61288Smrg 		args.u.cursorget.qc_maxnum =
11580c61288Smrg 			args32.u.cursorget.qc_maxnum;
11680c61288Smrg 		args.u.cursorget.qc_ret =
11780c61288Smrg 			NETBSD32PTR64(args32.u.cursorget.qc_ret);
11880c61288Smrg 		break;
11980c61288Smrg 	    case QUOTACTL_CURSORATEND:
12080c61288Smrg 		args.u.cursoratend.qc_cursor =
12180c61288Smrg 			NETBSD32PTR64(args32.u.cursoratend.qc_cursor);
12280c61288Smrg 		args.u.cursoratend.qc_ret =
12380c61288Smrg 			NETBSD32PTR64(args32.u.cursoratend.qc_ret);
12480c61288Smrg 		break;
12580c61288Smrg 	    case QUOTACTL_CURSORREWIND:
12680c61288Smrg 		args.u.cursorrewind.qc_cursor =
12780c61288Smrg 			NETBSD32PTR64(args32.u.cursorrewind.qc_cursor);
12880c61288Smrg 		break;
12980c61288Smrg 	    case QUOTACTL_QUOTAON:
13080c61288Smrg 		args.u.quotaon.qc_idtype = args32.u.quotaon.qc_idtype;
13180c61288Smrg 		args.u.quotaon.qc_quotafile =
13280c61288Smrg 			NETBSD32PTR64(args32.u.quotaon.qc_quotafile);
13380c61288Smrg 		break;
13480c61288Smrg 	    case QUOTACTL_QUOTAOFF:
13580c61288Smrg 		args.u.quotaoff.qc_idtype = args32.u.quotaoff.qc_idtype;
13680c61288Smrg 		break;
13780c61288Smrg 	    default:
13880c61288Smrg 		return EINVAL;
13980c61288Smrg 	}
14080c61288Smrg 
14180c61288Smrg 	return do_sys_quotactl(SCARG_P32(uap, path), &args);
14280c61288Smrg }
143*4b5fc12dSpgoyette static struct syscall_package compat_netbsd32_quota_syscalls[] = {
144*4b5fc12dSpgoyette 	{ NETBSD32_SYS_netbsd32___quotactl, 0,
145*4b5fc12dSpgoyette 	    (sy_call_t *)netbsd32___quotactl },
146*4b5fc12dSpgoyette 	{ 0, 0, NULL }
147*4b5fc12dSpgoyette };
148*4b5fc12dSpgoyette 
149*4b5fc12dSpgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_quota, "compat_netbsd32");
150*4b5fc12dSpgoyette 
151*4b5fc12dSpgoyette static int
compat_netbsd32_quota_modcmd(modcmd_t cmd,void * arg)152*4b5fc12dSpgoyette compat_netbsd32_quota_modcmd(modcmd_t cmd, void *arg)
153*4b5fc12dSpgoyette {
154*4b5fc12dSpgoyette 	int ret;
155*4b5fc12dSpgoyette 
156*4b5fc12dSpgoyette 	switch (cmd) {
157*4b5fc12dSpgoyette 	case MODULE_CMD_INIT:
158*4b5fc12dSpgoyette 		ret = syscall_establish(&emul_netbsd32,
159*4b5fc12dSpgoyette 		    compat_netbsd32_quota_syscalls);
160*4b5fc12dSpgoyette 		return ret;
161*4b5fc12dSpgoyette 	case MODULE_CMD_FINI:
162*4b5fc12dSpgoyette 		ret = syscall_disestablish(&emul_netbsd32,
163*4b5fc12dSpgoyette 		    compat_netbsd32_quota_syscalls);
164*4b5fc12dSpgoyette 		return ret;
165*4b5fc12dSpgoyette 	default:
166*4b5fc12dSpgoyette 		return ENOTTY;
167*4b5fc12dSpgoyette 	}
168*4b5fc12dSpgoyette }
1699ab1edd4Schristos #endif
170