From owner-svn-src-all@freebsd.org Sun Jul 23 21:28:02 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 07C09DAE0FA; Sun, 23 Jul 2017 21:28:02 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C9A9C705D8; Sun, 23 Jul 2017 21:28:01 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v6NLS0tJ016214; Sun, 23 Jul 2017 21:28:00 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v6NLS0Gs016213; Sun, 23 Jul 2017 21:28:00 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201707232128.v6NLS0Gs016213@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 23 Jul 2017 21:28:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r321400 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: ian X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 321400 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Jul 2017 21:28:02 -0000 Author: ian Date: Sun Jul 23 21:28:00 2017 New Revision: 321400 URL: https://svnweb.freebsd.org/changeset/base/321400 Log: Add common code to support realtime clocks that store year without century. Most realtime clocks store the year as 2 BCD digits. Some add a century bit to extend the range another hundred years. Every clock driver has its own code to determine the century and pass a full year value to clock_ct_to_ts(). Now clock drivers can just convert BCD to bin and store the result in the clocktime struct and let the common code figure out the century. Clocks with a century bit can just add 100 to year if the century bit is on. Modified: head/sys/kern/subr_clock.c Modified: head/sys/kern/subr_clock.c ============================================================================== --- head/sys/kern/subr_clock.c Sun Jul 23 20:41:58 2017 (r321399) +++ head/sys/kern/subr_clock.c Sun Jul 23 21:28:00 2017 (r321400) @@ -142,18 +142,27 @@ clock_ct_to_ts(struct clocktime *ct, struct timespec * { int i, year, days; - year = ct->year; - if (ct_debug) { printf("ct_to_ts("); print_ct(ct); printf(")"); } + /* + * Many realtime clocks store the year as 2-digit BCD; pivot on 70 to + * determine century. Some clocks have a "century bit" and drivers do + * year += 100, so interpret values between 70-199 as relative to 1900. + */ + year = ct->year; + if (year < 70) + year += 2000; + else if (year < 200) + year += 1900; + /* Sanity checks. */ if (ct->mon < 1 || ct->mon > 12 || ct->day < 1 || ct->day > days_in_month(year, ct->mon) || - ct->hour > 23 || ct->min > 59 || ct->sec > 59 || + ct->hour > 23 || ct->min > 59 || ct->sec > 59 || year < 1970 || (sizeof(time_t) == 4 && year > 2037)) { /* time_t overflow */ if (ct_debug) printf(" = EINVAL\n");