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

@ -1227,16 +1227,14 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) << inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
(inode->i_sb->s_blocksize_bits - 9); (inode->i_sb->s_blocksize_bits - 9);
if (!udf_stamp_to_time(&inode->i_atime, if (!udf_disk_stamp_to_time(&inode->i_atime, fe->accessTime))
lets_to_cpu(fe->accessTime)))
inode->i_atime = sbi->s_record_time; inode->i_atime = sbi->s_record_time;
if (!udf_stamp_to_time(&inode->i_mtime, if (!udf_disk_stamp_to_time(&inode->i_mtime,
lets_to_cpu(fe->modificationTime))) fe->modificationTime))
inode->i_mtime = sbi->s_record_time; inode->i_mtime = sbi->s_record_time;
if (!udf_stamp_to_time(&inode->i_ctime, if (!udf_disk_stamp_to_time(&inode->i_ctime, fe->attrTime))
lets_to_cpu(fe->attrTime)))
inode->i_ctime = sbi->s_record_time; inode->i_ctime = sbi->s_record_time;
iinfo->i_unique = le64_to_cpu(fe->uniqueID); iinfo->i_unique = le64_to_cpu(fe->uniqueID);
@ -1247,20 +1245,17 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) << inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
(inode->i_sb->s_blocksize_bits - 9); (inode->i_sb->s_blocksize_bits - 9);
if (!udf_stamp_to_time(&inode->i_atime, if (!udf_disk_stamp_to_time(&inode->i_atime, efe->accessTime))
lets_to_cpu(efe->accessTime)))
inode->i_atime = sbi->s_record_time; inode->i_atime = sbi->s_record_time;
if (!udf_stamp_to_time(&inode->i_mtime, if (!udf_disk_stamp_to_time(&inode->i_mtime,
lets_to_cpu(efe->modificationTime))) efe->modificationTime))
inode->i_mtime = sbi->s_record_time; inode->i_mtime = sbi->s_record_time;
if (!udf_stamp_to_time(&iinfo->i_crtime, if (!udf_disk_stamp_to_time(&iinfo->i_crtime, efe->createTime))
lets_to_cpu(efe->createTime)))
iinfo->i_crtime = sbi->s_record_time; iinfo->i_crtime = sbi->s_record_time;
if (!udf_stamp_to_time(&inode->i_ctime, if (!udf_disk_stamp_to_time(&inode->i_ctime, efe->attrTime))
lets_to_cpu(efe->attrTime)))
inode->i_ctime = sbi->s_record_time; inode->i_ctime = sbi->s_record_time;
iinfo->i_unique = le64_to_cpu(efe->uniqueID); iinfo->i_unique = le64_to_cpu(efe->uniqueID);
@ -1382,7 +1377,6 @@ static int udf_update_inode(struct inode *inode, int do_sync)
uint32_t udfperms; uint32_t udfperms;
uint16_t icbflags; uint16_t icbflags;
uint16_t crclen; uint16_t crclen;
kernel_timestamp cpu_time;
int err = 0; int err = 0;
struct udf_sb_info *sbi = UDF_SB(inode->i_sb); struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
@ -1485,12 +1479,9 @@ static int udf_update_inode(struct inode *inode, int do_sync)
(inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >> (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
(blocksize_bits - 9)); (blocksize_bits - 9));
if (udf_time_to_stamp(&cpu_time, inode->i_atime)) udf_time_to_disk_stamp(&fe->accessTime, inode->i_atime);
fe->accessTime = cpu_to_lets(cpu_time); udf_time_to_disk_stamp(&fe->modificationTime, inode->i_mtime);
if (udf_time_to_stamp(&cpu_time, inode->i_mtime)) udf_time_to_disk_stamp(&fe->attrTime, inode->i_ctime);
fe->modificationTime = cpu_to_lets(cpu_time);
if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
fe->attrTime = cpu_to_lets(cpu_time);
memset(&(fe->impIdent), 0, sizeof(regid)); memset(&(fe->impIdent), 0, sizeof(regid));
strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER); strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
@ -1525,14 +1516,10 @@ static int udf_update_inode(struct inode *inode, int do_sync)
iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec)) iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec))
iinfo->i_crtime = inode->i_ctime; iinfo->i_crtime = inode->i_ctime;
if (udf_time_to_stamp(&cpu_time, inode->i_atime)) udf_time_to_disk_stamp(&efe->accessTime, inode->i_atime);
efe->accessTime = cpu_to_lets(cpu_time); udf_time_to_disk_stamp(&efe->modificationTime, inode->i_mtime);
if (udf_time_to_stamp(&cpu_time, inode->i_mtime)) udf_time_to_disk_stamp(&efe->createTime, iinfo->i_crtime);
efe->modificationTime = cpu_to_lets(cpu_time); udf_time_to_disk_stamp(&efe->attrTime, inode->i_ctime);
if (udf_time_to_stamp(&cpu_time, iinfo->i_crtime))
efe->createTime = cpu_to_lets(cpu_time);
if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
efe->attrTime = cpu_to_lets(cpu_time);
memset(&(efe->impIdent), 0, sizeof(regid)); memset(&(efe->impIdent), 0, sizeof(regid));
strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER); strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);

