make vfs & filesystems use failable copying
[minix3.git] / kernel / system / do_settime.c
blobe21836eb8d50ee49503c9f3923a319dd66dc44fa
1 /* The kernel call implemented in this file:
2 * m_type: SYS_SETTIME
4 * The parameters for this kernel call are:
5 * m4_l2: T_SETTIME_NOW
6 * m4_l3: T_CLOCK_ID
7 * m4_ll1: T_TIME_SEC
8 * m4_l5: T_TIME_NSEC
9 */
11 #include "kernel/system.h"
12 #include <minix/endpoint.h>
13 #include <time.h>
15 /*===========================================================================*
16 * do_settime *
17 *===========================================================================*/
18 int do_settime(struct proc * caller, message * m_ptr)
20 clock_t newclock;
21 int32_t ticks;
22 time_t timediff, timediff_ticks;
24 if (m_ptr->T_CLOCK_ID != CLOCK_REALTIME) /* only realtime can change */
25 return EINVAL;
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);
32 return(OK);
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;
43 set_realtime(1);
44 return(OK);
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);
52 return(OK);