Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
exfat: fix CURRENT_TIME_SEC usage correctly
Browse files Browse the repository at this point in the history
Using current_kernel_time() is dumb.
Replace with correct, recommended API.

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
  • Loading branch information
arter97 committed Sep 14, 2019
1 parent f07411f commit 66570b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 50 deletions.
11 changes: 2 additions & 9 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@
#include "exfat.h"
#include "version.h"

/*************************************************************************
* FUNCTIONS WHICH HAS KERNEL VERSION DEPENDENCY
*************************************************************************/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
#define CURRENT_TIME_SEC timespec_trunc(current_kernel_time(), NSEC_PER_SEC)
#endif


/*
* exfat_fs_error reports a file system problem that might indicate fa data
* corruption/inconsistency. Depending on 'errors' mount option the
Expand Down Expand Up @@ -235,9 +227,10 @@ void exfat_time_unix2fat(struct exfat_sb_info *sbi, struct timespec *ts,

TIMESTAMP_T *tm_now(struct exfat_sb_info *sbi, TIMESTAMP_T *tp)
{
struct timespec ts = CURRENT_TIME_SEC;
struct timespec ts;
DATE_TIME_T dt;

ktime_get_real_ts(&ts);
exfat_time_unix2fat(sbi, &ts, &dt);

tp->year = dt.Year;
Expand Down
60 changes: 19 additions & 41 deletions super.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ static inline void bio_set_dev(struct bio *bio, struct block_device *bdev)
}
#endif


#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
#define CURRENT_TIME_SEC timespec_trunc(current_kernel_time(), NSEC_PER_SEC)
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,9,0)
#define current_time(x) CURRENT_TIME_SEC
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
Expand Down Expand Up @@ -1486,7 +1485,6 @@ static int __exfat_create(struct inode *dir, struct dentry *dentry)
{
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 @@ -1495,16 +1493,14 @@ static int __exfat_create(struct inode *dir, struct dentry *dentry)

TMSG("%s entered\n", __func__);

ts = CURRENT_TIME_SEC;

err = fsapi_create(dir, (u8 *) dentry->d_name.name, FM_REGULAR, &fid);
if (err)
goto out;

__lock_d_revalidate(dentry);

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 @@ -1517,7 +1513,7 @@ static int __exfat_create(struct inode *dir, struct dentry *dentry)
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. */

d_instantiate(dentry, inode);
Expand Down Expand Up @@ -1646,15 +1642,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);

TMSG("%s entered\n", __func__);

ts = CURRENT_TIME_SEC;

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

err = fsapi_unlink(dir, &(EXFAT_I(inode)->fid));
Expand All @@ -1664,14 +1657,14 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)
__lock_d_revalidate(dentry);

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);
dentry->d_time = dir->i_version;
out:
Expand All @@ -1685,7 +1678,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 @@ -1700,8 +1692,6 @@ static int exfat_symlink(struct inode *dir, struct dentry *dentry, const char *t

TMSG("%s entered\n", __func__);

ts = CURRENT_TIME_SEC;

err = fsapi_create(dir, (u8 *) dentry->d_name.name, FM_SYMLINK, &fid);
if (err)
goto out;
Expand All @@ -1716,7 +1706,7 @@ static int exfat_symlink(struct inode *dir, struct dentry *dentry, const char *t
__lock_d_revalidate(dentry);

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 @@ -1729,7 +1719,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 @@ -1752,7 +1742,6 @@ static int __exfat_mkdir(struct inode *dir, struct dentry *dentry)
{
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 @@ -1761,16 +1750,14 @@ static int __exfat_mkdir(struct inode *dir, struct dentry *dentry)

TMSG("%s entered\n", __func__);

ts = CURRENT_TIME_SEC;

err = fsapi_mkdir(dir, (u8 *) dentry->d_name.name, &fid);
if (err)
goto out;

__lock_d_revalidate(dentry);

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 @@ -1784,7 +1771,7 @@ static int __exfat_mkdir(struct inode *dir, struct dentry *dentry)
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. */

d_instantiate(dentry, inode);
Expand All @@ -1802,15 +1789,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);

TMSG("%s entered\n", __func__);

ts = CURRENT_TIME_SEC;

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

err = fsapi_rmdir(dir, &(EXFAT_I(inode)->fid));
Expand All @@ -1820,15 +1804,15 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
__lock_d_revalidate(dentry);

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);
dentry->d_time = dir->i_version;
out:
Expand All @@ -1843,7 +1827,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 @@ -1854,8 +1837,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 = fsapi_rename(old_dir, &(EXFAT_I(old_inode)->fid), new_dir, new_dentry);
Expand All @@ -1866,7 +1847,7 @@ static int __exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
__lock_d_revalidate(new_dentry);

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 @@ -1887,7 +1868,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 @@ -1906,7 +1887,7 @@ static int __exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
__func__);
WARN_ON(new_inode->i_nlink == 0);
}
new_inode->i_ctime = ts;
new_inode->i_ctime = current_time(new_inode);
#if 0
(void) exfat_sync_inode(new_inode);
#endif
Expand All @@ -1930,7 +1911,7 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
if (err)
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 @@ -2169,7 +2150,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 @@ -2688,7 +2669,7 @@ static int exfat_write_end(struct file *file, struct address_space *mapping,
exfat_write_failed(mapping, pos+len);

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 @@ -3492,12 +3473,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 *fsi = &(sbi->fsi);
DIR_ENTRY_T info;

ts = CURRENT_TIME_SEC;

EXFAT_I(inode)->fid.dir.dir = fsi->root_dir;
EXFAT_I(inode)->fid.dir.flags = 0x01;
EXFAT_I(inode)->fid.entry = -1;
Expand Down Expand Up @@ -3533,7 +3511,7 @@ static int exfat_read_root(struct inode *inode)
EXFAT_I(inode)->i_size_ondisk = 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);
set_nlink(inode, info.NumSubdirs + 2);
return 0;
}
Expand Down

0 comments on commit 66570b6

Please sign in to comment.