Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_20.c revision 1.1.14.3
      1  1.1.14.3  yamt /*	$NetBSD: netbsd32_compat_20.c,v 1.1.14.3 2007/02/26 09:09:30 yamt 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  * 3. The name of the author may not be used to endorse or promote products
     16       1.1  cube  *    derived from this software without specific prior written permission.
     17       1.1  cube  *
     18       1.1  cube  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19       1.1  cube  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20       1.1  cube  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21       1.1  cube  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22       1.1  cube  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23       1.1  cube  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24       1.1  cube  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25       1.1  cube  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26       1.1  cube  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27       1.1  cube  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28       1.1  cube  * SUCH DAMAGE.
     29       1.1  cube  */
     30       1.1  cube 
     31       1.1  cube #include <sys/cdefs.h>
     32  1.1.14.3  yamt __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_20.c,v 1.1.14.3 2007/02/26 09:09:30 yamt Exp $");
     33       1.1  cube 
     34       1.1  cube #include <sys/param.h>
     35       1.1  cube #include <sys/systm.h>
     36       1.1  cube #include <sys/malloc.h>
     37       1.1  cube #include <sys/mount.h>
     38       1.1  cube #include <sys/stat.h>
     39       1.1  cube #include <sys/time.h>
     40       1.1  cube #include <sys/ktrace.h>
     41       1.1  cube #include <sys/vnode.h>
     42       1.1  cube #include <sys/file.h>
     43       1.1  cube #include <sys/filedesc.h>
     44       1.1  cube #include <sys/namei.h>
     45       1.1  cube #include <sys/syscallargs.h>
     46       1.1  cube #include <sys/proc.h>
     47  1.1.14.1  yamt #include <sys/dirent.h>
     48       1.1  cube 
     49       1.1  cube #include <compat/netbsd32/netbsd32.h>
     50       1.1  cube #include <compat/netbsd32/netbsd32_syscallargs.h>
     51       1.1  cube #include <compat/netbsd32/netbsd32_conv.h>
     52       1.1  cube 
     53  1.1.14.1  yamt static inline void compat_20_netbsd32_from_statvfs(struct statvfs *,
     54       1.1  cube     struct netbsd32_statfs *);
     55       1.1  cube 
     56  1.1.14.1  yamt static inline void
     57       1.1  cube compat_20_netbsd32_from_statvfs(sbp, sb32p)
     58       1.1  cube 	struct statvfs *sbp;
     59       1.1  cube 	struct netbsd32_statfs *sb32p;
     60       1.1  cube {
     61       1.1  cube 	sb32p->f_flags = sbp->f_flag;
     62       1.1  cube 	sb32p->f_bsize = (netbsd32_long)sbp->f_bsize;
     63       1.1  cube 	sb32p->f_iosize = (netbsd32_long)sbp->f_iosize;
     64       1.1  cube 	sb32p->f_blocks = (netbsd32_long)sbp->f_blocks;
     65       1.1  cube 	sb32p->f_bfree = (netbsd32_long)sbp->f_bfree;
     66       1.1  cube 	sb32p->f_bavail = (netbsd32_long)sbp->f_bavail;
     67       1.1  cube 	sb32p->f_files = (netbsd32_long)sbp->f_files;
     68       1.1  cube 	sb32p->f_ffree = (netbsd32_long)sbp->f_ffree;
     69       1.1  cube 	sb32p->f_fsid = sbp->f_fsidx;
     70       1.1  cube 	sb32p->f_owner = sbp->f_owner;
     71       1.1  cube 	sb32p->f_spare[0] = 0;
     72       1.1  cube 	sb32p->f_spare[1] = 0;
     73       1.1  cube 	sb32p->f_spare[2] = 0;
     74       1.1  cube 	sb32p->f_spare[3] = 0;
     75       1.1  cube #if 1
     76       1.1  cube 	/* May as well do the whole batch in one go */
     77       1.1  cube 	memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN+MNAMELEN+MNAMELEN);
     78       1.1  cube #else
     79       1.1  cube 	/* If we want to be careful */
     80       1.1  cube 	memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN);
     81       1.1  cube 	memcpy(sb32p->f_mntonname, sbp->f_mntonname, MNAMELEN);
     82       1.1  cube 	memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, MNAMELEN);
     83       1.1  cube #endif
     84       1.1  cube }
     85       1.1  cube 
     86       1.1  cube int
     87       1.1  cube compat_20_netbsd32_getfsstat(l, v, retval)
     88       1.1  cube 	struct lwp *l;
     89       1.1  cube 	void *v;
     90       1.1  cube 	register_t *retval;
     91       1.1  cube {
     92       1.1  cube 	struct compat_20_netbsd32_getfsstat_args /* {
     93       1.1  cube 		syscallarg(netbsd32_statfsp_t) buf;
     94       1.1  cube 		syscallarg(netbsd32_long) bufsize;
     95       1.1  cube 		syscallarg(int) flags;
     96       1.1  cube 	} */ *uap = v;
     97       1.1  cube 	struct mount *mp, *nmp;
     98       1.1  cube 	struct statvfs *sp;
     99       1.1  cube 	struct netbsd32_statfs sb32;
    100       1.1  cube 	caddr_t sfsp;
    101       1.1  cube 	long count, maxcount, error;
    102       1.1  cube 
    103       1.1  cube 	maxcount = SCARG(uap, bufsize) / sizeof(struct netbsd32_statfs);
    104       1.1  cube 	sfsp = (caddr_t)NETBSD32PTR64(SCARG(uap, buf));
    105       1.1  cube 	simple_lock(&mountlist_slock);
    106       1.1  cube 	count = 0;
    107       1.1  cube 	for (mp = mountlist.cqh_first; mp != (void *)&mountlist; mp = nmp) {
    108       1.1  cube 		if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
    109       1.1  cube 			nmp = mp->mnt_list.cqe_next;
    110       1.1  cube 			continue;
    111       1.1  cube 		}
    112       1.1  cube 		if (sfsp && count < maxcount) {
    113       1.1  cube 			sp = &mp->mnt_stat;
    114       1.1  cube 			/*
    115       1.1  cube 			 * If MNT_NOWAIT or MNT_LAZY is specified, do not
    116       1.1  cube 			 * refresh the fsstat cache. MNT_WAIT or MNT_LAXY
    117       1.1  cube 			 * overrides MNT_NOWAIT.
    118       1.1  cube 			 */
    119       1.1  cube 			if (SCARG(uap, flags) != MNT_NOWAIT &&
    120       1.1  cube 			    SCARG(uap, flags) != MNT_LAZY &&
    121       1.1  cube 			    (SCARG(uap, flags) == MNT_WAIT ||
    122       1.1  cube 			     SCARG(uap, flags) == 0) &&
    123  1.1.14.1  yamt 			    (error = VFS_STATVFS(mp, sp, l)) != 0) {
    124       1.1  cube 				simple_lock(&mountlist_slock);
    125       1.1  cube 				nmp = mp->mnt_list.cqe_next;
    126       1.1  cube 				vfs_unbusy(mp);
    127       1.1  cube 				continue;
    128       1.1  cube 			}
    129       1.1  cube 			sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
    130       1.1  cube 			compat_20_netbsd32_from_statvfs(sp, &sb32);
    131       1.1  cube 			error = copyout(&sb32, sfsp, sizeof(sb32));
    132       1.1  cube 			if (error) {
    133       1.1  cube 				vfs_unbusy(mp);
    134       1.1  cube 				return (error);
    135       1.1  cube 			}
    136       1.1  cube 			sfsp += sizeof(sb32);
    137       1.1  cube 		}
    138       1.1  cube 		count++;
    139       1.1  cube 		simple_lock(&mountlist_slock);
    140       1.1  cube 		nmp = mp->mnt_list.cqe_next;
    141       1.1  cube 		vfs_unbusy(mp);
    142       1.1  cube 	}
    143       1.1  cube 	simple_unlock(&mountlist_slock);
    144       1.1  cube 	if (sfsp && count > maxcount)
    145       1.1  cube 		*retval = maxcount;
    146       1.1  cube 	else
    147       1.1  cube 		*retval = count;
    148       1.1  cube 	return (0);
    149       1.1  cube }
    150       1.1  cube 
    151       1.1  cube int
    152       1.1  cube compat_20_netbsd32_statfs(l, v, retval)
    153       1.1  cube 	struct lwp *l;
    154       1.1  cube 	void *v;
    155       1.1  cube 	register_t *retval;
    156       1.1  cube {
    157       1.1  cube 	struct compat_20_netbsd32_statfs_args /* {
    158       1.1  cube 		syscallarg(const netbsd32_charp) path;
    159       1.1  cube 		syscallarg(netbsd32_statfsp_t) buf;
    160       1.1  cube 	} */ *uap = v;
    161       1.1  cube 	struct mount *mp;
    162       1.1  cube 	struct statvfs *sp;
    163       1.1  cube 	struct netbsd32_statfs s32;
    164       1.1  cube 	int error;
    165       1.1  cube 	struct nameidata nd;
    166       1.1  cube 
    167       1.1  cube 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE,
    168  1.1.14.1  yamt 	    (char *)NETBSD32PTR64(SCARG(uap, path)), l);
    169       1.1  cube 	if ((error = namei(&nd)) != 0)
    170       1.1  cube 		return (error);
    171       1.1  cube 	mp = nd.ni_vp->v_mount;
    172       1.1  cube 	sp = &mp->mnt_stat;
    173       1.1  cube 	vrele(nd.ni_vp);
    174  1.1.14.1  yamt 	if ((error = VFS_STATVFS(mp, sp, l)) != 0)
    175       1.1  cube 		return (error);
    176       1.1  cube 	sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
    177       1.1  cube 	compat_20_netbsd32_from_statvfs(sp, &s32);
    178       1.1  cube 	return (copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
    179       1.1  cube 	    sizeof(s32)));
    180       1.1  cube }
    181       1.1  cube 
    182       1.1  cube int
    183       1.1  cube compat_20_netbsd32_fstatfs(l, v, retval)
    184       1.1  cube 	struct lwp *l;
    185       1.1  cube 	void *v;
    186       1.1  cube 	register_t *retval;
    187       1.1  cube {
    188       1.1  cube 	struct compat_20_netbsd32_fstatfs_args /* {
    189       1.1  cube 		syscallarg(int) fd;
    190       1.1  cube 		syscallarg(netbsd32_statfsp_t) buf;
    191       1.1  cube 	} */ *uap = v;
    192       1.1  cube 	struct file *fp;
    193       1.1  cube 	struct mount *mp;
    194       1.1  cube 	struct statvfs *sp;
    195       1.1  cube 	struct netbsd32_statfs s32;
    196       1.1  cube 	int error;
    197       1.1  cube 	struct proc *p = l->l_proc;
    198       1.1  cube 
    199       1.1  cube 	/* getvnode() will use the descriptor for us */
    200       1.1  cube 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    201       1.1  cube 		return (error);
    202       1.1  cube 	mp = ((struct vnode *)fp->f_data)->v_mount;
    203       1.1  cube 	sp = &mp->mnt_stat;
    204  1.1.14.1  yamt 	if ((error = VFS_STATVFS(mp, sp, l)) != 0)
    205       1.1  cube 		goto out;
    206       1.1  cube 	sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
    207       1.1  cube 	compat_20_netbsd32_from_statvfs(sp, &s32);
    208       1.1  cube 	error = copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
    209       1.1  cube 	    sizeof(s32));
    210       1.1  cube  out:
    211  1.1.14.1  yamt 	FILE_UNUSE(fp, l);
    212       1.1  cube 	return (error);
    213       1.1  cube }
    214       1.1  cube 
    215       1.1  cube int
    216       1.1  cube compat_20_netbsd32_fhstatfs(l, v, retval)
    217       1.1  cube 	struct lwp *l;
    218       1.1  cube 	void *v;
    219       1.1  cube 	register_t *retval;
    220       1.1  cube {
    221       1.1  cube 	struct compat_20_netbsd32_fhstatfs_args /* {
    222       1.1  cube 		syscallarg(const netbsd32_fhandlep_t) fhp;
    223       1.1  cube 		syscallarg(struct statvfs *) buf;
    224       1.1  cube 	} */ *uap = v;
    225  1.1.14.2  yamt 	struct compat_30_sys_fhstatvfs1_args ua;
    226       1.1  cube 
    227  1.1.14.2  yamt 	NETBSD32TOP_UAP(fhp, const struct compat_30_fhandle);
    228       1.1  cube 	NETBSD32TOP_UAP(buf, struct statvfs);
    229       1.1  cube #ifdef notyet
    230       1.1  cube 	NETBSD32TOP_UAP(flags, int);
    231       1.1  cube #endif
    232  1.1.14.2  yamt 	return (compat_30_sys_fhstatvfs1(l, &ua, retval));
    233       1.1  cube }
    234