fs: sdfat: Fix compilation on Linux >= 4.16

This commit is contained in:
KNnut 2019-01-20 21:38:32 +08:00 committed by Andreas Schneider
parent d5b9695214
commit 4f65bdd301
5 changed files with 89 additions and 53 deletions

6
core.c
View File

@ -143,7 +143,7 @@ static s32 __fs_set_vol_flags(struct super_block *sb, u16 new_flag, s32 always_s
/* skip updating volume dirty flag, /* skip updating volume dirty flag,
* if this volume has been mounted with read-only * if this volume has been mounted with read-only
*/ */
if (sb->s_flags & MS_RDONLY) if (SDFAT_IS_SB_RDONLY(sb))
return 0; return 0;
if (!fsi->pbr_bh) { if (!fsi->pbr_bh) {
@ -1956,10 +1956,10 @@ s32 fscore_lookup(struct inode *inode, u8 *path, FILE_ID_T *fid)
return ret; return ret;
/* check the validation of hint_stat and initialize it if required */ /* 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.clu = dir.dir;
dir_fid->hint_stat.eidx = 0; 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; dir_fid->hint_femp.eidx = -1;
} }

4
dfr.c
View File

@ -861,7 +861,7 @@ defrag_update_fat_prev(
int skip = 0, done = 0; int skip = 0, done = 0;
/* Check if FS_ERROR occurred */ /* Check if FS_ERROR occurred */
if (sb->s_flags & MS_RDONLY) { if (SDFAT_IS_SB_RDONLY(sb)) {
dfr_err("RDONLY partition (err %d)", -EPERM); dfr_err("RDONLY partition (err %d)", -EPERM);
goto out; goto out;
} }
@ -1040,7 +1040,7 @@ defrag_update_fat_next(
int done = 0, i = 0, j = 0, err = 0; int done = 0, i = 0, j = 0, err = 0;
/* Check if FS_ERROR occurred */ /* Check if FS_ERROR occurred */
if (sb->s_flags & MS_RDONLY) { if (SDFAT_IS_SB_RDONLY(sb)) {
dfr_err("RDONLY partition (err %d)", -EROFS); dfr_err("RDONLY partition (err %d)", -EROFS);
goto out; goto out;
} }

22
misc.c
View File

@ -52,14 +52,6 @@
#define ST_LOG(fmt, ...) #define ST_LOG(fmt, ...)
#endif #endif
/*************************************************************************
* 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
/* /*
* sdfat_fs_error reports a file system problem that might indicate fa data * sdfat_fs_error reports a file system problem that might indicate fa data
* corruption/inconsistency. Depending on 'errors' mount option the * corruption/inconsistency. Depending on 'errors' mount option the
@ -83,7 +75,7 @@ void __sdfat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
pr_err("[SDFAT](%s[%d:%d]):ERR: %pV\n", pr_err("[SDFAT](%s[%d:%d]):ERR: %pV\n",
sb->s_id, MAJOR(bd_dev), MINOR(bd_dev), &vaf); sb->s_id, MAJOR(bd_dev), MINOR(bd_dev), &vaf);
#ifdef CONFIG_SDFAT_SUPPORT_STLOG #ifdef CONFIG_SDFAT_SUPPORT_STLOG
if (opts->errors == SDFAT_ERRORS_RO && !(sb->s_flags & MS_RDONLY)) { if (opts->errors == SDFAT_ERRORS_RO && !SDFAT_IS_SB_RDONLY(sb)) {
ST_LOG("[SDFAT](%s[%d:%d]):ERR: %pV\n", ST_LOG("[SDFAT](%s[%d:%d]):ERR: %pV\n",
sb->s_id, MAJOR(bd_dev), MINOR(bd_dev), &vaf); sb->s_id, MAJOR(bd_dev), MINOR(bd_dev), &vaf);
} }
@ -94,8 +86,12 @@ void __sdfat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
if (opts->errors == SDFAT_ERRORS_PANIC) { if (opts->errors == SDFAT_ERRORS_PANIC) {
panic("[SDFAT](%s[%d:%d]): fs panic from previous error\n", panic("[SDFAT](%s[%d:%d]): fs panic from previous error\n",
sb->s_id, MAJOR(bd_dev), MINOR(bd_dev)); sb->s_id, MAJOR(bd_dev), MINOR(bd_dev));
} else if (opts->errors == SDFAT_ERRORS_RO && !(sb->s_flags & MS_RDONLY)) { } else if (opts->errors == SDFAT_ERRORS_RO && !SDFAT_IS_SB_RDONLY(sb)) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
sb->s_flags |= MS_RDONLY; sb->s_flags |= MS_RDONLY;
#else
sb->s_flags |= SB_RDONLY;
#endif
sdfat_statistics_set_mnt_ro(); sdfat_statistics_set_mnt_ro();
pr_err("[SDFAT](%s[%d:%d]): Filesystem has been set " pr_err("[SDFAT](%s[%d:%d]): Filesystem has been set "
"read-only\n", sb->s_id, MAJOR(bd_dev), MINOR(bd_dev)); "read-only\n", sb->s_id, MAJOR(bd_dev), MINOR(bd_dev));
@ -179,7 +175,7 @@ static time_t accum_days_in_year[] = {
}; };
/* 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 sdfat_time_fat2unix(struct sdfat_sb_info *sbi, struct timespec *ts, void sdfat_time_fat2unix(struct sdfat_sb_info *sbi, struct timespec_compat *ts,
DATE_TIME_T *tp) DATE_TIME_T *tp)
{ {
time_t year = tp->Year; time_t year = tp->Year;
@ -202,7 +198,7 @@ void sdfat_time_fat2unix(struct sdfat_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 sdfat_time_unix2fat(struct sdfat_sb_info *sbi, struct timespec *ts, void sdfat_time_unix2fat(struct sdfat_sb_info *sbi, struct timespec_compat *ts,
DATE_TIME_T *tp) DATE_TIME_T *tp)
{ {
time_t second = ts->tv_sec; time_t second = ts->tv_sec;
@ -266,7 +262,7 @@ void sdfat_time_unix2fat(struct sdfat_sb_info *sbi, struct timespec *ts,
TIMESTAMP_T *tm_now(struct sdfat_sb_info *sbi, TIMESTAMP_T *tp) TIMESTAMP_T *tm_now(struct sdfat_sb_info *sbi, TIMESTAMP_T *tp)
{ {
struct timespec ts = CURRENT_TIME_SEC; struct timespec_compat ts = CURRENT_TIME_SEC;
DATE_TIME_T dt; DATE_TIME_T dt;
sdfat_time_unix2fat(sbi, &ts, &dt); sdfat_time_unix2fat(sbi, &ts, &dt);

74
sdfat.c
View File

@ -147,11 +147,6 @@ static inline void bio_set_dev(struct bio *bio, struct block_device *bdev)
} }
#endif #endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
#define CURRENT_TIME_SEC timespec_trunc(current_kernel_time(), NSEC_PER_SEC)
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
static int sdfat_getattr(const struct path *path, struct kstat *stat, static int sdfat_getattr(const struct path *path, struct kstat *stat,
u32 request_mask, unsigned int query_flags) u32 request_mask, unsigned int query_flags)
@ -1220,7 +1215,7 @@ static int __sdfat_revalidate_common(struct dentry *dentry)
spin_lock(&dentry->d_lock); spin_lock(&dentry->d_lock);
if ((!dentry->d_inode) && (!__check_dstate_locked(dentry) && 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; ret = 0;
} }
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
@ -2166,7 +2161,7 @@ static int sdfat_dfr_ioctl(struct inode *inode, struct file *filp,
__lock_super(sb); __lock_super(sb);
/* Check if FS_ERROR occurred */ /* Check if FS_ERROR occurred */
if (sb->s_flags & MS_RDONLY) { if (SDFAT_IS_SB_RDONLY(sb)) {
dfr_err("RDONLY partition (err %d)", -EPERM); dfr_err("RDONLY partition (err %d)", -EPERM);
__unlock_super(sb); __unlock_super(sb);
return -EPERM; return -EPERM;
@ -2368,7 +2363,7 @@ static int __sdfat_create(struct inode *dir, struct dentry *dentry)
{ {
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
struct inode *inode; struct inode *inode;
struct timespec ts; struct timespec_compat ts;
FILE_ID_T fid; FILE_ID_T fid;
loff_t i_pos; loff_t i_pos;
int err; int err;
@ -2385,7 +2380,7 @@ static int __sdfat_create(struct inode *dir, struct dentry *dentry)
__lock_d_revalidate(dentry); __lock_d_revalidate(dentry);
dir->i_version++; INC_IVERSION(dir);
dir->i_ctime = dir->i_mtime = dir->i_atime = ts; dir->i_ctime = dir->i_mtime = dir->i_atime = ts;
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
(void) sdfat_sync_inode(dir); (void) sdfat_sync_inode(dir);
@ -2398,7 +2393,7 @@ static int __sdfat_create(struct inode *dir, struct dentry *dentry)
err = PTR_ERR(inode); err = PTR_ERR(inode);
goto out; goto out;
} }
inode->i_version++; INC_IVERSION(inode);
inode->i_mtime = inode->i_atime = inode->i_ctime = ts; inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
/* timestamp is already written, so mark_inode_dirty() is unneeded. */ /* timestamp is already written, so mark_inode_dirty() is unneeded. */
@ -2515,7 +2510,7 @@ static struct dentry *__sdfat_lookup(struct inode *dir, struct dentry *dentry)
dput(alias); dput(alias);
out: out:
/* initialize d_time even though it is positive dentry */ /* initialize d_time even though it is positive dentry */
dentry->d_time = dir->i_version; dentry->d_time = GET_IVERSION(dir);
__unlock_super(sb); __unlock_super(sb);
dentry = d_splice_alias(inode, dentry); dentry = d_splice_alias(inode, dentry);
@ -2533,7 +2528,7 @@ static int sdfat_unlink(struct inode *dir, struct dentry *dentry)
{ {
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
struct timespec ts; struct timespec_compat ts;
int err; int err;
__lock_super(sb); __lock_super(sb);
@ -2552,7 +2547,7 @@ static int sdfat_unlink(struct inode *dir, struct dentry *dentry)
__lock_d_revalidate(dentry); __lock_d_revalidate(dentry);
dir->i_version++; INC_IVERSION(dir);
dir->i_mtime = dir->i_atime = ts; dir->i_mtime = dir->i_atime = ts;
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
(void) sdfat_sync_inode(dir); (void) sdfat_sync_inode(dir);
@ -2562,7 +2557,7 @@ static int sdfat_unlink(struct inode *dir, struct dentry *dentry)
clear_nlink(inode); clear_nlink(inode);
inode->i_mtime = inode->i_atime = ts; inode->i_mtime = inode->i_atime = ts;
sdfat_detach(inode); sdfat_detach(inode);
dentry->d_time = dir->i_version; dentry->d_time = GET_IVERSION(dir);
out: out:
__unlock_d_revalidate(dentry); __unlock_d_revalidate(dentry);
__unlock_super(sb); __unlock_super(sb);
@ -2574,7 +2569,7 @@ static int sdfat_symlink(struct inode *dir, struct dentry *dentry, const char *t
{ {
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
struct inode *inode; struct inode *inode;
struct timespec ts; struct timespec_compat ts;
FILE_ID_T fid; FILE_ID_T fid;
loff_t i_pos; loff_t i_pos;
int err; int err;
@ -2604,7 +2599,7 @@ static int sdfat_symlink(struct inode *dir, struct dentry *dentry, const char *t
__lock_d_revalidate(dentry); __lock_d_revalidate(dentry);
dir->i_version++; INC_IVERSION(dir);
dir->i_ctime = dir->i_mtime = dir->i_atime = ts; dir->i_ctime = dir->i_mtime = dir->i_atime = ts;
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
(void) sdfat_sync_inode(dir); (void) sdfat_sync_inode(dir);
@ -2617,7 +2612,7 @@ static int sdfat_symlink(struct inode *dir, struct dentry *dentry, const char *t
err = PTR_ERR(inode); err = PTR_ERR(inode);
goto out; goto out;
} }
inode->i_version++; INC_IVERSION(inode);
inode->i_mtime = inode->i_atime = inode->i_ctime = ts; inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
/* timestamp is already written, so mark_inode_dirty() is unneeded. */ /* timestamp is already written, so mark_inode_dirty() is unneeded. */
@ -2641,7 +2636,7 @@ static int __sdfat_mkdir(struct inode *dir, struct dentry *dentry)
{ {
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
struct inode *inode; struct inode *inode;
struct timespec ts; struct timespec_compat ts;
FILE_ID_T fid; FILE_ID_T fid;
loff_t i_pos; loff_t i_pos;
int err; int err;
@ -2658,7 +2653,7 @@ static int __sdfat_mkdir(struct inode *dir, struct dentry *dentry)
__lock_d_revalidate(dentry); __lock_d_revalidate(dentry);
dir->i_version++; INC_IVERSION(dir);
dir->i_ctime = dir->i_mtime = dir->i_atime = ts; dir->i_ctime = dir->i_mtime = dir->i_atime = ts;
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
(void) sdfat_sync_inode(dir); (void) sdfat_sync_inode(dir);
@ -2672,7 +2667,7 @@ static int __sdfat_mkdir(struct inode *dir, struct dentry *dentry)
err = PTR_ERR(inode); err = PTR_ERR(inode);
goto out; goto out;
} }
inode->i_version++; INC_IVERSION(inode);
inode->i_mtime = inode->i_atime = inode->i_ctime = ts; inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
/* timestamp is already written, so mark_inode_dirty() is unneeded. */ /* timestamp is already written, so mark_inode_dirty() is unneeded. */
@ -2692,7 +2687,7 @@ static int sdfat_rmdir(struct inode *dir, struct dentry *dentry)
{ {
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
struct timespec ts; struct timespec_compat ts;
int err; int err;
__lock_super(sb); __lock_super(sb);
@ -2709,7 +2704,7 @@ static int sdfat_rmdir(struct inode *dir, struct dentry *dentry)
__lock_d_revalidate(dentry); __lock_d_revalidate(dentry);
dir->i_version++; INC_IVERSION(dir);
dir->i_mtime = dir->i_atime = ts; dir->i_mtime = dir->i_atime = ts;
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
(void) sdfat_sync_inode(dir); (void) sdfat_sync_inode(dir);
@ -2720,7 +2715,7 @@ static int sdfat_rmdir(struct inode *dir, struct dentry *dentry)
clear_nlink(inode); clear_nlink(inode);
inode->i_mtime = inode->i_atime = ts; inode->i_mtime = inode->i_atime = ts;
sdfat_detach(inode); sdfat_detach(inode);
dentry->d_time = dir->i_version; dentry->d_time = GET_IVERSION(dir);
out: out:
__unlock_d_revalidate(dentry); __unlock_d_revalidate(dentry);
__unlock_super(sb); __unlock_super(sb);
@ -2733,7 +2728,7 @@ static int __sdfat_rename(struct inode *old_dir, struct dentry *old_dentry,
{ {
struct inode *old_inode, *new_inode; struct inode *old_inode, *new_inode;
struct super_block *sb = old_dir->i_sb; struct super_block *sb = old_dir->i_sb;
struct timespec ts; struct timespec_compat ts;
loff_t i_pos; loff_t i_pos;
int err; int err;
@ -2757,7 +2752,7 @@ static int __sdfat_rename(struct inode *old_dir, struct dentry *old_dentry,
__lock_d_revalidate(old_dentry); __lock_d_revalidate(old_dentry);
__lock_d_revalidate(new_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 = ts; new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime = ts;
if (IS_DIRSYNC(new_dir)) if (IS_DIRSYNC(new_dir))
(void) sdfat_sync_inode(new_dir); (void) sdfat_sync_inode(new_dir);
@ -2778,7 +2773,7 @@ static int __sdfat_rename(struct inode *old_dir, struct dentry *old_dentry,
inc_nlink(new_dir); inc_nlink(new_dir);
} }
old_dir->i_version++; INC_IVERSION(old_dir);
old_dir->i_ctime = old_dir->i_mtime = ts; old_dir->i_ctime = old_dir->i_mtime = ts;
if (IS_DIRSYNC(old_dir)) if (IS_DIRSYNC(old_dir))
(void) sdfat_sync_inode(old_dir); (void) sdfat_sync_inode(old_dir);
@ -3716,7 +3711,7 @@ static int sdfat_check_writable(struct super_block *sb)
if (fsapi_check_bdi_valid(sb)) if (fsapi_check_bdi_valid(sb))
return -EIO; return -EIO;
if (sb->s_flags & MS_RDONLY) if (SDFAT_IS_SB_RDONLY(sb))
return -EROFS; return -EROFS;
return 0; return 0;
@ -3899,7 +3894,7 @@ static int sdfat_fill_inode(struct inode *inode, const FILE_ID_T *fid)
SDFAT_I(inode)->target = NULL; SDFAT_I(inode)->target = NULL;
inode->i_uid = sbi->options.fs_uid; inode->i_uid = sbi->options.fs_uid;
inode->i_gid = sbi->options.fs_gid; inode->i_gid = sbi->options.fs_gid;
inode->i_version++; INC_IVERSION(inode);
inode->i_generation = get_seconds(); inode->i_generation = get_seconds();
if (fsapi_read_inode(inode, &info) < 0) { if (fsapi_read_inode(inode, &info) < 0) {
@ -3977,7 +3972,7 @@ static struct inode *sdfat_build_inode(struct super_block *sb,
goto out; goto out;
} }
inode->i_ino = iunique(sb, SDFAT_ROOT_INO); inode->i_ino = iunique(sb, SDFAT_ROOT_INO);
inode->i_version = 1; SET_IVERSION(inode, 1);
err = sdfat_fill_inode(inode, fid); err = sdfat_fill_inode(inode, fid);
if (err) { if (err) {
iput(inode); iput(inode);
@ -4145,7 +4140,7 @@ static void sdfat_write_super(struct super_block *sb)
/* flush delayed FAT/DIR dirty */ /* flush delayed FAT/DIR dirty */
__flush_delayed_meta(sb, 0); __flush_delayed_meta(sb, 0);
if (!(sb->s_flags & MS_RDONLY)) if (!SDFAT_IS_SB_RDONLY(sb))
fsapi_sync_fs(sb, 0); fsapi_sync_fs(sb, 0);
__unlock_super(sb); __unlock_super(sb);
@ -4285,7 +4280,11 @@ static int sdfat_remount(struct super_block *sb, int *flags, char *data)
struct sdfat_sb_info *sbi = SDFAT_SB(sb); struct sdfat_sb_info *sbi = SDFAT_SB(sb);
FS_INFO_T *fsi = &(sbi->fsi); FS_INFO_T *fsi = &(sbi->fsi);
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
*flags |= MS_NODIRATIME; *flags |= MS_NODIRATIME;
#else
*flags |= SB_NODIRATIME;
#endif
prev_sb_flags = sb->s_flags; prev_sb_flags = sb->s_flags;
@ -4294,8 +4293,13 @@ static int sdfat_remount(struct super_block *sb, int *flags, char *data)
fsapi_set_vol_flags(sb, VOL_CLEAN, 1); fsapi_set_vol_flags(sb, VOL_CLEAN, 1);
sdfat_log_msg(sb, KERN_INFO, "re-mounted(%s->%s), eio=0x%x, Opts: %s", sdfat_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", (prev_sb_flags & MS_RDONLY) ? "ro" : "rw",
(*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); fsi->prev_eio, orig_data);
kfree(orig_data); kfree(orig_data);
return 0; return 0;
@ -4797,7 +4801,7 @@ static int sdfat_read_root(struct inode *inode)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
struct sdfat_sb_info *sbi = SDFAT_SB(sb); struct sdfat_sb_info *sbi = SDFAT_SB(sb);
struct timespec ts; struct timespec_compat ts;
FS_INFO_T *fsi = &(sbi->fsi); FS_INFO_T *fsi = &(sbi->fsi);
DIR_ENTRY_T info; DIR_ENTRY_T info;
@ -4823,7 +4827,7 @@ static int sdfat_read_root(struct inode *inode)
inode->i_uid = sbi->options.fs_uid; inode->i_uid = sbi->options.fs_uid;
inode->i_gid = sbi->options.fs_gid; inode->i_gid = sbi->options.fs_gid;
inode->i_version++; INC_IVERSION(inode);
inode->i_generation = 0; inode->i_generation = 0;
inode->i_mode = sdfat_make_mode(sbi, ATTR_SUBDIR, S_IRWXUGO); inode->i_mode = sdfat_make_mode(sbi, ATTR_SUBDIR, S_IRWXUGO);
inode->i_op = &sdfat_dir_inode_operations; inode->i_op = &sdfat_dir_inode_operations;
@ -4885,7 +4889,11 @@ static int sdfat_fill_super(struct super_block *sb, void *data, int silent)
mutex_init(&sbi->s_vlock); mutex_init(&sbi->s_vlock);
sb->s_fs_info = sbi; sb->s_fs_info = sbi;
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
sb->s_flags |= MS_NODIRATIME; sb->s_flags |= MS_NODIRATIME;
#else
sb->s_flags |= SB_NODIRATIME;
#endif
sb->s_magic = SDFAT_SUPER_MAGIC; sb->s_magic = SDFAT_SUPER_MAGIC;
sb->s_op = &sdfat_sops; sb->s_op = &sdfat_sops;
ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL, ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
@ -4947,7 +4955,7 @@ static int sdfat_fill_super(struct super_block *sb, void *data, int silent)
} }
root_inode->i_ino = SDFAT_ROOT_INO; root_inode->i_ino = SDFAT_ROOT_INO;
root_inode->i_version = 1; SET_IVERSION(root_inode, 1);
err = sdfat_read_root(root_inode); err = sdfat_read_root(root_inode);
if (err) { if (err) {

36
sdfat.h
View File

@ -33,6 +33,38 @@
#include "dfr.h" #include "dfr.h"
#endif #endif
/*************************************************************************
* 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
#else
#define timespec_compat timespec
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
#define CURRENT_TIME_SEC timespec64_trunc(current_kernel_time64(), NSEC_PER_SEC)
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
#define CURRENT_TIME_SEC timespec_trunc(current_kernel_time(), NSEC_PER_SEC)
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
#define SDFAT_IS_SB_RDONLY(sb) ((sb)->s_flags & MS_RDONLY)
#else
#define SDFAT_IS_SB_RDONLY(sb) ((sb)->s_flags & SB_RDONLY)
#endif
/* /*
* sdfat error flags * sdfat error flags
*/ */
@ -365,9 +397,9 @@ __sdfat_msg(struct super_block *sb, const char *lv, int st, const char *fmt, ...
#define sdfat_log_msg(sb, lv, fmt, args...) \ #define sdfat_log_msg(sb, lv, fmt, args...) \
__sdfat_msg(sb, lv, 1, fmt, ## args) __sdfat_msg(sb, lv, 1, fmt, ## args)
extern void sdfat_log_version(void); extern void sdfat_log_version(void);
extern void sdfat_time_fat2unix(struct sdfat_sb_info *sbi, struct timespec *ts, extern void sdfat_time_fat2unix(struct sdfat_sb_info *sbi, struct timespec_compat *ts,
DATE_TIME_T *tp); DATE_TIME_T *tp);
extern void sdfat_time_unix2fat(struct sdfat_sb_info *sbi, struct timespec *ts, extern void sdfat_time_unix2fat(struct sdfat_sb_info *sbi, struct timespec_compat *ts,
DATE_TIME_T *tp); DATE_TIME_T *tp);
extern TIMESTAMP_T *tm_now(struct sdfat_sb_info *sbi, TIMESTAMP_T *tm); extern TIMESTAMP_T *tm_now(struct sdfat_sb_info *sbi, TIMESTAMP_T *tm);