diff options
Diffstat (limited to 'fs/udf/udftime.c')
-rw-r--r-- | fs/udf/udftime.c | 93 |
1 files changed, 44 insertions, 49 deletions
diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c index 85d8dbe843f1..b9f3198080e9 100644 --- a/fs/udf/udftime.c +++ b/fs/udf/udftime.c | |||
@@ -46,37 +46,36 @@ | |||
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | /* How many days come before each month (0-12). */ | 48 | /* How many days come before each month (0-12). */ |
49 | static const unsigned short int __mon_yday[2][13] = | 49 | static const unsigned short int __mon_yday[2][13] = { |
50 | { | ||
51 | /* Normal years. */ | 50 | /* Normal years. */ |
52 | { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, | 51 | {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}, |
53 | /* Leap years. */ | 52 | /* Leap years. */ |
54 | { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } | 53 | {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366} |
55 | }; | 54 | }; |
56 | 55 | ||
57 | #define MAX_YEAR_SECONDS 69 | 56 | #define MAX_YEAR_SECONDS 69 |
58 | #define SPD 0x15180 /*3600*24*/ | 57 | #define SPD 0x15180 /*3600*24 */ |
59 | #define SPY(y,l,s) (SPD * (365*y+l)+s) | 58 | #define SPY(y,l,s) (SPD * (365*y+l)+s) |
60 | 59 | ||
61 | static time_t year_seconds[MAX_YEAR_SECONDS]= { | 60 | static time_t year_seconds[MAX_YEAR_SECONDS] = { |
62 | /*1970*/ SPY( 0, 0,0), SPY( 1, 0,0), SPY( 2, 0,0), SPY( 3, 1,0), | 61 | /*1970*/ SPY(0, 0, 0), SPY(1, 0, 0), SPY(2, 0, 0), SPY(3, 1, 0), |
63 | /*1974*/ SPY( 4, 1,0), SPY( 5, 1,0), SPY( 6, 1,0), SPY( 7, 2,0), | 62 | /*1974*/ SPY(4, 1, 0), SPY(5, 1, 0), SPY(6, 1, 0), SPY(7, 2, 0), |
64 | /*1978*/ SPY( 8, 2,0), SPY( 9, 2,0), SPY(10, 2,0), SPY(11, 3,0), | 63 | /*1978*/ SPY(8, 2, 0), SPY(9, 2, 0), SPY(10, 2, 0), SPY(11, 3, 0), |
65 | /*1982*/ SPY(12, 3,0), SPY(13, 3,0), SPY(14, 3,0), SPY(15, 4,0), | 64 | /*1982*/ SPY(12, 3, 0), SPY(13, 3, 0), SPY(14, 3, 0), SPY(15, 4, 0), |
66 | /*1986*/ SPY(16, 4,0), SPY(17, 4,0), SPY(18, 4,0), SPY(19, 5,0), | 65 | /*1986*/ SPY(16, 4, 0), SPY(17, 4, 0), SPY(18, 4, 0), SPY(19, 5, 0), |
67 | /*1990*/ SPY(20, 5,0), SPY(21, 5,0), SPY(22, 5,0), SPY(23, 6,0), | 66 | /*1990*/ SPY(20, 5, 0), SPY(21, 5, 0), SPY(22, 5, 0), SPY(23, 6, 0), |
68 | /*1994*/ SPY(24, 6,0), SPY(25, 6,0), SPY(26, 6,0), SPY(27, 7,0), | 67 | /*1994*/ SPY(24, 6, 0), SPY(25, 6, 0), SPY(26, 6, 0), SPY(27, 7, 0), |
69 | /*1998*/ SPY(28, 7,0), SPY(29, 7,0), SPY(30, 7,0), SPY(31, 8,0), | 68 | /*1998*/ SPY(28, 7, 0), SPY(29, 7, 0), SPY(30, 7, 0), SPY(31, 8, 0), |
70 | /*2002*/ SPY(32, 8,0), SPY(33, 8,0), SPY(34, 8,0), SPY(35, 9,0), | 69 | /*2002*/ SPY(32, 8, 0), SPY(33, 8, 0), SPY(34, 8, 0), SPY(35, 9, 0), |
71 | /*2006*/ SPY(36, 9,0), SPY(37, 9,0), SPY(38, 9,0), SPY(39,10,0), | 70 | /*2006*/ SPY(36, 9, 0), SPY(37, 9, 0), SPY(38, 9, 0), SPY(39, 10, 0), |
72 | /*2010*/ SPY(40,10,0), SPY(41,10,0), SPY(42,10,0), SPY(43,11,0), | 71 | /*2010*/ SPY(40, 10, 0), SPY(41, 10, 0), SPY(42, 10, 0), SPY(43, 11, 0), |
73 | /*2014*/ SPY(44,11,0), SPY(45,11,0), SPY(46,11,0), SPY(47,12,0), | 72 | /*2014*/ SPY(44, 11, 0), SPY(45, 11, 0), SPY(46, 11, 0), SPY(47, 12, 0), |
74 | /*2018*/ SPY(48,12,0), SPY(49,12,0), SPY(50,12,0), SPY(51,13,0), | 73 | /*2018*/ SPY(48, 12, 0), SPY(49, 12, 0), SPY(50, 12, 0), SPY(51, 13, 0), |
75 | /*2022*/ SPY(52,13,0), SPY(53,13,0), SPY(54,13,0), SPY(55,14,0), | 74 | /*2022*/ SPY(52, 13, 0), SPY(53, 13, 0), SPY(54, 13, 0), SPY(55, 14, 0), |
76 | /*2026*/ SPY(56,14,0), SPY(57,14,0), SPY(58,14,0), SPY(59,15,0), | 75 | /*2026*/ SPY(56, 14, 0), SPY(57, 14, 0), SPY(58, 14, 0), SPY(59, 15, 0), |
77 | /*2030*/ SPY(60,15,0), SPY(61,15,0), SPY(62,15,0), SPY(63,16,0), | 76 | /*2030*/ SPY(60, 15, 0), SPY(61, 15, 0), SPY(62, 15, 0), SPY(63, 16, 0), |
78 | /*2034*/ SPY(64,16,0), SPY(65,16,0), SPY(66,16,0), SPY(67,17,0), | 77 | /*2034*/ SPY(64, 16, 0), SPY(65, 16, 0), SPY(66, 16, 0), SPY(67, 17, 0), |
79 | /*2038*/ SPY(68,17,0) | 78 | /*2038*/ SPY(68, 17, 0) |
80 | }; | 79 | }; |
81 | 80 | ||
82 | extern struct timezone sys_tz; | 81 | extern struct timezone sys_tz; |
@@ -84,27 +83,23 @@ extern struct timezone sys_tz; | |||
84 | #define SECS_PER_HOUR (60 * 60) | 83 | #define SECS_PER_HOUR (60 * 60) |
85 | #define SECS_PER_DAY (SECS_PER_HOUR * 24) | 84 | #define SECS_PER_DAY (SECS_PER_HOUR * 24) |
86 | 85 | ||
87 | time_t * | 86 | time_t *udf_stamp_to_time(time_t * dest, long *dest_usec, kernel_timestamp src) |
88 | udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src) | ||
89 | { | 87 | { |
90 | int yday; | 88 | int yday; |
91 | uint8_t type = src.typeAndTimezone >> 12; | 89 | uint8_t type = src.typeAndTimezone >> 12; |
92 | int16_t offset; | 90 | int16_t offset; |
93 | 91 | ||
94 | if (type == 1) | 92 | if (type == 1) { |
95 | { | ||
96 | offset = src.typeAndTimezone << 4; | 93 | offset = src.typeAndTimezone << 4; |
97 | /* sign extent offset */ | 94 | /* sign extent offset */ |
98 | offset = (offset >> 4); | 95 | offset = (offset >> 4); |
99 | if (offset == -2047) /* unspecified offset */ | 96 | if (offset == -2047) /* unspecified offset */ |
100 | offset = 0; | 97 | offset = 0; |
101 | } | 98 | } else |
102 | else | ||
103 | offset = 0; | 99 | offset = 0; |
104 | 100 | ||
105 | if ((src.year < EPOCH_YEAR) || | 101 | if ((src.year < EPOCH_YEAR) || |
106 | (src.year >= EPOCH_YEAR+MAX_YEAR_SECONDS)) | 102 | (src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) { |
107 | { | ||
108 | *dest = -1; | 103 | *dest = -1; |
109 | *dest_usec = -1; | 104 | *dest_usec = -1; |
110 | return NULL; | 105 | return NULL; |
@@ -112,16 +107,16 @@ udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src) | |||
112 | *dest = year_seconds[src.year - EPOCH_YEAR]; | 107 | *dest = year_seconds[src.year - EPOCH_YEAR]; |
113 | *dest -= offset * 60; | 108 | *dest -= offset * 60; |
114 | 109 | ||
115 | yday = ((__mon_yday[__isleap (src.year)] | 110 | yday = ((__mon_yday[__isleap(src.year)] |
116 | [src.month-1]) + (src.day-1)); | 111 | [src.month - 1]) + (src.day - 1)); |
117 | *dest += ( ( (yday* 24) + src.hour ) * 60 + src.minute ) * 60 + src.second; | 112 | *dest += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second; |
118 | *dest_usec = src.centiseconds * 10000 + src.hundredsOfMicroseconds * 100 + src.microseconds; | 113 | *dest_usec = |
114 | src.centiseconds * 10000 + src.hundredsOfMicroseconds * 100 + | ||
115 | src.microseconds; | ||
119 | return dest; | 116 | return dest; |
120 | } | 117 | } |
121 | 118 | ||
122 | 119 | kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts) | |
123 | kernel_timestamp * | ||
124 | udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts) | ||
125 | { | 120 | { |
126 | long int days, rem, y; | 121 | long int days, rem, y; |
127 | const unsigned short int *ip; | 122 | const unsigned short int *ip; |
@@ -146,28 +141,28 @@ udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts) | |||
146 | #define DIV(a,b) ((a) / (b) - ((a) % (b) < 0)) | 141 | #define DIV(a,b) ((a) / (b) - ((a) % (b) < 0)) |
147 | #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) | 142 | #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) |
148 | 143 | ||
149 | while (days < 0 || days >= (__isleap(y) ? 366 : 365)) | 144 | while (days < 0 || days >= (__isleap(y) ? 366 : 365)) { |
150 | { | ||
151 | long int yg = y + days / 365 - (days % 365 < 0); | 145 | long int yg = y + days / 365 - (days % 365 < 0); |
152 | 146 | ||
153 | /* Adjust DAYS and Y to match the guessed year. */ | 147 | /* Adjust DAYS and Y to match the guessed year. */ |
154 | days -= ((yg - y) * 365 | 148 | days -= ((yg - y) * 365 + LEAPS_THRU_END_OF(yg - 1) |
155 | + LEAPS_THRU_END_OF (yg - 1) | 149 | - LEAPS_THRU_END_OF(y - 1)); |
156 | - LEAPS_THRU_END_OF (y - 1)); | ||
157 | y = yg; | 150 | y = yg; |
158 | } | 151 | } |
159 | dest->year = y; | 152 | dest->year = y; |
160 | ip = __mon_yday[__isleap(y)]; | 153 | ip = __mon_yday[__isleap(y)]; |
161 | for (y = 11; days < (long int) ip[y]; --y) | 154 | for (y = 11; days < (long int)ip[y]; --y) |
162 | continue; | 155 | continue; |
163 | days -= ip[y]; | 156 | days -= ip[y]; |
164 | dest->month = y + 1; | 157 | dest->month = y + 1; |
165 | dest->day = days + 1; | 158 | dest->day = days + 1; |
166 | 159 | ||
167 | dest->centiseconds = ts.tv_nsec / 10000000; | 160 | dest->centiseconds = ts.tv_nsec / 10000000; |
168 | dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000) / 100; | 161 | dest->hundredsOfMicroseconds = |
169 | dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 - | 162 | (ts.tv_nsec / 1000 - dest->centiseconds * 10000) / 100; |
170 | dest->hundredsOfMicroseconds * 100); | 163 | dest->microseconds = |
164 | (ts.tv_nsec / 1000 - dest->centiseconds * 10000 - | ||
165 | dest->hundredsOfMicroseconds * 100); | ||
171 | return dest; | 166 | return dest; |
172 | } | 167 | } |
173 | 168 | ||