]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/hwclock.h
sys-utils: cleanup license lines, add SPDX
[thirdparty/util-linux.git] / sys-utils / hwclock.h
1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9 #ifndef HWCLOCK_CLOCK_H
10 #define HWCLOCK_CLOCK_H
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <sys/time.h>
16 #include <time.h>
17
18 #include "c.h"
19 #include "debug.h"
20 #include "nls.h"
21
22 #define HWCLOCK_DEBUG_INIT (1 << 0)
23 #define HWCLOCK_DEBUG_RANDOM_SLEEP (1 << 1)
24 #define HWCLOCK_DEBUG_DELTA_VS_TARGET (1 << 2)
25 #define HWCLOCK_DEBUG_ALL 0xFFFF
26
27 UL_DEBUG_DECLARE_MASK(hwclock);
28 #define DBG(m, x) __UL_DBG(hwclock, HWCLOCK_DEBUG_, m, x)
29 #define ON_DBG(m, x) __UL_DBG_CALL(hwclock, HWCLOCK_DEBUG_, m, x)
30
31 struct hwclock_control {
32 char *date_opt;
33 char *adj_file_name;
34 double rtc_delay; /* --delay <seconds> */
35 #if defined(__linux__) && defined(__alpha__)
36 char *epoch_option;
37 #endif
38 #ifdef __linux__
39 char *rtc_dev_name;
40 #endif
41 char *param_get_option;
42 char *param_set_option;
43 unsigned int
44 hwaudit_on:1,
45 adjust:1,
46 show:1,
47 hctosys:1,
48 utc:1,
49 systohc:1,
50 #if defined(__linux__) && defined(__alpha__)
51 getepoch:1,
52 setepoch:1,
53 #endif
54 noadjfile:1,
55 local_opt:1,
56 directisa:1,
57 testing:1,
58 systz:1,
59 predict:1,
60 get:1,
61 set:1,
62 update:1,
63 universal:1, /* will store hw_clock_is_utc() return value */
64 vl_read:1,
65 vl_clear:1,
66 verbose:1;
67 };
68
69 struct clock_ops {
70 char *interface_name;
71 int (*get_permissions) (void);
72 int (*read_hardware_clock) (const struct hwclock_control *ctl, struct tm * tm);
73 int (*set_hardware_clock) (const struct hwclock_control *ctl, const struct tm * tm);
74 int (*synchronize_to_clock_tick) (const struct hwclock_control *ctl);
75 const char *(*get_device_path) (void);
76 };
77
78 extern const struct clock_ops *probe_for_cmos_clock(void);
79 extern const struct clock_ops *probe_for_rtc_clock(const struct hwclock_control *ctl);
80
81 /* hwclock.c */
82 extern double time_diff(struct timeval subtrahend, struct timeval subtractor);
83
84 /* rtc.c */
85 #if defined(__linux__) && defined(__alpha__)
86 extern int get_epoch_rtc(const struct hwclock_control *ctl, unsigned long *epoch);
87 extern int set_epoch_rtc(const struct hwclock_control *ctl);
88 #endif
89
90 struct hwclock_param {
91 int id;
92 const char *name;
93 const char *help;
94 };
95
96 extern const struct hwclock_param *get_hwclock_params(void);
97 extern int get_param_rtc(const struct hwclock_control *ctl,
98 const char *name, uint64_t *id, uint64_t *value);
99 extern int set_param_rtc(const struct hwclock_control *ctl, const char *name);
100
101 extern int rtc_vl_read(const struct hwclock_control *ctl);
102 extern int rtc_vl_clear(const struct hwclock_control *ctl);
103
104 extern void __attribute__((__noreturn__))
105 hwclock_exit(const struct hwclock_control *ctl, int status);
106
107 extern int parse_date(struct timespec *, char const *, struct timespec const *);
108
109 #endif /* HWCLOCK_CLOCK_H */