1 /* This file takes care of those system calls that deal with time.
3 * The entry points into this file are
4 * do_getres: perform the CLOCK_GETRES system call
5 * do_gettime: perform the CLOCK_GETTIME system call
6 * do_settime: perform the CLOCK_SETTIME system call
7 * do_time: perform the GETTIMEOFDAY system call
8 * do_stime: perform the STIME system call
12 #include <minix/callnr.h>
13 #include <minix/com.h>
18 /*===========================================================================*
20 *===========================================================================*/
23 clock_t ticks
, realtime
, clock
;
27 if ( (s
=getuptime(&ticks
, &realtime
, &boottime
)) != OK
)
28 panic("do_time couldn't get uptime: %d", s
);
30 switch (m_in
.m_lc_pm_time
.clk_id
) {
38 return EINVAL
; /* invalid/unsupported clock_id */
41 mp
->mp_reply
.m_pm_lc_time
.sec
= boottime
+ (clock
/ system_hz
);
42 mp
->mp_reply
.m_pm_lc_time
.nsec
=
43 (uint32_t) ((clock
% system_hz
) * 1000000000ULL / system_hz
);
48 /*===========================================================================*
50 *===========================================================================*/
53 switch (m_in
.m_lc_pm_time
.clk_id
) {
56 /* tv_sec is always 0 since system_hz is an int */
57 mp
->mp_reply
.m_pm_lc_time
.sec
= 0;
58 mp
->mp_reply
.m_pm_lc_time
.nsec
= 1000000000 / system_hz
;
61 return EINVAL
; /* invalid/unsupported clock_id */
65 /*===========================================================================*
67 *===========================================================================*/
72 if (mp
->mp_effuid
!= SUPER_USER
) {
76 switch (m_in
.m_lc_pm_time
.clk_id
) {
78 s
= sys_settime(m_in
.m_lc_pm_time
.now
, m_in
.m_lc_pm_time
.clk_id
,
79 m_in
.m_lc_pm_time
.sec
, m_in
.m_lc_pm_time
.nsec
);
81 case CLOCK_MONOTONIC
: /* monotonic cannot be changed */
83 return EINVAL
; /* invalid/unsupported clock_id */
87 /*===========================================================================*
89 *===========================================================================*/
92 /* Perform the time(tp) system call. This returns the time in seconds since
93 * 1.1.1970. MINIX is an astrophysically naive system that assumes the earth
94 * rotates at a constant rate and that such things as leap seconds do not
97 clock_t ticks
, realtime
;
101 if ( (s
=getuptime(&ticks
, &realtime
, &boottime
)) != OK
)
102 panic("do_time couldn't get uptime: %d", s
);
104 mp
->mp_reply
.m_pm_lc_time
.sec
= boottime
+ (realtime
/ system_hz
);
105 mp
->mp_reply
.m_pm_lc_time
.nsec
=
106 (uint32_t) ((realtime
% system_hz
) * 1000000000ULL / system_hz
);
110 /*===========================================================================*
112 *===========================================================================*/
115 /* Perform the stime(tp) system call. Retrieve the system's uptime (ticks
116 * since boot) and pass the new time in seconds at system boot to the kernel.
118 clock_t uptime
, realtime
;
122 if (mp
->mp_effuid
!= SUPER_USER
) {
125 if ( (s
=getuptime(&uptime
, &realtime
, &boottime
)) != OK
)
126 panic("do_stime couldn't get uptime: %d", s
);
127 boottime
= m_in
.m_lc_pm_time
.sec
- (realtime
/system_hz
);
129 s
= sys_stime(boottime
); /* Tell kernel about boottime */
131 panic("pm: sys_stime failed: %d", s
);