Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f65bdd3 authored by KNnut's avatar KNnut Committed by Andreas Schneider
Browse files

fs: sdfat: Fix compilation on Linux >= 4.16

parent d5b96952
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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,
	 * if this volume has been mounted with read-only
	 */
	if (sb->s_flags & MS_RDONLY)
	if (SDFAT_IS_SB_RDONLY(sb))
		return 0;

	if (!fsi->pbr_bh) {
@@ -1956,10 +1956,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;
	}

+2 −2
Original line number Diff line number Diff line
@@ -861,7 +861,7 @@ defrag_update_fat_prev(
	int skip = 0, done = 0;

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

	/* Check if FS_ERROR occurred */
	if (sb->s_flags & MS_RDONLY) {
	if (SDFAT_IS_SB_RDONLY(sb)) {
		dfr_err("RDONLY partition (err %d)", -EROFS);
		goto out;
	}
+9 −13
Original line number Diff line number Diff line
@@ -52,14 +52,6 @@
#define ST_LOG(fmt, ...)
#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
 * 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",
			sb->s_id, MAJOR(bd_dev), MINOR(bd_dev), &vaf);
#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",
				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) {
		panic("[SDFAT](%s[%d:%d]): fs panic from previous error\n",
			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;
#else
		sb->s_flags |= SB_RDONLY;
#endif
		sdfat_statistics_set_mnt_ro();
		pr_err("[SDFAT](%s[%d:%d]): Filesystem has been set "
			"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). */
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)
{
	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. */
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)
{
	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)
{
	struct timespec ts = CURRENT_TIME_SEC;
	struct timespec_compat ts = CURRENT_TIME_SEC;
	DATE_TIME_T dt;

	sdfat_time_unix2fat(sbi, &ts, &dt);
+41 −33
Original line number Diff line number Diff line
@@ -147,11 +147,6 @@ 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)
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
static int sdfat_getattr(const struct path *path, struct kstat *stat,
			u32 request_mask, unsigned int query_flags)
@@ -1220,7 +1215,7 @@ static int __sdfat_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);
@@ -2166,7 +2161,7 @@ static int sdfat_dfr_ioctl(struct inode *inode, struct file *filp,
		__lock_super(sb);

		/* Check if FS_ERROR occurred */
		if (sb->s_flags & MS_RDONLY) {
		if (SDFAT_IS_SB_RDONLY(sb)) {
			dfr_err("RDONLY partition (err %d)", -EPERM);
			__unlock_super(sb);
			return -EPERM;
@@ -2368,7 +2363,7 @@ static int __sdfat_create(struct inode *dir, struct dentry *dentry)
{
	struct super_block *sb = dir->i_sb;
	struct inode *inode;
	struct timespec ts;
	struct timespec_compat ts;
	FILE_ID_T fid;
	loff_t i_pos;
	int err;
@@ -2385,7 +2380,7 @@ static int __sdfat_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 = ts;
	if (IS_DIRSYNC(dir))
		(void) sdfat_sync_inode(dir);
@@ -2398,7 +2393,7 @@ static int __sdfat_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 = ts;
	/* 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);
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);
@@ -2533,7 +2528,7 @@ static int sdfat_unlink(struct inode *dir, struct dentry *dentry)
{
	struct inode *inode = dentry->d_inode;
	struct super_block *sb = dir->i_sb;
	struct timespec ts;
	struct timespec_compat ts;
	int err;

	__lock_super(sb);
@@ -2552,7 +2547,7 @@ static int sdfat_unlink(struct inode *dir, struct dentry *dentry)

	__lock_d_revalidate(dentry);

	dir->i_version++;
	INC_IVERSION(dir);
	dir->i_mtime = dir->i_atime = ts;
	if (IS_DIRSYNC(dir))
		(void) sdfat_sync_inode(dir);
@@ -2562,7 +2557,7 @@ static int sdfat_unlink(struct inode *dir, struct dentry *dentry)
	clear_nlink(inode);
	inode->i_mtime = inode->i_atime = ts;
	sdfat_detach(inode);
	dentry->d_time = dir->i_version;
	dentry->d_time = GET_IVERSION(dir);
out:
	__unlock_d_revalidate(dentry);
	__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 inode *inode;
	struct timespec ts;
	struct timespec_compat ts;
	FILE_ID_T fid;
	loff_t i_pos;
	int err;
@@ -2604,7 +2599,7 @@ static int sdfat_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 = ts;
	if (IS_DIRSYNC(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);
		goto out;
	}
	inode->i_version++;
	INC_IVERSION(inode);
	inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
	/* 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 inode *inode;
	struct timespec ts;
	struct timespec_compat ts;
	FILE_ID_T fid;
	loff_t i_pos;
	int err;
@@ -2658,7 +2653,7 @@ static int __sdfat_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 = ts;
	if (IS_DIRSYNC(dir))
		(void) sdfat_sync_inode(dir);
@@ -2672,7 +2667,7 @@ static int __sdfat_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 = ts;
	/* 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 super_block *sb = dir->i_sb;
	struct timespec ts;
	struct timespec_compat ts;
	int err;

	__lock_super(sb);
@@ -2709,7 +2704,7 @@ static int sdfat_rmdir(struct inode *dir, struct dentry *dentry)

	__lock_d_revalidate(dentry);

	dir->i_version++;
	INC_IVERSION(dir);
	dir->i_mtime = dir->i_atime = ts;
	if (IS_DIRSYNC(dir))
		(void) sdfat_sync_inode(dir);
@@ -2720,7 +2715,7 @@ static int sdfat_rmdir(struct inode *dir, struct dentry *dentry)
	clear_nlink(inode);
	inode->i_mtime = inode->i_atime = ts;
	sdfat_detach(inode);
	dentry->d_time = dir->i_version;
	dentry->d_time = GET_IVERSION(dir);
out:
	__unlock_d_revalidate(dentry);
	__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 super_block *sb = old_dir->i_sb;
	struct timespec ts;
	struct timespec_compat ts;
	loff_t i_pos;
	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(new_dentry);

	new_dir->i_version++;
	INC_IVERSION(new_dir);
	new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime = ts;
	if (IS_DIRSYNC(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);
	}

	old_dir->i_version++;
	INC_IVERSION(old_dir);
	old_dir->i_ctime = old_dir->i_mtime = ts;
	if (IS_DIRSYNC(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))
		return -EIO;

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

	return 0;
@@ -3899,7 +3894,7 @@ static int sdfat_fill_inode(struct inode *inode, const FILE_ID_T *fid)
	SDFAT_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) {
@@ -3977,7 +3972,7 @@ static struct inode *sdfat_build_inode(struct super_block *sb,
		goto out;
	}
	inode->i_ino = iunique(sb, SDFAT_ROOT_INO);
	inode->i_version = 1;
	SET_IVERSION(inode, 1);
	err = sdfat_fill_inode(inode, fid);
	if (err) {
		iput(inode);
@@ -4145,7 +4140,7 @@ static void sdfat_write_super(struct super_block *sb)
	/* flush delayed FAT/DIR dirty */
	__flush_delayed_meta(sb, 0);

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

	__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);
	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;

@@ -4294,8 +4293,13 @@ static int sdfat_remount(struct super_block *sb, int *flags, char *data)
	fsapi_set_vol_flags(sb, VOL_CLEAN, 1);

	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",
		(*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;
@@ -4797,7 +4801,7 @@ static int sdfat_read_root(struct inode *inode)
{
	struct super_block *sb = inode->i_sb;
	struct sdfat_sb_info *sbi = SDFAT_SB(sb);
	struct timespec ts;
	struct timespec_compat ts;
	FS_INFO_T *fsi = &(sbi->fsi);
	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_gid = sbi->options.fs_gid;
	inode->i_version++;
	INC_IVERSION(inode);
	inode->i_generation = 0;
	inode->i_mode = sdfat_make_mode(sbi, ATTR_SUBDIR, S_IRWXUGO);
	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);
	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 = SDFAT_SUPER_MAGIC;
	sb->s_op = &sdfat_sops;
	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_version = 1;
	SET_IVERSION(root_inode, 1);

	err = sdfat_read_root(root_inode);
	if (err) {
+34 −2
Original line number Diff line number Diff line
@@ -33,6 +33,38 @@
#include "dfr.h"
#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
 */
@@ -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...)          \
	__sdfat_msg(sb, lv, 1, fmt, ## args)
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);
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);
extern TIMESTAMP_T *tm_now(struct sdfat_sb_info *sbi, TIMESTAMP_T *tm);