Home | History | Annotate | Line # | Download | only in common
linux_misc_notalpha.c revision 1.77.2.2
      1  1.77.2.2      yamt /*	$NetBSD: linux_misc_notalpha.c,v 1.77.2.2 2006/06/26 12:46:18 yamt Exp $	*/
      2      1.47       erh 
      3      1.47       erh /*-
      4      1.49      fvdl  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
      5      1.47       erh  * All rights reserved.
      6      1.47       erh  *
      7      1.47       erh  * This code is derived from software contributed to The NetBSD Foundation
      8      1.51   thorpej  * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
      9      1.51   thorpej  * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center.
     10      1.47       erh  *
     11      1.47       erh  * Redistribution and use in source and binary forms, with or without
     12      1.47       erh  * modification, are permitted provided that the following conditions
     13      1.47       erh  * are met:
     14      1.47       erh  * 1. Redistributions of source code must retain the above copyright
     15      1.47       erh  *    notice, this list of conditions and the following disclaimer.
     16      1.47       erh  * 2. Redistributions in binary form must reproduce the above copyright
     17      1.47       erh  *    notice, this list of conditions and the following disclaimer in the
     18      1.47       erh  *    documentation and/or other materials provided with the distribution.
     19      1.47       erh  * 3. All advertising materials mentioning features or use of this software
     20      1.47       erh  *    must display the following acknowledgement:
     21      1.47       erh  *	This product includes software developed by the NetBSD
     22      1.47       erh  *	Foundation, Inc. and its contributors.
     23      1.47       erh  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24      1.47       erh  *    contributors may be used to endorse or promote products derived
     25      1.47       erh  *    from this software without specific prior written permission.
     26      1.47       erh  *
     27      1.47       erh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28      1.47       erh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29      1.47       erh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30      1.47       erh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31      1.47       erh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32      1.47       erh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33      1.47       erh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34      1.47       erh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35      1.47       erh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36      1.47       erh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37      1.47       erh  * POSSIBILITY OF SUCH DAMAGE.
     38       1.1      fvdl  */
     39      1.61     lukem 
     40      1.61     lukem #include <sys/cdefs.h>
     41  1.77.2.2      yamt __KERNEL_RCSID(0, "$NetBSD: linux_misc_notalpha.c,v 1.77.2.2 2006/06/26 12:46:18 yamt Exp $");
     42       1.1      fvdl 
     43       1.1      fvdl #include <sys/param.h>
     44       1.1      fvdl #include <sys/systm.h>
     45       1.1      fvdl #include <sys/kernel.h>
     46      1.47       erh #include <sys/mman.h>
     47      1.47       erh #include <sys/mount.h>
     48       1.1      fvdl #include <sys/malloc.h>
     49       1.1      fvdl #include <sys/mbuf.h>
     50      1.47       erh #include <sys/namei.h>
     51      1.57     itohy #include <sys/proc.h>
     52       1.1      fvdl #include <sys/ptrace.h>
     53       1.1      fvdl #include <sys/resource.h>
     54       1.1      fvdl #include <sys/resourcevar.h>
     55      1.64   thorpej #include <sys/time.h>
     56       1.1      fvdl #include <sys/wait.h>
     57  1.77.2.1      yamt #include <sys/kauth.h>
     58       1.1      fvdl 
     59      1.64   thorpej #include <sys/sa.h>
     60       1.1      fvdl #include <sys/syscallargs.h>
     61       1.1      fvdl 
     62      1.48  christos #include <compat/linux/common/linux_types.h>
     63      1.48  christos #include <compat/linux/common/linux_fcntl.h>
     64      1.48  christos #include <compat/linux/common/linux_misc.h>
     65      1.48  christos #include <compat/linux/common/linux_mmap.h>
     66      1.48  christos #include <compat/linux/common/linux_signal.h>
     67      1.48  christos #include <compat/linux/common/linux_util.h>
     68      1.48  christos 
     69       1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     70      1.26  christos 
     71       1.1      fvdl /*
     72      1.47       erh  * This file contains routines which are used
     73      1.47       erh  * on every linux architechture except the Alpha.
     74       1.1      fvdl  */
     75      1.21   mycroft 
     76      1.47       erh /* Used on: arm, i386, m68k, mips, ppc, sparc, sparc64 */
     77      1.47       erh /* Not used on: alpha */
     78       1.1      fvdl 
     79      1.70  jdolecek #ifdef DEBUG_LINUX
     80      1.70  jdolecek #define DPRINTF(a)	uprintf a
     81      1.70  jdolecek #else
     82      1.70  jdolecek #define DPRINTF(a)
     83      1.70  jdolecek #endif
     84      1.70  jdolecek 
     85      1.77      manu #ifndef COMPAT_LINUX32
     86      1.74      manu #if !defined(__m68k__)
     87      1.70  jdolecek static void bsd_to_linux_statfs64(const struct statvfs *,
     88      1.70  jdolecek 	struct linux_statfs64  *);
     89      1.71        he #endif
     90      1.70  jdolecek 
     91       1.1      fvdl /*
     92      1.47       erh  * Alarm. This is a libc call which uses setitimer(2) in NetBSD.
     93      1.47       erh  * Fiddle with the timers to make it work.
     94       1.1      fvdl  */
     95       1.1      fvdl int
     96      1.64   thorpej linux_sys_alarm(l, v, retval)
     97      1.64   thorpej 	struct lwp *l;
     98      1.20   thorpej 	void *v;
     99      1.20   thorpej 	register_t *retval;
    100      1.20   thorpej {
    101      1.47       erh 	struct linux_sys_alarm_args /* {
    102      1.47       erh 		syscallarg(unsigned int) secs;
    103      1.20   thorpej 	} */ *uap = v;
    104      1.64   thorpej 	struct proc *p = l->l_proc;
    105  1.77.2.2      yamt 	struct timeval now;
    106      1.47       erh 	struct itimerval *itp, it;
    107      1.64   thorpej 	struct ptimer *ptp;
    108  1.77.2.2      yamt 	int s;
    109       1.1      fvdl 
    110      1.64   thorpej 	if (p->p_timers && p->p_timers->pts_timers[ITIMER_REAL])
    111      1.64   thorpej 		itp = &p->p_timers->pts_timers[ITIMER_REAL]->pt_time;
    112      1.64   thorpej 	else
    113      1.64   thorpej 		itp = NULL;
    114      1.47       erh 	s = splclock();
    115      1.47       erh 	/*
    116      1.47       erh 	 * Clear any pending timer alarms.
    117      1.47       erh 	 */
    118      1.64   thorpej 	if (itp) {
    119      1.64   thorpej 		callout_stop(&p->p_timers->pts_timers[ITIMER_REAL]->pt_ch);
    120      1.64   thorpej 		timerclear(&itp->it_interval);
    121  1.77.2.2      yamt 		getmicrotime(&now);
    122      1.64   thorpej 		if (timerisset(&itp->it_value) &&
    123  1.77.2.2      yamt 		    timercmp(&itp->it_value, &now, >))
    124  1.77.2.2      yamt 			timersub(&itp->it_value, &now, &itp->it_value);
    125      1.64   thorpej 		/*
    126      1.64   thorpej 		 * Return how many seconds were left (rounded up)
    127      1.64   thorpej 		 */
    128      1.64   thorpej 		retval[0] = itp->it_value.tv_sec;
    129      1.64   thorpej 		if (itp->it_value.tv_usec)
    130      1.64   thorpej 			retval[0]++;
    131      1.64   thorpej 	} else {
    132      1.64   thorpej 		retval[0] = 0;
    133      1.73     perry 	}
    134       1.1      fvdl 
    135      1.47       erh 	/*
    136      1.47       erh 	 * alarm(0) just resets the timer.
    137      1.47       erh 	 */
    138      1.47       erh 	if (SCARG(uap, secs) == 0) {
    139      1.64   thorpej 		if (itp)
    140      1.64   thorpej 			timerclear(&itp->it_value);
    141      1.47       erh 		splx(s);
    142      1.47       erh 		return 0;
    143      1.47       erh 	}
    144       1.1      fvdl 
    145      1.47       erh 	/*
    146      1.47       erh 	 * Check the new alarm time for sanity, and set it.
    147      1.47       erh 	 */
    148      1.47       erh 	timerclear(&it.it_interval);
    149      1.47       erh 	it.it_value.tv_sec = SCARG(uap, secs);
    150      1.47       erh 	it.it_value.tv_usec = 0;
    151      1.47       erh 	if (itimerfix(&it.it_value) || itimerfix(&it.it_interval)) {
    152      1.47       erh 		splx(s);
    153      1.47       erh 		return (EINVAL);
    154      1.16      fvdl 	}
    155       1.1      fvdl 
    156      1.64   thorpej 	if (p->p_timers == NULL)
    157      1.64   thorpej 		timers_alloc(p);
    158      1.64   thorpej 	ptp = p->p_timers->pts_timers[ITIMER_REAL];
    159      1.64   thorpej 	if (ptp == NULL) {
    160      1.64   thorpej 		ptp = pool_get(&ptimer_pool, PR_WAITOK);
    161      1.64   thorpej 		ptp->pt_ev.sigev_notify = SIGEV_SIGNAL;
    162      1.64   thorpej 		ptp->pt_ev.sigev_signo = SIGALRM;
    163      1.65  jdolecek 		ptp->pt_overruns = 0;
    164      1.65  jdolecek 		ptp->pt_proc = p;
    165      1.64   thorpej 		ptp->pt_type = CLOCK_REALTIME;
    166      1.65  jdolecek 		ptp->pt_entry = CLOCK_REALTIME;
    167      1.64   thorpej 		callout_init(&ptp->pt_ch);
    168      1.66     enami 		p->p_timers->pts_timers[ITIMER_REAL] = ptp;
    169      1.64   thorpej 	}
    170      1.64   thorpej 
    171      1.47       erh 	if (timerisset(&it.it_value)) {
    172      1.56   thorpej 		/*
    173      1.56   thorpej 		 * Don't need to check hzto() return value, here.
    174      1.56   thorpej 		 * callout_reset() does it for us.
    175      1.56   thorpej 		 */
    176  1.77.2.2      yamt 		getmicrotime(&now);
    177  1.77.2.2      yamt 		timeradd(&it.it_value, &now, &it.it_value);
    178      1.64   thorpej 		callout_reset(&ptp->pt_ch, hzto(&it.it_value),
    179      1.64   thorpej 		    realtimerexpire, ptp);
    180      1.16      fvdl 	}
    181      1.64   thorpej 	ptp->pt_time = it;
    182      1.47       erh 	splx(s);
    183       1.1      fvdl 
    184      1.16      fvdl 	return 0;
    185       1.1      fvdl }
    186      1.77      manu #endif /* !COMPAT_LINUX32 */
    187       1.1      fvdl 
    188      1.77      manu #if !defined(__amd64__) || defined(COMPAT_LINUX32)
    189       1.1      fvdl int
    190      1.64   thorpej linux_sys_nice(l, v, retval)
    191      1.64   thorpej 	struct lwp *l;
    192      1.20   thorpej 	void *v;
    193      1.20   thorpej 	register_t *retval;
    194      1.20   thorpej {
    195      1.47       erh 	struct linux_sys_nice_args /* {
    196      1.47       erh 		syscallarg(int) incr;
    197      1.20   thorpej 	} */ *uap = v;
    198      1.47       erh         struct sys_setpriority_args bsa;
    199      1.20   thorpej 
    200      1.47       erh         SCARG(&bsa, which) = PRIO_PROCESS;
    201      1.47       erh         SCARG(&bsa, who) = 0;
    202      1.47       erh 	SCARG(&bsa, prio) = SCARG(uap, incr);
    203      1.64   thorpej         return sys_setpriority(l, &bsa, retval);
    204       1.1      fvdl }
    205      1.77      manu #endif /* !__amd64__ || COMPAT_LINUX32 */
    206       1.1      fvdl 
    207      1.77      manu #ifndef COMPAT_LINUX32
    208      1.74      manu #ifndef __amd64__
    209       1.1      fvdl /*
    210      1.47       erh  * The old Linux readdir was only able to read one entry at a time,
    211      1.47       erh  * even though it had a 'count' argument. In fact, the emulation
    212      1.47       erh  * of the old call was better than the original, because it did handle
    213      1.47       erh  * the count arg properly. Don't bother with it anymore now, and use
    214      1.47       erh  * it to distinguish between old and new. The difference is that the
    215      1.47       erh  * newer one actually does multiple entries, and the reclen field
    216      1.47       erh  * really is the reclen, not the namelength.
    217       1.1      fvdl  */
    218       1.1      fvdl int
    219      1.64   thorpej linux_sys_readdir(l, v, retval)
    220      1.64   thorpej 	struct lwp *l;
    221      1.20   thorpej 	void *v;
    222      1.20   thorpej 	register_t *retval;
    223      1.20   thorpej {
    224      1.47       erh 	struct linux_sys_readdir_args /* {
    225      1.47       erh 		syscallarg(int) fd;
    226      1.47       erh 		syscallarg(struct linux_dirent *) dent;
    227      1.47       erh 		syscallarg(unsigned int) count;
    228      1.20   thorpej 	} */ *uap = v;
    229       1.1      fvdl 
    230      1.47       erh 	SCARG(uap, count) = 1;
    231      1.64   thorpej 	return linux_sys_getdents(l, uap, retval);
    232       1.1      fvdl }
    233      1.74      manu #endif /* !amd64 */
    234       1.1      fvdl 
    235       1.1      fvdl /*
    236       1.1      fvdl  * I wonder why Linux has gettimeofday() _and_ time().. Still, we
    237       1.1      fvdl  * need to deal with it.
    238       1.1      fvdl  */
    239       1.1      fvdl int
    240      1.64   thorpej linux_sys_time(l, v, retval)
    241      1.64   thorpej 	struct lwp *l;
    242      1.20   thorpej 	void *v;
    243      1.20   thorpej 	register_t *retval;
    244      1.20   thorpej {
    245      1.21   mycroft 	struct linux_sys_time_args /* {
    246       1.1      fvdl 		linux_time_t *t;
    247      1.20   thorpej 	} */ *uap = v;
    248       1.1      fvdl 	struct timeval atv;
    249       1.1      fvdl 	linux_time_t tt;
    250       1.1      fvdl 	int error;
    251       1.1      fvdl 
    252       1.1      fvdl 	microtime(&atv);
    253       1.1      fvdl 
    254       1.1      fvdl 	tt = atv.tv_sec;
    255       1.1      fvdl 	if (SCARG(uap, t) && (error = copyout(&tt, SCARG(uap, t), sizeof tt)))
    256       1.1      fvdl 		return error;
    257       1.1      fvdl 
    258       1.1      fvdl 	retval[0] = tt;
    259       1.1      fvdl 	return 0;
    260       1.1      fvdl }
    261       1.1      fvdl 
    262       1.1      fvdl /*
    263      1.73     perry  * utime(). Do conversion to things that utimes() understands,
    264      1.47       erh  * and pass it on.
    265       1.1      fvdl  */
    266       1.1      fvdl int
    267      1.64   thorpej linux_sys_utime(l, v, retval)
    268      1.64   thorpej 	struct lwp *l;
    269      1.20   thorpej 	void *v;
    270      1.20   thorpej 	register_t *retval;
    271      1.20   thorpej {
    272      1.47       erh 	struct linux_sys_utime_args /* {
    273      1.50  christos 		syscallarg(const char *) path;
    274      1.47       erh 		syscallarg(struct linux_utimbuf *)times;
    275      1.20   thorpej 	} */ *uap = v;
    276      1.64   thorpej 	struct proc *p = l->l_proc;
    277       1.2      fvdl 	caddr_t sg;
    278       1.2      fvdl 	int error;
    279      1.47       erh 	struct sys_utimes_args ua;
    280      1.47       erh 	struct timeval tv[2], *tvp;
    281      1.47       erh 	struct linux_utimbuf lut;
    282       1.2      fvdl 
    283      1.62  christos 	sg = stackgap_init(p, 0);
    284      1.62  christos 	tvp = (struct timeval *) stackgap_alloc(p, &sg, sizeof(tv));
    285      1.76  christos 	CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
    286       1.2      fvdl 
    287      1.47       erh 	SCARG(&ua, path) = SCARG(uap, path);
    288       1.2      fvdl 
    289      1.47       erh 	if (SCARG(uap, times) != NULL) {
    290      1.47       erh 		if ((error = copyin(SCARG(uap, times), &lut, sizeof lut)))
    291      1.47       erh 			return error;
    292      1.47       erh 		tv[0].tv_usec = tv[1].tv_usec = 0;
    293      1.47       erh 		tv[0].tv_sec = lut.l_actime;
    294      1.47       erh 		tv[1].tv_sec = lut.l_modtime;
    295      1.47       erh 		if ((error = copyout(tv, tvp, sizeof tv)))
    296      1.47       erh 			return error;
    297      1.47       erh 		SCARG(&ua, tptr) = tvp;
    298      1.47       erh 	}
    299      1.47       erh 	else
    300      1.47       erh 		SCARG(&ua, tptr) = NULL;
    301       1.2      fvdl 
    302      1.64   thorpej 	return sys_utimes(l, &ua, retval);
    303       1.1      fvdl }
    304       1.1      fvdl 
    305      1.74      manu #ifndef __amd64__
    306      1.47       erh /*
    307      1.72       erh  * waitpid(2).  Just forward on to linux_sys_wait4 with a NULL rusage.
    308      1.47       erh  */
    309       1.1      fvdl int
    310      1.64   thorpej linux_sys_waitpid(l, v, retval)
    311      1.64   thorpej 	struct lwp *l;
    312      1.20   thorpej 	void *v;
    313      1.20   thorpej 	register_t *retval;
    314      1.20   thorpej {
    315      1.47       erh 	struct linux_sys_waitpid_args /* {
    316      1.47       erh 		syscallarg(int) pid;
    317      1.47       erh 		syscallarg(int *) status;
    318      1.47       erh 		syscallarg(int) options;
    319      1.20   thorpej 	} */ *uap = v;
    320      1.72       erh 	struct linux_sys_wait4_args linux_w4a;
    321       1.2      fvdl 
    322      1.72       erh 	SCARG(&linux_w4a, pid) = SCARG(uap, pid);
    323      1.72       erh 	SCARG(&linux_w4a, status) = SCARG(uap, status);
    324      1.72       erh 	SCARG(&linux_w4a, options) = SCARG(uap, options);
    325      1.72       erh 	SCARG(&linux_w4a, rusage) = NULL;
    326       1.2      fvdl 
    327      1.72       erh 	return linux_sys_wait4(l, &linux_w4a, retval);
    328      1.51   thorpej }
    329      1.74      manu #endif /* !amd64 */
    330      1.51   thorpej 
    331      1.51   thorpej int
    332      1.64   thorpej linux_sys_setresgid(l, v, retval)
    333      1.64   thorpej 	struct lwp *l;
    334      1.51   thorpej 	void *v;
    335      1.51   thorpej 	register_t *retval;
    336      1.51   thorpej {
    337      1.51   thorpej 	struct linux_sys_setresgid_args /* {
    338      1.51   thorpej 		syscallarg(gid_t) rgid;
    339      1.51   thorpej 		syscallarg(gid_t) egid;
    340      1.51   thorpej 		syscallarg(gid_t) sgid;
    341      1.51   thorpej 	} */ *uap = v;
    342      1.51   thorpej 
    343      1.51   thorpej 	/*
    344      1.51   thorpej 	 * Note: These checks are a little different than the NetBSD
    345      1.51   thorpej 	 * setregid(2) call performs.  This precisely follows the
    346      1.51   thorpej 	 * behavior of the Linux kernel.
    347      1.51   thorpej 	 */
    348      1.67       dsl 	return do_setresgid(l, SCARG(uap,rgid), SCARG(uap, egid),
    349      1.67       dsl 			    SCARG(uap, sgid),
    350      1.67       dsl 			    ID_R_EQ_R | ID_R_EQ_E | ID_R_EQ_S |
    351      1.67       dsl 			    ID_E_EQ_R | ID_E_EQ_E | ID_E_EQ_S |
    352      1.67       dsl 			    ID_S_EQ_R | ID_S_EQ_E | ID_S_EQ_S );
    353      1.51   thorpej }
    354      1.51   thorpej 
    355      1.51   thorpej int
    356      1.64   thorpej linux_sys_getresgid(l, v, retval)
    357      1.64   thorpej 	struct lwp *l;
    358      1.51   thorpej 	void *v;
    359      1.51   thorpej 	register_t *retval;
    360      1.51   thorpej {
    361      1.51   thorpej 	struct linux_sys_getresgid_args /* {
    362      1.51   thorpej 		syscallarg(gid_t *) rgid;
    363      1.51   thorpej 		syscallarg(gid_t *) egid;
    364      1.51   thorpej 		syscallarg(gid_t *) sgid;
    365      1.51   thorpej 	} */ *uap = v;
    366      1.64   thorpej 	struct proc *p = l->l_proc;
    367  1.77.2.1      yamt 	kauth_cred_t pc = p->p_cred;
    368      1.51   thorpej 	int error;
    369  1.77.2.1      yamt 	gid_t gid;
    370      1.51   thorpej 
    371      1.51   thorpej 	/*
    372      1.51   thorpej 	 * Linux copies these values out to userspace like so:
    373      1.51   thorpej 	 *
    374      1.51   thorpej 	 *	1. Copy out rgid.
    375      1.51   thorpej 	 *	2. If that succeeds, copy out egid.
    376      1.51   thorpej 	 *	3. If both of those succeed, copy out sgid.
    377      1.51   thorpej 	 */
    378  1.77.2.1      yamt 	gid = kauth_cred_getgid(pc);
    379  1.77.2.1      yamt 	if ((error = copyout(&gid, SCARG(uap, rgid), sizeof(gid_t))) != 0)
    380      1.51   thorpej 		return (error);
    381      1.51   thorpej 
    382  1.77.2.1      yamt 	gid = kauth_cred_getegid(pc);
    383  1.77.2.1      yamt 	if ((error = copyout(&gid, SCARG(uap, egid), sizeof(gid_t))) != 0)
    384      1.51   thorpej 		return (error);
    385      1.51   thorpej 
    386  1.77.2.1      yamt 	gid = kauth_cred_getsvgid(pc);
    387  1.77.2.1      yamt 
    388  1.77.2.1      yamt 	return (copyout(&gid, SCARG(uap, sgid), sizeof(gid_t)));
    389      1.52      tron }
    390      1.52      tron 
    391      1.74      manu #ifndef __amd64__
    392      1.52      tron /*
    393      1.52      tron  * I wonder why Linux has settimeofday() _and_ stime().. Still, we
    394      1.52      tron  * need to deal with it.
    395      1.52      tron  */
    396      1.52      tron int
    397      1.64   thorpej linux_sys_stime(l, v, retval)
    398      1.64   thorpej 	struct lwp *l;
    399      1.52      tron 	void *v;
    400      1.52      tron 	register_t *retval;
    401      1.52      tron {
    402      1.52      tron 	struct linux_sys_time_args /* {
    403      1.52      tron 		linux_time_t *t;
    404      1.52      tron 	} */ *uap = v;
    405      1.64   thorpej 	struct proc *p = l->l_proc;
    406      1.75  christos 	struct timespec ats;
    407      1.52      tron 	linux_time_t tt;
    408      1.52      tron 	int error;
    409      1.52      tron 
    410  1.77.2.1      yamt 	if ((error = kauth_authorize_generic(p->p_cred, KAUTH_GENERIC_ISSUSER, &p->p_acflag)) != 0)
    411      1.52      tron 		return (error);
    412      1.52      tron 
    413      1.52      tron 	if ((error = copyin(&tt, SCARG(uap, t), sizeof tt)) != 0)
    414      1.52      tron 		return error;
    415      1.52      tron 
    416      1.75  christos 	ats.tv_sec = tt;
    417      1.75  christos 	ats.tv_nsec = 0;
    418      1.52      tron 
    419      1.75  christos 	if ((error = settime(p, &ats)))
    420      1.52      tron 		return (error);
    421      1.52      tron 
    422      1.52      tron 	return 0;
    423       1.1      fvdl }
    424      1.74      manu #endif /* !amd64 */
    425      1.70  jdolecek 
    426      1.74      manu #if !defined(__m68k__)
    427      1.70  jdolecek /*
    428      1.70  jdolecek  * Convert NetBSD statvfs structure to Linux statfs64 structure.
    429      1.70  jdolecek  * See comments in bsd_to_linux_statfs() for further background.
    430      1.70  jdolecek  * We can safely pass correct bsize and frsize here, since Linux glibc
    431      1.70  jdolecek  * statvfs() doesn't use statfs64().
    432      1.70  jdolecek  */
    433      1.70  jdolecek static void
    434      1.70  jdolecek bsd_to_linux_statfs64(bsp, lsp)
    435      1.70  jdolecek 	const struct statvfs *bsp;
    436      1.70  jdolecek 	struct linux_statfs64 *lsp;
    437      1.70  jdolecek {
    438      1.70  jdolecek 	int i, div;
    439      1.70  jdolecek 
    440      1.70  jdolecek 	for (i = 0; i < linux_fstypes_cnt; i++) {
    441      1.70  jdolecek 		if (strcmp(bsp->f_fstypename, linux_fstypes[i].bsd) == 0) {
    442      1.70  jdolecek 			lsp->l_ftype = linux_fstypes[i].linux;
    443      1.70  jdolecek 			break;
    444      1.70  jdolecek 		}
    445      1.70  jdolecek 	}
    446      1.70  jdolecek 
    447      1.70  jdolecek 	if (i == linux_fstypes_cnt) {
    448      1.70  jdolecek 		DPRINTF(("unhandled fstype in linux emulation: %s\n",
    449      1.70  jdolecek 		    bsp->f_fstypename));
    450      1.70  jdolecek 		lsp->l_ftype = LINUX_DEFAULT_SUPER_MAGIC;
    451      1.70  jdolecek 	}
    452      1.70  jdolecek 
    453      1.70  jdolecek 	div = bsp->f_bsize / bsp->f_frsize;
    454      1.70  jdolecek 	lsp->l_fbsize = bsp->f_bsize;
    455      1.70  jdolecek 	lsp->l_ffrsize = bsp->f_frsize;
    456      1.70  jdolecek 	lsp->l_fblocks = bsp->f_blocks / div;
    457      1.70  jdolecek 	lsp->l_fbfree = bsp->f_bfree / div;
    458      1.70  jdolecek 	lsp->l_fbavail = bsp->f_bavail / div;
    459      1.70  jdolecek 	lsp->l_ffiles = bsp->f_files;
    460      1.70  jdolecek 	lsp->l_fffree = bsp->f_ffree / div;
    461      1.70  jdolecek 	/* Linux sets the fsid to 0..., we don't */
    462      1.70  jdolecek 	lsp->l_ffsid.val[0] = bsp->f_fsidx.__fsid_val[0];
    463      1.70  jdolecek 	lsp->l_ffsid.val[1] = bsp->f_fsidx.__fsid_val[1];
    464      1.70  jdolecek 	lsp->l_fnamelen = bsp->f_namemax;
    465      1.70  jdolecek 	(void)memset(lsp->l_fspare, 0, sizeof(lsp->l_fspare));
    466      1.70  jdolecek }
    467      1.70  jdolecek 
    468      1.70  jdolecek /*
    469      1.70  jdolecek  * Implement the fs stat functions. Straightforward.
    470      1.70  jdolecek  */
    471      1.70  jdolecek int
    472      1.70  jdolecek linux_sys_statfs64(l, v, retval)
    473      1.70  jdolecek 	struct lwp *l;
    474      1.70  jdolecek 	void *v;
    475      1.70  jdolecek 	register_t *retval;
    476      1.70  jdolecek {
    477      1.70  jdolecek 	struct linux_sys_statfs64_args /* {
    478      1.70  jdolecek 		syscallarg(const char *) path;
    479      1.70  jdolecek 		syscallarg(size_t) sz;
    480      1.70  jdolecek 		syscallarg(struct linux_statfs64 *) sp;
    481      1.70  jdolecek 	} */ *uap = v;
    482      1.70  jdolecek 	struct proc *p = l->l_proc;
    483  1.77.2.1      yamt 	struct statvfs *btmp, *bsp;
    484      1.70  jdolecek 	struct linux_statfs64 ltmp;
    485      1.70  jdolecek 	struct sys_statvfs1_args bsa;
    486      1.70  jdolecek 	caddr_t sg;
    487      1.70  jdolecek 	int error;
    488      1.70  jdolecek 
    489      1.70  jdolecek 	if (SCARG(uap, sz) != sizeof ltmp)
    490      1.70  jdolecek 		return (EINVAL);
    491      1.70  jdolecek 
    492      1.70  jdolecek 	sg = stackgap_init(p, 0);
    493  1.77.2.1      yamt 	bsp = stackgap_alloc(p, &sg, sizeof (struct statvfs));
    494      1.70  jdolecek 
    495      1.76  christos 	CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
    496      1.70  jdolecek 
    497      1.70  jdolecek 	SCARG(&bsa, path) = SCARG(uap, path);
    498      1.70  jdolecek 	SCARG(&bsa, buf) = bsp;
    499      1.70  jdolecek 	SCARG(&bsa, flags) = ST_WAIT;
    500      1.70  jdolecek 
    501      1.70  jdolecek 	if ((error = sys_statvfs1(l, &bsa, retval)))
    502      1.70  jdolecek 		return error;
    503      1.70  jdolecek 
    504  1.77.2.1      yamt 	btmp = STATVFSBUF_GET();
    505  1.77.2.1      yamt 	error = copyin(bsp, btmp, sizeof(*btmp));
    506  1.77.2.1      yamt 	if (error) {
    507  1.77.2.1      yamt 		goto out;
    508  1.77.2.1      yamt 	}
    509  1.77.2.1      yamt 	bsd_to_linux_statfs64(btmp, &ltmp);
    510  1.77.2.1      yamt 	error = copyout(&ltmp, SCARG(uap, sp), sizeof ltmp);
    511  1.77.2.1      yamt out:
    512  1.77.2.1      yamt 	STATVFSBUF_PUT(btmp);
    513  1.77.2.1      yamt 	return error;
    514      1.70  jdolecek }
    515      1.70  jdolecek 
    516      1.70  jdolecek int
    517      1.70  jdolecek linux_sys_fstatfs64(l, v, retval)
    518      1.70  jdolecek 	struct lwp *l;
    519      1.70  jdolecek 	void *v;
    520      1.70  jdolecek 	register_t *retval;
    521      1.70  jdolecek {
    522      1.70  jdolecek 	struct linux_sys_fstatfs64_args /* {
    523      1.70  jdolecek 		syscallarg(int) fd;
    524      1.70  jdolecek 		syscallarg(size_t) sz;
    525      1.70  jdolecek 		syscallarg(struct linux_statfs64 *) sp;
    526      1.70  jdolecek 	} */ *uap = v;
    527      1.70  jdolecek 	struct proc *p = l->l_proc;
    528  1.77.2.1      yamt 	struct statvfs *btmp, *bsp;
    529      1.70  jdolecek 	struct linux_statfs64 ltmp;
    530      1.70  jdolecek 	struct sys_fstatvfs1_args bsa;
    531      1.70  jdolecek 	caddr_t sg;
    532      1.70  jdolecek 	int error;
    533      1.70  jdolecek 
    534      1.70  jdolecek 	if (SCARG(uap, sz) != sizeof ltmp)
    535      1.70  jdolecek 		return (EINVAL);
    536      1.70  jdolecek 
    537      1.70  jdolecek 	sg = stackgap_init(p, 0);
    538  1.77.2.1      yamt 	bsp = stackgap_alloc(p, &sg, sizeof (struct statvfs));
    539      1.70  jdolecek 
    540      1.70  jdolecek 	SCARG(&bsa, fd) = SCARG(uap, fd);
    541      1.70  jdolecek 	SCARG(&bsa, buf) = bsp;
    542      1.70  jdolecek 	SCARG(&bsa, flags) = ST_WAIT;
    543      1.70  jdolecek 
    544      1.70  jdolecek 	if ((error = sys_fstatvfs1(l, &bsa, retval)))
    545      1.70  jdolecek 		return error;
    546      1.70  jdolecek 
    547  1.77.2.1      yamt 	btmp = STATVFSBUF_GET();
    548  1.77.2.1      yamt 	error = copyin(bsp, btmp, sizeof(*btmp));
    549  1.77.2.1      yamt 	if (error) {
    550  1.77.2.1      yamt 		goto out;
    551  1.77.2.1      yamt 	}
    552  1.77.2.1      yamt 	bsd_to_linux_statfs64(btmp, &ltmp);
    553  1.77.2.1      yamt 	error = copyout(&ltmp, SCARG(uap, sp), sizeof ltmp);
    554  1.77.2.1      yamt out:
    555  1.77.2.1      yamt 	STATVFSBUF_PUT(btmp);
    556  1.77.2.1      yamt 	return error;
    557      1.70  jdolecek }
    558      1.70  jdolecek #endif /* !__m68k__ */
    559      1.77      manu #endif /* !COMPAT_LINUX32 */
    560