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

Commit

Permalink
exfat: Fix compilation on Linux >= 4.16
Browse files Browse the repository at this point in the history
Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
  • Loading branch information
KNnut authored and arter97 committed Sep 14, 2019
1 parent d53392f commit 2dc0b2e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 30 deletions.
6 changes: 3 additions & 3 deletions core.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static s32 __fs_set_vol_flags(struct super_block *sb, u16 new_flag, s32 always_s
/* skip updating volume dirty flag,
* if this volume has been mounted with read-only
*/
if (sb->s_flags & MS_RDONLY)
if (EXFAT_IS_SB_RDONLY(sb))
return 0;

if (!fsi->pbr_bh) {
Expand Down Expand Up @@ -1701,10 +1701,10 @@ s32 fscore_lookup(struct inode *inode, u8 *path, FILE_ID_T *fid)
return ret;

/* check the validation of hint_stat and initialize it if required */
if (dir_fid->version != (u32)(inode->i_version & 0xffffffff)) {
if (dir_fid->version != (u32)(GET_IVERSION(inode) & 0xffffffff)) {
dir_fid->hint_stat.clu = dir.dir;
dir_fid->hint_stat.eidx = 0;
dir_fid->version = (u32)(inode->i_version & 0xffffffff);
dir_fid->version = (u32)(GET_IVERSION(inode) & 0xffffffff);
dir_fid->hint_femp.eidx = -1;
}

Expand Down
32 changes: 30 additions & 2 deletions exfat.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@
#include <linux/kobject.h>
#include "api.h"

/*************************************************************************
* FUNCTIONS WHICH HAS KERNEL VERSION DEPENDENCY
*************************************************************************/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
#include <linux/iversion.h>
#define INC_IVERSION(x) (inode_inc_iversion(x))
#define GET_IVERSION(x) (inode_peek_iversion_raw(x))
#define SET_IVERSION(x,y) (inode_set_iversion(x, y))
#else
#define INC_IVERSION(x) (x->i_version++)
#define GET_IVERSION(x) (x->i_version)
#define SET_IVERSION(x,y) (x->i_version = y)
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
#define timespec_compat timespec64
#define KTIME_GET_REAL_TS ktime_get_real_ts64
#else
#define timespec_compat timespec
#define KTIME_GET_REAL_TS ktime_get_real_ts
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
#define EXFAT_IS_SB_RDONLY(sb) ((sb)->s_flags & MS_RDONLY)
#else
#define EXFAT_IS_SB_RDONLY(sb) ((sb)->s_flags & SB_RDONLY)
#endif

/*
* exfat error flags
*/
Expand Down Expand Up @@ -275,9 +303,9 @@ __exfat_msg(struct super_block *sb, const char *lv, int st, const char *fmt, ...
#define exfat_log_msg(sb, lv, fmt, args...) \
__exfat_msg(sb, lv, 1, fmt, ## args)
extern void exfat_log_version(void);
extern void exfat_time_fat2unix(struct exfat_sb_info *sbi, struct timespec *ts,
extern void exfat_time_fat2unix(struct exfat_sb_info *sbi, struct timespec_compat *ts,
DATE_TIME_T *tp);
extern void exfat_time_unix2fat(struct exfat_sb_info *sbi, struct timespec *ts,
extern void exfat_time_unix2fat(struct exfat_sb_info *sbi, struct timespec_compat *ts,
DATE_TIME_T *tp);
extern TIMESTAMP_T *tm_now(struct exfat_sb_info *sbi, TIMESTAMP_T *tm);

Expand Down
14 changes: 9 additions & 5 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ void __exfat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
if (opts->errors == EXFAT_ERRORS_PANIC) {
panic("[EXFAT](%s[%d:%d]): fs panic from previous error\n",
sb->s_id, MAJOR(bd_dev), MINOR(bd_dev));
} else if (opts->errors == EXFAT_ERRORS_RO && !(sb->s_flags & MS_RDONLY)) {
} else if (opts->errors == EXFAT_ERRORS_RO && !EXFAT_IS_SB_RDONLY(sb)) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
sb->s_flags |= MS_RDONLY;
#else
sb->s_flags |= SB_RDONLY;
#endif
pr_err("[EXFAT](%s[%d:%d]): Filesystem has been set "
"read-only\n", sb->s_id, MAJOR(bd_dev), MINOR(bd_dev));
}
Expand Down Expand Up @@ -140,7 +144,7 @@ static time_t accum_days_in_year[] = {
};

/* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */
void exfat_time_fat2unix(struct exfat_sb_info *sbi, struct timespec *ts,
void exfat_time_fat2unix(struct exfat_sb_info *sbi, struct timespec_compat *ts,
DATE_TIME_T *tp)
{
time_t year = tp->Year;
Expand All @@ -163,7 +167,7 @@ void exfat_time_fat2unix(struct exfat_sb_info *sbi, struct timespec *ts,
}

/* Convert linear UNIX date to a FAT time/date pair. */
void exfat_time_unix2fat(struct exfat_sb_info *sbi, struct timespec *ts,
void exfat_time_unix2fat(struct exfat_sb_info *sbi, struct timespec_compat *ts,
DATE_TIME_T *tp)
{
time_t second = ts->tv_sec;
Expand Down Expand Up @@ -227,10 +231,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;
struct timespec_compat ts;
DATE_TIME_T dt;

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

tp->year = dt.Year;
Expand Down
53 changes: 33 additions & 20 deletions super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ static int __exfat_revalidate_common(struct dentry *dentry)

spin_lock(&dentry->d_lock);
if ((!dentry->d_inode) && (!__check_dstate_locked(dentry) &&
(dentry->d_time != dentry->d_parent->d_inode->i_version))) {
(dentry->d_time != GET_IVERSION(dentry->d_parent->d_inode)))) {
ret = 0;
}
spin_unlock(&dentry->d_lock);
Expand Down Expand Up @@ -1499,7 +1499,7 @@ static int __exfat_create(struct inode *dir, struct dentry *dentry)

__lock_d_revalidate(dentry);

dir->i_version++;
INC_IVERSION(dir);
dir->i_ctime = dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
Expand All @@ -1512,7 +1512,7 @@ static int __exfat_create(struct inode *dir, struct dentry *dentry)
err = PTR_ERR(inode);
goto out;
}
inode->i_version++;
INC_IVERSION(inode);
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
/* timestamp is already written, so mark_inode_dirty() is unneeded. */

Expand Down Expand Up @@ -1624,7 +1624,7 @@ static struct dentry *__exfat_lookup(struct inode *dir, struct dentry *dentry)
dput(alias);
out:
/* initialize d_time even though it is positive dentry */
dentry->d_time = dir->i_version;
dentry->d_time = GET_IVERSION(dir);
__unlock_super(sb);

dentry = d_splice_alias(inode, dentry);
Expand Down Expand Up @@ -1656,7 +1656,7 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)

__lock_d_revalidate(dentry);

dir->i_version++;
INC_IVERSION(dir);
dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
Expand All @@ -1666,7 +1666,7 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)
clear_nlink(inode);
inode->i_mtime = inode->i_atime = current_time(inode);
exfat_detach(inode);
dentry->d_time = dir->i_version;
dentry->d_time = GET_IVERSION(dir);
out:
__unlock_d_revalidate(dentry);
__unlock_super(sb);
Expand Down Expand Up @@ -1705,7 +1705,7 @@ static int exfat_symlink(struct inode *dir, struct dentry *dentry, const char *t

__lock_d_revalidate(dentry);

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

Expand Down Expand Up @@ -1756,7 +1756,7 @@ static int __exfat_mkdir(struct inode *dir, struct dentry *dentry)

__lock_d_revalidate(dentry);

dir->i_version++;
INC_IVERSION(dir);
dir->i_ctime = dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
Expand All @@ -1770,7 +1770,7 @@ static int __exfat_mkdir(struct inode *dir, struct dentry *dentry)
err = PTR_ERR(inode);
goto out;
}
inode->i_version++;
INC_IVERSION(inode);
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
/* timestamp is already written, so mark_inode_dirty() is unneeded. */

Expand Down Expand Up @@ -1803,7 +1803,7 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)

__lock_d_revalidate(dentry);

dir->i_version++;
INC_IVERSION(dir);
dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
Expand All @@ -1814,7 +1814,7 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
clear_nlink(inode);
inode->i_mtime = inode->i_atime = current_time(inode);
exfat_detach(inode);
dentry->d_time = dir->i_version;
dentry->d_time = GET_IVERSION(dir);
out:
__unlock_d_revalidate(dentry);
__unlock_super(sb);
Expand Down Expand Up @@ -1846,7 +1846,7 @@ static int __exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
__lock_d_revalidate(old_dentry);
__lock_d_revalidate(new_dentry);

new_dir->i_version++;
INC_IVERSION(new_dir);
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);
Expand All @@ -1867,7 +1867,7 @@ static int __exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
inc_nlink(new_dir);
}

old_dir->i_version++;
INC_IVERSION(old_dir);
old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
if (IS_DIRSYNC(old_dir))
(void) exfat_sync_inode(old_dir);
Expand Down Expand Up @@ -2608,7 +2608,7 @@ static int exfat_check_writable(struct super_block *sb)
if (fsapi_check_bdi_valid(sb))
return -EIO;

if (sb->s_flags & MS_RDONLY)
if (EXFAT_IS_SB_RDONLY(sb))
return -EROFS;

return 0;
Expand Down Expand Up @@ -2766,7 +2766,7 @@ static int exfat_fill_inode(struct inode *inode, const FILE_ID_T *fid)
EXFAT_I(inode)->target = NULL;
inode->i_uid = sbi->options.fs_uid;
inode->i_gid = sbi->options.fs_gid;
inode->i_version++;
INC_IVERSION(inode);
inode->i_generation = get_seconds();

if (fsapi_read_inode(inode, &info) < 0) {
Expand Down Expand Up @@ -2838,7 +2838,7 @@ static struct inode *exfat_build_inode(struct super_block *sb,
goto out;
}
inode->i_ino = iunique(sb, EXFAT_ROOT_INO);
inode->i_version = 1;
SET_IVERSION(inode, 1);
err = exfat_fill_inode(inode, fid);
if (err) {
iput(inode);
Expand Down Expand Up @@ -2994,7 +2994,7 @@ static void exfat_write_super(struct super_block *sb)
/* flush delayed FAT/DIR dirty */
__flush_delayed_meta(sb, 0);

if (!(sb->s_flags & MS_RDONLY))
if (!EXFAT_IS_SB_RDONLY(sb))
fsapi_sync_fs(sb, 0);

__unlock_super(sb);
Expand Down Expand Up @@ -3067,7 +3067,11 @@ static int exfat_remount(struct super_block *sb, int *flags, char *data)
struct exfat_sb_info *sbi = EXFAT_SB(sb);
FS_INFO_T *fsi = &(sbi->fsi);

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
*flags |= MS_NODIRATIME;
#else
*flags |= SB_NODIRATIME;
#endif

prev_sb_flags = sb->s_flags;

Expand All @@ -3076,8 +3080,13 @@ static int exfat_remount(struct super_block *sb, int *flags, char *data)
fsapi_set_vol_flags(sb, VOL_CLEAN, 1);

exfat_log_msg(sb, KERN_INFO, "re-mounted(%s->%s), eio=0x%x, Opts: %s",
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
(prev_sb_flags & MS_RDONLY) ? "ro" : "rw",
(*flags & MS_RDONLY) ? "ro" : "rw",
#else
(prev_sb_flags & SB_RDONLY) ? "ro" : "rw",
(*flags & SB_RDONLY) ? "ro" : "rw",
#endif
fsi->prev_eio, orig_data);
kfree(orig_data);
return 0;
Expand Down Expand Up @@ -3496,7 +3505,7 @@ static int exfat_read_root(struct inode *inode)

inode->i_uid = sbi->options.fs_uid;
inode->i_gid = sbi->options.fs_gid;
inode->i_version++;
INC_IVERSION(inode);
inode->i_generation = 0;
inode->i_mode = exfat_make_mode(sbi, ATTR_SUBDIR, S_IRWXUGO);
inode->i_op = &exfat_dir_inode_operations;
Expand Down Expand Up @@ -3557,7 +3566,11 @@ static int exfat_fill_super(struct super_block *sb, void *data, int silent)

mutex_init(&sbi->s_vlock);
sb->s_fs_info = sbi;
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
sb->s_flags |= MS_NODIRATIME;
#else
sb->s_flags |= SB_NODIRATIME;
#endif
sb->s_magic = EXFAT_SUPER_MAGIC;
sb->s_op = &exfat_sops;
ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
Expand Down Expand Up @@ -3612,7 +3625,7 @@ static int exfat_fill_super(struct super_block *sb, void *data, int silent)
}

root_inode->i_ino = EXFAT_ROOT_INO;
root_inode->i_version = 1;
SET_IVERSION(root_inode, 1);

err = exfat_read_root(root_inode);
if (err) {
Expand Down

0 comments on commit 2dc0b2e

Please sign in to comment.