Commit f423420c authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Linus Torvalds

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.deSigned-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Jeff Layton <jlayton@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0afa9626
...@@ -1130,7 +1130,7 @@ static int fat_zeroed_cluster(struct inode *dir, sector_t blknr, int nr_used, ...@@ -1130,7 +1130,7 @@ static int fat_zeroed_cluster(struct inode *dir, sector_t blknr, int nr_used,
return err; return err;
} }
int fat_alloc_new_dir(struct inode *dir, struct timespec *ts) int fat_alloc_new_dir(struct inode *dir, struct timespec64 *ts)
{ {
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
struct msdos_sb_info *sbi = MSDOS_SB(sb); struct msdos_sb_info *sbi = MSDOS_SB(sb);
......
...@@ -304,7 +304,7 @@ extern int fat_scan_logstart(struct inode *dir, int i_logstart, ...@@ -304,7 +304,7 @@ extern int fat_scan_logstart(struct inode *dir, int i_logstart,
struct fat_slot_info *sinfo); struct fat_slot_info *sinfo);
extern int fat_get_dotdot_entry(struct inode *dir, struct buffer_head **bh, extern int fat_get_dotdot_entry(struct inode *dir, struct buffer_head **bh,
struct msdos_dir_entry **de); struct msdos_dir_entry **de);
extern int fat_alloc_new_dir(struct inode *dir, struct timespec *ts); extern int fat_alloc_new_dir(struct inode *dir, struct timespec64 *ts);
extern int fat_add_entries(struct inode *dir, void *slots, int nr_slots, extern int fat_add_entries(struct inode *dir, void *slots, int nr_slots,
struct fat_slot_info *sinfo); struct fat_slot_info *sinfo);
extern int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo); 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, ...); ...@@ -412,9 +412,9 @@ void fat_msg(struct super_block *sb, const char *level, const char *fmt, ...);
} while (0) } while (0)
extern int fat_clusters_flush(struct super_block *sb); extern int fat_clusters_flush(struct super_block *sb);
extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster); extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster);
extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts, extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
__le16 __time, __le16 __date, u8 time_cs); __le16 __time, __le16 __date, u8 time_cs);
extern void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec *ts, extern void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts,
__le16 *time, __le16 *date, u8 *time_cs); __le16 *time, __le16 *date, u8 *time_cs);
extern int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs); extern int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs);
......
...@@ -508,7 +508,6 @@ static int fat_validate_dir(struct inode *dir) ...@@ -508,7 +508,6 @@ static int fat_validate_dir(struct inode *dir)
/* doesn't deal with root inode */ /* doesn't deal with root inode */
int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
{ {
struct timespec ts;
struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
int error; int error;
...@@ -559,14 +558,11 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) ...@@ -559,14 +558,11 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1)) inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
& ~((loff_t)sbi->cluster_size - 1)) >> 9; & ~((loff_t)sbi->cluster_size - 1)) >> 9;
fat_time_fat2unix(sbi, &ts, de->time, de->date, 0); fat_time_fat2unix(sbi, &inode->i_mtime, de->time, de->date, 0);
inode->i_mtime = timespec_to_timespec64(ts);
if (sbi->options.isvfat) { if (sbi->options.isvfat) {
fat_time_fat2unix(sbi, &ts, de->ctime, fat_time_fat2unix(sbi, &inode->i_ctime, de->ctime,
de->cdate, de->ctime_cs); de->cdate, de->ctime_cs);
inode->i_ctime = timespec_to_timespec64(ts); fat_time_fat2unix(sbi, &inode->i_atime, 0, de->adate, 0);
fat_time_fat2unix(sbi, &ts, 0, de->adate, 0);
inode->i_atime = timespec_to_timespec64(ts);
} else } else
inode->i_ctime = inode->i_atime = inode->i_mtime; inode->i_ctime = inode->i_atime = inode->i_mtime;
...@@ -843,7 +839,6 @@ static int fat_statfs(struct dentry *dentry, struct kstatfs *buf) ...@@ -843,7 +839,6 @@ static int fat_statfs(struct dentry *dentry, struct kstatfs *buf)
static int __fat_write_inode(struct inode *inode, int wait) static int __fat_write_inode(struct inode *inode, int wait)
{ {
struct timespec ts;
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
struct msdos_sb_info *sbi = MSDOS_SB(sb); struct msdos_sb_info *sbi = MSDOS_SB(sb);
struct buffer_head *bh; struct buffer_head *bh;
...@@ -881,16 +876,13 @@ static int __fat_write_inode(struct inode *inode, int wait) ...@@ -881,16 +876,13 @@ static int __fat_write_inode(struct inode *inode, int wait)
raw_entry->size = cpu_to_le32(inode->i_size); raw_entry->size = cpu_to_le32(inode->i_size);
raw_entry->attr = fat_make_attrs(inode); raw_entry->attr = fat_make_attrs(inode);
fat_set_start(raw_entry, MSDOS_I(inode)->i_logstart); fat_set_start(raw_entry, MSDOS_I(inode)->i_logstart);
ts = timespec64_to_timespec(inode->i_mtime); fat_time_unix2fat(sbi, &inode->i_mtime, &raw_entry->time,
fat_time_unix2fat(sbi, &ts, &raw_entry->time,
&raw_entry->date, NULL); &raw_entry->date, NULL);
if (sbi->options.isvfat) { if (sbi->options.isvfat) {
__le16 atime; __le16 atime;
ts = timespec64_to_timespec(inode->i_ctime); fat_time_unix2fat(sbi, &inode->i_ctime, &raw_entry->ctime,
fat_time_unix2fat(sbi, &ts, &raw_entry->ctime,
&raw_entry->cdate, &raw_entry->ctime_cs); &raw_entry->cdate, &raw_entry->ctime_cs);
ts = timespec64_to_timespec(inode->i_atime); fat_time_unix2fat(sbi, &inode->i_atime, &atime,
fat_time_unix2fat(sbi, &ts, &atime,
&raw_entry->adate, NULL); &raw_entry->adate, NULL);
} }
spin_unlock(&sbi->inode_hash_lock); spin_unlock(&sbi->inode_hash_lock);
......
...@@ -180,17 +180,18 @@ int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster) ...@@ -180,17 +180,18 @@ int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster)
#define IS_LEAP_YEAR(y) (!((y) & 3) && (y) != YEAR_2100) #define IS_LEAP_YEAR(y) (!((y) & 3) && (y) != YEAR_2100)
/* Linear day numbers of the respective 1sts in non-leap years. */ /* Linear day numbers of the respective 1sts in non-leap years. */
static time_t days_in_year[] = { static long days_in_year[] = {
/* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */ /* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */
0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0, 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0,
}; };
/* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */ /* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */
void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts, void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
__le16 __time, __le16 __date, u8 time_cs) __le16 __time, __le16 __date, u8 time_cs)
{ {
u16 time = le16_to_cpu(__time), date = le16_to_cpu(__date); u16 time = le16_to_cpu(__time), date = le16_to_cpu(__date);
time_t second, day, leap_day, month, year; time64_t second;
long day, leap_day, month, year;
year = date >> 9; year = date >> 9;
month = max(1, (date >> 5) & 0xf); month = max(1, (date >> 5) & 0xf);
...@@ -205,7 +206,7 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts, ...@@ -205,7 +206,7 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts,
second = (time & 0x1f) << 1; second = (time & 0x1f) << 1;
second += ((time >> 5) & 0x3f) * SECS_PER_MIN; second += ((time >> 5) & 0x3f) * SECS_PER_MIN;
second += (time >> 11) * SECS_PER_HOUR; second += (time >> 11) * SECS_PER_HOUR;
second += (year * 365 + leap_day second += (time64_t)(year * 365 + leap_day
+ days_in_year[month] + day + days_in_year[month] + day
+ DAYS_DELTA) * SECS_PER_DAY; + DAYS_DELTA) * SECS_PER_DAY;
...@@ -224,11 +225,11 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts, ...@@ -224,11 +225,11 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts,
} }
/* Convert linear UNIX date to a FAT time/date pair. */ /* Convert linear UNIX date to a FAT time/date pair. */
void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec *ts, void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts,
__le16 *time, __le16 *date, u8 *time_cs) __le16 *time, __le16 *date, u8 *time_cs)
{ {
struct tm tm; struct tm tm;
time_to_tm(ts->tv_sec, time64_to_tm(ts->tv_sec,
(sbi->options.tz_set ? sbi->options.time_offset : (sbi->options.tz_set ? sbi->options.time_offset :
-sys_tz.tz_minuteswest) * SECS_PER_MIN, &tm); -sys_tz.tz_minuteswest) * SECS_PER_MIN, &tm);
......
...@@ -225,7 +225,7 @@ static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry, ...@@ -225,7 +225,7 @@ static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry,
/***** Creates a directory entry (name is already formatted). */ /***** Creates a directory entry (name is already formatted). */
static int msdos_add_entry(struct inode *dir, const unsigned char *name, static int msdos_add_entry(struct inode *dir, const unsigned char *name,
int is_dir, int is_hid, int cluster, int is_dir, int is_hid, int cluster,
struct timespec *ts, struct fat_slot_info *sinfo) struct timespec64 *ts, struct fat_slot_info *sinfo)
{ {
struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb); struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
struct msdos_dir_entry de; struct msdos_dir_entry de;
...@@ -250,7 +250,7 @@ static int msdos_add_entry(struct inode *dir, const unsigned char *name, ...@@ -250,7 +250,7 @@ static int msdos_add_entry(struct inode *dir, const unsigned char *name,
if (err) if (err)
return err; return err;
dir->i_ctime = dir->i_mtime = timespec_to_timespec64(*ts); dir->i_ctime = dir->i_mtime = *ts;
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
(void)fat_sync_inode(dir); (void)fat_sync_inode(dir);
else else
...@@ -267,7 +267,6 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, umode_t mode, ...@@ -267,7 +267,6 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, umode_t mode,
struct inode *inode = NULL; struct inode *inode = NULL;
struct fat_slot_info sinfo; struct fat_slot_info sinfo;
struct timespec64 ts; struct timespec64 ts;
struct timespec t;
unsigned char msdos_name[MSDOS_NAME]; unsigned char msdos_name[MSDOS_NAME];
int err, is_hid; int err, is_hid;
...@@ -286,8 +285,7 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, umode_t mode, ...@@ -286,8 +285,7 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, umode_t mode,
} }
ts = current_time(dir); ts = current_time(dir);
t = timespec64_to_timespec(ts); err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo);
err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &t, &sinfo);
if (err) if (err)
goto out; goto out;
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos); 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) ...@@ -347,7 +345,6 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
struct inode *inode; struct inode *inode;
unsigned char msdos_name[MSDOS_NAME]; unsigned char msdos_name[MSDOS_NAME];
struct timespec64 ts; struct timespec64 ts;
struct timespec t;
int err, is_hid, cluster; int err, is_hid, cluster;
mutex_lock(&MSDOS_SB(sb)->s_lock); mutex_lock(&MSDOS_SB(sb)->s_lock);
...@@ -365,13 +362,12 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) ...@@ -365,13 +362,12 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
} }
ts = current_time(dir); ts = current_time(dir);
t = timespec64_to_timespec(ts); cluster = fat_alloc_new_dir(dir, &ts);
cluster = fat_alloc_new_dir(dir, &t);
if (cluster < 0) { if (cluster < 0) {
err = cluster; err = cluster;
goto out; goto out;
} }
err = msdos_add_entry(dir, msdos_name, 1, is_hid, cluster, &t, &sinfo); err = msdos_add_entry(dir, msdos_name, 1, is_hid, cluster, &ts, &sinfo);
if (err) if (err)
goto out_free; goto out_free;
inc_nlink(dir); inc_nlink(dir);
...@@ -503,9 +499,8 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name, ...@@ -503,9 +499,8 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
new_i_pos = MSDOS_I(new_inode)->i_pos; new_i_pos = MSDOS_I(new_inode)->i_pos;
fat_detach(new_inode); fat_detach(new_inode);
} else { } else {
struct timespec t = timespec64_to_timespec(ts);
err = msdos_add_entry(new_dir, new_name, is_dir, is_hid, 0, err = msdos_add_entry(new_dir, new_name, is_dir, is_hid, 0,
&t, &sinfo); &ts, &sinfo);
if (err) if (err)
goto out; goto out;
new_i_pos = sinfo.i_pos; new_i_pos = sinfo.i_pos;
......
...@@ -577,7 +577,7 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname, ...@@ -577,7 +577,7 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
static int vfat_build_slots(struct inode *dir, const unsigned char *name, static int vfat_build_slots(struct inode *dir, const unsigned char *name,
int len, int is_dir, int cluster, int len, int is_dir, int cluster,
struct timespec *ts, struct timespec64 *ts,
struct msdos_dir_slot *slots, int *nr_slots) struct msdos_dir_slot *slots, int *nr_slots)
{ {
struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb); 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, ...@@ -653,7 +653,7 @@ static int vfat_build_slots(struct inode *dir, const unsigned char *name,
} }
static int vfat_add_entry(struct inode *dir, const struct qstr *qname, static int vfat_add_entry(struct inode *dir, const struct qstr *qname,
int is_dir, int cluster, struct timespec *ts, int is_dir, int cluster, struct timespec64 *ts,
struct fat_slot_info *sinfo) struct fat_slot_info *sinfo)
{ {
struct msdos_dir_slot *slots; struct msdos_dir_slot *slots;
...@@ -678,7 +678,7 @@ static int vfat_add_entry(struct inode *dir, const struct qstr *qname, ...@@ -678,7 +678,7 @@ static int vfat_add_entry(struct inode *dir, const struct qstr *qname,
goto cleanup; goto cleanup;
/* update timestamp */ /* update timestamp */
dir->i_ctime = dir->i_mtime = dir->i_atime = timespec_to_timespec64(*ts); dir->i_ctime = dir->i_mtime = dir->i_atime = *ts;
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
(void)fat_sync_inode(dir); (void)fat_sync_inode(dir);
else else
...@@ -762,14 +762,12 @@ static int vfat_create(struct inode *dir, struct dentry *dentry, umode_t mode, ...@@ -762,14 +762,12 @@ static int vfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
struct inode *inode; struct inode *inode;
struct fat_slot_info sinfo; struct fat_slot_info sinfo;
struct timespec64 ts; struct timespec64 ts;
struct timespec t;
int err; int err;
mutex_lock(&MSDOS_SB(sb)->s_lock); mutex_lock(&MSDOS_SB(sb)->s_lock);
ts = current_time(dir); ts = current_time(dir);
t = timespec64_to_timespec(ts); err = vfat_add_entry(dir, &dentry->d_name, 0, 0, &ts, &sinfo);
err = vfat_add_entry(dir, &dentry->d_name, 0, 0, &t, &sinfo);
if (err) if (err)
goto out; goto out;
inode_inc_iversion(dir); inode_inc_iversion(dir);
...@@ -853,19 +851,17 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) ...@@ -853,19 +851,17 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
struct inode *inode; struct inode *inode;
struct fat_slot_info sinfo; struct fat_slot_info sinfo;
struct timespec64 ts; struct timespec64 ts;
struct timespec t;
int err, cluster; int err, cluster;
mutex_lock(&MSDOS_SB(sb)->s_lock); mutex_lock(&MSDOS_SB(sb)->s_lock);
ts = current_time(dir); ts = current_time(dir);
t = timespec64_to_timespec(ts); cluster = fat_alloc_new_dir(dir, &ts);
cluster = fat_alloc_new_dir(dir, &t);
if (cluster < 0) { if (cluster < 0) {
err = cluster; err = cluster;
goto out; goto out;
} }
err = vfat_add_entry(dir, &dentry->d_name, 1, cluster, &t, &sinfo); err = vfat_add_entry(dir, &dentry->d_name, 1, cluster, &ts, &sinfo);
if (err) if (err)
goto out_free; goto out_free;
inode_inc_iversion(dir); inode_inc_iversion(dir);
...@@ -904,7 +900,6 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -904,7 +900,6 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *old_inode, *new_inode; struct inode *old_inode, *new_inode;
struct fat_slot_info old_sinfo, sinfo; struct fat_slot_info old_sinfo, sinfo;
struct timespec64 ts; struct timespec64 ts;
struct timespec t;
loff_t new_i_pos; loff_t new_i_pos;
int err, is_dir, update_dotdot, corrupt = 0; int err, is_dir, update_dotdot, corrupt = 0;
struct super_block *sb = old_dir->i_sb; struct super_block *sb = old_dir->i_sb;
...@@ -939,9 +934,8 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -939,9 +934,8 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
new_i_pos = MSDOS_I(new_inode)->i_pos; new_i_pos = MSDOS_I(new_inode)->i_pos;
fat_detach(new_inode); fat_detach(new_inode);
} else { } else {
t = timespec64_to_timespec(ts);
err = vfat_add_entry(new_dir, &new_dentry->d_name, is_dir, 0, err = vfat_add_entry(new_dir, &new_dentry->d_name, is_dir, 0,
&t, &sinfo); &ts, &sinfo);
if (err) if (err)
goto out; goto out;
new_i_pos = sinfo.i_pos; new_i_pos = sinfo.i_pos;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment