Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_30.c revision 1.24.6.1
      1  1.24.6.1  wrstuden /*	$NetBSD: netbsd32_compat_30.c,v 1.24.6.1 2008/05/10 23:48:57 wrstuden Exp $	*/
      2       1.1  christos 
      3       1.1  christos /*
      4       1.1  christos  * Copyright (c) 1998, 2001 Matthew R. Green
      5       1.1  christos  * All rights reserved.
      6       1.1  christos  *
      7       1.1  christos  * Redistribution and use in source and binary forms, with or without
      8       1.1  christos  * modification, are permitted provided that the following conditions
      9       1.1  christos  * are met:
     10       1.1  christos  * 1. Redistributions of source code must retain the above copyright
     11       1.1  christos  *    notice, this list of conditions and the following disclaimer.
     12       1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  christos  *    documentation and/or other materials provided with the distribution.
     15       1.1  christos  * 3. The name of the author may not be used to endorse or promote products
     16       1.1  christos  *    derived from this software without specific prior written permission.
     17       1.1  christos  *
     18       1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19       1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20       1.1  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21       1.1  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22       1.1  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23       1.1  christos  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24       1.1  christos  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25       1.1  christos  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26       1.1  christos  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27       1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28       1.1  christos  * SUCH DAMAGE.
     29       1.1  christos  */
     30       1.1  christos 
     31       1.1  christos #include <sys/cdefs.h>
     32  1.24.6.1  wrstuden __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_30.c,v 1.24.6.1 2008/05/10 23:48:57 wrstuden Exp $");
     33       1.9    martin 
     34       1.9    martin #include "opt_nfsserver.h"
     35       1.1  christos 
     36       1.1  christos #include <sys/param.h>
     37       1.1  christos #include <sys/systm.h>
     38       1.1  christos #include <sys/malloc.h>
     39       1.1  christos #include <sys/mount.h>
     40       1.1  christos #include <sys/socket.h>
     41       1.1  christos #include <sys/socketvar.h>
     42       1.1  christos #include <sys/stat.h>
     43       1.1  christos #include <sys/time.h>
     44       1.1  christos #include <sys/ktrace.h>
     45       1.1  christos #include <sys/resourcevar.h>
     46       1.1  christos #include <sys/vnode.h>
     47       1.1  christos #include <sys/file.h>
     48       1.1  christos #include <sys/filedesc.h>
     49       1.1  christos #include <sys/namei.h>
     50       1.1  christos #include <sys/statvfs.h>
     51  1.24.6.1  wrstuden #include <sys/sa.h>
     52       1.1  christos #include <sys/syscallargs.h>
     53       1.1  christos #include <sys/proc.h>
     54       1.2  christos #include <sys/dirent.h>
     55       1.7      elad #include <sys/kauth.h>
     56      1.18       dsl #include <sys/vfs_syscalls.h>
     57       1.1  christos 
     58       1.1  christos #include <compat/netbsd32/netbsd32.h>
     59       1.1  christos #include <compat/netbsd32/netbsd32_syscallargs.h>
     60       1.1  christos #include <compat/netbsd32/netbsd32_conv.h>
     61       1.9    martin #include <compat/sys/mount.h>
     62       1.1  christos 
     63       1.1  christos 
     64       1.1  christos int
     65      1.23       dsl compat_30_netbsd32_getdents(struct lwp *l, const struct compat_30_netbsd32_getdents_args *uap, register_t *retval)
     66       1.1  christos {
     67      1.23       dsl 	/* {
     68       1.1  christos 		syscallarg(int) fd;
     69       1.1  christos 		syscallarg(netbsd32_charp) buf;
     70       1.1  christos 		syscallarg(netbsd32_size_t) count;
     71      1.23       dsl 	} */
     72      1.24        ad 	file_t *fp;
     73       1.1  christos 	int error, done;
     74       1.1  christos 	char  *buf;
     75       1.8    simonb 	netbsd32_size_t count;
     76       1.1  christos 
     77       1.8    simonb 	/* Limit the size on any kernel buffers used by VOP_READDIR */
     78       1.8    simonb 	count = min(MAXBSIZE, SCARG(uap, count));
     79       1.8    simonb 
     80       1.1  christos 	/* getvnode() will use the descriptor for us */
     81      1.24        ad 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
     82       1.1  christos 		return (error);
     83       1.1  christos 	if ((fp->f_flag & FREAD) == 0) {
     84       1.1  christos 		error = EBADF;
     85       1.1  christos 		goto out;
     86       1.1  christos 	}
     87       1.8    simonb 	buf = malloc(count, M_TEMP, M_WAITOK);
     88       1.8    simonb 	error = vn_readdir(fp, buf, UIO_SYSSPACE, count, &done, l, 0, 0);
     89       1.1  christos 	if (error == 0) {
     90       1.1  christos 		*retval = netbsd32_to_dirent12(buf, done);
     91      1.19       dsl 		error = copyout(buf, SCARG_P32(uap, buf), *retval);
     92       1.1  christos 	}
     93       1.1  christos 	free(buf, M_TEMP);
     94       1.1  christos  out:
     95      1.24        ad  	fd_putfile(SCARG(uap, fd));
     96       1.1  christos 	return (error);
     97       1.1  christos }
     98       1.1  christos 
     99       1.1  christos int
    100      1.23       dsl compat_30_netbsd32___stat13(struct lwp *l, const struct compat_30_netbsd32___stat13_args *uap, register_t *retval)
    101       1.1  christos {
    102      1.23       dsl 	/* {
    103       1.1  christos 		syscallarg(const netbsd32_charp) path;
    104       1.1  christos 		syscallarg(netbsd32_stat13p_t) ub;
    105      1.23       dsl 	} */
    106       1.2  christos 	struct netbsd32_stat13 sb32;
    107       1.1  christos 	struct stat sb;
    108       1.1  christos 	int error;
    109       1.1  christos 	const char *path;
    110       1.1  christos 
    111      1.19       dsl 	path = SCARG_P32(uap, path);
    112       1.1  christos 
    113      1.24        ad 	error = do_sys_stat(path, FOLLOW, &sb);
    114       1.1  christos 	if (error)
    115       1.1  christos 		return (error);
    116       1.1  christos 	netbsd32_from___stat13(&sb, &sb32);
    117      1.19       dsl 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    118       1.1  christos 	return (error);
    119       1.1  christos }
    120       1.1  christos 
    121       1.1  christos int
    122      1.23       dsl compat_30_netbsd32___fstat13(struct lwp *l, const struct compat_30_netbsd32___fstat13_args *uap, register_t *retval)
    123       1.1  christos {
    124      1.23       dsl 	/* {
    125       1.1  christos 		syscallarg(int) fd;
    126       1.1  christos 		syscallarg(netbsd32_stat13p_t) sb;
    127      1.23       dsl 	} */
    128       1.1  christos 	int fd = SCARG(uap, fd);
    129      1.24        ad 	file_t *fp;
    130       1.2  christos 	struct netbsd32_stat13 sb32;
    131       1.1  christos 	struct stat ub;
    132       1.1  christos 	int error = 0;
    133       1.1  christos 
    134      1.24        ad 	if ((fp = fd_getfile(fd)) == NULL)
    135       1.1  christos 		return (EBADF);
    136      1.24        ad 	error = (*fp->f_ops->fo_stat)(fp, &ub);
    137      1.24        ad 	fd_putfile(fd);
    138       1.1  christos 
    139       1.1  christos 	if (error == 0) {
    140       1.1  christos 		netbsd32_from___stat13(&ub, &sb32);
    141      1.19       dsl 		error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
    142       1.1  christos 	}
    143       1.1  christos 	return (error);
    144       1.1  christos }
    145       1.1  christos 
    146       1.1  christos int
    147      1.23       dsl compat_30_netbsd32___lstat13(struct lwp *l, const struct compat_30_netbsd32___lstat13_args *uap, register_t *retval)
    148       1.1  christos {
    149      1.23       dsl 	/* {
    150       1.1  christos 		syscallarg(const netbsd32_charp) path;
    151       1.1  christos 		syscallarg(netbsd32_stat13p_t) ub;
    152      1.23       dsl 	} */
    153       1.2  christos 	struct netbsd32_stat13 sb32;
    154       1.1  christos 	struct stat sb;
    155       1.1  christos 	int error;
    156       1.1  christos 	const char *path;
    157       1.1  christos 
    158      1.19       dsl 	path = SCARG_P32(uap, path);
    159       1.1  christos 
    160      1.24        ad 	error = do_sys_stat(path, NOFOLLOW, &sb);
    161       1.1  christos 	if (error)
    162       1.1  christos 		return (error);
    163       1.1  christos 	netbsd32_from___stat13(&sb, &sb32);
    164      1.19       dsl 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    165       1.1  christos 	return (error);
    166       1.1  christos }
    167       1.6      cube 
    168       1.6      cube int
    169      1.23       dsl compat_30_netbsd32_fhstat(struct lwp *l, const struct compat_30_netbsd32_fhstat_args *uap, register_t *retval)
    170       1.6      cube {
    171      1.23       dsl 	/* {
    172       1.6      cube 		syscallarg(const netbsd32_fhandlep_t) fhp;
    173      1.19       dsl 		syscallarg(netbsd32_stat13p_t) sb;
    174      1.23       dsl 	} */
    175       1.6      cube 	struct stat sb;
    176       1.6      cube 	struct netbsd32_stat13 sb32;
    177       1.6      cube 	int error;
    178       1.9    martin 	struct compat_30_fhandle fh;
    179       1.6      cube 	struct mount *mp;
    180       1.6      cube 	struct vnode *vp;
    181       1.6      cube 
    182       1.6      cube 	/*
    183       1.6      cube 	 * Must be super user
    184       1.6      cube 	 */
    185      1.15      elad 	if ((error = kauth_authorize_system(l->l_cred,
    186      1.15      elad 	    KAUTH_SYSTEM_FILEHANDLE, 0, NULL, NULL, NULL)))
    187       1.6      cube 		return (error);
    188       1.6      cube 
    189      1.19       dsl 	if ((error = copyin(SCARG_P32(uap, fhp), &fh, sizeof(fh))) != 0)
    190       1.6      cube 		return (error);
    191       1.6      cube 
    192       1.6      cube 	if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
    193       1.6      cube 		return (ESTALE);
    194       1.6      cube 	if (mp->mnt_op->vfs_fhtovp == NULL)
    195       1.6      cube 		return EOPNOTSUPP;
    196       1.9    martin 	if ((error = VFS_FHTOVP(mp, (struct fid*)&fh.fh_fid, &vp)))
    197       1.6      cube 		return (error);
    198      1.24        ad 	error = vn_stat(vp, &sb);
    199       1.6      cube 	vput(vp);
    200       1.6      cube 	if (error)
    201       1.6      cube 		return (error);
    202       1.6      cube 	netbsd32_from___stat13(&sb, &sb32);
    203      1.19       dsl 	error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb));
    204       1.6      cube 	return (error);
    205       1.6      cube }
    206       1.9    martin 
    207       1.9    martin int
    208      1.23       dsl compat_30_netbsd32_fhstatvfs1(struct lwp *l, const struct compat_30_netbsd32_fhstatvfs1_args *uap, register_t *retval)
    209      1.12    martin {
    210      1.23       dsl 	/* {
    211      1.12    martin 		syscallarg(const netbsd32_fhandlep_t) fhp;
    212      1.12    martin 		syscallarg(netbsd32_statvfsp_t) buf;
    213      1.12    martin 		syscallarg(int) flags;
    214      1.23       dsl 	} */
    215      1.12    martin 	struct statvfs *sbuf;
    216      1.12    martin 	struct netbsd32_statvfs *s32;
    217      1.12    martin 	int error;
    218      1.12    martin 
    219      1.21       dsl 	sbuf = STATVFSBUF_GET();
    220      1.21       dsl 	error = do_fhstatvfs(l, SCARG_P32(uap, fhp), FHANDLE_SIZE_COMPAT, sbuf,
    221      1.21       dsl 	    SCARG(uap, flags));
    222      1.21       dsl 
    223      1.21       dsl 	if (error != 0) {
    224      1.21       dsl 		s32 = malloc(sizeof *s32, M_TEMP, M_WAITOK);
    225      1.21       dsl 		netbsd32_from_statvfs(sbuf, s32);
    226      1.21       dsl 		error = copyout(s32, SCARG_P32(uap, buf), sizeof *s32);
    227      1.21       dsl 		free(s32, M_TEMP);
    228      1.21       dsl 	}
    229      1.21       dsl 	STATVFSBUF_PUT(sbuf);
    230      1.12    martin 
    231      1.12    martin 	return (error);
    232      1.12    martin }
    233      1.12    martin 
    234      1.12    martin int
    235      1.23       dsl compat_30_netbsd32_socket(struct lwp *l, const struct compat_30_netbsd32_socket_args *uap, register_t *retval)
    236       1.9    martin {
    237      1.23       dsl 	/* {
    238       1.9    martin 		syscallarg(int) domain;
    239       1.9    martin 		syscallarg(int) type;
    240       1.9    martin 		syscallarg(int) protocol;
    241      1.23       dsl 	} */
    242       1.9    martin 	struct compat_30_sys_socket_args ua;
    243       1.9    martin 
    244       1.9    martin 	NETBSD32TO64_UAP(domain);
    245       1.9    martin 	NETBSD32TO64_UAP(type);
    246       1.9    martin 	NETBSD32TO64_UAP(protocol);
    247       1.9    martin 	return (compat_30_sys_socket(l, &ua, retval));
    248       1.9    martin }
    249       1.9    martin 
    250       1.9    martin int
    251      1.23       dsl compat_30_netbsd32_getfh(struct lwp *l, const struct compat_30_netbsd32_getfh_args *uap, register_t *retval)
    252       1.9    martin {
    253      1.23       dsl 	/* {
    254       1.9    martin 		syscallarg(const netbsd32_charp) fname;
    255       1.9    martin 		syscallarg(netbsd32_compat_30_fhandlep_t) fhp;
    256      1.23       dsl 	} */
    257       1.9    martin 	struct compat_30_sys_getfh_args ua;
    258       1.9    martin 
    259       1.9    martin 	NETBSD32TOP_UAP(fname, const char);
    260       1.9    martin 	NETBSD32TOP_UAP(fhp, struct compat_30_fhandle);
    261       1.9    martin 	/* Lucky for us a fhandle_t doesn't change sizes */
    262       1.9    martin 	return (compat_30_sys_getfh(l, &ua, retval));
    263       1.9    martin }
    264      1.12    martin 
    265      1.12    martin 
    266      1.23       dsl int
    267      1.23       dsl compat_30_netbsd32_sys___fhstat30(struct lwp *l, const struct compat_30_netbsd32_sys___fhstat30_args *uap, register_t *retval)
    268      1.12    martin {
    269      1.23       dsl 	/* {
    270      1.12    martin 		syscallarg(const netbsd32_fhandlep_t) fhp;
    271      1.12    martin 		syscallarg(netbsd32_statp_t) sb;
    272      1.23       dsl 	} */
    273      1.12    martin 	struct stat sb;
    274      1.12    martin 	struct netbsd32_stat sb32;
    275      1.12    martin 	int error;
    276      1.12    martin 
    277      1.21       dsl 	error = do_fhstat(l, SCARG_P32(uap, fhp), FHANDLE_SIZE_COMPAT, &sb);
    278      1.21       dsl 	if (error)
    279      1.12    martin 		return error;
    280      1.12    martin 
    281      1.12    martin 	netbsd32_from___stat30(&sb, &sb32);
    282      1.21       dsl 	error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
    283      1.12    martin 	return error;
    284      1.12    martin }
    285      1.12    martin 
    286      1.12    martin /*
    287      1.12    martin  * Open a file given a file handle.
    288      1.12    martin  *
    289      1.12    martin  * Check permissions, allocate an open file structure,
    290      1.12    martin  * and call the device open routine if any.
    291      1.12    martin  */
    292      1.12    martin int
    293      1.23       dsl compat_30_netbsd32_fhopen(struct lwp *l, const struct compat_30_netbsd32_fhopen_args *uap, register_t *retval)
    294      1.12    martin {
    295      1.23       dsl 	/* {
    296      1.12    martin 		syscallarg(const fhandle_t *) fhp;
    297      1.12    martin 		syscallarg(int) flags;
    298      1.23       dsl 	} */
    299      1.12    martin 	struct compat_30_sys_fhopen_args ua;
    300      1.12    martin 
    301      1.12    martin 	NETBSD32TOP_UAP(fhp, struct compat_30_fhandle);
    302      1.12    martin 	NETBSD32TO64_UAP(flags);
    303      1.12    martin 	return (compat_30_sys_fhopen(l, &ua, retval));
    304      1.12    martin }
    305