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

1.26    ! mrg         1: /*      $NetBSD: clockctl.c,v 1.25 2009/02/18 05:17:56 mrg 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.26    ! mrg        34: __KERNEL_RCSID(0, "$NetBSD: clockctl.c,v 1.25 2009/02/18 05:17:56 mrg Exp $");
1.5       manu       35: 
                     36: #include "opt_ntp.h"
1.24      christos   37: #include "opt_compat_netbsd.h"
1.1       manu       38: 
                     39: #include <sys/param.h>
                     40: #include <sys/systm.h>
                     41: #include <sys/proc.h>
                     42: #include <sys/errno.h>
                     43: #include <sys/ioctl.h>
                     44: #include <sys/device.h>
                     45: #include <sys/time.h>
1.7       gehenna    46: #include <sys/conf.h>
1.1       manu       47: #ifdef NTP
                     48: #include <sys/timex.h>
                     49: #endif /* NTP */
                     50: 
                     51: #include <sys/clockctl.h>
1.24      christos   52: #ifdef COMPAT_50
                     53: #include <compat/sys/clockctl.h>
                     54: #endif
1.1       manu       55: 
                     56: struct clockctl_softc {
                     57:        struct device   clockctl_dev;
                     58: };
                     59: 
1.7       gehenna    60: dev_type_ioctl(clockctlioctl);
                     61: 
                     62: const struct cdevsw clockctl_cdevsw = {
                     63:        nullopen, nullclose, noread, nowrite, clockctlioctl,
1.18      christos   64:        nostop, notty, nopoll, nommap, nokqfilter, D_OTHER,
1.7       gehenna    65: };
1.1       manu       66: 
1.10      perry      67: /*ARGSUSED*/
1.1       manu       68: void
1.20      christos   69: clockctlattach(int num)
1.1       manu       70: {
                     71:        /* Nothing to set up before open is called */
                     72:        return;
                     73: }
                     74: 
                     75: int
1.19      christos   76: clockctlioctl(
1.20      christos   77:     dev_t dev,
1.19      christos   78:     u_long cmd,
1.21      christos   79:     void *data,
1.20      christos   80:     int flags,
1.19      christos   81:     struct lwp *l)
1.1       manu       82: {
                     83:        int error = 0;
1.13      perry      84: 
1.1       manu       85:        switch (cmd) {
1.24      christos   86:        case CLOCKCTL_SETTIMEOFDAY: {
                     87:                struct clockctl_settimeofday *args = data;
1.1       manu       88: 
1.24      christos   89:                error = settimeofday1(args->tv, true, args->tzp, l, false);
                     90:                break;
                     91:        }
                     92:        case CLOCKCTL_ADJTIME: {
                     93:                struct timeval atv, oldatv;
                     94:                struct clockctl_adjtime *args = data;
1.1       manu       95: 
1.24      christos   96:                if (args->delta) {
                     97:                        error = copyin(args->delta, &atv, sizeof(*args->delta));
1.1       manu       98:                        if (error)
1.13      perry      99:                                return (error);
1.1       manu      100:                }
1.24      christos  101:                adjtime1(args->delta ? &atv : NULL,
                    102:                    args->olddelta ? &oldatv : NULL, l->l_proc);
                    103:                if (args->olddelta)
                    104:                        error = copyout(&oldatv, args->olddelta,
                    105:                            sizeof(args->olddelta));
                    106:                break;
                    107:        }
                    108:        case CLOCKCTL_CLOCK_SETTIME: {
                    109:                struct clockctl_clock_settime *args = data;
1.25      mrg       110:                struct timespec ts;
1.1       manu      111: 
1.26    ! mrg       112:                error = copyin(args->tp, &ts, sizeof ts);
        !           113:                if (error)
        !           114:                        return (error);
        !           115:                error = clock_settime1(l->l_proc, args->clock_id, &ts, false);
1.24      christos  116:                break;
                    117:        }
1.1       manu      118: #ifdef NTP
1.24      christos  119:        case CLOCKCTL_NTP_ADJTIME: {
                    120:                struct clockctl_ntp_adjtime *args = data;
                    121:                struct timex ntv;
                    122:                register_t retval;
1.1       manu      123: 
1.24      christos  124:                error = copyin(args->tp, &ntv, sizeof(ntv));
                    125:                if (error)
                    126:                        return (error);
1.6       manu      127: 
1.24      christos  128:                ntp_adjtime1(&ntv);
1.17      kardel    129: 
1.24      christos  130:                error = copyout(&ntv, args->tp, sizeof(ntv));
                    131:                if (error == 0)
                    132:                        error = copyout(&retval, &args->retval, sizeof(retval));
                    133:        }
1.1       manu      134: #endif /* NTP */
1.24      christos  135:        default:
                    136: #ifdef COMPAT_50
                    137:                error = compat50_clockctlioctl(dev, cmd, data, flags, l);
                    138: #else
                    139:                error = EINVAL;
                    140: #endif
1.1       manu      141:        }
                    142: 
                    143:        return (error);
                    144: }
                    145: 
                    146: 

CVSweb <webmaster@jp.NetBSD.org>