This source file includes following definitions.
- udf_disk_stamp_to_time
- udf_time_to_disk_stamp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 #include "udfdecl.h"
38
39 #include <linux/types.h>
40 #include <linux/kernel.h>
41 #include <linux/time.h>
42
43 void
44 udf_disk_stamp_to_time(struct timespec64 *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
54 offset = (offset >> 4);
55 if (offset == -2047)
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
67
68
69 dest->tv_nsec %= NSEC_PER_SEC;
70 }
71
72 void
73 udf_time_to_disk_stamp(struct timestamp *dest, struct timespec64 ts)
74 {
75 time64_t seconds;
76 int16_t offset;
77 struct tm tm;
78
79 offset = -sys_tz.tz_minuteswest;
80
81 dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));
82
83 seconds = ts.tv_sec + offset * 60;
84 time64_to_tm(seconds, 0, &tm);
85 dest->year = cpu_to_le16(tm.tm_year + 1900);
86 dest->month = tm.tm_mon + 1;
87 dest->day = tm.tm_mday;
88 dest->hour = tm.tm_hour;
89 dest->minute = tm.tm_min;
90 dest->second = tm.tm_sec;
91 dest->centiseconds = ts.tv_nsec / 10000000;
92 dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 -
93 dest->centiseconds * 10000) / 100;
94 dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 -
95 dest->hundredsOfMicroseconds * 100);
96 }
97
98