From owner-svn-src-stable@FreeBSD.ORG Thu Mar 19 15:49:31 2009 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2C7B4106566C; Thu, 19 Mar 2009 15:49:31 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 19CC08FC1A; Thu, 19 Mar 2009 15:49:31 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n2JFnUmC067577; Thu, 19 Mar 2009 15:49:31 GMT (envelope-from avg@svn.freebsd.org) Received: (from avg@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n2JFnUku067576; Thu, 19 Mar 2009 15:49:30 GMT (envelope-from avg@svn.freebsd.org) Message-Id: <200903191549.n2JFnUku067576@svn.freebsd.org> From: Andriy Gapon Date: Thu, 19 Mar 2009 15:49:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r190074 - in stable/7/sys: . contrib/pf dev/ath/ath_hal dev/cxgb fs/udf X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2009 15:49:31 -0000 Author: avg Date: Thu Mar 19 15:49:30 2009 New Revision: 190074 URL: http://svn.freebsd.org/changeset/base/190074 Log: MFC 179060: udf: fix and speedup timestamp calculations markus and emax are notified Approved by: jhb (mentor) Modified: stable/7/sys/ (props changed) stable/7/sys/contrib/pf/ (props changed) stable/7/sys/dev/ath/ath_hal/ (props changed) stable/7/sys/dev/cxgb/ (props changed) stable/7/sys/fs/udf/udf_vnops.c Modified: stable/7/sys/fs/udf/udf_vnops.c ============================================================================== --- stable/7/sys/fs/udf/udf_vnops.c Thu Mar 19 15:46:33 2009 (r190073) +++ stable/7/sys/fs/udf/udf_vnops.c Thu Mar 19 15:49:30 2009 (r190074) @@ -188,9 +188,9 @@ udf_open(struct vop_open_args *ap) { return 0; } -static int mon_lens[2][12] = { - {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, - {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} +static const int mon_lens[2][12] = { + {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, + {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335} }; static int @@ -206,25 +206,25 @@ udf_isaleapyear(int year) } /* - * XXX This is just a rough hack. Daylight savings isn't calculated and tv_nsec - * is ignored. * Timezone calculation compliments of Julian Elischer . */ static void udf_timetotimespec(struct timestamp *time, struct timespec *t) { - int i, lpyear, daysinyear, year; + int i, lpyear, daysinyear, year, startyear; union { uint16_t u_tz_offset; int16_t s_tz_offset; } tz; - t->tv_nsec = 0; - - /* DirectCD seems to like using bogus year values */ + /* + * DirectCD seems to like using bogus year values. + * Don't trust time->month as it will be used for an array index. + */ year = le16toh(time->year); - if (year < 1970) { + if (year < 1970 || time->month < 1 || time->month > 12) { t->tv_sec = 0; + t->tv_nsec = 0; return; } @@ -232,25 +232,37 @@ udf_timetotimespec(struct timestamp *tim t->tv_sec = time->second; t->tv_sec += time->minute * 60; t->tv_sec += time->hour * 3600; - t->tv_sec += time->day * 3600 * 24; + t->tv_sec += (time->day - 1) * 3600 * 24; /* Calculate the month */ lpyear = udf_isaleapyear(year); - for (i = 1; i < time->month; i++) - t->tv_sec += mon_lens[lpyear][i] * 3600 * 24; + t->tv_sec += mon_lens[lpyear][time->month - 1] * 3600 * 24; /* Speed up the calculation */ - if (year > 1979) + startyear = 1970; + if (year > 2009) { + t->tv_sec += 1262304000; + startyear += 40; + } else if (year > 1999) { + t->tv_sec += 946684800; + startyear += 30; + } else if (year > 1989) { + t->tv_sec += 631152000; + startyear += 20; + } else if (year > 1979) { t->tv_sec += 315532800; - if (year > 1989) - t->tv_sec += 315619200; - if (year > 1999) - t->tv_sec += 315532800; - for (i = 2000; i < year; i++) { - daysinyear = udf_isaleapyear(i) + 365 ; - t->tv_sec += daysinyear * 3600 * 24; + startyear += 10; } + daysinyear = (year - startyear) * 365; + for (i = startyear; i < year; i++) + daysinyear += udf_isaleapyear(i); + t->tv_sec += daysinyear * 3600 * 24; + + /* Calculate microseconds */ + t->tv_nsec = time->centisec * 10000 + time->hund_usec * 100 + + time->usec; + /* * Calculate the time zone. The timezone is 12 bit signed 2's * complement, so we gotta do some extra magic to handle it right. @@ -259,7 +271,7 @@ udf_timetotimespec(struct timestamp *tim tz.u_tz_offset &= 0x0fff; if (tz.u_tz_offset & 0x0800) tz.u_tz_offset |= 0xf000; /* extend the sign to 16 bits */ - if ((time->type_tz & 0x1000) && (tz.s_tz_offset != -2047)) + if ((le16toh(time->type_tz) & 0x1000) && (tz.s_tz_offset != -2047)) t->tv_sec -= tz.s_tz_offset * 60; return;