Home | History | Annotate | Line # | Download | only in common
linux_misc_notalpha.c revision 1.69.2.4
      1  1.69.2.4     skrll /*	$NetBSD: linux_misc_notalpha.c,v 1.69.2.4 2004/09/24 10:53:18 skrll 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.69.2.4     skrll __KERNEL_RCSID(0, "$NetBSD: linux_misc_notalpha.c,v 1.69.2.4 2004/09/24 10:53:18 skrll 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.1      fvdl 
     58      1.64   thorpej #include <sys/sa.h>
     59       1.1      fvdl #include <sys/syscallargs.h>
     60       1.1      fvdl 
     61      1.48  christos #include <compat/linux/common/linux_types.h>
     62      1.48  christos #include <compat/linux/common/linux_fcntl.h>
     63      1.48  christos #include <compat/linux/common/linux_misc.h>
     64      1.48  christos #include <compat/linux/common/linux_mmap.h>
     65      1.48  christos #include <compat/linux/common/linux_signal.h>
     66      1.48  christos #include <compat/linux/common/linux_util.h>
     67      1.48  christos 
     68       1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     69      1.26  christos 
     70       1.1      fvdl /*
     71      1.47       erh  * This file contains routines which are used
     72      1.47       erh  * on every linux architechture except the Alpha.
     73       1.1      fvdl  */
     74      1.21   mycroft 
     75      1.47       erh /* Used on: arm, i386, m68k, mips, ppc, sparc, sparc64 */
     76      1.47       erh /* Not used on: alpha */
     77       1.1      fvdl 
     78  1.69.2.4     skrll #ifdef DEBUG_LINUX
     79  1.69.2.4     skrll #define DPRINTF(a)	uprintf a
     80  1.69.2.4     skrll #else
     81  1.69.2.4     skrll #define DPRINTF(a)
     82  1.69.2.4     skrll #endif
     83  1.69.2.4     skrll 
     84  1.69.2.4     skrll static void bsd_to_linux_statfs64(const struct statvfs *,
     85  1.69.2.4     skrll 	struct linux_statfs64  *);
     86  1.69.2.4     skrll 
     87       1.1      fvdl /*
     88      1.47       erh  * Alarm. This is a libc call which uses setitimer(2) in NetBSD.
     89      1.47       erh  * Fiddle with the timers to make it work.
     90       1.1      fvdl  */
     91       1.1      fvdl int
     92      1.64   thorpej linux_sys_alarm(l, v, retval)
     93      1.64   thorpej 	struct lwp *l;
     94      1.20   thorpej 	void *v;
     95      1.20   thorpej 	register_t *retval;
     96      1.20   thorpej {
     97      1.47       erh 	struct linux_sys_alarm_args /* {
     98      1.47       erh 		syscallarg(unsigned int) secs;
     99      1.20   thorpej 	} */ *uap = v;
    100      1.64   thorpej 	struct proc *p = l->l_proc;
    101      1.47       erh 	int s;
    102      1.47       erh 	struct itimerval *itp, it;
    103      1.64   thorpej 	struct ptimer *ptp;
    104       1.1      fvdl 
    105      1.64   thorpej 	if (p->p_timers && p->p_timers->pts_timers[ITIMER_REAL])
    106      1.64   thorpej 		itp = &p->p_timers->pts_timers[ITIMER_REAL]->pt_time;
    107      1.64   thorpej 	else
    108      1.64   thorpej 		itp = NULL;
    109      1.47       erh 	s = splclock();
    110      1.47       erh 	/*
    111      1.47       erh 	 * Clear any pending timer alarms.
    112      1.47       erh 	 */
    113      1.64   thorpej 	if (itp) {
    114      1.64   thorpej 		callout_stop(&p->p_timers->pts_timers[ITIMER_REAL]->pt_ch);
    115      1.64   thorpej 		timerclear(&itp->it_interval);
    116      1.64   thorpej 		if (timerisset(&itp->it_value) &&
    117      1.64   thorpej 		    timercmp(&itp->it_value, &time, >))
    118      1.64   thorpej 			timersub(&itp->it_value, &time, &itp->it_value);
    119      1.64   thorpej 		/*
    120      1.64   thorpej 		 * Return how many seconds were left (rounded up)
    121      1.64   thorpej 		 */
    122      1.64   thorpej 		retval[0] = itp->it_value.tv_sec;
    123      1.64   thorpej 		if (itp->it_value.tv_usec)
    124      1.64   thorpej 			retval[0]++;
    125      1.64   thorpej 	} else {
    126      1.64   thorpej 		retval[0] = 0;
    127      1.64   thorpej 	}
    128       1.1      fvdl 
    129      1.47       erh 	/*
    130      1.47       erh 	 * alarm(0) just resets the timer.
    131      1.47       erh 	 */
    132      1.47       erh 	if (SCARG(uap, secs) == 0) {
    133      1.64   thorpej 		if (itp)
    134      1.64   thorpej 			timerclear(&itp->it_value);
    135      1.47       erh 		splx(s);
    136      1.47       erh 		return 0;
    137      1.47       erh 	}
    138       1.1      fvdl 
    139      1.47       erh 	/*
    140      1.47       erh 	 * Check the new alarm time for sanity, and set it.
    141      1.47       erh 	 */
    142      1.47       erh 	timerclear(&it.it_interval);
    143      1.47       erh 	it.it_value.tv_sec = SCARG(uap, secs);
    144      1.47       erh 	it.it_value.tv_usec = 0;
    145      1.47       erh 	if (itimerfix(&it.it_value) || itimerfix(&it.it_interval)) {
    146      1.47       erh 		splx(s);
    147      1.47       erh 		return (EINVAL);
    148      1.16      fvdl 	}
    149       1.1      fvdl 
    150      1.64   thorpej 	if (p->p_timers == NULL)
    151      1.64   thorpej 		timers_alloc(p);
    152      1.64   thorpej 	ptp = p->p_timers->pts_timers[ITIMER_REAL];
    153      1.64   thorpej 	if (ptp == NULL) {
    154      1.64   thorpej 		ptp = pool_get(&ptimer_pool, PR_WAITOK);
    155      1.64   thorpej 		ptp->pt_ev.sigev_notify = SIGEV_SIGNAL;
    156      1.64   thorpej 		ptp->pt_ev.sigev_signo = SIGALRM;
    157      1.65  jdolecek 		ptp->pt_overruns = 0;
    158      1.65  jdolecek 		ptp->pt_proc = p;
    159      1.64   thorpej 		ptp->pt_type = CLOCK_REALTIME;
    160      1.65  jdolecek 		ptp->pt_entry = CLOCK_REALTIME;
    161      1.64   thorpej 		callout_init(&ptp->pt_ch);
    162      1.66     enami 		p->p_timers->pts_timers[ITIMER_REAL] = ptp;
    163      1.64   thorpej 	}
    164      1.64   thorpej 
    165      1.47       erh 	if (timerisset(&it.it_value)) {
    166      1.56   thorpej 		/*
    167      1.56   thorpej 		 * Don't need to check hzto() return value, here.
    168      1.56   thorpej 		 * callout_reset() does it for us.
    169      1.56   thorpej 		 */
    170      1.47       erh 		timeradd(&it.it_value, &time, &it.it_value);
    171      1.64   thorpej 		callout_reset(&ptp->pt_ch, hzto(&it.it_value),
    172      1.64   thorpej 		    realtimerexpire, ptp);
    173      1.16      fvdl 	}
    174      1.64   thorpej 	ptp->pt_time = it;
    175      1.47       erh 	splx(s);
    176       1.1      fvdl 
    177      1.16      fvdl 	return 0;
    178       1.1      fvdl }
    179       1.1      fvdl 
    180       1.1      fvdl int
    181      1.64   thorpej linux_sys_nice(l, v, retval)
    182      1.64   thorpej 	struct lwp *l;
    183      1.20   thorpej 	void *v;
    184      1.20   thorpej 	register_t *retval;
    185      1.20   thorpej {
    186      1.47       erh 	struct linux_sys_nice_args /* {
    187      1.47       erh 		syscallarg(int) incr;
    188      1.20   thorpej 	} */ *uap = v;
    189      1.47       erh         struct sys_setpriority_args bsa;
    190      1.20   thorpej 
    191      1.47       erh         SCARG(&bsa, which) = PRIO_PROCESS;
    192      1.47       erh         SCARG(&bsa, who) = 0;
    193      1.47       erh 	SCARG(&bsa, prio) = SCARG(uap, incr);
    194      1.64   thorpej         return sys_setpriority(l, &bsa, retval);
    195       1.1      fvdl }
    196       1.1      fvdl 
    197       1.1      fvdl /*
    198      1.47       erh  * The old Linux readdir was only able to read one entry at a time,
    199      1.47       erh  * even though it had a 'count' argument. In fact, the emulation
    200      1.47       erh  * of the old call was better than the original, because it did handle
    201      1.47       erh  * the count arg properly. Don't bother with it anymore now, and use
    202      1.47       erh  * it to distinguish between old and new. The difference is that the
    203      1.47       erh  * newer one actually does multiple entries, and the reclen field
    204      1.47       erh  * really is the reclen, not the namelength.
    205       1.1      fvdl  */
    206       1.1      fvdl int
    207      1.64   thorpej linux_sys_readdir(l, v, retval)
    208      1.64   thorpej 	struct lwp *l;
    209      1.20   thorpej 	void *v;
    210      1.20   thorpej 	register_t *retval;
    211      1.20   thorpej {
    212      1.47       erh 	struct linux_sys_readdir_args /* {
    213      1.47       erh 		syscallarg(int) fd;
    214      1.47       erh 		syscallarg(struct linux_dirent *) dent;
    215      1.47       erh 		syscallarg(unsigned int) count;
    216      1.20   thorpej 	} */ *uap = v;
    217       1.1      fvdl 
    218      1.47       erh 	SCARG(uap, count) = 1;
    219      1.64   thorpej 	return linux_sys_getdents(l, uap, retval);
    220       1.1      fvdl }
    221       1.1      fvdl 
    222       1.1      fvdl /*
    223       1.1      fvdl  * I wonder why Linux has gettimeofday() _and_ time().. Still, we
    224       1.1      fvdl  * need to deal with it.
    225       1.1      fvdl  */
    226       1.1      fvdl int
    227      1.64   thorpej linux_sys_time(l, v, retval)
    228      1.64   thorpej 	struct lwp *l;
    229      1.20   thorpej 	void *v;
    230      1.20   thorpej 	register_t *retval;
    231      1.20   thorpej {
    232      1.21   mycroft 	struct linux_sys_time_args /* {
    233       1.1      fvdl 		linux_time_t *t;
    234      1.20   thorpej 	} */ *uap = v;
    235       1.1      fvdl 	struct timeval atv;
    236       1.1      fvdl 	linux_time_t tt;
    237       1.1      fvdl 	int error;
    238       1.1      fvdl 
    239       1.1      fvdl 	microtime(&atv);
    240       1.1      fvdl 
    241       1.1      fvdl 	tt = atv.tv_sec;
    242       1.1      fvdl 	if (SCARG(uap, t) && (error = copyout(&tt, SCARG(uap, t), sizeof tt)))
    243       1.1      fvdl 		return error;
    244       1.1      fvdl 
    245       1.1      fvdl 	retval[0] = tt;
    246       1.1      fvdl 	return 0;
    247       1.1      fvdl }
    248       1.1      fvdl 
    249       1.1      fvdl /*
    250      1.47       erh  * utime(). Do conversion to things that utimes() understands,
    251      1.47       erh  * and pass it on.
    252       1.1      fvdl  */
    253       1.1      fvdl int
    254      1.64   thorpej linux_sys_utime(l, v, retval)
    255      1.64   thorpej 	struct lwp *l;
    256      1.20   thorpej 	void *v;
    257      1.20   thorpej 	register_t *retval;
    258      1.20   thorpej {
    259      1.47       erh 	struct linux_sys_utime_args /* {
    260      1.50  christos 		syscallarg(const char *) path;
    261      1.47       erh 		syscallarg(struct linux_utimbuf *)times;
    262      1.20   thorpej 	} */ *uap = v;
    263      1.64   thorpej 	struct proc *p = l->l_proc;
    264       1.2      fvdl 	caddr_t sg;
    265       1.2      fvdl 	int error;
    266      1.47       erh 	struct sys_utimes_args ua;
    267      1.47       erh 	struct timeval tv[2], *tvp;
    268      1.47       erh 	struct linux_utimbuf lut;
    269       1.2      fvdl 
    270      1.62  christos 	sg = stackgap_init(p, 0);
    271      1.62  christos 	tvp = (struct timeval *) stackgap_alloc(p, &sg, sizeof(tv));
    272  1.69.2.3     skrll 	CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
    273       1.2      fvdl 
    274      1.47       erh 	SCARG(&ua, path) = SCARG(uap, path);
    275       1.2      fvdl 
    276      1.47       erh 	if (SCARG(uap, times) != NULL) {
    277      1.47       erh 		if ((error = copyin(SCARG(uap, times), &lut, sizeof lut)))
    278      1.47       erh 			return error;
    279      1.47       erh 		tv[0].tv_usec = tv[1].tv_usec = 0;
    280      1.47       erh 		tv[0].tv_sec = lut.l_actime;
    281      1.47       erh 		tv[1].tv_sec = lut.l_modtime;
    282      1.47       erh 		if ((error = copyout(tv, tvp, sizeof tv)))
    283      1.47       erh 			return error;
    284      1.47       erh 		SCARG(&ua, tptr) = tvp;
    285      1.47       erh 	}
    286      1.47       erh 	else
    287      1.47       erh 		SCARG(&ua, tptr) = NULL;
    288       1.2      fvdl 
    289      1.64   thorpej 	return sys_utimes(l, &ua, retval);
    290       1.1      fvdl }
    291       1.1      fvdl 
    292      1.47       erh /*
    293      1.47       erh  * waitpid(2). Passed on to the NetBSD call, surrounded by code to
    294      1.47       erh  * reserve some space for a NetBSD-style wait status, and converting
    295      1.47       erh  * it to what Linux wants.
    296      1.47       erh  */
    297       1.1      fvdl int
    298      1.64   thorpej linux_sys_waitpid(l, v, retval)
    299      1.64   thorpej 	struct lwp *l;
    300      1.20   thorpej 	void *v;
    301      1.20   thorpej 	register_t *retval;
    302      1.20   thorpej {
    303      1.47       erh 	struct linux_sys_waitpid_args /* {
    304      1.47       erh 		syscallarg(int) pid;
    305      1.47       erh 		syscallarg(int *) status;
    306      1.47       erh 		syscallarg(int) options;
    307      1.20   thorpej 	} */ *uap = v;
    308      1.64   thorpej 	struct proc *p = l->l_proc;
    309      1.47       erh 	struct sys_wait4_args w4a;
    310      1.47       erh 	int error, *status, tstat;
    311       1.2      fvdl 	caddr_t sg;
    312       1.2      fvdl 
    313      1.47       erh 	if (SCARG(uap, status) != NULL) {
    314      1.62  christos 		sg = stackgap_init(p, 0);
    315      1.62  christos 		status = (int *) stackgap_alloc(p, &sg, sizeof status);
    316      1.47       erh 	} else
    317      1.47       erh 		status = NULL;
    318       1.2      fvdl 
    319      1.47       erh 	SCARG(&w4a, pid) = SCARG(uap, pid);
    320      1.47       erh 	SCARG(&w4a, status) = status;
    321      1.47       erh 	SCARG(&w4a, options) = SCARG(uap, options);
    322      1.47       erh 	SCARG(&w4a, rusage) = NULL;
    323       1.2      fvdl 
    324      1.64   thorpej 	if ((error = sys_wait4(l, &w4a, retval)))
    325       1.2      fvdl 		return error;
    326       1.2      fvdl 
    327      1.60  jdolecek 	sigdelset(&p->p_sigctx.ps_siglist, SIGCHLD);
    328       1.2      fvdl 
    329      1.47       erh 	if (status != NULL) {
    330      1.47       erh 		if ((error = copyin(status, &tstat, sizeof tstat)))
    331      1.47       erh 			return error;
    332       1.2      fvdl 
    333      1.47       erh 		bsd_to_linux_wstat(&tstat);
    334      1.47       erh 		return copyout(&tstat, SCARG(uap, status), sizeof tstat);
    335      1.44   thorpej 	}
    336       1.1      fvdl 
    337      1.47       erh 	return 0;
    338      1.51   thorpej }
    339      1.51   thorpej 
    340      1.51   thorpej int
    341      1.64   thorpej linux_sys_setresgid(l, v, retval)
    342      1.64   thorpej 	struct lwp *l;
    343      1.51   thorpej 	void *v;
    344      1.51   thorpej 	register_t *retval;
    345      1.51   thorpej {
    346      1.51   thorpej 	struct linux_sys_setresgid_args /* {
    347      1.51   thorpej 		syscallarg(gid_t) rgid;
    348      1.51   thorpej 		syscallarg(gid_t) egid;
    349      1.51   thorpej 		syscallarg(gid_t) sgid;
    350      1.51   thorpej 	} */ *uap = v;
    351      1.51   thorpej 
    352      1.51   thorpej 	/*
    353      1.51   thorpej 	 * Note: These checks are a little different than the NetBSD
    354      1.51   thorpej 	 * setregid(2) call performs.  This precisely follows the
    355      1.51   thorpej 	 * behavior of the Linux kernel.
    356      1.51   thorpej 	 */
    357      1.67       dsl 	return do_setresgid(l, SCARG(uap,rgid), SCARG(uap, egid),
    358      1.67       dsl 			    SCARG(uap, sgid),
    359      1.67       dsl 			    ID_R_EQ_R | ID_R_EQ_E | ID_R_EQ_S |
    360      1.67       dsl 			    ID_E_EQ_R | ID_E_EQ_E | ID_E_EQ_S |
    361      1.67       dsl 			    ID_S_EQ_R | ID_S_EQ_E | ID_S_EQ_S );
    362      1.51   thorpej }
    363      1.51   thorpej 
    364      1.51   thorpej int
    365      1.64   thorpej linux_sys_getresgid(l, v, retval)
    366      1.64   thorpej 	struct lwp *l;
    367      1.51   thorpej 	void *v;
    368      1.51   thorpej 	register_t *retval;
    369      1.51   thorpej {
    370      1.51   thorpej 	struct linux_sys_getresgid_args /* {
    371      1.51   thorpej 		syscallarg(gid_t *) rgid;
    372      1.51   thorpej 		syscallarg(gid_t *) egid;
    373      1.51   thorpej 		syscallarg(gid_t *) sgid;
    374      1.51   thorpej 	} */ *uap = v;
    375      1.64   thorpej 	struct proc *p = l->l_proc;
    376      1.51   thorpej 	struct pcred *pc = p->p_cred;
    377      1.51   thorpej 	int error;
    378      1.51   thorpej 
    379      1.51   thorpej 	/*
    380      1.51   thorpej 	 * Linux copies these values out to userspace like so:
    381      1.51   thorpej 	 *
    382      1.51   thorpej 	 *	1. Copy out rgid.
    383      1.51   thorpej 	 *	2. If that succeeds, copy out egid.
    384      1.51   thorpej 	 *	3. If both of those succeed, copy out sgid.
    385      1.51   thorpej 	 */
    386      1.51   thorpej 	if ((error = copyout(&pc->p_rgid, SCARG(uap, rgid),
    387      1.51   thorpej 			     sizeof(gid_t))) != 0)
    388      1.51   thorpej 		return (error);
    389      1.51   thorpej 
    390      1.63      tron 	if ((error = copyout(&pc->pc_ucred->cr_gid, SCARG(uap, egid),
    391      1.51   thorpej 			     sizeof(gid_t))) != 0)
    392      1.51   thorpej 		return (error);
    393      1.51   thorpej 
    394      1.51   thorpej 	return (copyout(&pc->p_svgid, SCARG(uap, sgid), sizeof(gid_t)));
    395      1.52      tron }
    396      1.52      tron 
    397      1.52      tron /*
    398      1.52      tron  * I wonder why Linux has settimeofday() _and_ stime().. Still, we
    399      1.52      tron  * need to deal with it.
    400      1.52      tron  */
    401      1.52      tron int
    402      1.64   thorpej linux_sys_stime(l, v, retval)
    403      1.64   thorpej 	struct lwp *l;
    404      1.52      tron 	void *v;
    405      1.52      tron 	register_t *retval;
    406      1.52      tron {
    407      1.52      tron 	struct linux_sys_time_args /* {
    408      1.52      tron 		linux_time_t *t;
    409      1.52      tron 	} */ *uap = v;
    410      1.64   thorpej 	struct proc *p = l->l_proc;
    411      1.52      tron 	struct timeval atv;
    412      1.52      tron 	linux_time_t tt;
    413      1.52      tron 	int error;
    414      1.52      tron 
    415      1.52      tron 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
    416      1.52      tron 		return (error);
    417      1.52      tron 
    418      1.52      tron 	if ((error = copyin(&tt, SCARG(uap, t), sizeof tt)) != 0)
    419      1.52      tron 		return error;
    420      1.52      tron 
    421      1.52      tron 	atv.tv_sec = tt;
    422      1.52      tron 	atv.tv_usec = 0;
    423      1.52      tron 
    424      1.52      tron 	if ((error = settime(&atv)))
    425      1.52      tron 		return (error);
    426      1.52      tron 
    427      1.52      tron 	return 0;
    428       1.1      fvdl }
    429  1.69.2.4     skrll 
    430  1.69.2.4     skrll #ifndef __m68k__
    431  1.69.2.4     skrll /*
    432  1.69.2.4     skrll  * Convert NetBSD statvfs structure to Linux statfs64 structure.
    433  1.69.2.4     skrll  * See comments in bsd_to_linux_statfs() for further background.
    434  1.69.2.4     skrll  * We can safely pass correct bsize and frsize here, since Linux glibc
    435  1.69.2.4     skrll  * statvfs() doesn't use statfs64().
    436  1.69.2.4     skrll  */
    437  1.69.2.4     skrll static void
    438  1.69.2.4     skrll bsd_to_linux_statfs64(bsp, lsp)
    439  1.69.2.4     skrll 	const struct statvfs *bsp;
    440  1.69.2.4     skrll 	struct linux_statfs64 *lsp;
    441  1.69.2.4     skrll {
    442  1.69.2.4     skrll 	int i, div;
    443  1.69.2.4     skrll 
    444  1.69.2.4     skrll 	for (i = 0; i < linux_fstypes_cnt; i++) {
    445  1.69.2.4     skrll 		if (strcmp(bsp->f_fstypename, linux_fstypes[i].bsd) == 0) {
    446  1.69.2.4     skrll 			lsp->l_ftype = linux_fstypes[i].linux;
    447  1.69.2.4     skrll 			break;
    448  1.69.2.4     skrll 		}
    449  1.69.2.4     skrll 	}
    450  1.69.2.4     skrll 
    451  1.69.2.4     skrll 	if (i == linux_fstypes_cnt) {
    452  1.69.2.4     skrll 		DPRINTF(("unhandled fstype in linux emulation: %s\n",
    453  1.69.2.4     skrll 		    bsp->f_fstypename));
    454  1.69.2.4     skrll 		lsp->l_ftype = LINUX_DEFAULT_SUPER_MAGIC;
    455  1.69.2.4     skrll 	}
    456  1.69.2.4     skrll 
    457  1.69.2.4     skrll 	div = bsp->f_bsize / bsp->f_frsize;
    458  1.69.2.4     skrll 	lsp->l_fbsize = bsp->f_bsize;
    459  1.69.2.4     skrll 	lsp->l_ffrsize = bsp->f_frsize;
    460  1.69.2.4     skrll 	lsp->l_fblocks = bsp->f_blocks / div;
    461  1.69.2.4     skrll 	lsp->l_fbfree = bsp->f_bfree / div;
    462  1.69.2.4     skrll 	lsp->l_fbavail = bsp->f_bavail / div;
    463  1.69.2.4     skrll 	lsp->l_ffiles = bsp->f_files;
    464  1.69.2.4     skrll 	lsp->l_fffree = bsp->f_ffree / div;
    465  1.69.2.4     skrll 	/* Linux sets the fsid to 0..., we don't */
    466  1.69.2.4     skrll 	lsp->l_ffsid.val[0] = bsp->f_fsidx.__fsid_val[0];
    467  1.69.2.4     skrll 	lsp->l_ffsid.val[1] = bsp->f_fsidx.__fsid_val[1];
    468  1.69.2.4     skrll 	lsp->l_fnamelen = bsp->f_namemax;
    469  1.69.2.4     skrll 	(void)memset(lsp->l_fspare, 0, sizeof(lsp->l_fspare));
    470  1.69.2.4     skrll }
    471  1.69.2.4     skrll 
    472  1.69.2.4     skrll /*
    473  1.69.2.4     skrll  * Implement the fs stat functions. Straightforward.
    474  1.69.2.4     skrll  */
    475  1.69.2.4     skrll int
    476  1.69.2.4     skrll linux_sys_statfs64(l, v, retval)
    477  1.69.2.4     skrll 	struct lwp *l;
    478  1.69.2.4     skrll 	void *v;
    479  1.69.2.4     skrll 	register_t *retval;
    480  1.69.2.4     skrll {
    481  1.69.2.4     skrll 	struct linux_sys_statfs64_args /* {
    482  1.69.2.4     skrll 		syscallarg(const char *) path;
    483  1.69.2.4     skrll 		syscallarg(size_t) sz;
    484  1.69.2.4     skrll 		syscallarg(struct linux_statfs64 *) sp;
    485  1.69.2.4     skrll 	} */ *uap = v;
    486  1.69.2.4     skrll 	struct proc *p = l->l_proc;
    487  1.69.2.4     skrll 	struct statvfs btmp, *bsp;
    488  1.69.2.4     skrll 	struct linux_statfs64 ltmp;
    489  1.69.2.4     skrll 	struct sys_statvfs1_args bsa;
    490  1.69.2.4     skrll 	caddr_t sg;
    491  1.69.2.4     skrll 	int error;
    492  1.69.2.4     skrll 
    493  1.69.2.4     skrll 	if (SCARG(uap, sz) != sizeof ltmp)
    494  1.69.2.4     skrll 		return (EINVAL);
    495  1.69.2.4     skrll 
    496  1.69.2.4     skrll 	sg = stackgap_init(p, 0);
    497  1.69.2.4     skrll 	bsp = (struct statvfs *) stackgap_alloc(p, &sg, sizeof (struct statvfs));
    498  1.69.2.4     skrll 
    499  1.69.2.4     skrll 	CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
    500  1.69.2.4     skrll 
    501  1.69.2.4     skrll 	SCARG(&bsa, path) = SCARG(uap, path);
    502  1.69.2.4     skrll 	SCARG(&bsa, buf) = bsp;
    503  1.69.2.4     skrll 	SCARG(&bsa, flags) = ST_WAIT;
    504  1.69.2.4     skrll 
    505  1.69.2.4     skrll 	if ((error = sys_statvfs1(l, &bsa, retval)))
    506  1.69.2.4     skrll 		return error;
    507  1.69.2.4     skrll 
    508  1.69.2.4     skrll 	if ((error = copyin((caddr_t) bsp, (caddr_t) &btmp, sizeof btmp)))
    509  1.69.2.4     skrll 		return error;
    510  1.69.2.4     skrll 
    511  1.69.2.4     skrll 	bsd_to_linux_statfs64(&btmp, &ltmp);
    512  1.69.2.4     skrll 
    513  1.69.2.4     skrll 	return copyout((caddr_t) &ltmp, (caddr_t) SCARG(uap, sp), sizeof ltmp);
    514  1.69.2.4     skrll }
    515  1.69.2.4     skrll 
    516  1.69.2.4     skrll int
    517  1.69.2.4     skrll linux_sys_fstatfs64(l, v, retval)
    518  1.69.2.4     skrll 	struct lwp *l;
    519  1.69.2.4     skrll 	void *v;
    520  1.69.2.4     skrll 	register_t *retval;
    521  1.69.2.4     skrll {
    522  1.69.2.4     skrll 	struct linux_sys_fstatfs64_args /* {
    523  1.69.2.4     skrll 		syscallarg(int) fd;
    524  1.69.2.4     skrll 		syscallarg(size_t) sz;
    525  1.69.2.4     skrll 		syscallarg(struct linux_statfs64 *) sp;
    526  1.69.2.4     skrll 	} */ *uap = v;
    527  1.69.2.4     skrll 	struct proc *p = l->l_proc;
    528  1.69.2.4     skrll 	struct statvfs btmp, *bsp;
    529  1.69.2.4     skrll 	struct linux_statfs64 ltmp;
    530  1.69.2.4     skrll 	struct sys_fstatvfs1_args bsa;
    531  1.69.2.4     skrll 	caddr_t sg;
    532  1.69.2.4     skrll 	int error;
    533  1.69.2.4     skrll 
    534  1.69.2.4     skrll 	if (SCARG(uap, sz) != sizeof ltmp)
    535  1.69.2.4     skrll 		return (EINVAL);
    536  1.69.2.4     skrll 
    537  1.69.2.4     skrll 	sg = stackgap_init(p, 0);
    538  1.69.2.4     skrll 	bsp = (struct statvfs *) stackgap_alloc(p, &sg, sizeof (struct statvfs));
    539  1.69.2.4     skrll 
    540  1.69.2.4     skrll 	SCARG(&bsa, fd) = SCARG(uap, fd);
    541  1.69.2.4     skrll 	SCARG(&bsa, buf) = bsp;
    542  1.69.2.4     skrll 	SCARG(&bsa, flags) = ST_WAIT;
    543  1.69.2.4     skrll 
    544  1.69.2.4     skrll 	if ((error = sys_fstatvfs1(l, &bsa, retval)))
    545  1.69.2.4     skrll 		return error;
    546  1.69.2.4     skrll 
    547  1.69.2.4     skrll 	if ((error = copyin((caddr_t) bsp, (caddr_t) &btmp, sizeof btmp)))
    548  1.69.2.4     skrll 		return error;
    549  1.69.2.4     skrll 
    550  1.69.2.4     skrll 	bsd_to_linux_statfs64(&btmp, &ltmp);
    551  1.69.2.4     skrll 
    552  1.69.2.4     skrll 	return copyout((caddr_t) &ltmp, (caddr_t) SCARG(uap, sp), sizeof ltmp);
    553  1.69.2.4     skrll }
    554  1.69.2.4     skrll #endif /* !__m68k__ */
    555