Skip to content

Commit 5677480

Browse files
mslusarzjankara
authored andcommitted
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>
1 parent cbf5676 commit 5677480

4 files changed

Lines changed: 41 additions & 53 deletions

File tree

‎fs/udf/inode.c‎

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,16 +1227,14 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
12271227
inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
12281228
(inode->i_sb->s_blocksize_bits - 9);
12291229

1230-
if (!udf_stamp_to_time(&inode->i_atime,
1231-
lets_to_cpu(fe->accessTime)))
1230+
if (!udf_disk_stamp_to_time(&inode->i_atime, fe->accessTime))
12321231
inode->i_atime = sbi->s_record_time;
12331232

1234-
if (!udf_stamp_to_time(&inode->i_mtime,
1235-
lets_to_cpu(fe->modificationTime)))
1233+
if (!udf_disk_stamp_to_time(&inode->i_mtime,
1234+
fe->modificationTime))
12361235
inode->i_mtime = sbi->s_record_time;
12371236

1238-
if (!udf_stamp_to_time(&inode->i_ctime,
1239-
lets_to_cpu(fe->attrTime)))
1237+
if (!udf_disk_stamp_to_time(&inode->i_ctime, fe->attrTime))
12401238
inode->i_ctime = sbi->s_record_time;
12411239

12421240
iinfo->i_unique = le64_to_cpu(fe->uniqueID);
@@ -1247,20 +1245,17 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
12471245
inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
12481246
(inode->i_sb->s_blocksize_bits - 9);
12491247

1250-
if (!udf_stamp_to_time(&inode->i_atime,
1251-
lets_to_cpu(efe->accessTime)))
1248+
if (!udf_disk_stamp_to_time(&inode->i_atime, efe->accessTime))
12521249
inode->i_atime = sbi->s_record_time;
12531250

1254-
if (!udf_stamp_to_time(&inode->i_mtime,
1255-
lets_to_cpu(efe->modificationTime)))
1251+
if (!udf_disk_stamp_to_time(&inode->i_mtime,
1252+
efe->modificationTime))
12561253
inode->i_mtime = sbi->s_record_time;
12571254

1258-
if (!udf_stamp_to_time(&iinfo->i_crtime,
1259-
lets_to_cpu(efe->createTime)))
1255+
if (!udf_disk_stamp_to_time(&iinfo->i_crtime, efe->createTime))
12601256
iinfo->i_crtime = sbi->s_record_time;
12611257

1262-
if (!udf_stamp_to_time(&inode->i_ctime,
1263-
lets_to_cpu(efe->attrTime)))
1258+
if (!udf_disk_stamp_to_time(&inode->i_ctime, efe->attrTime))
12641259
inode->i_ctime = sbi->s_record_time;
12651260

12661261
iinfo->i_unique = le64_to_cpu(efe->uniqueID);
@@ -1382,7 +1377,6 @@ static int udf_update_inode(struct inode *inode, int do_sync)
13821377
uint32_t udfperms;
13831378
uint16_t icbflags;
13841379
uint16_t crclen;
1385-
kernel_timestamp cpu_time;
13861380
int err = 0;
13871381
struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
13881382
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)
14851479
(inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
14861480
(blocksize_bits - 9));
14871481

1488-
if (udf_time_to_stamp(&cpu_time, inode->i_atime))
1489-
fe->accessTime = cpu_to_lets(cpu_time);
1490-
if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
1491-
fe->modificationTime = cpu_to_lets(cpu_time);
1492-
if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
1493-
fe->attrTime = cpu_to_lets(cpu_time);
1482+
udf_time_to_disk_stamp(&fe->accessTime, inode->i_atime);
1483+
udf_time_to_disk_stamp(&fe->modificationTime, inode->i_mtime);
1484+
udf_time_to_disk_stamp(&fe->attrTime, inode->i_ctime);
14941485
memset(&(fe->impIdent), 0, sizeof(regid));
14951486
strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
14961487
fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
@@ -1525,14 +1516,10 @@ static int udf_update_inode(struct inode *inode, int do_sync)
15251516
iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec))
15261517
iinfo->i_crtime = inode->i_ctime;
15271518

1528-
if (udf_time_to_stamp(&cpu_time, inode->i_atime))
1529-
efe->accessTime = cpu_to_lets(cpu_time);
1530-
if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
1531-
efe->modificationTime = cpu_to_lets(cpu_time);
1532-
if (udf_time_to_stamp(&cpu_time, iinfo->i_crtime))
1533-
efe->createTime = cpu_to_lets(cpu_time);
1534-
if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
1535-
efe->attrTime = cpu_to_lets(cpu_time);
1519+
udf_time_to_disk_stamp(&efe->accessTime, inode->i_atime);
1520+
udf_time_to_disk_stamp(&efe->modificationTime, inode->i_mtime);
1521+
udf_time_to_disk_stamp(&efe->createTime, iinfo->i_crtime);
1522+
udf_time_to_disk_stamp(&efe->attrTime, inode->i_ctime);
15361523

15371524
memset(&(efe->impIdent), 0, sizeof(regid));
15381525
strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);

‎fs/udf/super.c‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,8 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
943943

944944
pvoldesc = (struct primaryVolDesc *)bh->b_data;
945945

