1 /* The kernel call implemented in this file:
4 * The parameters for this kernel call are:
11 #include "kernel/system.h"
12 #include <minix/endpoint.h>
15 /*===========================================================================*
17 *===========================================================================*/
18 int do_settime(struct proc
* caller
, message
* m_ptr
)
22 time_t timediff
, timediff_ticks
;
24 if (m_ptr
->T_CLOCK_ID
!= CLOCK_REALTIME
) /* only realtime can change */
27 if (m_ptr
->T_SETTIME_NOW
== 0) { /* user just wants to adjtime() */
28 /* convert delta value from seconds and nseconds to ticks */
29 ticks
= (m_ptr
->T_TIME_SEC
* system_hz
) +
30 (m_ptr
->T_TIME_NSEC
/(1000000000/system_hz
));
31 set_adjtime_delta(ticks
);
33 } /* else user wants to set the time */
35 timediff
= m_ptr
->T_TIME_SEC
- boottime
;
36 timediff_ticks
= timediff
* system_hz
;
38 /* prevent a negative value for realtime */
39 if (m_ptr
->T_TIME_SEC
<= boottime
||
40 timediff_ticks
< LONG_MIN
/2 || timediff_ticks
> LONG_MAX
/2) {
41 /* boottime was likely wrong, try to correct it. */
42 boottime
= m_ptr
->T_TIME_SEC
;
47 /* calculate the new value of realtime in ticks */
48 newclock
= timediff_ticks
+ (m_ptr
->T_TIME_NSEC
/(1000000000/system_hz
));
50 set_realtime(newclock
);