Skip to contentSkip to conversation

Various exfat fixes

PATCH In review [email protected] 4 participants 13 messages Oct 9, 2019 – Oct 10, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Various exfat fixes

From: Philipp Ammann <[email protected]>

These patches are not mine; they are pulled from Github:

https://github.com/dorimanx/exfat-nofuse/pull/124

Supposedly they're from Samsung.

I've been running them on 4.19 for about over a year without issues.

I know the commit messages are not exactly stellar. Please excuse my not improving them, but I'm no filesystem guy.

Cheers
Philipp

Andreas Schneider (6):
Return a valid count in count_used_clusters()
Add missing fs_error() in sector functions
Check that the new path while moving a file is not too long Add the exfat version to the module info
Sync blocks on remount
Add device ejected to mount options

 drivers/staging/exfat/exfat_core.c  | 19 +++++++++++++++----
 drivers/staging/exfat/exfat_super.c |  9 +++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/6 Return a valid count in count_used_clusters()

From: Andreas Schneider <[email protected]>

---
 drivers/staging/exfat/exfat_core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/staging/exfat/exfat_core.c +3 -0
index b3e9cf725cf5..eef9e2726b6b 100644
@@ -482,6 +482,9 @@ s32 exfat_count_used_clusters(struct super_block *sb)
 		}
 	}
 
+	if ((p_fs->num_clusters - 2) < (s32)count)
+		count = p_fs->num_clusters - 2;
+
 	return count;
 }
 
Signature · 1 line
2.21.0
#2 lore raw

PATCH 2/6 Add missing fs_error() in sector functions

In reply to [email protected]

From: Andreas Schneider <[email protected]>

---
 drivers/staging/exfat/exfat_core.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/staging/exfat/exfat_core.c +12 -4
