Skip to content

Commit f423420

Browse files
arndbtorvalds
authored andcommitted
fat: propagate 64-bit inode timestamps
Now that we pass down 64-bit timestamps from VFS, we just need to convert that correctly into on-disk timestamps. To make that work correctly, this changes the last use of time_to_tm() in the kernel to time64_to_tm(), which also lets use remove that deprecated interfaces. Similarly, the time_t use in fat_time_fat2unix() truncates the timestamp on the way in, which can be avoided by using types that are wide enough to hold the intermediate values during the conversion. [hirofumi@mail.parknet.co.jp: remove useless temporary variable, needless long long] Link: http://lkml.kernel.org/r/20180619153646.3637529-1-arnd@arndb.de Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Cc: Jeff Layton <jlayton@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0afa962 commit f423420

6 files changed

Lines changed: 30 additions & 48 deletions

File tree

‎fs/fat/dir.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ static int fat_zeroed_cluster(struct inode *dir, sector_t blknr, int nr_used,
11301130
return err;
11311131
}
11321132

1133-
int fat_alloc_new_dir(struct inode *dir, struct timespec *ts)
1133+
int fat_alloc_new_dir(struct inode *dir, struct timespec64 *ts)
11341134
{
11351135
struct super_block *sb = dir->i_sb;
11361136
struct msdos_sb_info *sbi = MSDOS_SB(sb);

‎fs/fat/fat.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ extern int fat_scan_logstart(struct inode *dir, int i_logstart,
304304
struct fat_slot_info *sinfo);
305305
extern int fat_get_dotdot_entry(struct inode *dir, struct buffer_head **bh,
306306
struct msdos_dir_entry **de);
307-
extern int fat_alloc_new_dir(struct inode *dir, struct timespec *ts);
307+
extern int fat_alloc_new_dir(struct inode *dir, struct timespec64 *ts);
308308
extern int fat_add_entries(struct inode *dir, void *slots, int nr_slots,
309309
struct fat_slot_info *sinfo);
310310
extern int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo);
@@ -412,9 +412,9 @@ void fat_msg(struct super_block *sb, const char *level, const char *fmt, ...);
412412
} while (0)
413413
extern int fat_clusters_flush(struct super_block *sb);
414414
extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster);
415-
extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts,
415+
extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
416416
__le16 __time, __le16 __date, u8 time_cs);
417-
extern void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec *ts,
417+
extern void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts,
418418
__le16 *time, __le16 *date, u8 *time_cs);
419419
extern int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs);
420420

‎fs/fat/inode.c‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,6 @@ static int fat_validate_dir(struct inode *dir)
508508
/* doesn't deal with root inode */
509509
int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
510510
{
511-
struct timespec ts;
512511
struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
513512
int error;
514513

@@ -559,14 +558,11 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
559558
inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
560559
& ~((loff_t)sbi->cluster_size - 1)) >> 9;
561560

