diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 6587fd9..c161ede 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -17,10 +17,10 @@ jobs: run: | sudo apt-get update sudo apt-get install libelf-dev wget tar gzip python2.7 - wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.1.36.tar.gz - tar xf linux-4.1.36.tar.gz - mv linux-4.1.36 linux-stable - rm -rf linux-4.1.36.tar.gz + wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.15.140.tar.gz + tar xf linux-5.15.140.tar.gz + mv linux-5.15.140 linux-stable + rm -rf linux-5.15.140.tar.gz - name: Prerequisite for xfstests testing run: | sudo apt-get install linux-headers-$(uname -r) @@ -35,14 +35,11 @@ jobs: - name: Copy exfat source to kernel run: | mv linux-stable ../ - mkdir ../linux-stable/fs/exfat cp -ar * ../linux-stable/fs/exfat/ - - name: Compile with 4.1 kernel + - name: Compile with 5.15 kernel run: | cd ../linux-stable yes "" | make oldconfig > /dev/null - echo 'obj-$(CONFIG_EXFAT_FS) += exfat/' >> fs/Makefile - echo 'source "fs/exfat/Kconfig"' >> fs/Kconfig echo 'CONFIG_EXFAT_FS=m' >> .config echo 'CONFIG_EXFAT_DEFAULT_IOCHARSET="utf8"' >> .config make -j$((`nproc`+1)) fs/exfat/exfat.ko diff --git a/README.md b/README.md index cee3699..1992f42 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ## exFAT filesystem -This is the exfat filesystem for support from the linux 4.1 kernel +This is the exfat filesystem for support from the linux 5.15 kernel to the latest kernel. ## Installing as a stand-alone module diff --git a/balloc.c b/balloc.c index c226d5d..71814b0 100644 --- a/balloc.c +++ b/balloc.c @@ -7,11 +7,7 @@ #include #include #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) #include -#else -#include -#endif #include #include "exfat_raw.h" @@ -76,12 +72,8 @@ static int exfat_allocate_bitmap(struct super_block *sb, } sbi->map_sectors = ((need_map_size - 1) >> (sb->s_blocksize_bits)) + 1; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) sbi->vol_amap = kvmalloc_array(sbi->map_sectors, sizeof(struct buffer_head *), GFP_KERNEL); -#else - sbi->vol_amap = vmalloc(sbi->map_sectors * sizeof(struct buffer_head *)); -#endif if (!sbi->vol_amap) return -ENOMEM; diff --git a/dir.c b/dir.c index 4d5b863..7ac26d0 100644 --- a/dir.c +++ b/dir.c @@ -461,19 +461,11 @@ int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir, { struct super_block *sb = inode->i_sb; struct exfat_sb_info *sbi = EXFAT_SB(sb); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) struct timespec64 ts; -#else - struct timespec ts; -#endif struct exfat_dentry *ep; struct buffer_head *bh; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) ts = current_time(inode); -#else - ts = CURRENT_TIME_SEC; -#endif /* * We cannot use exfat_get_dentry_set here because file ep is not diff --git a/exfat_fs.h b/exfat_fs.h index 124dfd5..62bb7b9 100644 --- a/exfat_fs.h +++ b/exfat_fs.h @@ -222,15 +222,9 @@ struct exfat_dir_entry { unsigned short attr; loff_t size; unsigned int num_subdirs; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) struct timespec64 atime; struct timespec64 mtime; struct timespec64 crtime; -#else - struct timespec atime; - struct timespec mtime; - struct timespec crtime; -#endif struct exfat_dentry_namebuf namebuf; }; @@ -344,11 +338,7 @@ struct exfat_inode_info { struct rw_semaphore truncate_lock; struct inode vfs_inode; /* File creation time */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) struct timespec64 i_crtime; -#else - struct timespec i_crtime; -#endif }; static inline struct exfat_sb_info *EXFAT_SB(struct super_block *sb) @@ -478,7 +468,6 @@ extern const struct file_operations exfat_file_operations; int __exfat_truncate(struct inode *inode); void exfat_truncate(struct inode *inode); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) int exfat_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr); @@ -492,16 +481,6 @@ int exfat_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat, unsigned int request_mask, unsigned int query_flags); #endif -#else -int exfat_setattr(struct dentry *dentry, struct iattr *attr); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) -int exfat_getattr(const struct path *path, struct kstat *stat, - unsigned int request_mask, unsigned int query_flags); -#else -int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry, - struct kstat *stat); -#endif -#endif int exfat_file_fsync(struct file *file, loff_t start, loff_t end, int datasync); long exfat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); long exfat_compat_ioctl(struct file *filp, unsigned int cmd, @@ -594,7 +573,6 @@ void __exfat_fs_error(struct super_block *sb, int report, const char *fmt, ...) #define exfat_debug(sb, fmt, ...) \ pr_debug("exFAT-fs (%s): " fmt "\n", (sb)->s_id, ##__VA_ARGS__) -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts, u8 tz, __le16 time, __le16 date, u8 time_cs); void exfat_truncate_atime(struct timespec64 *ts); @@ -603,13 +581,6 @@ void exfat_truncate_inode_atime(struct inode *inode); #endif void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts, u8 *tz, __le16 *time, __le16 *date, u8 *time_cs); -#else -void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec *ts, - u8 tz, __le16 time, __le16 date, u8 time_cs); -void exfat_truncate_atime(struct timespec *ts); -void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec *ts, - u8 *tz, __le16 *time, __le16 *date, u8 *time_cs); -#endif u16 exfat_calc_chksum16(void *data, int len, u16 chksum, int type); u32 exfat_calc_chksum32(void *data, int len, u32 chksum, int type); void exfat_update_bh(struct buffer_head *bh, int sync); diff --git a/fatent.c b/fatent.c index c13a04e..81f03ea 100644 --- a/fatent.c +++ b/fatent.c @@ -27,11 +27,7 @@ static int exfat_mirror_bh(struct super_block *sb, sector_t sec, memcpy(c_bh->b_data, bh->b_data, sb->s_blocksize); set_buffer_uptodate(c_bh); mark_buffer_dirty(c_bh); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) if (sb->s_flags & SB_SYNCHRONOUS) -#else - if (sb->s_flags & MS_SYNCHRONOUS) -#endif err = sync_dirty_buffer(c_bh); brelse(c_bh); } @@ -80,11 +76,7 @@ int exfat_ent_set(struct super_block *sb, unsigned int loc, fat_entry = (__le32 *)&(bh->b_data[off]); *fat_entry = cpu_to_le32(content); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS); -#else - exfat_update_bh(bh, sb->s_flags & MS_SYNCHRONOUS); -#endif exfat_mirror_bh(sb, sec, bh); brelse(bh); return 0; diff --git a/file.c b/file.c index 749c349..ef9b199 100644 --- a/file.c +++ b/file.c @@ -6,9 +6,7 @@ #include #include #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) #include -#endif #include #include #include @@ -29,7 +27,6 @@ static int exfat_cont_expand(struct inode *inode, loff_t size) if (err) return err; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); @@ -38,9 +35,6 @@ static int exfat_cont_expand(struct inode *inode, loff_t size) #endif #else inode->i_ctime = inode->i_mtime = current_time(inode); -#endif -#else - inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC; #endif mark_inode_dirty(inode); @@ -211,11 +205,7 @@ void exfat_truncate(struct inode *inode) struct super_block *sb = inode->i_sb; struct exfat_sb_info *sbi = EXFAT_SB(sb); struct exfat_inode_info *ei = EXFAT_I(inode); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 72) unsigned int blocksize = i_blocksize(inode); -#else - unsigned int blocksize = 1 << inode->i_blkbits; -#endif loff_t aligned_size; int err; @@ -248,7 +238,6 @@ void exfat_truncate(struct inode *inode) mutex_unlock(&sbi->s_lock); } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) int exfat_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, unsigned int request_mask, @@ -258,24 +247,10 @@ int exfat_getattr(struct user_namespace *mnt_uerns, const struct path *path, struct kstat *stat, unsigned int request_mask, unsigned int query_flags) #endif -#else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) -int exfat_getattr(const struct path *path, struct kstat *stat, - unsigned int request_mask, unsigned int query_flags) -#else -int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry, - struct kstat *stat) -#endif -#endif { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) struct inode *inode = d_backing_inode(path->dentry); struct exfat_inode_info *ei = EXFAT_I(inode); -#else - struct inode *inode = d_inode(dentry); -#endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat); @@ -284,21 +259,15 @@ int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry, #endif #else generic_fillattr(&init_user_ns, inode, stat); -#endif -#else - generic_fillattr(inode, stat); #endif exfat_truncate_atime(&stat->atime); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) stat->result_mask |= STATX_BTIME; stat->btime.tv_sec = ei->i_crtime.tv_sec; stat->btime.tv_nsec = ei->i_crtime.tv_nsec; -#endif stat->blksize = EXFAT_SB(inode->i_sb)->cluster_size; return 0; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) int exfat_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr) @@ -306,9 +275,6 @@ int exfat_setattr(struct mnt_idmap *idmap, struct dentry *dentry, int exfat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, struct iattr *attr) #endif -#else -int exfat_setattr(struct dentry *dentry, struct iattr *attr) -#endif { struct exfat_sb_info *sbi = EXFAT_SB(dentry->d_sb); struct inode *inode = dentry->d_inode; @@ -331,20 +297,10 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr) ATTR_TIMES_SET); } -#if ((LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)) && \ - (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 37))) || \ - (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)) -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) error = setattr_prepare(&nop_mnt_idmap, dentry, attr); #else error = setattr_prepare(&init_user_ns, dentry, attr); -#endif -#else - error = setattr_prepare(dentry, attr); -#endif -#else - error = inode_change_ok(inode, attr); #endif attr->ia_valid = ia_valid; if (error) @@ -370,7 +326,6 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr) } if (attr->ia_valid & ATTR_SIZE) -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); @@ -380,22 +335,15 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr) #else inode->i_mtime = inode->i_ctime = current_time(inode); #endif -#else - inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; -#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) setattr_copy(&nop_mnt_idmap, inode, attr); exfat_truncate_inode_atime(inode); #else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) setattr_copy(&nop_mnt_idmap, inode, attr); #else setattr_copy(&init_user_ns, inode, attr); -#endif -#else - setattr_copy(inode, attr); #endif exfat_truncate_atime(&inode->i_atime); #endif @@ -426,17 +374,9 @@ static int exfat_ioctl_get_attributes(struct inode *inode, u32 __user *user_attr { u32 attr; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) inode_lock_shared(inode); -#else - mutex_lock(&inode->i_mutex); -#endif attr = exfat_make_attr(inode); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) inode_unlock_shared(inode); -#else - mutex_unlock(&inode->i_mutex); -#endif return put_user(attr, user_attr); } @@ -458,11 +398,7 @@ static int exfat_ioctl_set_attributes(struct file *file, u32 __user *user_attr) if (err) goto out; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) inode_lock(inode); -#else - mutex_lock(&inode->i_mutex); -#endif oldattr = exfat_make_attr(inode); @@ -475,11 +411,7 @@ static int exfat_ioctl_set_attributes(struct file *file, u32 __user *user_attr) /* Equivalent to a chmod() */ ia.ia_valid = ATTR_MODE | ATTR_CTIME; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) ia.ia_ctime = current_time(inode); -#else - ia.ia_ctime = current_fs_time(inode->i_sb); -#endif if (is_dir) ia.ia_mode = exfat_make_mode(sbi, attr, 0777); else @@ -516,15 +448,11 @@ static int exfat_ioctl_set_attributes(struct file *file, u32 __user *user_attr) if (err) goto out_unlock_inode; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) /* This MUST be done before doing anything irreversible... */ err = exfat_setattr(file_mnt_idmap(file), file->f_path.dentry, &ia); #else err = exfat_setattr(file_mnt_user_ns(file), file->f_path.dentry, &ia); -#endif -#else - err = exfat_setattr(file->f_path.dentry, &ia); #endif if (err) goto out_unlock_inode; @@ -534,11 +462,7 @@ static int exfat_ioctl_set_attributes(struct file *file, u32 __user *user_attr) exfat_save_attr(inode, attr); mark_inode_dirty(inode); out_unlock_inode: -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) inode_unlock(inode); -#else - mutex_unlock(&inode->i_mutex); -#endif mnt_drop_write_file(file); out: return err; @@ -621,15 +545,7 @@ int exfat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync) if (err) return err; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) return blkdev_issue_flush(inode->i_sb->s_bdev); -#else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0) - return blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL); -#else - return blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL); -#endif -#endif } const struct file_operations exfat_file_operations = { diff --git a/inode.c b/inode.c index 479db42..4149801 100644 --- a/inode.c +++ b/inode.c @@ -13,9 +13,7 @@ #include #include #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) #include -#endif #include "exfat_raw.h" #include "exfat_fs.h" @@ -365,18 +363,10 @@ static int exfat_readpage(struct file *file, struct page *page) } #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0) static void exfat_readahead(struct readahead_control *rac) { mpage_readahead(rac, exfat_get_block); } -#else -static int exfat_readpages(struct file *file, struct address_space *mapping, - struct list_head *pages, unsigned int nr_pages) -{ - return mpage_readpages(mapping, pages, nr_pages, exfat_get_block); -} -#endif #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0) static int exfat_writepage(struct page *page, struct writeback_control *wbc) @@ -397,7 +387,6 @@ static void exfat_write_failed(struct address_space *mapping, loff_t to) if (to > i_size_read(inode)) { truncate_pagecache(inode, i_size_read(inode)); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); @@ -406,9 +395,6 @@ static void exfat_write_failed(struct address_space *mapping, loff_t to) #endif #else inode->i_mtime = inode->i_ctime = current_time(inode); -#endif -#else - inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; #endif exfat_truncate(inode); } @@ -463,7 +449,6 @@ static int exfat_write_end(struct file *file, struct address_space *mapping, exfat_write_failed(mapping, pos+len); if (!(err < 0) && !(ei->attr & EXFAT_ATTR_ARCHIVE)) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); @@ -472,9 +457,6 @@ static int exfat_write_end(struct file *file, struct address_space *mapping, #endif #else inode->i_mtime = inode->i_ctime = current_time(inode); -#endif -#else - inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; #endif ei->attr |= EXFAT_ATTR_ARCHIVE; mark_inode_dirty(inode); @@ -484,12 +466,7 @@ static int exfat_write_end(struct file *file, struct address_space *mapping, } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) static ssize_t exfat_direct_IO(struct kiocb *iocb, struct iov_iter *iter) -#else -static ssize_t exfat_direct_IO(struct kiocb *iocb, struct iov_iter *iter, - loff_t offset) -#endif { struct address_space *mapping = iocb->ki_filp->f_mapping; struct inode *inode = mapping->host; @@ -515,11 +492,7 @@ static ssize_t exfat_direct_IO(struct kiocb *iocb, struct iov_iter *iter, * Need to use the DIO_LOCKING for avoiding the race * condition of exfat_get_block() and ->truncate(). */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) ret = blockdev_direct_IO(iocb, inode, iter, exfat_get_block); -#else - ret = blockdev_direct_IO(iocb, inode, iter, offset, exfat_get_block); -#endif if (ret < 0 && (rw & WRITE)) exfat_write_failed(mapping, size); return ret; @@ -562,11 +535,7 @@ static const struct address_space_operations exfat_aops = { #else .readpage = exfat_readpage, #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0) .readahead = exfat_readahead, -#else - .readpages = exfat_readpages, -#endif #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0) .writepage = exfat_writepage, #endif @@ -652,11 +621,7 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info) inode->i_uid = sbi->options.fs_uid; inode->i_gid = sbi->options.fs_gid; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_inc_iversion(inode); -#else - inode->i_version++; -#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) inode->i_generation = get_random_u32(); #else @@ -727,11 +692,7 @@ struct inode *exfat_build_inode(struct super_block *sb, goto out; } inode->i_ino = iunique(sb, EXFAT_ROOT_INO); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_set_iversion(inode, 1); -#else - inode->i_version = 1; -#endif err = exfat_fill_inode(inode, info); if (err) { iput(inode); diff --git a/misc.c b/misc.c index a744a1f..6a9a488 100644 --- a/misc.c +++ b/misc.c @@ -40,14 +40,8 @@ void __exfat_fs_error(struct super_block *sb, int report, const char *fmt, ...) if (opts->errors == EXFAT_ERRORS_PANIC) { panic("exFAT-fs (%s): fs panic from previous error\n", sb->s_id); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) } else if (opts->errors == EXFAT_ERRORS_RO && !sb_rdonly(sb)) { sb->s_flags |= SB_RDONLY; -#else - } else if (opts->errors == EXFAT_ERRORS_RO && - !(sb->s_flags & MS_RDONLY)) { - sb->s_flags |= MS_RDONLY; -#endif exfat_err(sb, "Filesystem has been set read-only"); } } @@ -55,11 +49,7 @@ void __exfat_fs_error(struct super_block *sb, int report, const char *fmt, ...) #define SECS_PER_MIN (60) #define TIMEZONE_SEC(x) ((x) * 15 * SECS_PER_MIN) -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) static void exfat_adjust_tz(struct timespec64 *ts, u8 tz_off) -#else -static void exfat_adjust_tz(struct timespec *ts, u8 tz_off) -#endif { if (tz_off <= 0x3F) ts->tv_sec -= TIMEZONE_SEC(tz_off); @@ -75,13 +65,8 @@ static inline int exfat_tz_offset(struct exfat_sb_info *sbi) } /* Convert a EXFAT time/date pair to a UNIX date (seconds since 1 1 70). */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts, u8 tz, __le16 time, __le16 date, u8 time_cs) -#else -void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec *ts, - u8 tz, __le16 time, __le16 date, u8 time_cs) -#endif { u16 t = le16_to_cpu(time); u16 d = le16_to_cpu(date); @@ -105,35 +90,13 @@ void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec *ts, } /* Convert linear UNIX date to a EXFAT time/date pair. */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts, u8 *tz, __le16 *time, __le16 *date, u8 *time_cs) -#else -#undef EXFAT_MAX_TIMESTAMP_SECS -#define EXFAT_MAX_TIMESTAMP_SECS 0xffffffff -void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec *ts, - u8 *tz, __le16 *time, __le16 *date, u8 *time_cs) -#endif { struct tm tm; u16 t, d; -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) - if (ts->tv_sec < EXFAT_MIN_TIMESTAMP_SECS) { - ts->tv_sec = EXFAT_MIN_TIMESTAMP_SECS; - ts->tv_nsec = 0; - } - else if (ts->tv_sec > EXFAT_MAX_TIMESTAMP_SECS) { - ts->tv_sec = EXFAT_MAX_TIMESTAMP_SECS; - ts->tv_nsec = 0; - } -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) time64_to_tm(ts->tv_sec, 0, &tm); -#else - time_to_tm(ts->tv_sec, 0, &tm); -#endif t = (tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1); d = ((tm.tm_year - 80) << 9) | ((tm.tm_mon + 1) << 5) | tm.tm_mday; @@ -153,11 +116,7 @@ void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec *ts, } /* atime has only a 2-second resolution */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) void exfat_truncate_atime(struct timespec64 *ts) -#else -void exfat_truncate_atime(struct timespec *ts) -#endif { ts->tv_sec = round_down(ts->tv_sec, 2); ts->tv_nsec = 0; @@ -217,11 +176,7 @@ int exfat_update_bhs(struct buffer_head **bhs, int nr_bhs, int sync) set_buffer_uptodate(bhs[i]); mark_buffer_dirty(bhs[i]); if (sync) -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) write_dirty_buffer(bhs[i], REQ_SYNC); -#else - write_dirty_buffer(bhs[i], WRITE_SYNC); -#endif } for (i = 0; i < nr_bhs && sync; i++) { diff --git a/namei.c b/namei.c index ef9a6df..52c437e 100644 --- a/namei.c +++ b/namei.c @@ -4,9 +4,7 @@ */ #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) #include -#endif #include #include #include @@ -62,13 +60,8 @@ static int exfat_d_revalidate(struct dentry *dentry, unsigned int flags) return 0; spin_lock(&dentry->d_lock); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) ret = inode_eq_iversion(d_inode(dentry->d_parent), exfat_d_version(dentry)); -#else - if (dentry->d_parent->d_inode->i_version != exfat_d_version(dentry)) - ret = 0; -#endif spin_unlock(&dentry->d_lock); return ret; } @@ -96,11 +89,7 @@ static int exfat_d_hash(const struct dentry *dentry, struct qstr *qstr) const unsigned char *name = qstr->name; unsigned int len = exfat_striptail_len(qstr->len, qstr->name, EXFAT_SB(sb)->options.keep_last_dots); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) unsigned long hash = init_name_hash(dentry); -#else - unsigned long hash = init_name_hash(); -#endif int i, charlen; wchar_t c; @@ -115,13 +104,8 @@ static int exfat_d_hash(const struct dentry *dentry, struct qstr *qstr) return 0; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) static int exfat_d_cmp(const struct dentry *dentry, unsigned int len, const char *str, const struct qstr *name) -#else -static int exfat_d_cmp(const struct dentry *parent, const struct dentry *dentry, - unsigned int len, const char *str, const struct qstr *name) -#endif { struct super_block *sb = dentry->d_sb; struct nls_table *t = EXFAT_SB(sb)->nls_io; @@ -161,11 +145,7 @@ static int exfat_utf8_d_hash(const struct dentry *dentry, struct qstr *qstr) const unsigned char *name = qstr->name; unsigned int len = exfat_striptail_len(qstr->len, qstr->name, EXFAT_SB(sb)->options.keep_last_dots); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) unsigned long hash = init_name_hash(dentry); -#else - unsigned long hash = init_name_hash(); -#endif int i, charlen; unicode_t u; @@ -185,14 +165,8 @@ static int exfat_utf8_d_hash(const struct dentry *dentry, struct qstr *qstr) return 0; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) static int exfat_utf8_d_cmp(const struct dentry *dentry, unsigned int len, const char *str, const struct qstr *name) -#else -static int exfat_utf8_d_cmp(const struct dentry *parent, - const struct dentry *dentry, unsigned int len, - const char *str, const struct qstr *name) -#endif { struct super_block *sb = dentry->d_sb; unsigned int alen = exfat_striptail_len(name->len, name->name, @@ -592,7 +566,6 @@ static int exfat_add_entry(struct inode *inode, const char *path, return ret; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) static int exfat_create(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) @@ -600,10 +573,6 @@ static int exfat_create(struct mnt_idmap *idmap, struct inode *dir, static int exfat_create(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) #endif -#else -static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode, - bool excl) -#endif { struct super_block *sb = dir->i_sb; struct inode *inode; @@ -619,12 +588,7 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode, if (err) goto unlock; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_inc_iversion(dir); -#else - dir->i_version++; -#endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); @@ -633,9 +597,6 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode, #endif #else dir->i_ctime = dir->i_mtime = current_time(dir); -#endif -#else - dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; #endif if (IS_DIRSYNC(dir)) exfat_sync_inode(dir); @@ -648,26 +609,17 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode, if (err) goto unlock; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_inc_iversion(inode); -#else - inode->i_version++; -#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) EXFAT_I(inode)->i_crtime = simple_inode_init_ts(inode); exfat_truncate_inode_atime(inode); #else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) inode->i_mtime = inode->i_atime = EXFAT_I(inode)->i_crtime = inode_set_ctime_current(inode); #else inode->i_mtime = inode->i_atime = inode->i_ctime = EXFAT_I(inode)->i_crtime = current_time(inode); -#endif -#else - inode->i_mtime = inode->i_atime = inode->i_ctime = - EXFAT_I(inode)->i_crtime = CURRENT_TIME_SEC; #endif exfat_truncate_atime(&inode->i_atime); #endif @@ -703,18 +655,10 @@ static int exfat_find(struct inode *dir, struct qstr *qname, return ret; /* check the validation of hint_stat and initialize it if required */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) if (ei->version != (inode_peek_iversion_raw(dir) & 0xffffffff)) { -#else - if (ei->version != (dir->i_version & 0xffffffff)) { -#endif ei->hint_stat.clu = cdir.dir; ei->hint_stat.eidx = 0; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) ei->version = (inode_peek_iversion_raw(dir) & 0xffffffff); -#else - ei->version = (dir->i_version & 0xffffffff); -#endif ei->hint_femp.eidx = EXFAT_HINT_NONE; } @@ -858,11 +802,7 @@ static struct dentry *exfat_lookup(struct inode *dir, struct dentry *dentry, out: mutex_unlock(&EXFAT_SB(sb)->s_lock); if (!inode) -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) exfat_d_version_set(dentry, inode_query_iversion(dir)); -#else - exfat_d_version_set(dentry, dir->i_version); -#endif return d_splice_alias(inode, dentry); unlock: @@ -914,24 +854,16 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry) /* This doesn't modify ei */ ei->dir.dir = DIR_DELETED; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_inc_iversion(dir); -#else - dir->i_version++; -#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) simple_inode_init_ts(dir); exfat_truncate_inode_atime(dir); #else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) dir->i_mtime = dir->i_atime = inode_set_ctime_current(dir); #else dir->i_mtime = dir->i_atime = dir->i_ctime = current_time(dir); -#endif -#else - dir->i_mtime = dir->i_atime = dir->i_ctime = CURRENT_TIME_SEC; #endif exfat_truncate_atime(&dir->i_atime); #endif @@ -945,29 +877,20 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry) simple_inode_init_ts(inode); exfat_truncate_inode_atime(inode); #else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) inode->i_mtime = inode->i_atime = inode_set_ctime_current(inode); #else inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); -#endif -#else - inode->i_mtime = inode->i_atime = dir->i_ctime = CURRENT_TIME_SEC; #endif exfat_truncate_atime(&inode->i_atime); #endif exfat_unhash_inode(inode); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) exfat_d_version_set(dentry, inode_query_iversion(dir)); -#else - exfat_d_version_set(dentry, dir->i_version); -#endif unlock: mutex_unlock(&EXFAT_SB(sb)->s_lock); return err; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) static int exfat_mkdir(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode) @@ -975,9 +898,6 @@ static int exfat_mkdir(struct mnt_idmap *idmap, struct inode *dir, static int exfat_mkdir(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode) #endif -#else -static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) -#endif { struct super_block *sb = dir->i_sb; struct inode *inode; @@ -993,13 +913,8 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) if (err) goto unlock; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_inc_iversion(dir); -#else - dir->i_version++; -#endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); @@ -1008,9 +923,6 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) #endif #else dir->i_ctime = dir->i_mtime = current_time(dir); -#endif -#else - dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; #endif if (IS_DIRSYNC(dir)) exfat_sync_inode(dir); @@ -1024,25 +936,16 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) if (err) goto unlock; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_inc_iversion(inode); -#else - inode->i_version++; -#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) EXFAT_I(inode)->i_crtime = simple_inode_init_ts(inode); exfat_truncate_inode_atime(inode); #else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) inode->i_mtime = inode->i_atime = EXFAT_I(inode)->i_crtime = inode_set_ctime_current(inode); #else inode->i_mtime = inode->i_atime = inode->i_ctime = EXFAT_I(inode)->i_crtime = current_time(inode); -#endif -#else - inode->i_mtime = inode->i_atime = inode->i_ctime = - EXFAT_I(inode)->i_crtime = CURRENT_TIME_SEC; #endif exfat_truncate_atime(&inode->i_atime); #endif @@ -1158,23 +1061,15 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry) } ei->dir.dir = DIR_DELETED; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_inc_iversion(dir); -#else - dir->i_version++; -#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) simple_inode_init_ts(dir); exfat_truncate_inode_atime(dir); #else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) dir->i_mtime = dir->i_atime = inode_set_ctime_current(dir); #else dir->i_mtime = dir->i_atime = dir->i_ctime = current_time(dir); -#endif -#else - dir->i_mtime = dir->i_atime = inode->i_ctime = CURRENT_TIME_SEC; #endif exfat_truncate_atime(&dir->i_atime); #endif @@ -1189,23 +1084,15 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry) simple_inode_init_ts(inode); exfat_truncate_inode_atime(inode); #else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) inode->i_mtime = inode->i_atime = inode_set_ctime_current(inode); #else inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); -#endif -#else - inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC; #endif exfat_truncate_atime(&inode->i_atime); #endif exfat_unhash_inode(inode); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) exfat_d_version_set(dentry, inode_query_iversion(dir)); -#else - exfat_d_version_set(dentry, dir->i_version); -#endif unlock: mutex_unlock(&EXFAT_SB(inode->i_sb)->s_lock); return err; @@ -1500,7 +1387,6 @@ static int __exfat_rename(struct inode *old_parent_inode, return ret; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) static int exfat_rename(struct mnt_idmap *idmap, struct inode *old_dir, struct dentry *old_dentry, @@ -1512,23 +1398,12 @@ static int exfat_rename(struct user_namespace *mnt_userns, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) #endif -#else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0) -static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, - struct inode *new_dir, struct dentry *new_dentry, - unsigned int flags) -#else -static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, - struct inode *new_dir, struct dentry *new_dentry) -#endif -#endif { struct inode *old_inode, *new_inode; struct super_block *sb = old_dir->i_sb; loff_t i_pos; int err; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) /* * The VFS already checks for existence, so for local filesystems * the RENAME_NOREPLACE implementation is equivalent to plain rename. @@ -1536,7 +1411,6 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, */ if (flags & ~RENAME_NOREPLACE) return -EINVAL; -#endif mutex_lock(&EXFAT_SB(sb)->s_lock); old_inode = old_dentry->d_inode; @@ -1546,12 +1420,7 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, if (err) goto unlock; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_inc_iversion(new_dir); -#else - new_dir->i_version++; -#endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) simple_rename_timestamp(old_dir, old_dentry, new_dir, new_dentry); EXFAT_I(new_dir)->i_crtime = current_time(new_dir); @@ -1559,10 +1428,6 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime = EXFAT_I(new_dir)->i_crtime = current_time(new_dir); #endif -#else - new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime = - EXFAT_I(new_dir)->i_crtime = CURRENT_TIME_SEC; -#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0) exfat_truncate_inode_atime(new_dir); #else @@ -1588,17 +1453,9 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, inc_nlink(new_dir); } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_inc_iversion(old_dir); -#else - old_dir->i_version++; -#endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE <= KERNEL_VERSION(6, 6, 0) old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir); -#endif -#else - old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC; #endif if (IS_DIRSYNC(old_dir)) exfat_sync_inode(old_dir); @@ -1617,16 +1474,11 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, exfat_warn(sb, "abnormal access to an inode dropped"); WARN_ON(new_inode->i_nlink == 0); } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) EXFAT_I(new_inode)->i_crtime = current_time(new_inode); #else new_inode->i_ctime = EXFAT_I(new_inode)->i_crtime = current_time(new_inode); -#endif -#else - new_inode->i_ctime = EXFAT_I(new_inode)->i_crtime = - CURRENT_TIME_SEC; #endif } diff --git a/nls.c b/nls.c index 3b9fd46..a5d5e25 100644 --- a/nls.c +++ b/nls.c @@ -7,9 +7,6 @@ #include #include #include -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0) -#include -#endif #include #include "exfat_raw.h" @@ -663,11 +660,7 @@ static int exfat_load_upcase_table(struct super_block *sb, unsigned char skip = false; unsigned short *upcase_table; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0) upcase_table = kvcalloc(UTBL_COUNT, sizeof(unsigned short), GFP_KERNEL); -#else - upcase_table = vzalloc(UTBL_COUNT * sizeof(unsigned short)); -#endif if (!upcase_table) return -ENOMEM; @@ -723,11 +716,7 @@ static int exfat_load_default_upcase_table(struct super_block *sb) unsigned short uni = 0, *upcase_table; unsigned int index = 0; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0) upcase_table = kvcalloc(UTBL_COUNT, sizeof(unsigned short), GFP_KERNEL); -#else - upcase_table = vzalloc(UTBL_COUNT * sizeof(unsigned short)); -#endif if (!upcase_table) return -ENOMEM; @@ -815,9 +804,5 @@ int exfat_create_upcase_table(struct super_block *sb) void exfat_free_upcase_table(struct exfat_sb_info *sbi) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0) kvfree(sbi->vol_utbl); -#else - vfree(sbi->vol_utbl); -#endif } diff --git a/super.c b/super.c index decf1c6..9250090 100644 --- a/super.c +++ b/super.c @@ -4,13 +4,8 @@ */ #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) #include #include -#else -#include -#include -#endif #include #include #include @@ -22,10 +17,7 @@ #include #include #include - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) #include -#endif #include "exfat_raw.h" #include "exfat_fs.h" @@ -126,11 +118,7 @@ static int exfat_set_vol_flags(struct super_block *sb, unsigned short new_flags) /* skip updating volume dirty flag, * if this volume has been mounted with read-only */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) if (sb_rdonly(sb)) -#else - if (sb->s_flags & MS_RDONLY) -#endif return 0; p_boot->vol_flags = cpu_to_le16(new_flags); @@ -138,11 +126,7 @@ static int exfat_set_vol_flags(struct super_block *sb, unsigned short new_flags) set_buffer_uptodate(sbi->boot_bh); mark_buffer_dirty(sbi->boot_bh); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) __sync_dirty_buffer(sbi->boot_bh, REQ_SYNC | REQ_FUA | REQ_PREFLUSH); -#else - __sync_dirty_buffer(sbi->boot_bh, WRITE_FLUSH_FUA); -#endif return 0; } @@ -216,48 +200,14 @@ static struct inode *exfat_alloc_inode(struct super_block *sb) return &ei->vfs_inode; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0) static void exfat_free_inode(struct inode *inode) { kmem_cache_free(exfat_inode_cachep, EXFAT_I(inode)); } -#else -static void exfat_i_callback(struct rcu_head *head) -{ - struct inode *inode = container_of(head, struct inode, i_rcu); - kmem_cache_free(exfat_inode_cachep, EXFAT_I(inode)); -} - -static void exfat_destroy_inode(struct inode *inode) -{ - call_rcu(&inode->i_rcu, exfat_i_callback); -} -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0) -static int exfat_remount(struct super_block *sb, int *flags, char *data) -{ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) - *flags |= SB_NODIRATIME; -#else - *flags |= MS_NODIRATIME; -#endif - - sync_filesystem(sb); - return 0; -} -#endif static const struct super_operations exfat_sops = { .alloc_inode = exfat_alloc_inode, -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0) .free_inode = exfat_free_inode, -#else - .destroy_inode = exfat_destroy_inode, -#endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0) - .remount_fs = exfat_remount, -#endif .write_inode = exfat_write_inode, .evict_inode = exfat_evict_inode, .put_super = exfat_put_super, @@ -266,7 +216,6 @@ static const struct super_operations exfat_sops = { .show_options = exfat_show_options, }; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) enum { Opt_uid, Opt_gid, @@ -289,27 +238,14 @@ enum { Opt_codepage, }; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) static const struct constant_table exfat_param_enums[] = { { "continue", EXFAT_ERRORS_CONT }, { "panic", EXFAT_ERRORS_PANIC }, { "remount-ro", EXFAT_ERRORS_RO }, {} }; -#else -static const struct fs_parameter_enum exfat_param_enums[] = { - { Opt_errors, "continue", EXFAT_ERRORS_CONT }, - { Opt_errors, "panic", EXFAT_ERRORS_PANIC }, - { Opt_errors, "remount-ro", EXFAT_ERRORS_RO }, - {} -}; -#endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) static const struct fs_parameter_spec exfat_parameters[] = { -#else -static const struct fs_parameter_spec exfat_param_specs[] = { -#endif fsparam_u32("uid", Opt_uid), fsparam_u32("gid", Opt_gid), fsparam_u32oct("umask", Opt_umask), @@ -317,11 +253,7 @@ static const struct fs_parameter_spec exfat_param_specs[] = { fsparam_u32oct("fmask", Opt_fmask), fsparam_u32oct("allow_utime", Opt_allow_utime), fsparam_string("iocharset", Opt_charset), -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) fsparam_enum("errors", Opt_errors, exfat_param_enums), -#else - fsparam_enum("errors", Opt_errors), -#endif fsparam_flag("discard", Opt_discard), fsparam_flag("keep_last_dots", Opt_keep_last_dots), fsparam_flag("sys_tz", Opt_sys_tz), @@ -338,14 +270,6 @@ static const struct fs_parameter_spec exfat_param_specs[] = { {} }; -#if LINUX_VERSION_CODE <= KERNEL_VERSION(5, 6, 0) -static const struct fs_parameter_description exfat_parameters = { - .name = "exfat", - .specs = exfat_param_specs, - .enums = exfat_param_enums, -}; -#endif - static int exfat_parse_param(struct fs_context *fc, struct fs_parameter *param) { struct exfat_sb_info *sbi = fc->s_fs_info; @@ -353,11 +277,7 @@ static int exfat_parse_param(struct fs_context *fc, struct fs_parameter *param) struct fs_parse_result result; int opt; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) opt = fs_parse(fc, exfat_parameters, param, &result); -#else - opt = fs_parse(fc, &exfat_parameters, param, &result); -#endif if (opt < 0) return opt; @@ -421,176 +341,6 @@ static int exfat_parse_param(struct fs_context *fc, struct fs_parameter *param) return 0; } -#else -enum { - Opt_uid, - Opt_gid, - Opt_umask, - Opt_dmask, - Opt_fmask, - Opt_allow_utime, - Opt_charset, - Opt_err_cont, - Opt_err_panic, - Opt_err_ro, - Opt_err, - Opt_discard, - Opt_time_offset, - - /* Deprecated options */ - Opt_utf8, - Opt_debug, - Opt_namecase, - Opt_codepage, - Opt_zero_size_dir, - Opt_fs, -}; - -static const match_table_t exfat_tokens = { - {Opt_uid, "uid=%u"}, - {Opt_gid, "gid=%u"}, - {Opt_umask, "umask=%o"}, - {Opt_dmask, "dmask=%o"}, - {Opt_fmask, "fmask=%o"}, - {Opt_allow_utime, "allow_utime=%o"}, - {Opt_charset, "iocharset=%s"}, - {Opt_err_cont, "errors=continue"}, - {Opt_err_panic, "errors=panic"}, - {Opt_err_ro, "errors=remount-ro"}, - {Opt_discard, "discard"}, - {Opt_codepage, "codepage=%u"}, - {Opt_namecase, "namecase=%u"}, - {Opt_debug, "debug"}, - {Opt_utf8, "utf8"}, - {Opt_zero_size_dir, "zero_size_dir"}, - {Opt_err, NULL} -}; - -static int parse_options(struct super_block *sb, char *options, int silent, - struct exfat_mount_options *opts) -{ - char *p; - substring_t args[MAX_OPT_ARGS]; - int option; - char *tmpstr; - - opts->fs_uid = current_uid(); - opts->fs_gid = current_gid(); - opts->fs_fmask = opts->fs_dmask = current->fs->umask; - opts->allow_utime = -1; - opts->iocharset = exfat_default_iocharset; - opts->utf8 = 0; - opts->errors = EXFAT_ERRORS_RO; - opts->discard = 0; - - if (!options) - goto out; - - while ((p = strsep(&options, ",")) != NULL) { - int token; - - if (!*p) - continue; - token = match_token(p, exfat_tokens, args); - switch (token) { - case Opt_uid: - if (match_int(&args[0], &option)) - return 0; - opts->fs_uid = make_kuid(current_user_ns(), option); - break; - case Opt_gid: - if (match_int(&args[0], &option)) - return 0; - opts->fs_gid = make_kgid(current_user_ns(), option); - break; - case Opt_umask: - case Opt_dmask: - case Opt_fmask: - if (match_octal(&args[0], &option)) - return 0; - if (token != Opt_dmask) - opts->fs_fmask = option; - if (token != Opt_fmask) - opts->fs_dmask = option; - break; - case Opt_allow_utime: - if (match_octal(&args[0], &option)) - return 0; - opts->allow_utime = option & (0022); - break; - case Opt_charset: - if (opts->iocharset != exfat_default_iocharset) - kfree(opts->iocharset); - tmpstr = match_strdup(&args[0]); - if (!tmpstr) - return -ENOMEM; - opts->iocharset = tmpstr; - break; - case Opt_err_cont: - opts->errors = EXFAT_ERRORS_CONT; - break; - case Opt_err_panic: - opts->errors = EXFAT_ERRORS_PANIC; - break; - case Opt_err_ro: - opts->errors = EXFAT_ERRORS_RO; - break; - case Opt_discard: - opts->discard = 1; - break; - case Opt_time_offset: - if (match_int(&args[0], &option)) - return -EINVAL; - /* - * Make the limit 24 just in case someone - * invents something unusual. - */ - if (option < -24 * 60 || option > 24 * 60) - return -EINVAL; - opts->time_offset = option; - break; - case Opt_utf8: - case Opt_debug: - case Opt_namecase: - case Opt_codepage: - break; - case Opt_zero_size_dir: - opts->zero_size_dir = true; - break; - default: - if (!silent) { - exfat_err(sb, - "unrecognized mount option \"%s\" or missing value", - p); - } - return -EINVAL; - } - } - -out: - if (opts->allow_utime == -1) - opts->allow_utime = ~opts->fs_dmask & (0022); - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0) - if (opts->discard && !bdev_max_discard_sectors(sb->s_bdev)) { - exfat_warn(sb, "mounting with \"discard\" option, but the device does not support discard"); - opts->discard = 0; - } -#else - if (opts->discard) { - struct request_queue *q = bdev_get_queue(sb->s_bdev); - - if (!blk_queue_discard(q)) { - exfat_warn(sb, "mounting with \"discard\" option, but the device does not support discard"); - opts->discard = 0; - } - } -#endif - - return 0; -} -#endif - static void exfat_hash_init(struct super_block *sb) { @@ -634,11 +384,7 @@ static int exfat_read_root(struct inode *inode) inode->i_uid = sbi->options.fs_uid; inode->i_gid = sbi->options.fs_gid; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_inc_iversion(inode); -#else - inode->i_version++; -#endif inode->i_generation = 0; inode->i_mode = exfat_make_mode(sbi, EXFAT_ATTR_SUBDIR, 0777); inode->i_op = &exfat_dir_inode_operations; @@ -654,16 +400,11 @@ static int exfat_read_root(struct inode *inode) ei->i_crtime = simple_inode_init_ts(inode); exfat_truncate_inode_atime(inode); #else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0) inode->i_mtime = inode->i_atime = ei->i_crtime = inode_set_ctime_current(inode); #else inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime = current_time(inode); -#endif -#else - inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime = - CURRENT_TIME_SEC; #endif exfat_truncate_atime(&inode->i_atime); #endif @@ -908,15 +649,10 @@ static int __exfat_fill_super(struct super_block *sb) return ret; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) static int exfat_fill_super(struct super_block *sb, struct fs_context *fc) -#else -static int exfat_fill_super(struct super_block *sb, void *data, int silent) -#endif { struct inode *root_inode; int err; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) struct exfat_sb_info *sbi = sb->s_fs_info; struct exfat_mount_options *opts = &sbi->options; @@ -938,44 +674,14 @@ static int exfat_fill_super(struct super_block *sb, void *data, int silent) } } #endif -#else - struct exfat_sb_info *sbi; - - /* - * GFP_KERNEL is ok here, because while we do hold the - * supeblock lock, memory pressure can't call back into - * the filesystem, since we're only just about to mount - * it and have no inodes etc active! - */ - sbi = kzalloc(sizeof(struct exfat_sb_info), GFP_KERNEL); - if (!sbi) - return -ENOMEM; - mutex_init(&sbi->s_lock); - mutex_init(&sbi->bitmap_lock); - sb->s_fs_info = sbi; - ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL, - DEFAULT_RATELIMIT_BURST); - err = parse_options(sb, data, silent, &sbi->options); - if (err) { - exfat_err(sb, "failed to parse options"); - goto check_nls_io; - } -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) sb->s_flags |= SB_NODIRATIME; -#else - sb->s_flags |= MS_NODIRATIME; -#endif sb->s_magic = EXFAT_SUPER_MAGIC; sb->s_op = &exfat_sops; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0) sb->s_time_gran = 10 * NSEC_PER_MSEC; sb->s_time_min = EXFAT_MIN_TIMESTAMP_SECS; sb->s_time_max = EXFAT_MAX_TIMESTAMP_SECS; -#endif err = __exfat_fill_super(sb); if (err) { @@ -987,11 +693,7 @@ static int exfat_fill_super(struct super_block *sb, void *data, int silent) exfat_hash_init(sb); if (!strcmp(sbi->options.iocharset, "utf8")) -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) opts->utf8 = 1; -#else - sbi->options.utf8 = 1; -#endif else { sbi->nls_io = load_nls(sbi->options.iocharset); if (!sbi->nls_io) { @@ -1016,11 +718,7 @@ static int exfat_fill_super(struct super_block *sb, void *data, int silent) root_inode->i_ino = EXFAT_ROOT_INO; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) inode_set_iversion(root_inode, 1); -#else - root_inode->i_version = 1; -#endif err = exfat_read_root(root_inode); if (err) { exfat_err(sb, "failed to initialize root inode"); @@ -1056,7 +754,6 @@ static int exfat_fill_super(struct super_block *sb, void *data, int silent) return err; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) static int exfat_get_tree(struct fs_context *fc) { return get_tree_bdev(fc, exfat_fill_super); @@ -1113,23 +810,12 @@ static int exfat_init_fs_context(struct fs_context *fc) fc->ops = &exfat_context_ops; return 0; } -#else -static struct dentry *exfat_fs_mount(struct file_system_type *fs_type, - int flags, const char *dev_name, void *data) -{ - return mount_bdev(fs_type, flags, dev_name, data, exfat_fill_super); -} -#endif static struct file_system_type exfat_fs_type = { .owner = THIS_MODULE, .name = "exfat", -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) .init_fs_context = exfat_init_fs_context, .parameters = exfat_parameters, -#else - .mount = exfat_fs_mount, -#endif .kill_sb = kill_block_super, .fs_flags = FS_REQUIRES_DEV, };