index eef9e2726b6b..043091565578 100644
@@ -3616,8 +3616,10 @@ int sector_read(struct super_block *sb, sector_t sec, struct buffer_head **bh,
 
 	if (!p_fs->dev_ejected) {
 		ret = bdev_read(sb, sec, bh, 1, read);
-		if (ret != FFS_SUCCESS)
+		if (ret != FFS_SUCCESS) {
+			fs_error(sb);
 			p_fs->dev_ejected = 1;
+		}
 	}
 
 	return ret;
@@ -3645,8 +3647,10 @@ int sector_write(struct super_block *sb, sector_t sec, struct buffer_head *bh,
 
 	if (!p_fs->dev_ejected) {
 		ret = bdev_write(sb, sec, bh, 1, sync);
-		if (ret != FFS_SUCCESS)
+		if (ret != FFS_SUCCESS) {
+			fs_error(sb);
 			p_fs->dev_ejected = 1;
+		}
 	}
 
 	return ret;
@@ -3668,8 +3672,10 @@ int multi_sector_read(struct super_block *sb, sector_t sec,
 
 	if (!p_fs->dev_ejected) {
 		ret = bdev_read(sb, sec, bh, num_secs, read);
-		if (ret != FFS_SUCCESS)
+		if (ret != FFS_SUCCESS) {
+			fs_error(sb);
 			p_fs->dev_ejected = 1;
+		}
 	}
 
 	return ret;
@@ -3696,8 +3702,10 @@ int multi_sector_write(struct super_block *sb, sector_t sec,
 
 	if (!p_fs->dev_ejected) {
 		ret = bdev_write(sb, sec, bh, num_secs, sync);
-		if (ret != FFS_SUCCESS)
+		if (ret != FFS_SUCCESS) {
+			fs_error(sb);
 			p_fs->dev_ejected = 1;
+		}
 	}
 
 	return ret;
Signature · 1 line
2.21.0
#3 lore raw

PATCH 3/6 Check that the new path while moving a file is not too long

In reply to [email protected]

From: Andreas Schneider <[email protected]>

---
 drivers/staging/exfat/exfat_super.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/staging/exfat/exfat_super.c +3 -0
index 5f6caee819a6..b63186a67af6 100644
@@ -1300,6 +1300,9 @@ static int ffsMoveFile(struct inode *old_parent_inode, struct file_id_t *fid,
 	}
 
 	/* check the validity of directory name in the given new pathname */
+	if (strlen(new_path) >= MAX_NAME_LENGTH)
+		return FFS_NAMETOOLONG;
+
 	ret = resolve_path(new_parent_inode, new_path, &newdir, &uni_name);
 	if (ret)
 		goto out2;
Signature · 1 line
2.21.0
#4 lore raw

Re: [PATCH 3/6] Check that the new path while moving a file is not too long

Quoted 1 line · On Wed, Oct 09, 2019 at 03:31:54PM +0200, [email protected] wrote:

From: Andreas Schneider <[email protected]>

[no subject prefix, and maybe use scripts/get_maintainer.pl... ]

Quoted 11 lines
---
 drivers/staging/exfat/exfat_super.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/staging/exfat/exfat_super.c +0 -0
index 5f6caee819a6..b63186a67af6 100644

drivers/staging/exfat/exfat_super.c static int ffsMoveFile(struct inode *old_parent_inode, struct file_id_t *fid, · line 1305

Quoted 6 lines
drivers/staging/exfat/exfat_super.c +3 -0
@@ -1300,6 +1300,9 @@ static int ffsMoveFile(struct inode *old_parent_inode, struct file_id_t *fid,
 	}
 
 	/* check the validity of directory name in the given new pathname */
+	if (strlen(new_path) >= MAX_NAME_LENGTH)
+		return FFS_NAMETOOLONG;
+

odd here, AFAIK, namelen should be checked in ->lookup() for many filesystems (why such dentries exist?) and the length can be also gotten by dentry->d_name.len (it's also stable here).

Maybe sort out what original problem here is better and not blindly get patches from random github repos...

Thanks,
Gao Xiang

Quoted 6 lines
drivers/staging/exfat/exfat_super.c +0 -0
 	ret = resolve_path(new_parent_inode, new_path, &newdir, &uni_name);
 	if (ret)
 		goto out2;
Signature · 1 line
2.21.0
#5 lore raw

Re: [PATCH 3/6] Check that the new path while moving a file is not too long

Am 09.10.19 um 17:25 schrieb Gao Xiang:

Quoted 2 lines

Maybe sort out what original problem here is better and not blindly get patches from random github repos...

That's kinda hard to do given that Samsung doesn't provide a history of the code...and my lack of knowledge of FS drivers ;-) I just posted Bugfixes that probably originated from Samsung and somehow haven't made it in the initial mainline exfat commit.

Do you know where the code originally came from?

Regards
Philipp

Quoted 11 lines

Thanks,
Gao Xiang

Quoted 6 lines

ret = resolve_path(new_parent_inode, new_path, &newdir, &uni_name); if (ret)
goto out2;

Signature · 1 line
2.21.0
#6 lore raw

PATCH 4/6 Add the exfat version to the module info

In reply to [email protected]

From: Andreas Schneider <[email protected]>

---
 drivers/staging/exfat/exfat_super.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/exfat/exfat_super.c +1 -0
index b63186a67af6..29fb5e88fe5f 100644
@@ -4049,4 +4049,5 @@ module_exit(exit_exfat);
 
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("exFAT Filesystem Driver");
+MODULE_VERSION(EXFAT_VERSION);
 MODULE_ALIAS_FS("exfat");
Signature · 1 line
2.21.0
#7 lore raw

PATCH 5/6 Sync blocks on remount

In reply to [email protected]

From: Andreas Schneider <[email protected]>

---
 drivers/staging/exfat/exfat_super.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/staging/exfat/exfat_super.c +2 -0
index 29fb5e88fe5f..e8e481a5ddc9 100644
@@ -3532,6 +3532,8 @@ static int exfat_statfs(struct dentry *dentry, struct kstatfs *buf)
 static int exfat_remount(struct super_block *sb, int *flags, char *data)
 {
 	*flags |= SB_NODIRATIME;
+	sync_filesystem(sb);
+
 	return 0;
 }
 
Signature · 1 line
2.21.0
#8 lore raw

PATCH 6/6 Add device ejected to mount options

In reply to [email protected]

From: Andreas Schneider <[email protected]>

---
 drivers/staging/exfat/exfat_super.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/staging/exfat/exfat_super.c +3 -0
index e8e481a5ddc9..d97616351159 100644
@@ -3541,6 +3541,7 @@ static int exfat_show_options(struct seq_file *m, struct dentry *root)
 {
 	struct exfat_sb_info *sbi = EXFAT_SB(root->d_sb);
 	struct exfat_mount_options *opts = &sbi->options;
+	FS_INFO_T *p_fs = &(sbi->fs_info);
 
 	if (__kuid_val(opts->fs_uid))
 		seq_printf(m, ",uid=%u", __kuid_val(opts->fs_uid));
@@ -3565,6 +3566,8 @@ static int exfat_show_options(struct seq_file *m, struct dentry *root)
 	if (opts->discard)
 		seq_puts(m, ",discard");
 #endif
+	if (p_fs->dev_ejected)
+		seq_puts(m, ",ejected");
 	return 0;
 }
 
Signature · 1 line
2.21.0
#9 lore raw

Re: [PATCH 6/6] Add device ejected to mount options

Thank you for the patch! Yet something to improve:

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on staging/staging-testing]
[cannot apply to v5.4-rc2 next-20191009]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/philipp-ammann-posteo-de/Various-exfat-fixes/20191010-101029
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

drivers/staging/exfat/exfat_super.c: In function 'exfat_show_options':

>> drivers/staging/exfat/exfat_super.c:3544:2: error: unknown type name 'FS_INFO_T'; did you mean 'FW_INFO'?
     FS_INFO_T *p_fs = &(sbi->fs_info);
     ^~~~~~~~~
     FW_INFO
>> drivers/staging/exfat/exfat_super.c:3544:20: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
     FS_INFO_T *p_fs = &(sbi->fs_info);
                       ^
>> drivers/staging/exfat/exfat_super.c:3569:10: error: request for member 'dev_ejected' in something not a structure or union
     if (p_fs->dev_ejected)
             ^~

cc1: some warnings being treated as errors

vim +3544 drivers/staging/exfat/exfat_super.c

3539
3540 static int exfat_show_options(struct seq_file *m, struct dentry *root)
3541 {
3542 struct exfat_sb_info *sbi = EXFAT_SB(root->d_sb);
3543 struct exfat_mount_options *opts = &sbi->options;

> 3544		FS_INFO_T *p_fs = &(sbi->fs_info);
  3545	
  3546		if (__kuid_val(opts->fs_uid))
  3547			seq_printf(m, ",uid=%u", __kuid_val(opts->fs_uid));
  3548		if (__kgid_val(opts->fs_gid))
  3549			seq_printf(m, ",gid=%u", __kgid_val(opts->fs_gid));
  3550		seq_printf(m, ",fmask=%04o", opts->fs_fmask);
  3551		seq_printf(m, ",dmask=%04o", opts->fs_dmask);
  3552		if (opts->allow_utime)
  3553			seq_printf(m, ",allow_utime=%04o", opts->allow_utime);
  3554		if (sbi->nls_disk)
  3555			seq_printf(m, ",codepage=%s", sbi->nls_disk->charset);
  3556		if (sbi->nls_io)
  3557			seq_printf(m, ",iocharset=%s", sbi->nls_io->charset);
  3558		seq_printf(m, ",namecase=%u", opts->casesensitive);
  3559		if (opts->errors == EXFAT_ERRORS_CONT)
  3560			seq_puts(m, ",errors=continue");
  3561		else if (opts->errors == EXFAT_ERRORS_PANIC)
  3562			seq_puts(m, ",errors=panic");
  3563		else
  3564			seq_puts(m, ",errors=remount-ro");
  3565	#ifdef CONFIG_EXFAT_DISCARD
  3566		if (opts->discard)
  3567			seq_puts(m, ",discard");
  3568	#endif
> 3569		if (p_fs->dev_ejected)

3570 seq_puts(m, ",ejected");
3571 return 0;
3572 }
3573

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#10 lore raw

Re: [PATCH 6/6] Add device ejected to mount options

In reply to [email protected]
Thank you for the patch! Yet something to improve:

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on staging/staging-testing]
[cannot apply to v5.4-rc2 next-20191009]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/philipp-ammann-posteo-de/Various-exfat-fixes/20191010-101029
config: nds32-allmodconfig (attached as .config)
compiler: nds32le-linux-gcc (GCC) 8.1.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=8.1.0 make.cross ARCH=nds32

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

drivers/staging//exfat/exfat_super.c: In function 'exfat_show_options':
drivers/staging//exfat/exfat_super.c:3544:2: error: unknown type name 'FS_INFO_T'; did you mean 'FW_INFO'?

     FS_INFO_T *p_fs = &(sbi->fs_info);
     ^~~~~~~~~
     FW_INFO
>> drivers/staging//exfat/exfat_super.c:3544:20: error: initialization of 'int *' from incompatible pointer type 'struct fs_info_t *' [-Werror=incompatible-pointer-types]
     FS_INFO_T *p_fs = &(sbi->fs_info);
                       ^
   drivers/staging//exfat/exfat_super.c:3569:10: error: request for member 'dev_ejected' in something not a structure or union
     if (p_fs->dev_ejected)
             ^~

cc1: some warnings being treated as errors

vim +3544 drivers/staging//exfat/exfat_super.c

3539
3540 static int exfat_show_options(struct seq_file *m, struct dentry *root)
3541 {
3542 struct exfat_sb_info *sbi = EXFAT_SB(root->d_sb);
3543 struct exfat_mount_options *opts = &sbi->options;

> 3544		FS_INFO_T *p_fs = &(sbi->fs_info);

3545
3546 if (__kuid_val(opts->fs_uid))
3547 seq_printf(m, ",uid=%u", __kuid_val(opts->fs_uid));
3548 if (__kgid_val(opts->fs_gid))
3549 seq_printf(m, ",gid=%u", __kgid_val(opts->fs_gid));
3550 seq_printf(m, ",fmask=%04o", opts->fs_fmask);
3551 seq_printf(m, ",dmask=%04o", opts->fs_dmask);
3552 if (opts->allow_utime)
3553 seq_printf(m, ",allow_utime=%04o", opts->allow_utime);
3554 if (sbi->nls_disk)
3555 seq_printf(m, ",codepage=%s", sbi->nls_disk->charset);
3556 if (sbi->nls_io)
3557 seq_printf(m, ",iocharset=%s", sbi->nls_io->charset);
3558 seq_printf(m, ",namecase=%u", opts->casesensitive);
3559 if (opts->errors == EXFAT_ERRORS_CONT)
3560 seq_puts(m, ",errors=continue");
3561 else if (opts->errors == EXFAT_ERRORS_PANIC)
3562 seq_puts(m, ",errors=panic");
3563 else
3564 seq_puts(m, ",errors=remount-ro");
3565 #ifdef CONFIG_EXFAT_DISCARD
3566 if (opts->discard)
3567 seq_puts(m, ",discard");
3568 #endif
3569 if (p_fs->dev_ejected)
3570 seq_puts(m, ",ejected");
3571 return 0;
3572 }
3573

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#11 lore raw
In reply to [email protected]
Quoted 24 lines · On 9.10.19 г. 16:31 ч., [email protected] wrote:

From: Philipp Ammann <[email protected]>

These patches are not mine; they are pulled from Github:

https://github.com/dorimanx/exfat-nofuse/pull/124

Supposedly they're from Samsung.

I've been running them on 4.19 for about over a year without issues.

I know the commit messages are not exactly stellar. Please excuse my not improving them, but I'm no filesystem guy.

Cheers
Philipp

Andreas Schneider (6):
Return a valid count in count_used_clusters()
Add missing fs_error() in sector functions
Check that the new path while moving a file is not too long Add the exfat version to the module info
Sync blocks on remount
Add device ejected to mount options

Quoted 4 lines
 drivers/staging/exfat/exfat_core.c  | 19 +++++++++++++++----
 drivers/staging/exfat/exfat_super.c |  9 +++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)

From the same pull :

"
No, please use kernel-sdfat. It shouldn't be very hard to get it working on 4.18. exfat-nofuse has a lot of issues, don't use it.
"

#12 lore raw

Am 09.10.19 um 19:36 schrieb Nikolay Borisov:

Quoted 7 lines

From the same pull :

"
No, please use kernel-sdfat. It shouldn't be very hard to get it working on 4.18. exfat-nofuse has a lot of issues, don't use it.
"

...which is this discussion here: https://lkml.org/lkml/2019/9/15/135
The version in mainline is exfat, not sdfat.