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