View File

@ -943,8 +943,8 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
pvoldesc = (struct primaryVolDesc *)bh->b_data; pvoldesc = (struct primaryVolDesc *)bh->b_data;
if (udf_stamp_to_time(&UDF_SB(sb)->s_record_time, if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
lets_to_cpu(pvoldesc->recordingDateAndTime))) { pvoldesc->recordingDateAndTime)) {
kernel_timestamp ts; kernel_timestamp ts;
ts = lets_to_cpu(pvoldesc->recordingDateAndTime); ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
udf_debug("recording time %04u/%02u/%02u" udf_debug("recording time %04u/%02u/%02u"
@ -1589,7 +1589,6 @@ static void udf_open_lvid(struct super_block *sb)
struct udf_sb_info *sbi = UDF_SB(sb); struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh; struct buffer_head *bh = sbi->s_lvid_bh;
if (bh) { if (bh) {
kernel_timestamp cpu_time;
struct logicalVolIntegrityDesc *lvid = struct logicalVolIntegrityDesc *lvid =
(struct logicalVolIntegrityDesc *)bh->b_data; (struct logicalVolIntegrityDesc *)bh->b_data;
struct logicalVolIntegrityDescImpUse *lvidiu = struct logicalVolIntegrityDescImpUse *lvidiu =
@ -1597,8 +1596,8 @@ static void udf_open_lvid(struct super_block *sb)
lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
lvid->recordingDateAndTime = cpu_to_lets(cpu_time); CURRENT_TIME);
lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN; lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
lvid->descTag.descCRC = cpu_to_le16( lvid->descTag.descCRC = cpu_to_le16(
@ -1613,7 +1612,6 @@ static void udf_open_lvid(struct super_block *sb)
static void udf_close_lvid(struct super_block *sb) static void udf_close_lvid(struct super_block *sb)
{ {
kernel_timestamp cpu_time;
struct udf_sb_info *sbi = UDF_SB(sb); struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh; struct buffer_head *bh = sbi->s_lvid_bh;
struct logicalVolIntegrityDesc *lvid; struct logicalVolIntegrityDesc *lvid;
@ -1628,8 +1626,8 @@ static void udf_close_lvid(struct super_block *sb)
udf_sb_lvidiu(sbi); udf_sb_lvidiu(sbi);
lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
lvid->recordingDateAndTime = cpu_to_lets(cpu_time); CURRENT_TIME);
if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev)) if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
lvidiu->maxUDFWriteRev = lvidiu->maxUDFWriteRev =
cpu_to_le16(UDF_MAX_WRITE_VERSION); cpu_to_le16(UDF_MAX_WRITE_VERSION);
@ -1801,12 +1799,12 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
} }
if (!silent) { if (!silent) {
kernel_timestamp ts; timestamp ts;
udf_time_to_stamp(&ts, sbi->s_record_time); udf_time_to_disk_stamp(&ts, sbi->s_record_time);
udf_info("UDF: Mounting volume '%s', " udf_info("UDF: Mounting volume '%s', "
"timestamp %04u/%02u/%02u %02u:%02u (%x)\n", "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
sbi->s_volume_ident, ts.year, ts.month, ts.day, sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day,
ts.hour, ts.minute, ts.typeAndTimezone); ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
} }
if (!(sb->s_flags & MS_RDONLY)) if (!(sb->s_flags & MS_RDONLY))
udf_open_lvid(sb); udf_open_lvid(sb);

View File

@ -222,7 +222,8 @@ extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t); extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t);
/* udftime.c */ /* udftime.c */
extern struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src); extern struct timespec *udf_disk_stamp_to_time(struct timespec *dest,
extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec src); timestamp src);
extern timestamp *udf_time_to_disk_stamp(timestamp *dest, struct timespec src);
#endif /* __UDF_DECL_H */ #endif /* __UDF_DECL_H */

View File

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