Skip to content

Commit

Permalink
exfat: Stop using CURRENT_TIME_SEC
Browse files Browse the repository at this point in the history
 * This is going away in 4.12 and is not y2038 safe.
 * Use current_time(inode) and ktime_get_real_ts where appropriate.
  • Loading branch information
hyperb1iss committed Jun 10, 2017
1 parent ef703b2 commit 1e91a9f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 41 deletions.
12 changes: 9 additions & 3 deletions exfat_oal.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@ static time_t accum_days_in_year[] = {

TIMESTAMP_T *tm_current(TIMESTAMP_T *tp)
{
struct timespec ts = CURRENT_TIME_SEC;
time_t second = ts.tv_sec;
time_t day, leap_day, month, year;
struct timespec ts;
time_t second, day, leap_day, month, year;

#if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
ts = CURRENT_TIME_SEC;
#else
ktime_get_real_ts(&ts);
#endif

second = ts.tv_sec;
second -= sys_tz.tz_minuteswest * SECS_PER_MIN;

/* Jan 1 GMT 00:00:00 1980. But what about another time zone? */
Expand Down
59 changes: 21 additions & 38 deletions exfat_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ static char exfat_default_iocharset[] = CONFIG_EXFAT_DEFAULT_IOCHARSET;

extern struct timezone sys_tz;

#if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
#define current_time(x) (CURRENT_TIME_SEC)
#endif

#define CHECK_ERR(x) BUG_ON(x)

#define UNIX_SECS_1980 315532800L
Expand Down Expand Up @@ -721,7 +725,6 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, int mode,
{
struct super_block *sb = dir->i_sb;
struct inode *inode;
struct timespec ts;
FILE_ID_T fid;
loff_t i_pos;
int err;
Expand All @@ -730,8 +733,6 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, int mode,

DPRINTK("exfat_create entered\n");

ts = CURRENT_TIME_SEC;

err = FsCreateFile(dir, (u8 *) dentry->d_name.name, FM_REGULAR, &fid);
if (err) {
if (err == FFS_INVALIDPATH)
Expand All @@ -747,7 +748,7 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, int mode,
goto out;
}
dir->i_version++;
dir->i_ctime = dir->i_mtime = dir->i_atime = ts;
dir->i_ctime = dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
else
Expand All @@ -761,7 +762,7 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, int mode,
goto out;
}
inode->i_version++;
inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
/* timestamp is already written, so mark_inode_dirty() is unnecessary. */

dentry->d_time = dentry->d_parent->d_inode->i_version;
Expand Down Expand Up @@ -879,15 +880,12 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)
{
struct inode *inode = dentry->d_inode;
struct super_block *sb = dir->i_sb;
struct timespec ts;
int err;

__lock_super(sb);

DPRINTK("exfat_unlink entered\n");

ts = CURRENT_TIME_SEC;

EXFAT_I(inode)->fid.size = i_size_read(inode);

err = FsRemoveFile(dir, &(EXFAT_I(inode)->fid));
Expand All @@ -899,14 +897,14 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)
goto out;
}
dir->i_version++;
dir->i_mtime = dir->i_atime = ts;
dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
else
mark_inode_dirty(dir);

clear_nlink(inode);
inode->i_mtime = inode->i_atime = ts;
inode->i_mtime = inode->i_atime = current_time(inode);
exfat_detach(inode);
remove_inode_hash(inode);

Expand All @@ -920,7 +918,6 @@ static int exfat_symlink(struct inode *dir, struct dentry *dentry, const char *t
{
struct super_block *sb = dir->i_sb;
struct inode *inode;
struct timespec ts;
FILE_ID_T fid;
loff_t i_pos;
int err;
Expand All @@ -931,8 +928,6 @@ static int exfat_symlink(struct inode *dir, struct dentry *dentry, const char *t

DPRINTK("exfat_symlink entered\n");

ts = CURRENT_TIME_SEC;

err = FsCreateFile(dir, (u8 *) dentry->d_name.name, FM_SYMLINK, &fid);
if (err) {
if (err == FFS_INVALIDPATH)
Expand All @@ -959,7 +954,7 @@ static int exfat_symlink(struct inode *dir, struct dentry *dentry, const char *t
}

dir->i_version++;
dir->i_ctime = dir->i_mtime = dir->i_atime = ts;
dir->i_ctime = dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
else
Expand All @@ -973,7 +968,7 @@ static int exfat_symlink(struct inode *dir, struct dentry *dentry, const char *t
goto out;
}
inode->i_version++;
inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
/* timestamp is already written, so mark_inode_dirty() is unneeded. */

EXFAT_I(inode)->target = kmalloc(len+1, GFP_KERNEL);
Expand All @@ -1000,7 +995,6 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, int mode)
{
struct super_block *sb = dir->i_sb;
struct inode *inode;
struct timespec ts;
FILE_ID_T fid;
loff_t i_pos;
int err;
Expand All @@ -1009,8 +1003,6 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, int mode)

DPRINTK("exfat_mkdir entered\n");

ts = CURRENT_TIME_SEC;

err = FsCreateDir(dir, (u8 *) dentry->d_name.name, &fid);
if (err) {
if (err == FFS_INVALIDPATH)
Expand All @@ -1026,7 +1018,7 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, int mode)
goto out;
}
dir->i_version++;
dir->i_ctime = dir->i_mtime = dir->i_atime = ts;
dir->i_ctime = dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
else
Expand All @@ -1041,7 +1033,7 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, int mode)
goto out;
}
inode->i_version++;
inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
/* timestamp is already written, so mark_inode_dirty() is unneeded. */

