Ejemplo n.º 1
0
static int read_hardware_clock_rtc(struct tm *tm)
{
	int rtc_fd, rc;

	rtc_fd = open_rtc_or_exit();

	/* Read the RTC time/date, return answer via tm */
	rc = do_rtc_read_ioctl(rtc_fd, tm);

	return rc;
}
Ejemplo n.º 2
0
static int
set_hardware_clock_rtc(const struct tm *new_broken_time) {
/*-------------------------------------------------------------------------
  Set the Hardware Clock to the broken down time <new_broken_time>.
  Use ioctls to "rtc" device /dev/rtc.
  -------------------------------------------------------------------------*/
	int rc = -1;
	int rtc_fd;
	char *ioctlname;

	rtc_fd = open_rtc_or_exit();

#ifdef __sparc__
	{
		struct sparc_rtc_time stm;

		stm.sec = new_broken_time->tm_sec;
		stm.min = new_broken_time->tm_min;
		stm.hour = new_broken_time->tm_hour;
		stm.dom = new_broken_time->tm_mday;
		stm.month = new_broken_time->tm_mon + 1;
		stm.year = new_broken_time->tm_year + 1900;
		stm.dow = new_broken_time->tm_wday + 1;

		ioctlname = "RTCSET";
		rc = ioctl(rtc_fd, RTCSET, &stm);
	}
#endif
	if (rc == -1) {		/* no sparc, or RTCSET failed */
		ioctlname = "RTC_SET_TIME";
		rc = ioctl(rtc_fd, RTC_SET_TIME, new_broken_time);
	}

	if (rc == -1) {
		perror(ioctlname);
		fprintf(stderr, _("ioctl() to %s to set the time failed.\n"),
			rtc_dev_name);
		hwclock_exit(EX_IOERR);
	}

	if (debug)
		printf(_("ioctl(%s) was successful.\n"), ioctlname);

	return 0;
}
Ejemplo n.º 3
0
/*
 * Set the Hardware Clock to the broken down time <new_broken_time>. Use
 * ioctls to "rtc" device /dev/rtc.
 */
static int set_hardware_clock_rtc(const struct hwclock_control *ctl,
				  const struct tm *new_broken_time)
{
	int rc = -1;
	int rtc_fd;
	char *ioctlname;

	rtc_fd = open_rtc_or_exit(ctl);

	ioctlname = "RTC_SET_TIME";
	rc = ioctl(rtc_fd, RTC_SET_TIME, new_broken_time);

#ifdef __sparc__
	if (rc == -1) {		/* sparc sbus */
		struct sparc_rtc_time stm;

		stm.sec = new_broken_time->tm_sec;
		stm.min = new_broken_time->tm_min;
		stm.hour = new_broken_time->tm_hour;
		stm.dom = new_broken_time->tm_mday;
		stm.month = new_broken_time->tm_mon + 1;
		stm.year = new_broken_time->tm_year + 1900;
		stm.dow = new_broken_time->tm_wday + 1;

		ioctlname = "RTCSET";
		rc = ioctl(rtc_fd, RTCSET, &stm);
	}
#endif

	if (rc == -1) {
		warn(_("ioctl(%s) to %s to set the time failed"),
			ioctlname, rtc_dev_name);
		hwclock_exit(ctl, EXIT_FAILURE);
	}

	if (ctl->verbose)
		printf(_("ioctl(%s) was successful.\n"), ioctlname);

	return 0;
}