• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
print_rtc_time(struct tcb * tcp,const struct rtc_time * rt)34 print_rtc_time(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 static void
decode_rtc_time(struct tcb * tcp,const long addr)48 decode_rtc_time(struct tcb *tcp, const long addr)
49 {
50 	struct rtc_time rt;
51 
52 	tprints(", ");
53 	if (!umove_or_printaddr(tcp, addr, &rt))
54 		print_rtc_time(tcp, &rt);
55 }
56 
57 static void
decode_rtc_wkalrm(struct tcb * tcp,const long addr)58 decode_rtc_wkalrm(struct tcb *tcp, const long addr)
59 {
60 	struct rtc_wkalrm wk;
61 
62 	tprints(", ");
63 	if (!umove_or_printaddr(tcp, addr, &wk)) {
64 		tprintf("{enabled=%d, pending=%d, ", wk.enabled, wk.pending);
65 		print_rtc_time(tcp, &wk.time);
66 		tprints("}");
67 	}
68 }
69 
70 int
rtc_ioctl(struct tcb * tcp,const unsigned int code,const long arg)71 rtc_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
72 {
73 	switch (code) {
74 	case RTC_ALM_SET:
75 	case RTC_SET_TIME:
76 		decode_rtc_time(tcp, arg);
77 		break;
78 	case RTC_ALM_READ:
79 	case RTC_RD_TIME:
80 		if (entering(tcp))
81 			return 0;
82 		decode_rtc_time(tcp, arg);
83 		break;
84 	case RTC_IRQP_SET:
85 	case RTC_EPOCH_SET:
86 		tprintf(", %lu", arg);
87 		break;
88 	case RTC_IRQP_READ:
89 	case RTC_EPOCH_READ:
90 		if (entering(tcp))
91 			return 0;
92 		tprints(", ");
93 		printnum_ulong(tcp, arg);
94 		break;
95 	case RTC_WKALM_SET:
96 		decode_rtc_wkalrm(tcp, arg);
97 		break;
98 	case RTC_WKALM_RD:
99 		if (entering(tcp))
100 			return 0;
101 		decode_rtc_wkalrm(tcp, arg);
102 		break;
103 #ifdef RTC_VL_READ
104 	case RTC_VL_READ:
105 		if (entering(tcp))
106 			return 0;
107 		tprints(", ");
108 		printnum_int(tcp, arg, "%d");
109 		break;
110 #endif
111 	default:
112 		return RVAL_DECODED;
113 	}
114 
115 	return RVAL_DECODED | 1;
116 }
117