Annotation of src/sys/dev/clockctl.c, revision 1.6

1.6     ! manu        1: /*      $NetBSD: clockctl.c,v 1.5 2002/02/25 21:16:36 manu Exp $ */
1.1       manu        2: 
                      3: /*-
                      4:  * Copyright (c) 2001 The NetBSD Foundation, Inc.
                      5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to The NetBSD Foundation
                      8:  * by Emmanuel Dreyfus.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. The name of the author may not be used to endorse or promote products
                     19:  *    derived from this software without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     22:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     23:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     24:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     25:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     26:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     27:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     28:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     29:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     30:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     31:  */
1.2       lukem      32: 
                     33: #include <sys/cdefs.h>
1.6     ! manu       34: __KERNEL_RCSID(0, "$NetBSD: clockctl.c,v 1.5 2002/02/25 21:16:36 manu Exp $");
1.5       manu       35: 
                     36: #include "opt_ntp.h"
1.1       manu       37: 
                     38: #include <sys/param.h>
                     39: #include <sys/systm.h>
                     40: #include <sys/proc.h>
                     41: #include <sys/errno.h>
                     42: #include <sys/ioctl.h>
                     43: #include <sys/device.h>
                     44: #include <sys/time.h>
                     45: #ifdef NTP
                     46: #include <sys/timex.h>
                     47: #endif /* NTP */
                     48: 
                     49: #include <sys/clockctl.h>
                     50: 
                     51: struct clockctl_softc {
                     52:        struct device   clockctl_dev;
                     53: };
                     54: 
                     55: 
                     56: void
                     57: clockctlattach(parent, self, aux)
                     58:        struct device *self;
                     59:        struct device *parent;
                     60:        void *aux;
                     61: {
                     62:        /* Nothing to set up before open is called */
                     63:        return;
                     64: }
                     65: 
                     66: int
                     67: clockctlopen(dev, flags, fmt, p)
                     68:        dev_t dev;
                     69:        int flags, fmt;
                     70:        struct proc *p;
                     71: {
                     72:        return 0; 
                     73: }
                     74: 
                     75: int
                     76: clockctlclose(dev, flags, fmt, p)
                     77:        dev_t dev;
                     78:        int flags, fmt;
                     79:        struct proc *p;
                     80: {
                     81:        return 0;
                     82: }
                     83: 
                     84: int
                     85: clockctlioctl(dev, cmd, data, flags, p)
                     86:        dev_t dev;
                     87:        u_long cmd;
                     88:        caddr_t data;
                     89:        int flags;
                     90:        struct proc *p;
                     91: {
                     92:        int error = 0;
                     93:        
                     94:        switch (cmd) {
                     95:                case CLOCKCTL_SETTIMEOFDAY: {
1.4       manu       96:                        struct sys_settimeofday_args *args =
                     97:                            (struct sys_settimeofday_args *)data;
1.1       manu       98: 
1.4       manu       99:                        error = settimeofday1(SCARG(args, tv), 
                    100:                            SCARG(args, tzp), p);
1.1       manu      101:                        if (error)
                    102:                                return (error);
                    103:                        break;
                    104:                }
                    105:                case CLOCKCTL_ADJTIME: {
1.4       manu      106:                        struct sys_adjtime_args *args = 
                    107:                            (struct sys_adjtime_args *)data;
1.1       manu      108: 
1.4       manu      109:                        error = adjtime1(SCARG(args, delta), 
                    110:                            SCARG(args, olddelta), p);
1.1       manu      111:                        if (error)
                    112:                                return (error); 
                    113:                        break;
                    114:                }
                    115:                case CLOCKCTL_CLOCK_SETTIME: {
1.4       manu      116:                        struct sys_clock_settime_args *args = 
                    117:                            (struct sys_clock_settime_args *)data;
1.1       manu      118: 
1.4       manu      119:                        error = clock_settime1(SCARG(args, clock_id), 
                    120:                            SCARG(args, tp));
1.1       manu      121:                        if (error)
                    122:                                return (error); 
                    123:                        break;
                    124:                }
                    125: #ifdef NTP
                    126:                case CLOCKCTL_NTP_ADJTIME: {
                    127:                        struct clockctl_ntp_adjtime_args *args =
1.4       manu      128:                            (struct clockctl_ntp_adjtime_args *)data;
1.6     ! manu      129:                        struct timex ntv;
1.1       manu      130: 
1.6     ! manu      131:                        error = copyin((caddr_t)SCARG(args,uas.tp), 
        !           132:                            (caddr_t)&ntv, sizeof(ntv));
        !           133:                        if (error)
        !           134:                                return (error);
        !           135: 
        !           136:                        error = ntp_adjtime1(&ntv, args, &args->retval);
        !           137:                        return (error);
        !           138:                        break;
1.1       manu      139:                }
                    140: #endif /* NTP */
                    141:                default:
                    142:                        error = EINVAL;
                    143:        }
                    144: 
                    145:        return (error);
                    146: }
                    147: 
                    148: 

CVSweb <webmaster@jp.NetBSD.org>