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 *===========================================================================*/
24 clock_t ticks
, realtime
, clock
;
28 if ( (s
=getuptime(&ticks
, &realtime
, &boottime
)) != OK
)
29 panic("do_time couldn't get uptime: %d", s
);
31 switch (m_in
.m_lc_pm_time
.clk_id
) {
39 return EINVAL
; /* invalid/unsupported clock_id */
42 mp
->mp_reply
.m_pm_lc_time
.sec
= boottime
+ (clock
/ system_hz
);
43 mp
->mp_reply
.m_pm_lc_time
.nsec
=
44 (uint32_t) ((clock
% system_hz
) * 1000000000ULL / system_hz
);
49 /*===========================================================================*
51 *===========================================================================*/
55 switch (m_in
.m_lc_pm_time
.clk_id
) {
58 /* tv_sec is always 0 since system_hz is an int */
59 mp
->mp_reply
.m_pm_lc_time
.sec
= 0;
60 mp
->mp_reply
.m_pm_lc_time
.nsec
= 1000000000 / system_hz
;
63 return EINVAL
; /* invalid/unsupported clock_id */
67 /*===========================================================================*
69 *===========================================================================*/
75 if (mp
->mp_effuid
!= SUPER_USER
) {
79 switch (m_in
.m_lc_pm_time
.clk_id
) {
81 s
= sys_settime(m_in
.m_lc_pm_time
.now
, m_in
.m_lc_pm_time
.clk_id
,
82 m_in
.m_lc_pm_time
.sec
, m_in
.m_lc_pm_time
.nsec
);
84 case CLOCK_MONOTONIC
: /* monotonic cannot be changed */
86 return EINVAL
; /* invalid/unsupported clock_id */
90 /*===========================================================================*
92 *===========================================================================*/
96 /* Perform the time(tp) system call. */
99 (void)clock_time(&tv
);
101 mp
->mp_reply
.m_pm_lc_time
.sec
= tv
.tv_sec
;
102 mp
->mp_reply
.m_pm_lc_time
.nsec
= tv
.tv_nsec
;
106 /*===========================================================================*
108 *===========================================================================*/
112 /* Perform the stime(tp) system call. Retrieve the system's uptime (ticks
113 * since boot) and pass the new time in seconds at system boot to the kernel.
115 clock_t uptime
, realtime
;
119 if (mp
->mp_effuid
!= SUPER_USER
) {
122 if ( (s
=getuptime(&uptime
, &realtime
, &boottime
)) != OK
)
123 panic("do_stime couldn't get uptime: %d", s
);
124 boottime
= m_in
.m_lc_pm_time
.sec
- (realtime
/system_hz
);
126 s
= sys_stime(boottime
); /* Tell kernel about boottime */
128 panic("pm: sys_stime failed: %d", s
);