Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_20.c revision 1.28.18.2
      1  1.28.18.1       tls /*	$NetBSD: netbsd32_compat_20.c,v 1.28.18.2 2017/12/03 11:36:55 jdolecek Exp $	*/
      2        1.1      cube 
      3        1.1      cube /*
      4        1.1      cube  * Copyright (c) 1998, 2001 Matthew R. Green
      5        1.1      cube  * All rights reserved.
      6        1.1      cube  *
      7        1.1      cube  * Redistribution and use in source and binary forms, with or without
      8        1.1      cube  * modification, are permitted provided that the following conditions
      9        1.1      cube  * are met:
     10        1.1      cube  * 1. Redistributions of source code must retain the above copyright
     11        1.1      cube  *    notice, this list of conditions and the following disclaimer.
     12        1.1      cube  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1      cube  *    notice, this list of conditions and the following disclaimer in the
     14        1.1      cube  *    documentation and/or other materials provided with the distribution.
     15        1.1      cube  *
     16        1.1      cube  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17        1.1      cube  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18        1.1      cube  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19        1.1      cube  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20        1.1      cube  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21        1.1      cube  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22        1.1      cube  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23        1.1      cube  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24        1.1      cube  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25        1.1      cube  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26        1.1      cube  * SUCH DAMAGE.
     27        1.1      cube  */
     28        1.1      cube 
     29        1.1      cube #include <sys/cdefs.h>
     30  1.28.18.1       tls __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_20.c,v 1.28.18.2 2017/12/03 11:36:55 jdolecek Exp $");
     31        1.1      cube 
     32        1.1      cube #include <sys/param.h>
     33        1.1      cube #include <sys/systm.h>
     34        1.1      cube #include <sys/mount.h>
     35        1.1      cube #include <sys/stat.h>
     36        1.1      cube #include <sys/time.h>
     37        1.1      cube #include <sys/ktrace.h>
     38        1.1      cube #include <sys/vnode.h>
     39        1.1      cube #include <sys/file.h>
     40        1.1      cube #include <sys/filedesc.h>
     41        1.1      cube #include <sys/namei.h>
     42        1.1      cube #include <sys/syscallargs.h>
     43        1.1      cube #include <sys/proc.h>
     44        1.2  christos #include <sys/dirent.h>
     45        1.1      cube 
     46        1.1      cube #include <compat/netbsd32/netbsd32.h>
     47        1.1      cube #include <compat/netbsd32/netbsd32_syscallargs.h>
     48        1.1      cube #include <compat/netbsd32/netbsd32_conv.h>
     49        1.1      cube 
     50        1.4     perry static inline void compat_20_netbsd32_from_statvfs(struct statvfs *,
     51        1.1      cube     struct netbsd32_statfs *);
     52        1.1      cube 
     53        1.4     perry static inline void
     54       1.17       dsl compat_20_netbsd32_from_statvfs(struct statvfs *sbp, struct netbsd32_statfs *sb32p)
     55        1.1      cube {
     56        1.1      cube 	sb32p->f_flags = sbp->f_flag;
     57        1.1      cube 	sb32p->f_bsize = (netbsd32_long)sbp->f_bsize;
     58        1.1      cube 	sb32p->f_iosize = (netbsd32_long)sbp->f_iosize;
     59        1.1      cube 	sb32p->f_blocks = (netbsd32_long)sbp->f_blocks;
     60        1.1      cube 	sb32p->f_bfree = (netbsd32_long)sbp->f_bfree;
     61        1.1      cube 	sb32p->f_bavail = (netbsd32_long)sbp->f_bavail;
     62        1.1      cube 	sb32p->f_files = (netbsd32_long)sbp->f_files;
     63        1.1      cube 	sb32p->f_ffree = (netbsd32_long)sbp->f_ffree;
     64        1.1      cube 	sb32p->f_fsid = sbp->f_fsidx;
     65        1.1      cube 	sb32p->f_owner = sbp->f_owner;
     66        1.1      cube 	sb32p->f_spare[0] = 0;
     67        1.1      cube 	sb32p->f_spare[1] = 0;
     68        1.1      cube 	sb32p->f_spare[2] = 0;
     69        1.1      cube 	sb32p->f_spare[3] = 0;
     70       1.13  christos 	(void)memcpy(sb32p->f_fstypename, sbp->f_fstypename,
     71       1.13  christos 	    sizeof(sb32p->f_fstypename));
     72       1.13  christos 	(void)memcpy(sb32p->f_mntonname, sbp->f_mntonname,
     73       1.13  christos 	    sizeof(sb32p->f_mntonname));
     74       1.13  christos 	(void)memcpy(sb32p->f_mntfromname, sbp->f_mntfromname,
     75       1.13  christos 	    sizeof(sb32p->f_mntfromname));
     76        1.1      cube }
     77        1.1      cube 
     78        1.1      cube int
     79       1.19       dsl compat_20_netbsd32_getfsstat(struct lwp *l, const struct compat_20_netbsd32_getfsstat_args *uap, register_t *retval)
     80        1.1      cube {
     81       1.19       dsl 	/* {
     82        1.1      cube 		syscallarg(netbsd32_statfsp_t) buf;
     83        1.1      cube 		syscallarg(netbsd32_long) bufsize;
     84        1.1      cube 		syscallarg(int) flags;
     85       1.19       dsl 	} */
     86  1.28.18.1       tls 	int root = 0;
     87  1.28.18.1       tls 	struct proc *p = l->l_proc;
     88  1.28.18.2  jdolecek 	mount_iterator_t *iter;
     89  1.28.18.2  jdolecek 	struct mount *mp;
     90  1.28.18.1       tls 	struct statvfs *sb;
     91        1.1      cube 	struct netbsd32_statfs sb32;
     92        1.8  christos 	void *sfsp;
     93  1.28.18.1       tls 	size_t count, maxcount;
     94  1.28.18.1       tls 	int error = 0;
     95        1.1      cube 
     96  1.28.18.1       tls 	sb = STATVFSBUF_GET();
     97        1.1      cube 	maxcount = SCARG(uap, bufsize) / sizeof(struct netbsd32_statfs);
     98       1.10       dsl 	sfsp = SCARG_P32(uap, buf);
     99  1.28.18.2  jdolecek 	mountlist_iterator_init(&iter);
    100        1.1      cube 	count = 0;
    101  1.28.18.2  jdolecek 	while ((mp = mountlist_iterator_next(iter)) != NULL) {
    102        1.1      cube 		if (sfsp && count < maxcount) {
    103  1.28.18.1       tls 			error = dostatvfs(mp, sb, l, SCARG(uap, flags), 0);
    104  1.28.18.1       tls 			if (error) {
    105  1.28.18.1       tls 				error = 0;
    106        1.1      cube 				continue;
    107        1.1      cube 			}
    108  1.28.18.1       tls 			compat_20_netbsd32_from_statvfs(sb, &sb32);
    109        1.1      cube 			error = copyout(&sb32, sfsp, sizeof(sb32));
    110  1.28.18.2  jdolecek 			if (error)
    111  1.28.18.1       tls 				goto out;
    112        1.9  christos 			sfsp = (char *)sfsp + sizeof(sb32);
    113  1.28.18.1       tls 			root |= strcmp(sb->f_mntonname, "/") == 0;
    114        1.1      cube 		}
    115        1.1      cube 		count++;
    116        1.1      cube 	}
    117  1.28.18.1       tls 
    118  1.28.18.1       tls 	if (root == 0 && p->p_cwdi->cwdi_rdir) {
    119  1.28.18.1       tls 		/*
    120  1.28.18.1       tls 		 * fake a root entry
    121  1.28.18.1       tls 		 */
    122  1.28.18.1       tls 		error = dostatvfs(p->p_cwdi->cwdi_rdir->v_mount,
    123  1.28.18.1       tls 		    sb, l, SCARG(uap, flags), 1);
    124  1.28.18.1       tls 		if (error != 0)
    125  1.28.18.1       tls 			goto out;
    126  1.28.18.1       tls 		if (sfsp) {
    127  1.28.18.1       tls 			compat_20_netbsd32_from_statvfs(sb, &sb32);
    128  1.28.18.1       tls 			error = copyout(&sb32, sfsp, sizeof(sb32));
    129  1.28.18.1       tls 			if (error != 0)
    130  1.28.18.1       tls 				goto out;
    131  1.28.18.1       tls 		}
    132  1.28.18.1       tls 		count++;
    133  1.28.18.1       tls 	}
    134  1.28.18.1       tls 
    135        1.1      cube 	if (sfsp && count > maxcount)
    136        1.1      cube 		*retval = maxcount;
    137        1.1      cube 	else
    138        1.1      cube 		*retval = count;
    139  1.28.18.1       tls out:
    140  1.28.18.2  jdolecek 	mountlist_iterator_destroy(iter);
    141  1.28.18.1       tls 	STATVFSBUF_PUT(sb);
    142  1.28.18.1       tls 	return error;
    143        1.1      cube }
    144        1.1      cube 
    145        1.1      cube int
    146       1.19       dsl compat_20_netbsd32_statfs(struct lwp *l, const struct compat_20_netbsd32_statfs_args *uap, register_t *retval)
    147        1.1      cube {
    148       1.19       dsl 	/* {
    149        1.1      cube 		syscallarg(const netbsd32_charp) path;
    150        1.1      cube 		syscallarg(netbsd32_statfsp_t) buf;
    151       1.19       dsl 	} */
    152        1.1      cube 	struct mount *mp;
    153  1.28.18.1       tls 	struct statvfs *sb;
    154        1.1      cube 	struct netbsd32_statfs s32;
    155        1.1      cube 	int error;
    156       1.27  dholland 	struct vnode *vp;
    157        1.1      cube 
    158       1.27  dholland 	error = namei_simple_user(SCARG_P32(uap, path),
    159       1.27  dholland 				NSM_FOLLOW_TRYEMULROOT, &vp);
    160       1.27  dholland 	if (error != 0)
    161        1.1      cube 		return (error);
    162       1.27  dholland 	mp = vp->v_mount;
    163       1.27  dholland 	vrele(vp);
    164  1.28.18.2  jdolecek 	sb = STATVFSBUF_GET();
    165  1.28.18.1       tls 	if ((error = dostatvfs(mp, sb, l, 0, 0)) != 0)
    166  1.28.18.2  jdolecek 		goto out;
    167  1.28.18.1       tls 	compat_20_netbsd32_from_statvfs(sb, &s32);
    168  1.28.18.2  jdolecek 	error = copyout(&s32, SCARG_P32(uap, buf), sizeof(s32));
    169  1.28.18.2  jdolecek out:
    170  1.28.18.2  jdolecek 	STATVFSBUF_PUT(sb);
    171  1.28.18.2  jdolecek 	return error;
    172        1.1      cube }
    173        1.1      cube 
    174        1.1      cube int
    175       1.19       dsl compat_20_netbsd32_fstatfs(struct lwp *l, const struct compat_20_netbsd32_fstatfs_args *uap, register_t *retval)
    176        1.1      cube {
    177       1.19       dsl 	/* {
    178        1.1      cube 		syscallarg(int) fd;
    179        1.1      cube 		syscallarg(netbsd32_statfsp_t) buf;
    180       1.19       dsl 	} */
    181       1.21        ad 	file_t *fp;
    182        1.1      cube 	struct mount *mp;
    183  1.28.18.1       tls 	struct statvfs *sb;
    184        1.1      cube 	struct netbsd32_statfs s32;
    185        1.1      cube 	int error;
    186        1.1      cube 
    187       1.26        ad 	/* fd_getvnode() will use the descriptor for us */
    188       1.21        ad 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    189        1.1      cube 		return (error);
    190  1.28.18.2  jdolecek 	mp = fp->f_vnode->v_mount;
    191  1.28.18.2  jdolecek 	sb = STATVFSBUF_GET();
    192  1.28.18.1       tls 	if ((error = dostatvfs(mp, sb, l, 0, 0)) != 0)
    193        1.1      cube 		goto out;
    194  1.28.18.1       tls 	compat_20_netbsd32_from_statvfs(sb, &s32);
    195       1.10       dsl 	error = copyout(&s32, SCARG_P32(uap, buf), sizeof(s32));
    196        1.1      cube  out:
    197  1.28.18.2  jdolecek 	STATVFSBUF_PUT(sb);
    198       1.21        ad 	fd_putfile(SCARG(uap, fd));
    199        1.1      cube 	return (error);
    200        1.1      cube }
    201        1.1      cube 
    202        1.1      cube int
    203       1.19       dsl compat_20_netbsd32_fhstatfs(struct lwp *l, const struct compat_20_netbsd32_fhstatfs_args *uap, register_t *retval)
    204        1.1      cube {
    205       1.19       dsl 	/* {
    206        1.1      cube 		syscallarg(const netbsd32_fhandlep_t) fhp;
    207        1.1      cube 		syscallarg(struct statvfs *) buf;
    208       1.19       dsl 	} */
    209        1.6    martin 	struct compat_30_sys_fhstatvfs1_args ua;
    210        1.1      cube 
    211        1.6    martin 	NETBSD32TOP_UAP(fhp, const struct compat_30_fhandle);
    212        1.1      cube 	NETBSD32TOP_UAP(buf, struct statvfs);
    213        1.1      cube #ifdef notyet
    214        1.1      cube 	NETBSD32TOP_UAP(flags, int);
    215        1.1      cube #endif
    216        1.6    martin 	return (compat_30_sys_fhstatvfs1(l, &ua, retval));
    217        1.1      cube }
    218