From d2baca1f8dae58ddbca4f1ab9b86c3fd1778b6ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E8=87=B4=E9=82=A6?= Date: Fri, 28 Aug 2015 12:11:44 +0800 Subject: [PATCH] Add support for linux-2.6.31. --- exfat_data.c | 8 +++++++ exfat_oal.c | 4 ++++ exfat_super.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/exfat_data.c b/exfat_data.c index 01f0544..65da07a 100644 --- a/exfat_data.c +++ b/exfat_data.c @@ -57,13 +57,21 @@ /*----------------------------------------------------------------------*/ /* FAT cache */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +DECLARE_MUTEX(f_sem); +#else DEFINE_SEMAPHORE(f_sem); +#endif BUF_CACHE_T FAT_cache_array[FAT_CACHE_SIZE]; BUF_CACHE_T FAT_cache_lru_list; BUF_CACHE_T FAT_cache_hash_list[FAT_CACHE_HASH_SIZE]; /* buf cache */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +DECLARE_MUTEX(b_sem); +#else DEFINE_SEMAPHORE(b_sem); +#endif BUF_CACHE_T buf_cache_array[BUF_CACHE_SIZE]; BUF_CACHE_T buf_cache_lru_list; BUF_CACHE_T buf_cache_hash_list[BUF_CACHE_HASH_SIZE]; diff --git a/exfat_oal.c b/exfat_oal.c index 6ef7c7b..9b33998 100644 --- a/exfat_oal.c +++ b/exfat_oal.c @@ -55,7 +55,11 @@ /* */ /*======================================================================*/ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +DECLARE_MUTEX(z_sem); +#else DEFINE_SEMAPHORE(z_sem); +#endif s32 sm_init(struct semaphore *sm) { diff --git a/exfat_super.c b/exfat_super.c index dde8055..1c4a77e 100644 --- a/exfat_super.c +++ b/exfat_super.c @@ -218,7 +218,11 @@ static struct inode *exfat_build_inode(struct super_block *sb, FILE_ID_T *fid, l static void exfat_detach(struct inode *inode); static void exfat_attach(struct inode *inode, loff_t i_pos); static inline unsigned long exfat_hash(loff_t i_pos); +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +static int exfat_write_inode(struct inode *inode, int wait); +#else static int exfat_write_inode(struct inode *inode, struct writeback_control *wbc); +#endif static void exfat_write_super(struct super_block *sb); static void __lock_super(struct super_block *sb) @@ -338,6 +342,8 @@ static unsigned int exfat_striptail_len(const struct qstr *qstr) #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0) static int exfat_d_hash(const struct dentry *dentry, struct qstr *qstr) +#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +static int exfat_d_hash(struct dentry *dentry, struct qstr *qstr) #else static int exfat_d_hash(const struct dentry *dentry, const struct inode *inode, struct qstr *qstr) @@ -349,6 +355,8 @@ static int exfat_d_hash(const struct dentry *dentry, const struct inode *inode, #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0) static int exfat_d_hashi(const struct dentry *dentry, struct qstr *qstr) +#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +static int exfat_d_hashi(struct dentry *dentry, struct qstr *qstr) #else static int exfat_d_hashi(const struct dentry *dentry, const struct inode *inode, struct qstr *qstr) @@ -373,6 +381,8 @@ static int exfat_d_hashi(const struct dentry *dentry, const struct inode *inode, #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0) static int exfat_cmpi(const struct dentry *parent, const struct dentry *dentry, unsigned int len, const char *str, const struct qstr *name) +#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +static int exfat_cmpi(struct dentry *parent, struct qstr *a, struct qstr *b) #else static int exfat_cmpi(const struct dentry *parent, const struct inode *pinode, const struct dentry *dentry, const struct inode *inode, @@ -382,13 +392,26 @@ static int exfat_cmpi(const struct dentry *parent, const struct inode *pinode, struct nls_table *t = EXFAT_SB(parent->d_sb)->nls_io; unsigned int alen, blen; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) + alen = exfat_striptail_len(a); + blen = exfat_striptail_len(b); +#else alen = exfat_striptail_len(name); blen = __exfat_striptail_len(len, str); +#endif if (alen == blen) { if (t == NULL) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) + if (strncasecmp(a->name, b->name, alen) == 0) +#else if (strncasecmp(name->name, str, alen) == 0) +#endif return 0; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) + } else if (nls_strnicmp(t, a->name, b->name, alen) == 0) +#else } else if (nls_strnicmp(t, name->name, str, alen) == 0) +#endif return 0; } return 1; @@ -397,6 +420,9 @@ static int exfat_cmpi(const struct dentry *parent, const struct inode *pinode, #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0) static int exfat_cmp(const struct dentry *parent, const struct dentry *dentry, unsigned int len, const char *str, const struct qstr *name) +#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +static int exfat_cmp(struct dentry *parent, struct qstr *a, + struct qstr *b) #else static int exfat_cmp(const struct dentry *parent, const struct inode *pinode, const struct dentry *dentry, const struct inode *inode, @@ -405,10 +431,19 @@ static int exfat_cmp(const struct dentry *parent, const struct inode *pinode, { unsigned int alen, blen; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) + alen = exfat_striptail_len(a); + blen = exfat_striptail_len(b); +#else alen = exfat_striptail_len(name); blen = __exfat_striptail_len(len, str); +#endif if (alen == blen) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) + if (strncmp(a->name, b->name, alen) == 0) +#else if (strncmp(name->name, str, alen) == 0) +#endif return 0; } return 1; @@ -617,13 +652,22 @@ static long exfat_generic_ioctl(struct file *filp, } #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +static int exfat_file_fsync(struct file *filp, struct dentry *dentry, + int datasync) +#else static int exfat_file_fsync(struct file *filp, int datasync) +#endif { struct inode *inode = filp->f_mapping->host; struct super_block *sb = inode->i_sb; int res, err; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) + res = simple_fsync(filp, dentry, datasync); +#else res = generic_file_fsync(filp, datasync); +#endif err = FsSyncVol(sb, 1); return res ? res : err; @@ -1140,7 +1184,13 @@ static int exfat_cont_expand(struct inode *inode, loff_t size) err2 = write_inode_now(inode, 1); err = (err) ? (err) : (err2); if (!err) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) + err = wait_on_page_writeback_range(mapping, + start >> PAGE_CACHE_SHIFT, + (start + count - 1) >> PAGE_CACHE_SHIFT); +#else err = filemap_fdatawait_range(mapping, start, start + count - 1); +#endif } return err; } @@ -1205,7 +1255,9 @@ static int exfat_setattr(struct dentry *dentry, struct iattr *attr) struct inode *inode = dentry->d_inode; unsigned int ia_valid; int error; +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35) loff_t old_size; +#endif DPRINTK("exfat_setattr entered\n"); @@ -1842,7 +1894,11 @@ static struct inode *exfat_build_inode(struct super_block *sb, static int exfat_sync_inode(struct inode *inode) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) + return exfat_write_inode(inode, 0); +#else return exfat_write_inode(inode, NULL); +#endif } static struct inode *exfat_alloc_inode(struct super_block *sb) @@ -1869,7 +1925,11 @@ static void exfat_destroy_inode(struct inode *inode) kmem_cache_free(exfat_inode_cachep, EXFAT_I(inode)); } +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +static int exfat_write_inode(struct inode *inode, int wait) +#else static int exfat_write_inode(struct inode *inode, struct writeback_control *wbc) +#endif { struct super_block *sb = inode->i_sb; struct exfat_sb_info *sbi = EXFAT_SB(sb); @@ -2296,6 +2356,7 @@ static int exfat_read_root(struct inode *inode) return 0; } +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,37) static void setup_dops(struct super_block *sb) { if (EXFAT_SB(sb)->options.casesensitive == 0) @@ -2303,6 +2364,7 @@ static void setup_dops(struct super_block *sb) else sb->s_d_op = &exfat_dentry_ops; } +#endif static int exfat_fill_super(struct super_block *sb, void *data, int silent) { @@ -2333,7 +2395,9 @@ static int exfat_fill_super(struct super_block *sb, void *data, int silent) if (error) goto out_fail; +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,37) setup_dops(sb); +#endif error = -EIO; sb_min_blocksize(sb, 512);