Linux Audio

Check our new training course

Linux BSP upgrade and security maintenance

Need help to get security updates for your Linux BSP?
Loading...
v6.13.7
 1// SPDX-License-Identifier: LGPL-2.0+
 2/* Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
 3   This file is part of the GNU C Library.
 4   Contributed by Paul Eggert (eggert@twinsun.com). */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 5
 6/*
 7 * dgb 10/02/98: ripped this from glibc source to help convert timestamps
 8 *               to unix time
 9 *     10/04/98: added new table-based lookup after seeing how ugly
10 *               the gnu code is
11 * blf 09/27/99: ripped out all the old code and inserted new table from
12 *		 John Brockmeyer (without leap second corrections)
13 *		 rewrote udf_stamp_to_time and fixed timezone accounting in
14 *		 udf_time_to_stamp.
15 */
16
17/*
18 * We don't take into account leap seconds. This may be correct or incorrect.
19 * For more NIST information (especially dealing with leap seconds), see:
20 * http://www.boulder.nist.gov/timefreq/pubs/bulletin/leapsecond.htm
21 */
22
23#include "udfdecl.h"
24
25#include <linux/types.h>
26#include <linux/kernel.h>
27#include <linux/time.h>
28
29void
30udf_disk_stamp_to_time(struct timespec64 *dest, struct timestamp src)
31{
32	u16 typeAndTimezone = le16_to_cpu(src.typeAndTimezone);
33	u16 year = le16_to_cpu(src.year);
34	uint8_t type = typeAndTimezone >> 12;
35	int16_t offset;
36
37	if (type == 1) {
38		offset = typeAndTimezone << 4;
39		/* sign extent offset */
40		offset = (offset >> 4);
41		if (offset == -2047) /* unspecified offset */
42			offset = 0;
43	} else
44		offset = 0;
45
46	dest->tv_sec = mktime64(year, src.month, src.day, src.hour, src.minute,
47			src.second);
48	dest->tv_sec -= offset * 60;
49
 
50	/*
51	 * Sanitize nanosecond field since reportedly some filesystems are
52	 * recorded with bogus sub-second values.
53	 */
54	if (src.centiseconds < 100 && src.hundredsOfMicroseconds < 100 &&
55	    src.microseconds < 100) {
56		dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
57			src.hundredsOfMicroseconds * 100 + src.microseconds);
58	} else {
59		dest->tv_nsec = 0;
60	}
61}
62
63void
64udf_time_to_disk_stamp(struct timestamp *dest, struct timespec64 ts)
65{
66	time64_t seconds;
67	int16_t offset;
68	struct tm tm;
69
70	offset = -sys_tz.tz_minuteswest;
71
 
 
 
72	dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));
73
74	seconds = ts.tv_sec + offset * 60;
75	time64_to_tm(seconds, 0, &tm);
76	dest->year = cpu_to_le16(tm.tm_year + 1900);
77	dest->month = tm.tm_mon + 1;
78	dest->day = tm.tm_mday;
79	dest->hour = tm.tm_hour;
80	dest->minute = tm.tm_min;
81	dest->second = tm.tm_sec;
82	dest->centiseconds = ts.tv_nsec / 10000000;
83	dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 -
84					dest->centiseconds * 10000) / 100;
85	dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 -
86			      dest->hundredsOfMicroseconds * 100);
 
87}
88
89/* EOF */
v4.17
 
  1/* Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
  2   This file is part of the GNU C Library.
  3   Contributed by Paul Eggert (eggert@twinsun.com).
  4
  5   The GNU C Library is free software; you can redistribute it and/or
  6   modify it under the terms of the GNU Library General Public License as
  7   published by the Free Software Foundation; either version 2 of the
  8   License, or (at your option) any later version.
  9
 10   The GNU C Library is distributed in the hope that it will be useful,
 11   but WITHOUT ANY WARRANTY; without even the implied warranty of
 12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13   Library General Public License for more details.
 14
 15   You should have received a copy of the GNU Library General Public
 16   License along with the GNU C Library; see the file COPYING.LIB.  If not,
 17   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 18   Boston, MA 02111-1307, USA.  */
 19
 20/*
 21 * dgb 10/02/98: ripped this from glibc source to help convert timestamps
 22 *               to unix time
 23 *     10/04/98: added new table-based lookup after seeing how ugly
 24 *               the gnu code is
 25 * blf 09/27/99: ripped out all the old code and inserted new table from
 26 *		 John Brockmeyer (without leap second corrections)
 27 *		 rewrote udf_stamp_to_time and fixed timezone accounting in
 28 *		 udf_time_to_stamp.
 29 */
 30
 31/*
 32 * We don't take into account leap seconds. This may be correct or incorrect.
 33 * For more NIST information (especially dealing with leap seconds), see:
 34 * http://www.boulder.nist.gov/timefreq/pubs/bulletin/leapsecond.htm
 35 */
 36
 37#include "udfdecl.h"
 38
 39#include <linux/types.h>
 40#include <linux/kernel.h>
 41#include <linux/time.h>
 42
 43struct timespec *
 44udf_disk_stamp_to_time(struct timespec *dest, struct timestamp src)
 45{
 46	u16 typeAndTimezone = le16_to_cpu(src.typeAndTimezone);
 47	u16 year = le16_to_cpu(src.year);
 48	uint8_t type = typeAndTimezone >> 12;
 49	int16_t offset;
 50
 51	if (type == 1) {
 52		offset = typeAndTimezone << 4;
 53		/* sign extent offset */
 54		offset = (offset >> 4);
 55		if (offset == -2047) /* unspecified offset */
 56			offset = 0;
 57	} else
 58		offset = 0;
 59
 60	dest->tv_sec = mktime64(year, src.month, src.day, src.hour, src.minute,
 61			src.second);
 62	dest->tv_sec -= offset * 60;
 63	dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
 64			src.hundredsOfMicroseconds * 100 + src.microseconds);
 65	/*
 66	 * Sanitize nanosecond field since reportedly some filesystems are
 67	 * recorded with bogus sub-second values.
 68	 */
 69	dest->tv_nsec %= NSEC_PER_SEC;
 70	return dest;
 
 
 
 
 
 71}
 72
 73struct timestamp *
 74udf_time_to_disk_stamp(struct timestamp *dest, struct timespec ts)
 75{
 76	long seconds;
 77	int16_t offset;
 78	struct tm tm;
 79
 80	offset = -sys_tz.tz_minuteswest;
 81
 82	if (!dest)
 83		return NULL;
 84
 85	dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));
 86
 87	seconds = ts.tv_sec + offset * 60;
 88	time64_to_tm(seconds, 0, &tm);
 89	dest->year = cpu_to_le16(tm.tm_year + 1900);
 90	dest->month = tm.tm_mon + 1;
 91	dest->day = tm.tm_mday;
 92	dest->hour = tm.tm_hour;
 93	dest->minute = tm.tm_min;
 94	dest->second = tm.tm_sec;
 95	dest->centiseconds = ts.tv_nsec / 10000000;
 96	dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 -
 97					dest->centiseconds * 10000) / 100;
 98	dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 -
 99			      dest->hundredsOfMicroseconds * 100);
100	return dest;
101}
102
103/* EOF */