562-
fat_time_fat2unix(sbi, &ts, de->time, de->date, 0);
563-
inode->i_mtime = timespec_to_timespec64(ts);
561+
fat_time_fat2unix(sbi, &inode->i_mtime, de->time, de->date, 0);
564562
if (sbi->options.isvfat) {
565-
fat_time_fat2unix(sbi, &ts, de->ctime,
563+
fat_time_fat2unix(sbi, &inode->i_ctime, de->ctime,
566564
de->cdate, de->ctime_cs);
567-
inode->i_ctime = timespec_to_timespec64(ts);
568-
fat_time_fat2unix(sbi, &ts, 0, de->adate, 0);
569-
inode->i_atime = timespec_to_timespec64(ts);
565+
fat_time_fat2unix(sbi, &inode->i_atime, 0, de->adate, 0);
570566
} else
571567
inode->i_ctime = inode->i_atime = inode->i_mtime;
572568

@@ -843,7 +839,6 @@ static int fat_statfs(struct dentry *dentry, struct kstatfs *buf)
843839

844840
static int __fat_write_inode(struct inode *inode, int wait)
845841
{
846-
struct timespec ts;
847842
struct super_block *sb = inode->i_sb;
848843
struct msdos_sb_info *sbi = MSDOS_SB(sb);
849844
struct buffer_head *bh;
@@ -881,16 +876,13 @@ static int __fat_write_inode(struct inode *inode, int wait)
881876
raw_entry->size = cpu_to_le32(inode->i_size);
882877
raw_entry->attr = fat_make_attrs(inode);
883878
fat_set_start(raw_entry, MSDOS_I(inode)->i_logstart);
884-
ts = timespec64_to_timespec(inode->i_mtime);
885-
fat_time_unix2fat(sbi, &ts, &raw_entry->time,
879+
fat_time_unix2fat(sbi, &inode->i_mtime, &raw_entry->time,
886880
&raw_entry->date, NULL);
887881
if (sbi->options.isvfat) {
888882
__le16 atime;
889-
ts = timespec64_to_timespec(inode->i_ctime);
890-
fat_time_unix2fat(sbi, &ts, &raw_entry->ctime,
883+
fat_time_unix2fat(sbi, &inode->i_ctime, &raw_entry->ctime,
891884
&raw_entry->cdate, &raw_entry->ctime_cs);
892-
ts = timespec64_to_timespec(inode->i_atime);
893-
fat_time_unix2fat(sbi, &ts, &atime,
885+
fat_time_unix2fat(sbi, &inode->i_atime, &atime,
894886
&raw_entry->adate, NULL);
895887
}
896888
spin_unlock(&sbi->inode_hash_lock);

‎fs/fat/misc.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,18 @@ int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster)
180180
#define IS_LEAP_YEAR(y) (!((y) & 3) && (y) != YEAR_2100)
181181

182182
/* Linear day numbers of the respective 1sts in non-leap years. */
183-
static time_t days_in_year[] = {
183+
static long days_in_year[] = {
184184
/* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */
185185
0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0,
186186
};
187187

188188
/* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */
189-
void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts,
189+
void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
190190
__le16 __time, __le16 __date, u8 time_cs)
191191
{
192192
u16 time = le16_to_cpu(__time), date = le16_to_cpu(__date);
193-
time_t second, day, leap_day, month, year;
193+
time64_t second;
194+
long day, leap_day, month, year;
194195

195196
year = date >> 9;
196197
month = max(1, (date >> 5) & 0xf);
@@ -205,7 +206,7 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts,
205206
second = (time & 0x1f) << 1;
206207
second += ((time >> 5) & 0x3f) * SECS_PER_MIN;
207208
second += (time >> 11) * SECS_PER_HOUR;
208-
second += (year * 365 + leap_day
209+
second += (time64_t)(year * 365 + leap_day
209210
+ days_in_year[month] + day
210211
+ DAYS_DELTA) * SECS_PER_DAY;
211212

@@ -224,11 +225,11 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts,
224225
}
225226

226227
/* Convert linear UNIX date to a FAT time/date pair. */
227-
void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec *ts,
228+
void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts,
228229
__le16 *time, __le16 *date, u8 *time_cs)
229230
{
230231
struct tm tm;
231-
time_to_tm(ts->tv_sec,
232+
time64_to_tm(ts->tv_sec,
232233
(sbi->options.tz_set ? sbi->options.time_offset :
233234
-sys_tz.tz_minuteswest) * SECS_PER_MIN, &tm);
234235

‎fs/fat/namei_msdos.c‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry,
225225
/***** Creates a directory entry (name is already formatted). */
226226
static int msdos_add_entry(struct inode *dir, const unsigned char *name,
227227
int is_dir, int is_hid, int cluster,
228-
struct timespec *ts, struct fat_slot_info *sinfo)
228+
struct timespec64 *ts, struct fat_slot_info *sinfo)
229229
{
230230
struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
231231
struct msdos_dir_entry de;
@@ -250,7 +250,7 @@ static int msdos_add_entry(struct inode *dir, const unsigned char *name,
250250
if (err)
251251
return err;
252252

253-
dir->i_ctime = dir->i_mtime = timespec_to_timespec64(*ts);
253+
dir->i_ctime = dir->i_mtime = *ts;
254254
if (IS_DIRSYNC(dir))
255255
(void)fat_sync_inode(dir);
256256
else
@@ -267,7 +267,6 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, umode_t mode,
267267
struct inode *inode = NULL;
268268
struct fat_slot_info sinfo;
269269
struct timespec64 ts;
270-
struct timespec t;
271270
unsigned char msdos_name[MSDOS_NAME];
272271
int err, is_hid;
273272

@@ -286,8 +285,7 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, umode_t mode,
286285
}
287286

288287
ts = current_time(dir);
289-
t = timespec64_to_timespec(ts);
290-
err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &t, &sinfo);
288+
err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo);
291289
if (err)
292290
goto out;
293291
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
@@ -347,7 +345,6 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
347345
struct inode *inode;
348346
unsigned char msdos_name[MSDOS_NAME];
349347
struct timespec64 ts;
350-
struct timespec t;
351348
int err, is_hid, cluster;
352349

353350
mutex_lock(&MSDOS_SB(sb)->s_lock);
@@ -365,13 +362,12 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
365362
}
366363

367364
ts = current_time(dir);
368-
t = timespec64_to_timespec(ts);
369-
cluster = fat_alloc_new_dir(dir, &t);
365+
cluster = fat_alloc_new_dir(dir, &ts);
370366
if (cluster < 0) {
371367
err = cluster;
372368
goto out;
373369
}
374-
err = msdos_add_entry(dir, msdos_name, 1, is_hid, cluster, &t, &sinfo);
370+
err = msdos_add_entry(dir, msdos_name, 1, is_hid, cluster, &ts, &sinfo);
375371
if (err)
376372
goto out_free;
377373
inc_nlink(dir);
@@ -503,9 +499,8 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
503499
new_i_pos = MSDOS_I(new_inode)->i_pos;
504500
fat_detach(new_inode);
505501
} else {
506-
struct timespec t = timespec64_to_timespec(ts);
507502
err = msdos_add_entry(new_dir, new_name, is_dir, is_hid, 0,
508-
&t, &sinfo);
503+
&ts, &sinfo);
509504
if (err)
510505
goto out;
511506
new_i_pos = sinfo.i_pos;

‎fs/fat/namei_vfat.c‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
577577

578578
static int vfat_build_slots(struct inode *dir, const unsigned char *name,
579579
int len, int is_dir, int cluster,
580-
struct timespec *ts,
580+
struct timespec64 *ts,
581581
struct msdos_dir_slot *slots, int *nr_slots)
582582
{
583583
struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
@@ -653,7 +653,7 @@ static int vfat_build_slots(struct inode *dir, const unsigned char *name,
653653
}
654654

655655
static int vfat_add_entry(struct inode *dir, const struct qstr *qname,
656-
int is_dir, int cluster, struct timespec *ts,
656+
int is_dir, int cluster, struct timespec64 *ts,
657657
struct fat_slot_info *sinfo)
658658
{
659659
struct msdos_dir_slot *slots;
@@ -678,7 +678,7 @@ static int vfat_add_entry(struct inode *dir, const struct qstr *qname,
678678
goto cleanup;
679679

680680
/* update timestamp */
681-
dir->i_ctime = dir->i_mtime = dir->i_atime = timespec_to_timespec64(*ts);
681+
dir->i_ctime = dir->i_mtime = dir->i_atime = *ts;
682682
if (IS_DIRSYNC(dir))
683683
(void)fat_sync_inode(dir);
684684
else
@@ -762,14 +762,12 @@ static int vfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
762762
struct inode *inode;
763763
struct fat_slot_info sinfo;
764764
struct timespec64 ts;
765-
struct timespec t;
766765
int err;
767766

768767
mutex_lock(&MSDOS_SB(sb)->s_lock);
769768

770769
ts = current_time(dir);
771-
t = timespec64_to_timespec(ts);
772-
err = vfat_add_entry(dir, &dentry->d_name, 0, 0, &t, &sinfo);
770+
err = vfat_add_entry(dir, &dentry->d_name, 0, 0, &ts, &sinfo);
773771
if (err)
774772
goto out;
775773
inode_inc_iversion(dir);
@@ -853,19 +851,17 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
853851
struct inode *inode;
854852
struct fat_slot_info sinfo;
855853
struct timespec64 ts;
856-
struct timespec t;
857854
int err, cluster;
858855

859856
mutex_lock(&MSDOS_SB(sb)->s_lock);
860857

861858
ts = current_time(dir);
862-
t = timespec64_to_timespec(ts);
863-
cluster = fat_alloc_new_dir(dir, &t);
859+
cluster = fat_alloc_new_dir(dir, &ts);
864860
if (cluster < 0) {
865861
err = cluster;
866862
goto out;
867863
}
868-
err = vfat_add_entry(dir, &dentry->d_name, 1, cluster, &t, &sinfo);
864+
err = vfat_add_entry(dir, &dentry->d_name, 1, cluster, &ts, &sinfo);
869865
if (err)
870866
goto out_free;
871867
inode_inc_iversion(dir);
@@ -904,7 +900,6 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
904900
struct inode *old_inode, *new_inode;
905901
struct fat_slot_info old_sinfo, sinfo;
906902
struct timespec64 ts;
907-
struct timespec t;
908903
loff_t new_i_pos;
909904
int err, is_dir, update_dotdot, corrupt = 0;
910905
struct super_block *sb = old_dir->i_sb;
@@ -939,9 +934,8 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
939934
new_i_pos = MSDOS_I(new_inode)->i_pos;
940935
fat_detach(new_inode);
941936
} else {
942-
t = timespec64_to_timespec(ts);
943937
err = vfat_add_entry(new_dir, &new_dentry->d_name, is_dir, 0,
944-
&t, &sinfo);
938+
&ts, &sinfo);
945939
if (err)
946940
goto out;
947941
new_i_pos = sinfo.i_pos;

0 commit comments

Comments
 (0)