aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf/udftime.c
diff options
context:
space:
mode:
authorMarcin Slusarz <marcin.slusarz@gmail.com>2008-02-10 05:25:31 -0500
committerJan Kara <jack@suse.cz>2008-04-17 08:22:29 -0400
commit56774805d5eeecd3f1fb700603e593a35dc523c8 (patch)
tree525665c2a2b4fe93cf4a74b8c50332e70acf357f /fs/udf/udftime.c
parentcbf5676a0e0463f05e5073589f3194846dfb02e7 (diff)
udf: convert udf_stamp_to_time and udf_time_to_stamp to use timestamps
* kernel_timestamp type was almost unused - only callers of udf_stamp_to_time and udf_time_to_stamp used it, so let these functions handle endianness internally and don't clutter code with conversions * rename udf_stamp_to_time to udf_disk_stamp_to_time and udf_time_to_stamp to udf_time_to_disk_stamp Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/udf/udftime.c')
-rw-r--r--fs/udf/udftime.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c
index 12fae6cd444c..5f811655c9b5 100644
--- a/fs/udf/udftime.c
+++ b/fs/udf/udftime.c
@@ -85,14 +85,16 @@ extern struct timezone sys_tz;
85#define SECS_PER_HOUR (60 * 60) 85#define SECS_PER_HOUR (60 * 60)
86#define SECS_PER_DAY (SECS_PER_HOUR * 24) 86#define SECS_PER_DAY (SECS_PER_HOUR * 24)
87 87
88struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src) 88struct timespec *udf_disk_stamp_to_time(struct timespec *dest, timestamp src)
89{ 89{
90 int yday; 90 int yday;
91 uint8_t type = src.typeAndTimezone >> 12; 91 u16 typeAndTimezone = le16_to_cpu(src.typeAndTimezone);
92 u16 year = le16_to_cpu(src.year);
93 uint8_t type = typeAndTimezone >> 12;
92 int16_t offset; 94 int16_t offset;
93 95
94 if (type == 1) { 96 if (type == 1) {
95 offset = src.typeAndTimezone << 4; 97 offset = typeAndTimezone << 4;
96 /* sign extent offset */ 98 /* sign extent offset */
97 offset = (offset >> 4); 99 offset = (offset >> 4);
98 if (offset == -2047) /* unspecified offset */ 100 if (offset == -2047) /* unspecified offset */
@@ -100,21 +102,21 @@ struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
100 } else 102 } else
101 offset = 0; 103 offset = 0;
102 104
103 if ((src.year < EPOCH_YEAR) || 105 if ((year < EPOCH_YEAR) ||
104 (src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) { 106 (year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
105 return NULL; 107 return NULL;
106 } 108 }
107 dest->tv_sec = year_seconds[src.year - EPOCH_YEAR]; 109 dest->tv_sec = year_seconds[year - EPOCH_YEAR];
108 dest->tv_sec -= offset * 60; 110 dest->tv_sec -= offset * 60;
109 111
110 yday = ((__mon_yday[__isleap(src.year)][src.month - 1]) + src.day - 1); 112 yday = ((__mon_yday[__isleap(year)][src.month - 1]) + src.day - 1);
111 dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second; 113 dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
112 dest->tv_nsec = 1000 * (src.centiseconds * 10000 + 114 dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
113 src.hundredsOfMicroseconds * 100 + src.microseconds); 115 src.hundredsOfMicroseconds * 100 + src.microseconds);
114 return dest; 116 return dest;
115} 117}
116 118
117kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts) 119timestamp *udf_time_to_disk_stamp(timestamp *dest, struct timespec ts)
118{ 120{
119 long int days, rem, y; 121 long int days, rem, y;
120 const unsigned short int *ip; 122 const unsigned short int *ip;
@@ -125,7 +127,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
125 if (!dest) 127 if (!dest)
126 return NULL; 128 return NULL;
127 129
128 dest->typeAndTimezone = 0x1000 | (offset & 0x0FFF); 130 dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));
129 131
130 ts.tv_sec += offset * 60; 132 ts.tv_sec += offset * 60;
131 days = ts.tv_sec / SECS_PER_DAY; 133 days = ts.tv_sec / SECS_PER_DAY;
@@ -148,7 +150,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
148 - LEAPS_THRU_END_OF(y - 1)); 150 - LEAPS_THRU_END_OF(y - 1));
149 y = yg; 151 y = yg;
150 } 152 }
151 dest->year = y; 153 dest->year = cpu_to_le16(y);
152 ip = __mon_yday[__isleap(y)]; 154 ip = __mon_yday[__isleap(y)];
153 for (y = 11; days < (long int)ip[y]; --y) 155 for (y = 11; days < (long int)ip[y]; --y)
154 continue; 156 continue;