dentry->d_time = dentry->d_parent->d_inode->i_version;
Expand All @@ -1057,15 +1049,12 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
{
struct inode *inode = dentry->d_inode;
struct super_block *sb = dir->i_sb;
struct timespec ts;
int err;

__lock_super(sb);

DPRINTK("exfat_rmdir entered\n");

ts = CURRENT_TIME_SEC;

EXFAT_I(inode)->fid.size = i_size_read(inode);

err = FsRemoveDir(dir, &(EXFAT_I(inode)->fid));
Expand All @@ -1083,15 +1072,15 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
goto out;
}
dir->i_version++;
dir->i_mtime = dir->i_atime = ts;
dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
else
mark_inode_dirty(dir);
drop_nlink(dir);

clear_nlink(inode);
inode->i_mtime = inode->i_atime = ts;
inode->i_mtime = inode->i_atime = current_time(inode);
exfat_detach(inode);
remove_inode_hash(inode);

Expand All @@ -1112,7 +1101,6 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
{
struct inode *old_inode, *new_inode;
struct super_block *sb = old_dir->i_sb;
struct timespec ts;
loff_t i_pos;
int err;

Expand All @@ -1128,8 +1116,6 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
old_inode = old_dentry->d_inode;
new_inode = new_dentry->d_inode;

ts = CURRENT_TIME_SEC;

EXFAT_I(old_inode)->fid.size = i_size_read(old_inode);

err = FsMoveFile(old_dir, &(EXFAT_I(old_inode)->fid), new_dir, new_dentry);
Expand All @@ -1149,7 +1135,7 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
goto out;
}
new_dir->i_version++;
new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime = ts;
new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime = current_time(new_dir);
if (IS_DIRSYNC(new_dir))
(void) exfat_sync_inode(new_dir);
else
Expand All @@ -1172,7 +1158,7 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
}

old_dir->i_version++;
old_dir->i_ctime = old_dir->i_mtime = ts;
old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
if (IS_DIRSYNC(old_dir))
(void) exfat_sync_inode(old_dir);
else
Expand All @@ -1183,7 +1169,7 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
drop_nlink(new_inode);
if (S_ISDIR(new_inode->i_mode))
drop_nlink(new_inode);
new_inode->i_ctime = ts;
new_inode->i_ctime = current_time(new_inode);
}

out:
Expand All @@ -1202,7 +1188,7 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
if (err != 0)
return err;

inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
inode->i_ctime = inode->i_mtime = current_time(inode);
mark_inode_dirty(inode);

if (IS_SYNC(inode)) {
Expand Down Expand Up @@ -1496,7 +1482,7 @@ static void _exfat_truncate(struct inode *inode, loff_t old_size)
if (err)
goto out;

inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
inode->i_ctime = inode->i_mtime = current_time(inode);
if (IS_DIRSYNC(inode))
(void) exfat_sync_inode(inode);
else
Expand Down Expand Up @@ -1692,7 +1678,7 @@ static int exfat_write_end(struct file *file, struct address_space *mapping,
#endif

if (!(err < 0) && !(fid->attr & ATTR_ARCHIVE)) {
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
inode->i_mtime = inode->i_ctime = current_time(inode);
fid->attr |= ATTR_ARCHIVE;
mark_inode_dirty(inode);
}
Expand Down Expand Up @@ -2418,12 +2404,9 @@ static int exfat_read_root(struct inode *inode)
{
struct super_block *sb = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct timespec ts;
FS_INFO_T *p_fs = &(sbi->fs_info);
DIR_ENTRY_T info;

ts = CURRENT_TIME_SEC;

EXFAT_I(inode)->fid.dir.dir = p_fs->root_dir;
EXFAT_I(inode)->fid.dir.flags = 0x01;
EXFAT_I(inode)->fid.entry = -1;
Expand Down Expand Up @@ -2452,7 +2435,7 @@ static int exfat_read_root(struct inode *inode)
EXFAT_I(inode)->mmu_private = i_size_read(inode);

exfat_save_attr(inode, ATTR_SUBDIR);
inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,00)
set_nlink(inode, info.NumSubdirs + 2);
#else
Expand Down

0 comments on commit 1e91a9f

Please sign in to comment.