2023-05-22 08:54:35 +08:00
|
|
|
// SPDX-License-Identifier: LGPL-2.0+
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
|
|
|
|
This file is part of the GNU C Library.
|
2023-05-22 08:54:35 +08:00
|
|
|
Contributed by Paul Eggert (eggert@twinsun.com). */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2008-02-08 20:20:36 +08:00
|
|
|
* dgb 10/02/98: ripped this from glibc source to help convert timestamps
|
|
|
|
* to unix time
|
|
|
|
* 10/04/98: added new table-based lookup after seeing how ugly
|
|
|
|
* the gnu code is
|
2005-04-17 06:20:36 +08:00
|
|
|
* blf 09/27/99: ripped out all the old code and inserted new table from
|
2007-07-21 19:37:18 +08:00
|
|
|
* John Brockmeyer (without leap second corrections)
|
|
|
|
* rewrote udf_stamp_to_time and fixed timezone accounting in
|
|
|
|
* udf_time_to_stamp.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't take into account leap seconds. This may be correct or incorrect.
|
|
|
|
* For more NIST information (especially dealing with leap seconds), see:
|
2007-07-21 19:37:18 +08:00
|
|
|
* http://www.boulder.nist.gov/timefreq/pubs/bulletin/leapsecond.htm
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2011-10-10 16:08:05 +08:00
|
|
|
#include "udfdecl.h"
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
2017-06-14 15:51:20 +08:00
|
|
|
#include <linux/time.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-05-10 23:26:17 +08:00
|
|
|
void
|
2018-06-20 16:15:13 +08:00
|
|
|
udf_disk_stamp_to_time(struct timespec64 *dest, struct timestamp src)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-10 18:25:31 +08:00
|
|
|
u16 typeAndTimezone = le16_to_cpu(src.typeAndTimezone);
|
|
|
|
u16 year = le16_to_cpu(src.year);
|
|
|
|
uint8_t type = typeAndTimezone >> 12;
|
2005-04-17 06:20:36 +08:00
|
|
|
int16_t offset;
|
|
|
|
|
2007-07-19 16:47:43 +08:00
|
|
|
if (type == 1) {
|
2008-02-10 18:25:31 +08:00
|
|
|
offset = typeAndTimezone << 4;
|
2005-04-17 06:20:36 +08:00
|
|
|
/* sign extent offset */
|
|
|
|
offset = (offset >> 4);
|
2007-07-21 19:37:18 +08:00
|
|
|
if (offset == -2047) /* unspecified offset */
|
2005-04-17 06:20:36 +08:00
|
|
|
offset = 0;
|
2008-02-28 05:50:14 +08:00
|
|
|
} else
|
2005-04-17 06:20:36 +08:00
|
|
|
offset = 0;
|
|
|
|
|
2017-06-14 16:42:48 +08:00
|
|
|
dest->tv_sec = mktime64(year, src.month, src.day, src.hour, src.minute,
|
|
|
|
src.second);
|
2008-02-28 05:50:14 +08:00
|
|
|
dest->tv_sec -= offset * 60;
|
|
|
|
dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
|
|
|
|
src.hundredsOfMicroseconds * 100 + src.microseconds);
|
2017-12-19 15:11:01 +08:00
|
|
|
/*
|
|
|
|
* Sanitize nanosecond field since reportedly some filesystems are
|
|
|
|
* recorded with bogus sub-second values.
|
|
|
|
*/
|
|
|
|
dest->tv_nsec %= NSEC_PER_SEC;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-05-10 23:26:17 +08:00
|
|
|
void
|
2018-06-20 16:15:13 +08:00
|
|
|
udf_time_to_disk_stamp(struct timestamp *dest, struct timespec64 ts)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-06-20 16:15:13 +08:00
|
|
|
time64_t seconds;
|
2005-04-17 06:20:36 +08:00
|
|
|
int16_t offset;
|
2017-06-14 15:51:20 +08:00
|
|
|
struct tm tm;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
offset = -sys_tz.tz_minuteswest;
|
|
|
|
|
2008-02-10 18:25:31 +08:00
|
|
|
dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-06-14 15:51:20 +08:00
|
|
|
seconds = ts.tv_sec + offset * 60;
|
|
|
|
time64_to_tm(seconds, 0, &tm);
|
|
|
|
dest->year = cpu_to_le16(tm.tm_year + 1900);
|
|
|
|
dest->month = tm.tm_mon + 1;
|
|
|
|
dest->day = tm.tm_mday;
|
|
|
|
dest->hour = tm.tm_hour;
|
|
|
|
dest->minute = tm.tm_min;
|
|
|
|
dest->second = tm.tm_sec;
|
2005-04-17 06:20:36 +08:00
|
|
|
dest->centiseconds = ts.tv_nsec / 10000000;
|
2008-02-08 20:20:36 +08:00
|
|
|
dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 -
|
|
|
|
dest->centiseconds * 10000) / 100;
|
2007-07-21 19:37:18 +08:00
|
|
|
dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 -
|
|
|
|
dest->hundredsOfMicroseconds * 100);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|