Blame view

fs/udf/udftime.c 3.18 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  /* Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
     This file is part of the GNU C Library.
     Contributed by Paul Eggert (eggert@twinsun.com).
  
     The GNU C Library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public License as
     published by the Free Software Foundation; either version 2 of the
     License, or (at your option) any later version.
  
     The GNU C Library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     Library General Public License for more details.
  
     You should have received a copy of the GNU Library General Public
     License along with the GNU C Library; see the file COPYING.LIB.  If not,
     write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.  */
  
  /*
4b11111ab   Marcin Slusarz   udf: fix coding s...
21
22
23
24
   * 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
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
   * blf 09/27/99: ripped out all the old code and inserted new table from
28de7948a   Cyrill Gorcunov   UDF: coding style...
26
27
28
   *		 John Brockmeyer (without leap second corrections)
   *		 rewrote udf_stamp_to_time and fixed timezone accounting in
   *		 udf_time_to_stamp.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
32
33
   */
  
  /*
   * We don't take into account leap seconds. This may be correct or incorrect.
   * For more NIST information (especially dealing with leap seconds), see:
28de7948a   Cyrill Gorcunov   UDF: coding style...
34
   * http://www.boulder.nist.gov/timefreq/pubs/bulletin/leapsecond.htm
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
   */
78ace70c4   Joe Perches   udf: Convert prin...
36
  #include "udfdecl.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
  #include <linux/types.h>
  #include <linux/kernel.h>
3c399fa40   Jan Kara   udf: Use time64_t...
39
  #include <linux/time.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40

0220eddac   Deepa Dinamani   udf: Simplify cal...
41
  void
c3b9cecd8   Arnd Bergmann   udf: convert inod...
42
  udf_disk_stamp_to_time(struct timespec64 *dest, struct timestamp src)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
  {
56774805d   Marcin Slusarz   udf: convert udf_...
44
45
46
  	u16 typeAndTimezone = le16_to_cpu(src.typeAndTimezone);
  	u16 year = le16_to_cpu(src.year);
  	uint8_t type = typeAndTimezone >> 12;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
  	int16_t offset;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
48
  	if (type == 1) {
56774805d   Marcin Slusarz   udf: convert udf_...
49
  		offset = typeAndTimezone << 4;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
51
  		/* sign extent offset */
  		offset = (offset >> 4);
28de7948a   Cyrill Gorcunov   UDF: coding style...
52
  		if (offset == -2047) /* unspecified offset */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
  			offset = 0;
cbf5676a0   marcin.slusarz@gmail.com   udf: convert udf_...
54
  	} else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
  		offset = 0;
fd3cfad37   Jan Kara   udf: Convert udf_...
56
57
  	dest->tv_sec = mktime64(year, src.month, src.day, src.hour, src.minute,
  			src.second);
cbf5676a0   marcin.slusarz@gmail.com   udf: convert udf_...
58
  	dest->tv_sec -= offset * 60;
cbf5676a0   marcin.slusarz@gmail.com   udf: convert udf_...
59
60
  	dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
  			src.hundredsOfMicroseconds * 100 + src.microseconds);
d5bd82135   Jan Kara   udf: Sanitize nan...
61
62
63
64
65
  	/*
  	 * Sanitize nanosecond field since reportedly some filesystems are
  	 * recorded with bogus sub-second values.
  	 */
  	dest->tv_nsec %= NSEC_PER_SEC;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
  }
0220eddac   Deepa Dinamani   udf: Simplify cal...
67
  void
c3b9cecd8   Arnd Bergmann   udf: convert inod...
68
  udf_time_to_disk_stamp(struct timestamp *dest, struct timespec64 ts)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
  {
c3b9cecd8   Arnd Bergmann   udf: convert inod...
70
  	time64_t seconds;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
  	int16_t offset;
3c399fa40   Jan Kara   udf: Use time64_t...
72
  	struct tm tm;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
74
  
  	offset = -sys_tz.tz_minuteswest;
56774805d   Marcin Slusarz   udf: convert udf_...
75
  	dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76

3c399fa40   Jan Kara   udf: Use time64_t...
77
78
79
80
81
82
83
84
  	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;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
  	dest->centiseconds = ts.tv_nsec / 10000000;
4b11111ab   Marcin Slusarz   udf: fix coding s...
86
87
  	dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 -
  					dest->centiseconds * 10000) / 100;
28de7948a   Cyrill Gorcunov   UDF: coding style...
88
89
  	dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 -
  			      dest->hundredsOfMicroseconds * 100);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
91
92
  }
  
  /* EOF */