~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to hwclock/kd.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones, Roger Leigh, LaMont Jones, 김종규, Niels Thykier
  • Date: 2011-11-03 15:38:23 UTC
  • mfrom: (1.7.2)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-n2nt15ce74gyvnaa
Tags: 2.20.1-1
* New upstream

[Roger Leigh]

* Various merge fixes [with edits - lamont]
  - drop old unused patches
  - cleanup debian/rules
  - updated symbols files for lib{blkid,mount,uuid}1

[LaMont Jones]

* merge in 2.19.1-{3..5}
* deliver /etc/fstab.d

[김종규]

* add korean debconf pofile.  Closes: #632421, #632425

[Niels Thykier]

* Add build-arch and build-indep targets.  Closes: #648467

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* kd.c - KDGHWCLK stuff, possibly m68k only - deprecated */
 
1
/*
 
2
 * kd.c - KDGHWCLK stuff, possibly m68k only, likely to be deprecated
 
3
 */
2
4
 
3
 
#include "clock.h"
4
5
 
5
6
#ifdef __m68k__
6
7
 
7
 
#include <unistd.h>             /* for close() */
8
 
#include <fcntl.h>              /* for O_RDONLY */
9
 
#include <sysexits.h>
10
 
#include <sys/ioctl.h>
 
8
# include <fcntl.h>
 
9
# include <sysexits.h>
 
10
# include <sys/ioctl.h>
 
11
# include <unistd.h>
11
12
 
12
 
#include "nls.h"
13
 
#include "usleep.h"
 
13
# include "clock.h"
 
14
# include "nls.h"
 
15
# include "usleep.h"
14
16
 
15
17
/* Get defines for KDGHWCLK and KDSHWCLK (m68k) */
16
 
#include <linux/kd.h>
 
18
# include <linux/kd.h>
17
19
 
18
20
/* Even on m68k, if KDGHWCLK (antique) is not defined, don't build this */
19
21
 
21
23
 
22
24
#if !defined(__m68k__) || !defined(KDGHWCLK)
23
25
 
24
 
struct clock_ops *
25
 
