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>
This commit is contained in:
Marcin Slusarz
2008-02-10 11:25:31 +01:00
committed by Jan Kara
parent cbf5676a0e
commit 56774805d5
4 changed files with 41 additions and 53 deletions

View File

@@ -85,14 +85,16 @@ extern struct timezone sys_tz;
#define SECS_PER_HOUR (60 * 60)
#define SECS_PER_DAY (SECS_PER_HOUR * 24)
struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
struct timespec *udf_disk_stamp_to_time(struct timespec *dest, timestamp src)
{
int yday;
uint8_t type = src.typeAndTimezone >> 12;
u16 typeAndTimezone = le16_to_cpu(src.typeAndTimezone);
u16 year = le16_to_cpu(src.year);
uint8_t type = typeAndTimezone >> 12;
int16_t offset;
if (type == 1) {
offset = src.typeAndTimezone << 4;
offset = typeAndTimezone << 4;
/* sign extent offset */
offset = (offset >> 4);
if (offset == -2047) /* unspecified offset */
@@ -100,21 +102,21 @@ struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
} else
offset = 0;
if ((src.year < EPOCH_YEAR) ||
(src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
if ((year < EPOCH_YEAR) ||
(year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
return NULL;
}
dest->tv_sec = year_seconds[src.year - EPOCH_YEAR];
dest->tv_sec = year_seconds[year - EPOCH_YEAR];
dest->tv_sec -= offset * 60;
yday = ((__mon_yday[__isleap(src.year)][src.month - 1]) + src.day - 1);
yday = ((__mon_yday[__isleap(year)][src.month - 1]) + src.day - 1);
dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
src.hundredsOfMicroseconds * 100 + src.microseconds);
return dest;
}
kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
timestamp *udf_time_to_disk_stamp(timestamp *dest, struct timespec ts)
{
long int days, rem, y;
const unsigned short int *ip;
@@ -125,7 +127,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
if (!dest)
return NULL;
dest->typeAndTimezone = 0x1000 | (offset & 0x0FFF);
dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));
ts.tv_sec += offset * 60;
days = ts.tv_sec / SECS_PER_DAY;
@@ -148,7 +150,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
- LEAPS_THRU_END_OF(y - 1));
y = yg;
}
dest->year = y;
dest->year = cpu_to_le16(y);
ip = __mon_yday[__isleap(y)];
for (y = 11; days < (long int)ip[y]; --y)
continue;