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