Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_nfssvc.c revision 1.7
      1  1.7  riastrad /*	$NetBSD: netbsd32_nfssvc.c,v 1.7 2021/08/30 08:39:24 riastradh 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.7  riastrad __KERNEL_RCSID(0, "$NetBSD: netbsd32_nfssvc.c,v 1.7 2021/08/30 08:39:24 riastradh Exp $");
     33  1.1       mrg 
     34  1.1       mrg #if defined(_KERNEL_OPT)
     35  1.1       mrg #include "opt_nfs.h"
     36  1.2  dholland #include "opt_nfsserver.h"
     37  1.1       mrg #include "opt_compat_netbsd.h"
     38  1.1       mrg #endif
     39  1.1       mrg 
     40  1.1       mrg #include <sys/param.h>
     41  1.1       mrg #include <sys/vnode.h>
     42  1.1       mrg #include <sys/filedesc.h>
     43  1.4  pgoyette #include <sys/module.h>
     44  1.4  pgoyette #include <sys/syscallvar.h>
     45  1.1       mrg 
     46  1.1       mrg #include <compat/netbsd32/netbsd32.h>
     47  1.1       mrg #include <compat/netbsd32/netbsd32_syscall.h>
     48  1.1       mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
     49  1.1       mrg #include <compat/netbsd32/netbsd32_conv.h>
     50  1.1       mrg 
     51  1.1       mrg #include <nfs/rpcv2.h>
     52  1.1       mrg #include <nfs/nfsproto.h>
     53  1.1       mrg #include <nfs/nfs.h>
     54  1.1       mrg #include <nfs/nfs_var.h>
     55  1.1       mrg 
     56  1.1       mrg static int nfssvc32_addsock_in(struct nfsd_args *, const void *);
     57  1.1       mrg static int nfssvc32_setexports_in(struct mountd_exports_list *, const void *);
     58  1.1       mrg static int nfssvc32_nsd_in(struct nfsd_srvargs *, const void *);
     59  1.1       mrg static int nfssvc32_nsd_out(void *, const struct nfsd_srvargs *);
     60  1.1       mrg static int nfssvc32_exp_in(struct export_args *, const void *, size_t);
     61  1.1       mrg 
     62  1.1       mrg static int
     63  1.1       mrg nfssvc32_addsock_in(struct nfsd_args *nfsdarg, const void *argp)
     64  1.1       mrg {
     65  1.1       mrg 	struct netbsd32_nfsd_args args32;
     66  1.1       mrg 	int error;
     67  1.1       mrg 
     68  1.1       mrg 	error = copyin(argp, &args32, sizeof args32);
     69  1.1       mrg 	if (!error) {
     70  1.1       mrg 		nfsdarg->sock = args32.sock;
     71  1.1       mrg 		nfsdarg->name = NETBSD32PTR64(args32.name);
     72  1.1       mrg 		nfsdarg->namelen = args32.namelen;
     73  1.1       mrg 	}
     74  1.1       mrg 
     75  1.1       mrg 	return error;
     76  1.1       mrg }
     77  1.1       mrg 
     78  1.1       mrg static int
     79  1.1       mrg nfssvc32_setexports_in(struct mountd_exports_list *mel, const void *argp)
     80  1.1       mrg {
     81  1.1       mrg 	struct netbsd32_mountd_exports_list args32;
     82  1.1       mrg 	int error;
     83  1.1       mrg 
     84  1.1       mrg 	error = copyin(argp, &args32, sizeof args32);
     85  1.1       mrg 	if (!error) {
     86  1.1       mrg 		mel->mel_path = NETBSD32PTR64(args32.mel_path);
     87  1.1       mrg 		mel->mel_nexports = args32.mel_nexports;
     88  1.1       mrg 		mel->mel_exports = NETBSD32PTR64(args32.mel_exports);
     89  1.1       mrg 	}
     90  1.1       mrg 
     91  1.1       mrg 	return error;
     92  1.1       mrg }
     93  1.1       mrg 
     94  1.1       mrg static int
     95  1.1       mrg nfssvc32_nsd_in(struct nfsd_srvargs *nsd, const void *argp)
     96  1.1       mrg {
     97  1.1       mrg 	struct netbsd32_nfsd_srvargs args32;
     98  1.1       mrg 	int error;
     99  1.1       mrg 
    100  1.1       mrg 	error = copyin(argp, &args32, sizeof args32);
    101  1.1       mrg 	if (!error) {
    102  1.1       mrg 		nsd->nsd_nfsd = NETBSD32PTR64(args32.nsd_nfsd);
    103  1.1       mrg 		nsd->nsd_uid = args32.nsd_uid;
    104  1.1       mrg 		nsd->nsd_haddr = args32.nsd_haddr;
    105  1.1       mrg 		nsd->nsd_cr = args32.nsd_cr;
    106  1.1       mrg 		nsd->nsd_authlen = args32.nsd_authlen;
    107  1.1       mrg 		nsd->nsd_authstr = NETBSD32PTR64(args32.nsd_authstr);
    108  1.1       mrg 		nsd->nsd_verflen = args32.nsd_verflen;
    109  1.1       mrg 		nsd->nsd_uid = args32.nsd_uid;
    110  1.1       mrg 		netbsd32_to_timeval(&args32.nsd_timestamp, &nsd->nsd_timestamp);
    111  1.1       mrg 		nsd->nsd_ttl = args32.nsd_ttl;
    112  1.1       mrg 		nsd->nsd_key[0] = args32.nsd_key[0];
    113  1.1       mrg 		nsd->nsd_key[1] = args32.nsd_key[1];
    114  1.1       mrg 	}
    115  1.1       mrg 
    116  1.1       mrg 	return error;
    117  1.1       mrg }
    118  1.1       mrg 
    119  1.1       mrg static int
    120  1.1       mrg nfssvc32_nsd_out(void *argp, const struct nfsd_srvargs *nsd)
    121  1.1       mrg {
    122  1.1       mrg 	struct netbsd32_nfsd_srvargs args32;
    123  1.1       mrg 
    124  1.1       mrg 	NETBSD32PTR32(args32.nsd_nfsd, nsd->nsd_nfsd);
    125  1.1       mrg 	args32.nsd_uid = nsd->nsd_uid;
    126  1.1       mrg 	args32.nsd_haddr = nsd->nsd_haddr;
    127  1.1       mrg 	args32.nsd_cr = nsd->nsd_cr;
    128  1.1       mrg 	args32.nsd_authlen = nsd->nsd_authlen;
    129  1.1       mrg 	NETBSD32PTR32(args32.nsd_authstr, nsd->nsd_authstr);
    130  1.1       mrg 	args32.nsd_verflen = nsd->nsd_verflen;
    131  1.1       mrg 	args32.nsd_uid = nsd->nsd_uid;
    132  1.1       mrg 	netbsd32_from_timeval(&nsd->nsd_timestamp, &args32.nsd_timestamp);
    133  1.1       mrg 	args32.nsd_ttl = nsd->nsd_ttl;
    134  1.1       mrg 	args32.nsd_key[0] = nsd->nsd_key[0];
    135  1.1       mrg 	args32.nsd_key[1] = nsd->nsd_key[1];
    136  1.1       mrg 
    137  1.7  riastrad 	return copyout(&args32, argp, sizeof args32);
    138  1.1       mrg }
    139  1.1       mrg 
    140  1.1       mrg static int
    141  1.1       mrg nfssvc32_exp_in(struct export_args *exp, const void *argp, size_t nexports)
    142  1.1       mrg {
    143  1.3       mrg 	struct netbsd32_export_args exp32;
    144  1.3       mrg 	struct netbsd32_export_args const *argp32 = argp;
    145  1.1       mrg 	int error = 0;
    146  1.1       mrg 
    147  1.1       mrg 	for (size_t i = 0; i < nexports; i++) {
    148  1.3       mrg 		error = copyin(argp32, &exp32, sizeof exp32);
    149  1.1       mrg 		if (error)
    150  1.1       mrg 			break;
    151  1.3       mrg 		exp->ex_flags = exp32.ex_flags;
    152  1.3       mrg 		exp->ex_root = exp32.ex_root;
    153  1.3       mrg 		exp->ex_anon = exp32.ex_anon;
    154  1.3       mrg 		exp->ex_addr = NETBSD32PTR64(exp32.ex_addr);
    155  1.3       mrg 		exp->ex_addrlen = exp32.ex_addrlen;
    156  1.3       mrg 		exp->ex_mask = NETBSD32PTR64(exp32.ex_mask);
    157  1.3       mrg 		exp->ex_masklen = exp32.ex_masklen;
    158  1.3       mrg 		exp->ex_indexfile = NETBSD32PTR64(exp32.ex_indexfile);
    159  1.1       mrg 		exp++;
    160  1.3       mrg 		argp32++;
    161  1.1       mrg 	}
    162  1.1       mrg 
    163  1.1       mrg 	return error;
    164  1.1       mrg }
    165  1.1       mrg 
    166  1.1       mrg /*
    167  1.1       mrg  * NFS server system calls
    168  1.1       mrg  */
    169  1.1       mrg 
    170  1.1       mrg static struct nfssvc_copy_ops netbsd32_ops = {
    171  1.1       mrg 	.addsock_in = nfssvc32_addsock_in,
    172  1.1       mrg 	.setexports_in = nfssvc32_setexports_in,
    173  1.1       mrg 	.nsd_in = nfssvc32_nsd_in,
    174  1.1       mrg 	.nsd_out = nfssvc32_nsd_out,
    175  1.1       mrg 	.exp_in = nfssvc32_exp_in,
    176  1.1       mrg };
    177  1.1       mrg 
    178  1.1       mrg int
    179  1.1       mrg netbsd32_nfssvc(struct lwp *l, const struct netbsd32_nfssvc_args *uap,
    180  1.1       mrg     register_t *retval)
    181  1.1       mrg {
    182  1.1       mrg 	/* {
    183  1.1       mrg 		syscallarg(int) flag;
    184  1.1       mrg 		syscallarg(netbsd32_voidp *) argp;
    185  1.1       mrg 	} */
    186  1.1       mrg 	int	flag = SCARG(uap, flag);
    187  1.1       mrg 	void	*argp = SCARG_P32(uap, argp);
    188  1.1       mrg 
    189  1.1       mrg 	return do_nfssvc(&netbsd32_ops, l, flag, argp, retval);
    190  1.1       mrg }
    191  1.4  pgoyette 
    192  1.4  pgoyette static const struct syscall_package compat_nfssvc_syscalls[] = {
    193  1.4  pgoyette 	{ NETBSD32_SYS_netbsd32_nfssvc, 0, (sy_call_t *)netbsd32_nfssvc },
    194  1.4  pgoyette 	{ 0, 0, NULL },
    195  1.4  pgoyette };
    196  1.4  pgoyette 
    197  1.4  pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_nfssrv, "nfsserver,compat_netbsd32");
    198  1.4  pgoyette 
    199  1.5     skrll static int
    200  1.4  pgoyette compat_netbsd32_nfssrv_modcmd(modcmd_t cmd, void *arg)
    201  1.5     skrll {
    202  1.5     skrll 	int error;
    203  1.5     skrll 
    204  1.4  pgoyette 	switch (cmd) {
    205  1.4  pgoyette 	case MODULE_CMD_INIT:
    206  1.4  pgoyette 		error = syscall_establish(&emul_netbsd32,
    207  1.4  pgoyette 		    compat_nfssvc_syscalls);
    208  1.4  pgoyette 		break;
    209  1.4  pgoyette 	case MODULE_CMD_FINI:
    210  1.4  pgoyette 		error = syscall_disestablish(&emul_netbsd32,
    211  1.4  pgoyette 		    compat_nfssvc_syscalls);
    212  1.4  pgoyette 		break;
    213  1.4  pgoyette 	default:
    214  1.4  pgoyette 		error = ENOTTY;
    215  1.4  pgoyette 		break;
    216  1.4  pgoyette 	}
    217  1.4  pgoyette 	return error;
    218  1.4  pgoyette }
    219