probe_for_kd_clock() {
 
26
#include <stddef.h>
 
27
struct clock_ops *probe_for_kd_clock()
 
28
{
26
29
        return NULL;
27
30
}
28
31
 
29
 
#else /* __m68k__ && KDGHWCLK */
 
32
#else                           /* __m68k__ && KDGHWCLK */
30
33
 
31
 
static int con_fd = -1;         /* opened by probe_for_kd_clock() */
32
 
                                /* never closed */
 
34
/* Opened by probe_for_kd_clock(), and never closed. */
 
35
static int con_fd = -1;
33
36
static char *con_fd_filename;   /* usually "/dev/tty1" */
34
37
 
35
 
static int
36
 
synchronize_to_clock_tick_kd(void) {
37
 
/*----------------------------------------------------------------------------
38
 
   Wait for the top of a clock tick by calling KDGHWCLK in a busy loop until
39
 
   we see it.
40
 
-----------------------------------------------------------------------------*/
41
 
 
42
 
  /* The time when we were called (and started waiting) */
43
 
  struct hwclk_time start_time, nowtime;
44
 
  struct timeval begin, now;
45
 
 
46
 
  if (debug)
47
 
    printf(_("Waiting in loop for time from KDGHWCLK to change\n"));
48
 
 
49
 
  if (ioctl(con_fd, KDGHWCLK, &start_time) == -1) {
50
 
    outsyserr(_("KDGHWCLK ioctl to read time failed"));
51
 
    return 3;
52
 
  }
53
 
 
54
 
  /* Wait for change.  Should be within a second, but in case something
55
 
   * weird happens, we have a time limit (1.5s) on this loop to reduce the
56
 
   * impact of this failure.
57
 
   */
58
 
  gettimeofday(&begin, NULL);
59
 
  do {
60
 
    /* Added by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
61
 
     * "The culprit is the fast loop with KDGHWCLK ioctls. It seems
62
 
     *  the kernel gets confused by those on Amigas with A2000 RTCs
63
 
     *  and simply hangs after some time. Inserting a sleep helps."
64
 
     */
65
 
    usleep(1);
66
 
 
67
 
    if (ioctl(con_fd, KDGHWCLK, &nowtime) == -1) {
68
 
      outsyserr(_("KDGHWCLK ioctl to read time failed in loop"));
69
 
      return 3;
70
 
    }
71
 
    if (start_time.tm_sec != nowtime.tm_sec)
72
 
      break;
73
 
    gettimeofday(&now, NULL);
74
 
    if (time_diff(now, begin) > 1.5) {
75
 
      fprintf(stderr, _("Timed out waiting for time change.\n"));
76
 
      return 2;
77
 
    }
78
 
  } while(1);
79
 
 
80
 
  return 0;
81
 
}
82
 
 
83
 
 
84
 
static int
85
 
read_hardware_clock_kd(struct tm *tm) {
86
 
/*----------------------------------------------------------------------------
87
 
  Read the hardware clock and return the current time via <tm>
88
 
  argument.  Use ioctls to /dev/tty1 on what we assume is an m68k
89
 
  machine.
90
 
 
91
 
  Note that we don't use /dev/console here.  That might be a serial
92
 
  console.
93
 
-----------------------------------------------------------------------------*/
94
 
  struct hwclk_time t;
95
 
 
96
 
  if (ioctl(con_fd, KDGHWCLK, &t) == -1) {
97
 
    outsyserr(_("ioctl() failed to read time from %s"), con_fd_filename);
98
 
    hwclock_exit(EX_IOERR);
99
 
  }
100
 
 
101
 
  tm->tm_sec  = t.sec;
102
 
  tm->tm_min  = t.min;
103
 
  tm->tm_hour = t.hour;
104
 
  tm->tm_mday = t.day;
105
 
  tm->tm_mon  = t.mon;
106
 
  tm->tm_year = t.year;
107
 
  tm->tm_wday = t.wday;
108
 
  tm->tm_isdst = -1;     /* Don't know if it's Daylight Savings Time */
109
 
 
110
 
  return 0;
111
 
}
112
 
 
113
 
 
114
 
static int
115
 
set_hardware_clock_kd(const struct tm *new_broken_time) {
116
 
/*----------------------------------------------------------------------------
117
 
  Set the Hardware Clock to the time <new_broken_time>.  Use ioctls to
118
 
  /dev/tty1 on what we assume is an m68k machine.
119
 
 
120
 
  Note that we don't use /dev/console here.  That might be a serial console.
121
 
----------------------------------------------------------------------------*/
122
 
  struct hwclk_time t;
123
 
 
124
 
  t.sec  = new_broken_time->tm_sec;
125
 
  t.min  = new_broken_time->tm_min;
126
 
  t.hour = new_broken_time->tm_hour;
127
 
  t.day  = new_broken_time->tm_mday;
128
 
  t.mon  = new_broken_time->tm_mon;
129
 
  t.year = new_broken_time->tm_year;
130
 
  t.wday = new_broken_time->tm_wday;
131
 
 
132
 
  if (ioctl(con_fd, KDSHWCLK, &t ) == -1) {
133
 
    outsyserr(_("ioctl KDSHWCLK failed"));
134
 
    hwclock_exit(1);
135
 
  }
136
 
  return 0;
137
 
}
138
 
 
139
 
static int
140
 
get_permissions_kd(void) {
141
 
  return 0;
 
38
/*
 
39
 * Wait for the top of a clock tick by calling KDGHWCLK in a busy loop until
 
40
 * we see it.
 
41
 */
 
42
static int synchronize_to_clock_tick_kd(void)
 
43
{
 
44
        /* The time when we were called (and started waiting) */
 
45
        struct hwclk_time start_time, nowtime;
 
46
        struct timeval begin, now;
 
47
 
 
48
        if (debug)
 
49
                printf(_("Waiting in loop for time from KDGHWCLK to change\n"));
 
50
 
 
51
        if (ioctl(con_fd, KDGHWCLK, &start_time) == -1) {
 
52
                warn(_("KDGHWCLK ioctl to read time failed"));
 
53
                return 3;
 
54
        }
 
55
 
 
56
        /*
 
57
         * Wait for change. Should be within a second, but in case something
 
58
         * weird happens, we have a time limit (1.5s) on this loop to reduce
 
59
         * the impact of this failure.
 
60
         */
 
61
        gettimeofday(&begin, NULL);
 
62
        do {
 
63
                /*
 
64
                 * Added by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
 
65
                 *
 
66
                 * "The culprit is the fast loop with KDGHWCLK ioctls. It
 
67
                 *  seems the kernel gets confused by those on Amigas with
 
68
                 *  A2000 RTCs and simply hangs after some time. Inserting a
 
69
                 *  sleep helps."
 
70
                 */
 
71
                usleep(1);
 
72
 
 
73
                if (ioctl(con_fd, KDGHWCLK, &nowtime) == -1) {
 
74
                        warn(_("KDGHWCLK ioctl to read time failed in loop"));
 
75
                        return 3;
 
76
                }
 
77
                if (start_time.tm_sec != nowtime.tm_sec)
 
78
                        break;
 
79
                gettimeofday(&now, NULL);
 
80
                if (time_diff(now, begin) > 1.5) {
 
81
                        warnx(_("Timed out waiting for time change."));
 
82
                        return 2;
 
83
                }
 
84
        } while (1);
 
85
 
 
86
        return 0;
 
87
}
 
88
 
 
89
/*
 
90
 * Read the hardware clock and return the current time via <tm> argument.
 
91
 * Use ioctls to /dev/tty1 on what we assume is an m68k machine.
 
92
 *
 
93
 * Note that we don't use /dev/console here. That might be a serial console.
 
94
 */
 
95
static int read_hardware_clock_kd(struct tm *tm)
 
96
{
 
97
        struct hwclk_time t;
 
98
 
 
99
        if (ioctl(con_fd, KDGHWCLK, &t) == -1) {
 
100
                warn(_("ioctl() failed to read time from %s"),
 
101
                          con_fd_filename);
 
102
                hwclock_exit(EX_IOERR);
 
103
        }
 
104
 
 
105
        tm->tm_sec = t.sec;
 
106
        tm->tm_min = t.min;
 
107
        tm->tm_hour = t.hour;
 
108
        tm->tm_mday = t.day;
 
109
        tm->tm_mon = t.mon;
 
110
        tm->tm_year = t.year;
 
111
        tm->tm_wday = t.wday;
 
112
        tm->tm_isdst = -1;      /* Don't know if it's Daylight Savings Time */
 
113
 
 
114
        return 0;
 
115
}
 
116
 
 
117
/*
 
118
 * Set the Hardware Clock to the time <new_broken_time>. Use ioctls to
 
119
 * /dev/tty1 on what we assume is an m68k machine.
 
120
 *
 
121
 * Note that we don't use /dev/console here. That might be a serial console.
 
122
 */
 
123
static int set_hardware_clock_kd(const struct tm *new_broken_time)
 
124
{
 
125
        struct hwclk_time t;
 
126
 
 
127
        t.sec = new_broken_time->tm_sec;
 
128
        t.min = new_broken_time->tm_min;
 
129
        t.hour = new_broken_time->tm_hour;
 
130
        t.day = new_broken_time->tm_mday;
 
131
        t.mon = new_broken_time->tm_mon;
 
132
        t.year = new_broken_time->tm_year;
 
133
        t.wday = new_broken_time->tm_wday;
 
134
 
 
135
        if (ioctl(con_fd, KDSHWCLK, &t) == -1) {
 
136
                warn(_("ioctl KDSHWCLK failed"));
 
137
                hwclock_exit(EX_IOERR);
 
138
        }
 
139
        return 0;
 
140
}
 
141
 
 
142
static int get_permissions_kd(void)
 
143
{
 
144
        return 0;
142
145
}
143
146
 
144
147
static struct clock_ops kd = {
150
153
};
151
154
 
152
155
/* return &kd if KDGHWCLK works, NULL otherwise */
153
 
struct clock_ops *
154
 
probe_for_kd_clock() {
 
156
struct clock_ops *probe_for_kd_clock()
 
157
{
155
158
        struct clock_ops *ret = NULL;
156
159
        struct hwclk_time t;
157
160
 
166
169
        }
167
170
        if (con_fd < 0) {
168
171
                /* probably KDGHWCLK exists on m68k only */
169
 
                outsyserr(_("Can't open /dev/tty1 or /dev/vc/1"));
 
172
                warn(_("Can't open /dev/tty1 or /dev/vc/1"));
170
173
        } else {
171
174
                if (ioctl(con_fd, KDGHWCLK, &t) == -1) {
172
175
                        if (errno != EINVAL)
173
 
                                outsyserr(_("KDGHWCLK ioctl failed"));
 
176
                                warn(_("KDGHWCLK ioctl failed"));
174
177
                } else
175
178
                        ret = &kd;
176
179
        }
177
180
        return ret;
178
181
}
179
 
#endif /* __m68k__ && KDGHWCLK */
 
182
#endif                          /* __m68k__ && KDGHWCLK */