minix3/kernel/system/do_settime.c

55 lines
1.7 KiB
C

/* The kernel call implemented in this file:
* m_type: SYS_SETTIME
*
* The parameters for this kernel call are:
* m_lsys_krn_sys_settime.now
* m_lsys_krn_sys_settime.clock_id
* m_lsys_krn_sys_settime.sec
* m_lsys_krn_sys_settime.nsec
*/
#include "kernel/system.h"
#include <minix/endpoint.h>
#include <time.h>
/*===========================================================================*
* do_settime *
*===========================================================================*/
int do_settime(struct proc * caller, message * m_ptr)
{
clock_t newclock;
int32_t ticks;
time_t timediff, timediff_ticks;
if (m_ptr->m_lsys_krn_sys_settime.clock_id != CLOCK_REALTIME) /* only realtime can change */
return EINVAL;
if (m_ptr->m_lsys_krn_sys_settime.now == 0) { /* user just wants to adjtime() */
/* convert delta value from seconds and nseconds to ticks */
ticks = (m_ptr->m_lsys_krn_sys_settime.sec * system_hz) +
(m_ptr->m_lsys_krn_sys_settime.nsec/(1000000000/system_hz));
set_adjtime_delta(ticks);
return(OK);
} /* else user wants to set the time */
timediff = m_ptr->m_lsys_krn_sys_settime.sec - boottime;
timediff_ticks = timediff * system_hz;
/* prevent a negative value for realtime */
if (m_ptr->m_lsys_krn_sys_settime.sec <= boottime ||
timediff_ticks < LONG_MIN/2 || timediff_ticks > LONG_MAX/2) {
/* boottime was likely wrong, try to correct it. */
boottime = m_ptr->m_lsys_krn_sys_settime.sec;
set_realtime(1);
return(OK);
}
/* calculate the new value of realtime in ticks */
newclock = timediff_ticks +
(m_ptr->m_lsys_krn_sys_settime.nsec/(1000000000/system_hz));
set_realtime(newclock);
return(OK);
}