946-
if (udf_stamp_to_time(&UDF_SB(sb)->s_record_time,
947-
lets_to_cpu(pvoldesc->recordingDateAndTime))) {
946+
if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
947+
pvoldesc->recordingDateAndTime)) {
948948
kernel_timestamp ts;
949949
ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
950950
udf_debug("recording time %04u/%02u/%02u"
@@ -1589,16 +1589,15 @@ static void udf_open_lvid(struct super_block *sb)
15891589
struct udf_sb_info *sbi = UDF_SB(sb);
15901590
struct buffer_head *bh = sbi->s_lvid_bh;
15911591
if (bh) {
1592-
kernel_timestamp cpu_time;
15931592
struct logicalVolIntegrityDesc *lvid =
15941593
(struct logicalVolIntegrityDesc *)bh->b_data;
15951594
struct logicalVolIntegrityDescImpUse *lvidiu =
15961595
udf_sb_lvidiu(sbi);
15971596

15981597
lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
15991598
lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1600-
if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1601-
lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
1599+
udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
1600+
CURRENT_TIME);
16021601
lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
16031602

16041603
lvid->descTag.descCRC = cpu_to_le16(
@@ -1613,7 +1612,6 @@ static void udf_open_lvid(struct super_block *sb)
16131612

16141613
static void udf_close_lvid(struct super_block *sb)
16151614
{
1616-
kernel_timestamp cpu_time;
16171615
struct udf_sb_info *sbi = UDF_SB(sb);
16181616
struct buffer_head *bh = sbi->s_lvid_bh;
16191617
struct logicalVolIntegrityDesc *lvid;
@@ -1628,8 +1626,8 @@ static void udf_close_lvid(struct super_block *sb)
16281626
udf_sb_lvidiu(sbi);
16291627
lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
16301628
lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1631-
if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1632-
lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
1629+
udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
1630+
CURRENT_TIME);
16331631
if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
16341632
lvidiu->maxUDFWriteRev =
16351633
cpu_to_le16(UDF_MAX_WRITE_VERSION);
@@ -1801,12 +1799,12 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
18011799
}
18021800

18031801
if (!silent) {
1804-
kernel_timestamp ts;
1805-
udf_time_to_stamp(&ts, sbi->s_record_time);
1802+
timestamp ts;
1803+
udf_time_to_disk_stamp(&ts, sbi->s_record_time);
18061804
udf_info("UDF: Mounting volume '%s', "
18071805
"timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1808-
sbi->s_volume_ident, ts.year, ts.month, ts.day,
1809-
ts.hour, ts.minute, ts.typeAndTimezone);
1806+
sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day,
1807+
ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
18101808
}
18111809
if (!(sb->s_flags & MS_RDONLY))
18121810
udf_open_lvid(sb);

‎fs/udf/udfdecl.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
222222
extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t);
223223

224224
/* udftime.c */
225-
extern struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src);
226-
extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec src);
225+
extern struct timespec *udf_disk_stamp_to_time(struct timespec *dest,
226+
timestamp src);
227+
extern timestamp *udf_time_to_disk_stamp(timestamp *dest, struct timespec src);
227228

228229
#endif /* __UDF_DECL_H */

‎fs/udf/udftime.c‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,38 @@ extern struct timezone sys_tz;
8585
#define SECS_PER_HOUR (60 * 60)
8686
#define SECS_PER_DAY (SECS_PER_HOUR * 24)
8787

88-
struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
88+
struct timespec *udf_disk_stamp_to_time(struct timespec *dest, timestamp src)
8989
{
9090
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;
9294
int16_t offset;
9395

9496
if (type == 1) {
95-
offset = src.typeAndTimezone << 4;
97+
offset = typeAndTimezone << 4;
9698
/* sign extent offset */
9799
offset = (offset >> 4);
98100
if (offset == -2047) /* unspecified offset */
99101
offset = 0;
100102
} else
101103
offset = 0;
102104

103-
if ((src.year < EPOCH_YEAR) ||
104-
(src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
105+
if ((year < EPOCH_YEAR) ||
106+
(year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
105107
return NULL;
106108
}
107-
dest->tv_sec = year_seconds[src.year - EPOCH_YEAR];
109+
dest->tv_sec = year_seconds[year - EPOCH_YEAR];
108110
dest->tv_sec -= offset * 60;
109111

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);
111113
dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
112114
dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
113115
src.hundredsOfMicroseconds * 100 + src.microseconds);
114116
return dest;
115117
}
116118

117-
kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
119+
timestamp *udf_time_to_disk_stamp(timestamp *dest, struct timespec ts)
118120
{
119121
long int days, rem, y;
120122
const unsigned short int *ip;
@@ -125,7 +127,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
125127
if (!dest)
126128
return NULL;
127129

128-
dest->typeAndTimezone = 0x1000 | (offset & 0x0FFF);
130+
dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));
129131

130132
ts.tv_sec += offset * 60;
131133
days = ts.tv_sec / SECS_PER_DAY;
@@ -148,7 +150,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
148150
- LEAPS_THRU_END_OF(y - 1));
149151
y = yg;
150152
}
151-
dest->year = y;
153+
dest->year = cpu_to_le16(y);
152154
ip = __mon_yday[__isleap(y)];
153155
for (y = 11; days < (long int)ip[y]; --y)
154156
continue;

0 commit comments

Comments
 (0)