Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004 Ulrich Drepper <drepper@redhat.com> |
| 3 | * Copyright (c) 2004 Dmitry V. Levin <ldv@altlinux.org> |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. The name of the author may not be used to endorse or promote products |
| 15 | * derived from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include "defs.h" |
| 30 | #include <linux/ioctl.h> |
| 31 | #include <linux/rtc.h> |
| 32 | |
| 33 | static void |
| 34 | print_rtc(struct tcb *tcp, const struct rtc_time *rt) |
| 35 | { |
| 36 | tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, " |
| 37 | "tm_mday=%d, tm_mon=%d, tm_year=%d, ", |
| 38 | rt->tm_sec, rt->tm_min, rt->tm_hour, |
| 39 | rt->tm_mday, rt->tm_mon, rt->tm_year); |
| 40 | if (!abbrev(tcp)) |
| 41 | tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}", |
| 42 | rt->tm_wday, rt->tm_yday, rt->tm_isdst); |
| 43 | else |
| 44 | tprints("...}"); |
| 45 | } |
| 46 | |
| 47 | int |
| 48 | rtc_ioctl(struct tcb *tcp, const unsigned int code, const long arg) |
| 49 | { |
| 50 | switch (code) { |
| 51 | case RTC_ALM_SET: |
| 52 | case RTC_SET_TIME: |
| 53 | if (entering(tcp)) { |
| 54 | struct rtc_time rt; |
| 55 | if (umove(tcp, arg, &rt) < 0) |
| 56 | tprintf(", %#lx", arg); |
| 57 | else { |
| 58 | tprints(", "); |
| 59 | print_rtc(tcp, &rt); |
| 60 | } |
| 61 | } |
| 62 | break; |
| 63 | case RTC_ALM_READ: |
| 64 | case RTC_RD_TIME: |
| 65 | if (exiting(tcp)) { |
| 66 | struct rtc_time rt; |
| 67 | if (syserror(tcp) || umove(tcp, arg, &rt) < 0) |
| 68 | tprintf(", %#lx", arg); |
| 69 | else { |
| 70 | tprints(", "); |
| 71 | print_rtc(tcp, &rt); |
| 72 | } |
| 73 | } |
| 74 | break; |
| 75 | case RTC_IRQP_SET: |
| 76 | case RTC_EPOCH_SET: |
| 77 | if (entering(tcp)) |
| 78 | tprintf(", %lu", arg); |
| 79 | break; |
| 80 | case RTC_IRQP_READ: |
| 81 | case RTC_EPOCH_READ: |
| 82 | if (exiting(tcp)) |
| 83 | tprintf(", %lu", arg); |
| 84 | break; |
| 85 | case RTC_WKALM_SET: |
| 86 | if (entering(tcp)) { |
| 87 | struct rtc_wkalrm wk; |
| 88 | if (umove(tcp, arg, &wk) < 0) |
| 89 | tprintf(", %#lx", arg); |
| 90 | else { |
| 91 | tprintf(", {enabled=%d, pending=%d, ", |
| 92 | wk.enabled, wk.pending); |
| 93 | print_rtc(tcp, &wk.time); |
| 94 | tprints("}"); |
| 95 | } |
| 96 | } |
| 97 | break; |
| 98 | case RTC_WKALM_RD: |
| 99 | if (exiting(tcp)) { |
| 100 | struct rtc_wkalrm wk; |
| 101 | if (syserror(tcp) || umove(tcp, arg, &wk) < 0) |
| 102 | tprintf(", %#lx", arg); |
| 103 | else { |
| 104 | tprintf(", {enabled=%d, pending=%d, ", |
| 105 | wk.enabled, wk.pending); |
| 106 | print_rtc(tcp, &wk.time); |
| 107 | tprints("}"); |
| 108 | } |
| 109 | } |
| 110 | break; |
| 111 | default: |
| 112 | return 0; |
| 113 | } |
| 114 | return 1; |
| 115 | } |