aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaeho Jeong2020-10-29 23:10:34 -0500
committerJaegeuk Kim2020-12-21 15:33:11 -0600
commit4a6741771b58570f6a14b603a0885f2a5e2843e4 (patch)
tree2780d2d09e550c6c54a1ae561406730b4df9a925
parenta6d99e8e3169d02c7c4999f8cca70776ca0b3913 (diff)
downloadkernel-4a6741771b58570f6a14b603a0885f2a5e2843e4.tar.gz
kernel-4a6741771b58570f6a14b603a0885f2a5e2843e4.tar.xz
kernel-4a6741771b58570f6a14b603a0885f2a5e2843e4.zip
f2fs: add F2FS_IOC_GET_COMPRESS_OPTION ioctl
Added a new F2FS_IOC_GET_COMPRESS_OPTION ioctl to get file compression option of a file. struct f2fs_comp_option { u8 algorithm; => compression algorithm => 0:lzo, 1:lz4, 2:zstd, 3:lzorle u8 log_cluster_size; => log scale cluster size => 2 ~ 8 }; struct f2fs_comp_option option; ioctl(fd, F2FS_IOC_GET_COMPRESS_OPTION, &option); Signed-off-by: Daeho Jeong <daehojeong@google.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/file.c30
-rw-r--r--include/uapi/linux/f2fs.h7
2 files changed, 37 insertions, 0 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 89c451f09344..c747f5dd595c 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3945,6 +3945,33 @@ err:
3945 return ret; 3945 return ret;
3946} 3946}
3947 3947
3948static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg)
3949{
3950 struct inode *inode = file_inode(filp);
3951 struct f2fs_comp_option option;
3952
3953 if (!f2fs_sb_has_compression(F2FS_I_SB(inode)))
3954 return -EOPNOTSUPP;
3955
3956 inode_lock_shared(inode);
3957
3958 if (!f2fs_compressed_file(inode)) {
3959 inode_unlock_shared(inode);
3960 return -ENODATA;
3961 }
3962
3963 option.algorithm = F2FS_I(inode)->i_compress_algorithm;
3964 option.log_cluster_size = F2FS_I(inode)->i_log_cluster_size;
3965
3966 inode_unlock_shared(inode);
3967
3968 if (copy_to_user((struct f2fs_comp_option __user *)arg, &option,
3969 sizeof(option)))
3970 return -EFAULT;
3971
3972 return 0;
3973}
3974
3948long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 3975long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3949{ 3976{
3950 if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) 3977 if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp)))))
@@ -4033,6 +4060,8 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4033 return f2fs_reserve_compress_blocks(filp, arg); 4060 return f2fs_reserve_compress_blocks(filp, arg);
4034 case F2FS_IOC_SEC_TRIM_FILE: 4061 case F2FS_IOC_SEC_TRIM_FILE:
4035 return f2fs_sec_trim_file(filp, arg); 4062 return f2fs_sec_trim_file(filp, arg);
4063 case F2FS_IOC_GET_COMPRESS_OPTION:
4064 return f2fs_ioc_get_compress_option(filp, arg);
4036 default: 4065 default:
4037 return -ENOTTY; 4066 return -ENOTTY;
4038 } 4067 }
@@ -4203,6 +4232,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
4203 case F2FS_IOC_RELEASE_COMPRESS_BLOCKS: 4232 case F2FS_IOC_RELEASE_COMPRESS_BLOCKS:
4204 case F2FS_IOC_RESERVE_COMPRESS_BLOCKS: 4233 case F2FS_IOC_RESERVE_COMPRESS_BLOCKS:
4205 case F2FS_IOC_SEC_TRIM_FILE: 4234 case F2FS_IOC_SEC_TRIM_FILE:
4235 case F2FS_IOC_GET_COMPRESS_OPTION:
4206 break; 4236 break;
4207 default: 4237 default:
4208 return -ENOIOCTLCMD; 4238 return -ENOIOCTLCMD;
diff --git a/include/uapi/linux/f2fs.h b/include/uapi/linux/f2fs.h
index 28bcfe8d2c27..872e61d78f29 100644
--- a/include/uapi/linux/f2fs.h
+++ b/include/uapi/linux/f2fs.h
@@ -36,6 +36,8 @@
36 _IOR(F2FS_IOCTL_MAGIC, 19, __u64) 36 _IOR(F2FS_IOCTL_MAGIC, 19, __u64)
37#define F2FS_IOC_SEC_TRIM_FILE _IOW(F2FS_IOCTL_MAGIC, 20, \ 37#define F2FS_IOC_SEC_TRIM_FILE _IOW(F2FS_IOCTL_MAGIC, 20, \
38 struct f2fs_sectrim_range) 38 struct f2fs_sectrim_range)
39#define F2FS_IOC_GET_COMPRESS_OPTION _IOR(F2FS_IOCTL_MAGIC, 21, \
40 struct f2fs_comp_option)
39 41
40/* 42/*
41 * should be same as XFS_IOC_GOINGDOWN. 43 * should be same as XFS_IOC_GOINGDOWN.
@@ -84,4 +86,9 @@ struct f2fs_sectrim_range {
84 __u64 flags; 86 __u64 flags;
85}; 87};
86 88
89struct f2fs_comp_option {
90 __u8 algorithm;
91 __u8 log_cluster_size;
92};
93
87#endif /* _UAPI_LINUX_F2FS_H */ 94#endif /* _UAPI_LINUX_F2FS_H */