Home | History | Annotate | Line # | Download | only in common
kern_time_30.c revision 1.3.4.2
      1  1.3.4.2  skrll /*	$NetBSD: kern_time_30.c,v 1.3.4.2 2009/01/19 13:17:17 skrll Exp $	*/
      2  1.3.4.2  skrll 
      3  1.3.4.2  skrll /*-
      4  1.3.4.2  skrll  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5  1.3.4.2  skrll  * All rights reserved.
      6  1.3.4.2  skrll  *
      7  1.3.4.2  skrll  * This code is derived from software contributed to The NetBSD Foundation
      8  1.3.4.2  skrll  * by Christos Zoulas.
      9  1.3.4.2  skrll  *
     10  1.3.4.2  skrll  * Redistribution and use in source and binary forms, with or without
     11  1.3.4.2  skrll  * modification, are permitted provided that the following conditions
     12  1.3.4.2  skrll  * are met:
     13  1.3.4.2  skrll  * 1. Redistributions of source code must retain the above copyright
     14  1.3.4.2  skrll  *    notice, this list of conditions and the following disclaimer.
     15  1.3.4.2  skrll  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.3.4.2  skrll  *    notice, this list of conditions and the following disclaimer in the
     17  1.3.4.2  skrll  *    documentation and/or other materials provided with the distribution.
     18  1.3.4.2  skrll  * 3. All advertising materials mentioning features or use of this software
     19  1.3.4.2  skrll  *    must display the following acknowledgement:
     20  1.3.4.2  skrll  *        This product includes software developed by the NetBSD
     21  1.3.4.2  skrll  *        Foundation, Inc. and its contributors.
     22  1.3.4.2  skrll  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.3.4.2  skrll  *    contributors may be used to endorse or promote products derived
     24  1.3.4.2  skrll  *    from this software without specific prior written permission.
     25  1.3.4.2  skrll  *
     26  1.3.4.2  skrll  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.3.4.2  skrll  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.3.4.2  skrll  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.3.4.2  skrll  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.3.4.2  skrll  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.3.4.2  skrll  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.3.4.2  skrll  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.3.4.2  skrll  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.3.4.2  skrll  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.3.4.2  skrll  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.3.4.2  skrll  * POSSIBILITY OF SUCH DAMAGE.
     37  1.3.4.2  skrll  */
     38  1.3.4.2  skrll #include <sys/cdefs.h>
     39  1.3.4.2  skrll __KERNEL_RCSID(0, "$NetBSD: kern_time_30.c,v 1.3.4.2 2009/01/19 13:17:17 skrll Exp $");
     40  1.3.4.2  skrll 
     41  1.3.4.2  skrll #include "opt_ntp.h"
     42  1.3.4.2  skrll 
     43  1.3.4.2  skrll #include <sys/param.h>
     44  1.3.4.2  skrll #include <sys/systm.h>
     45  1.3.4.2  skrll #include <sys/time.h>
     46  1.3.4.2  skrll #include <sys/timex.h>
     47  1.3.4.2  skrll 
     48  1.3.4.2  skrll #include <compat/common/compat_util.h>
     49  1.3.4.2  skrll #include <compat/sys/time.h>
     50  1.3.4.2  skrll #include <compat/sys/timex.h>
     51  1.3.4.2  skrll 
     52  1.3.4.2  skrll #include <sys/sched.h>
     53  1.3.4.2  skrll #include <sys/syscallargs.h>
     54  1.3.4.2  skrll 
     55  1.3.4.2  skrll int
     56  1.3.4.2  skrll compat_30_sys_ntp_gettime(struct lwp *l,
     57  1.3.4.2  skrll     const struct compat_30_sys_ntp_gettime_args *uap, register_t *retval)
     58  1.3.4.2  skrll {
     59  1.3.4.2  skrll #ifdef NTP
     60  1.3.4.2  skrll 	/* {
     61  1.3.4.2  skrll 		syscallarg(struct ntptimeval30 *) ontvp;
     62  1.3.4.2  skrll 	} */
     63  1.3.4.2  skrll 	struct ntptimeval ntv;
     64  1.3.4.2  skrll 	struct ntptimeval30 ntv30;
     65  1.3.4.2  skrll 	struct timeval tv;
     66  1.3.4.2  skrll 	int error;
     67  1.3.4.2  skrll 
     68  1.3.4.2  skrll 	if (SCARG(uap, ntvp)) {
     69  1.3.4.2  skrll 		ntp_gettime(&ntv);
     70  1.3.4.2  skrll 		TIMESPEC_TO_TIMEVAL(&tv, &ntv.time);
     71  1.3.4.2  skrll 		timeval_to_timeval50(&tv, &ntv30.time);
     72  1.3.4.2  skrll 		ntv30.maxerror = ntv.maxerror;
     73  1.3.4.2  skrll 		ntv30.esterror = ntv.esterror;
     74  1.3.4.2  skrll 
     75  1.3.4.2  skrll 		error = copyout(&ntv30, SCARG(uap, ntvp), sizeof(ntv30));
     76  1.3.4.2  skrll 		if (error)
     77  1.3.4.2  skrll 			return error;
     78  1.3.4.2  skrll  	}
     79  1.3.4.2  skrll 	*retval = ntp_timestatus();
     80  1.3.4.2  skrll 	return 0;
     81  1.3.4.2  skrll #else
     82  1.3.4.2  skrll 	return ENOSYS;
     83  1.3.4.2  skrll #endif
     84  1.3.4.2  skrll }
     85