[PATCH] f2fs: fix to check compression feature before enabling file compression

Chao Yu posted 1 patch 3 years, 8 months ago
fs/f2fs/file.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] f2fs: fix to check compression feature before enabling file compression
Posted by Chao Yu 3 years, 8 months ago
From: Chao Yu <chao.yu@oppo.com>

This patch disallow to enable file compression in image which doesn't
support compression feature.

Signed-off-by: Chao Yu <chao.yu@oppo.com>
---
 fs/f2fs/file.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 24f5b02c78e7..4a3f4eaa3fc5 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1872,6 +1872,8 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)
 			if (!f2fs_disable_compressed_file(inode))
 				return -EINVAL;
 		} else {
+			if (!f2fs_sb_has_compression(F2FS_I_SB(inode)))
+				return -EOPNOTSUPP;
 			if (!f2fs_may_compress(inode))
 				return -EINVAL;
 			if (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode))
-- 
2.36.1
Re: [f2fs-dev] [PATCH] f2fs: fix to check compression feature before enabling file compression
Posted by Eric Biggers 3 years, 8 months ago
On Thu, Aug 04, 2022 at 09:41:40PM +0800, Chao Yu wrote:
> From: Chao Yu <chao.yu@oppo.com>
> 
> This patch disallow to enable file compression in image which doesn't
> support compression feature.
> 
> Signed-off-by: Chao Yu <chao.yu@oppo.com>
> ---
>  fs/f2fs/file.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 24f5b02c78e7..4a3f4eaa3fc5 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1872,6 +1872,8 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)
>  			if (!f2fs_disable_compressed_file(inode))
>  				return -EINVAL;
>  		} else {
> +			if (!f2fs_sb_has_compression(F2FS_I_SB(inode)))
> +				return -EOPNOTSUPP;
>  			if (!f2fs_may_compress(inode))
>  				return -EINVAL;
>  			if (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode))
> -- 

How is this different from the same check that occurs earlier in the function?

- Eric
Re: [f2fs-dev] [PATCH] f2fs: fix to check compression feature before enabling file compression
Posted by Chao Yu 3 years, 8 months ago
On 2022/8/5 2:28, Eric Biggers wrote:
> How is this different from the same check that occurs earlier in the function?

Oops, I missed that one, please ignore this patch.

Thanks,