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

1.13    ! perry       1: /*      $NetBSD: clockctl.c,v 1.12 2003/06/29 22:29:58 fvdl 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.13    ! perry      34: __KERNEL_RCSID(0, "$NetBSD: clockctl.c,v 1.12 2003/06/29 22:29:58 fvdl 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>
1.7       gehenna    45: #include <sys/conf.h>
1.1       manu       46: #ifdef NTP
                     47: #include <sys/timex.h>
                     48: #endif /* NTP */
                     49: 
                     50: #include <sys/clockctl.h>
                     51: 
                     52: struct clockctl_softc {
                     53:        struct device   clockctl_dev;
                     54: };
                     55: 
1.7       gehenna    56: dev_type_ioctl(clockctlioctl);
                     57: 
                     58: const struct cdevsw clockctl_cdevsw = {
                     59:        nullopen, nullclose, noread, nowrite, clockctlioctl,
1.9       jdolecek   60:        nostop, notty, nopoll, nommap, nokqfilter,
1.7       gehenna    61: };
1.1       manu       62: 
1.10      perry      63: /*ARGSUSED*/
1.1       manu       64: void
1.10      perry      65: clockctlattach(int num)
1.1       manu       66: {
                     67:        /* Nothing to set up before open is called */
                     68:        return;
                     69: }
                     70: 
                     71: int
1.12      fvdl       72: clockctlioctl(dev, cmd, data, flags, p)
1.1       manu       73:        dev_t dev;
                     74:        u_long cmd;
                     75:        caddr_t data;
                     76:        int flags;
1.12      fvdl       77:        struct proc *p;
1.1       manu       78: {
                     79:        int error = 0;
1.13    ! perry      80: 
1.1       manu       81:        switch (cmd) {
                     82:                case CLOCKCTL_SETTIMEOFDAY: {
1.4       manu       83:                        struct sys_settimeofday_args *args =
                     84:                            (struct sys_settimeofday_args *)data;
1.1       manu       85: 
1.13    ! perry      86:                        error = settimeofday1(SCARG(args, tv),
1.12      fvdl       87:                            SCARG(args, tzp), p);
1.1       manu       88:                        if (error)
                     89:                                return (error);
                     90:                        break;
                     91:                }
                     92:                case CLOCKCTL_ADJTIME: {
1.13    ! perry      93:                        struct sys_adjtime_args *args =
1.4       manu       94:                            (struct sys_adjtime_args *)data;
1.1       manu       95: 
1.13    ! perry      96:                        error = adjtime1(SCARG(args, delta),
1.12      fvdl       97:                            SCARG(args, olddelta), p);
1.1       manu       98:                        if (error)
1.13    ! perry      99:                                return (error);
1.1       manu      100:                        break;
                    101:                }
                    102:                case CLOCKCTL_CLOCK_SETTIME: {
1.13    ! perry     103:                        struct sys_clock_settime_args *args =
1.4       manu      104:                            (struct sys_clock_settime_args *)data;
1.1       manu      105: 
1.13    ! perry     106:                        error = clock_settime1(SCARG(args, clock_id),
1.4       manu      107:                            SCARG(args, tp));
1.1       manu      108:                        if (error)
1.13    ! perry     109:                                return (error);
1.1       manu      110:                        break;
                    111:                }
                    112: #ifdef NTP
                    113:                case CLOCKCTL_NTP_ADJTIME: {
                    114:                        struct clockctl_ntp_adjtime_args *args =
1.4       manu      115:                            (struct clockctl_ntp_adjtime_args *)data;
1.6       manu      116:                        struct timex ntv;
1.1       manu      117: 
1.13    ! perry     118:                        error = copyin((caddr_t)SCARG(args,uas.tp),
1.6       manu      119:                            (caddr_t)&ntv, sizeof(ntv));
                    120:                        if (error)
                    121:                                return (error);
                    122: 
                    123:                        error = ntp_adjtime1(&ntv, args, &args->retval);
                    124:                        return (error);
1.1       manu      125:                }
                    126: #endif /* NTP */
                    127:                default:
                    128:                        error = EINVAL;
                    129:        }
                    130: 
                    131:        return (error);
                    132: }
                    133: 
                    134: 

CVSweb <webmaster@jp.NetBSD.org>