From: Yangtao Li <frank.li@vivo.com>
To: jaegeuk@kernel.org, chao@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Yangtao Li <frank.li@vivo.com>
Subject: [PATCH v2 2/2] f2fs: add F2FS_IOC_GET_COMPRESS_OPTION_V2 ioctl
Date: Sun, 22 Jan 2023 23:00:49 +0800 [thread overview]
Message-ID: <20230122150049.66607-2-frank.li@vivo.com> (raw)
In-Reply-To: <20230122150049.66607-1-frank.li@vivo.com>
Added a new F2FS_IOC_GET_COMPRESS_OPTION_V2 ioctl to get file compression
option of a file.
struct f2fs_comp_option_v2 {
union {
struct {
__u8 algorithm;
__u8 log_cluster_size;
__u16 compress_flag;
};
struct f2fs_comp_option option;
};
};
struct f2fs_comp_option_v2 option;
ioctl(fd, F2FS_IOC_GET_COMPRESS_OPTION_V2, &option);
printf("compression algorithm:%u\n", option.algorithm);
printf("compression cluster log size:%u\n", option.log_cluster_size);
printf("compress level:%u\n", GET_COMPRESS_LEVEL(option.compress_flag));
printf("compress chksum:%s\n",
(BIT(COMPRESS_CHKSUM) & option.compress_flag) ? "true" : "false");
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
v2:
-handle F2FS_IOC_GET_COMPRESS_OPTION_V2 in f2fs_compat_ioctl
fs/f2fs/file.c | 21 ++++++++++++++++-----
include/uapi/linux/f2fs.h | 4 +++-
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 78b97c1fa6af..b3bcb50490bd 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3899,10 +3899,12 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
return ret;
}
-static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg)
+static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg,
+ unsigned int cmd)
{
struct inode *inode = file_inode(filp);
- struct f2fs_comp_option option;
+ struct f2fs_comp_option_v2 option;
+ int len;
if (!f2fs_sb_has_compression(F2FS_I_SB(inode)))
return -EOPNOTSUPP;
@@ -3916,11 +3918,17 @@ static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg)
option.algorithm = F2FS_I(inode)->i_compress_algorithm;
option.log_cluster_size = F2FS_I(inode)->i_log_cluster_size;
+ if (cmd == F2FS_IOC_GET_COMPRESS_OPTION_V2)
+ option.compress_flag = F2FS_I(inode)->i_compress_flag;
inode_unlock_shared(inode);
- if (copy_to_user((struct f2fs_comp_option __user *)arg, &option,
- sizeof(option)))
+ if (cmd == F2FS_IOC_GET_COMPRESS_OPTION_V2)
+ len = sizeof(struct f2fs_comp_option_v2);
+ else
+ len = sizeof(struct f2fs_comp_option);
+
+ if (copy_to_user((void __user *)arg, &option, len))
return -EFAULT;
return 0;
@@ -4263,7 +4271,9 @@ static long __f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
case F2FS_IOC_SEC_TRIM_FILE:
return f2fs_sec_trim_file(filp, arg);
case F2FS_IOC_GET_COMPRESS_OPTION:
- return f2fs_ioc_get_compress_option(filp, arg);
+ return f2fs_ioc_get_compress_option(filp, arg, F2FS_IOC_GET_COMPRESS_OPTION);
+ case F2FS_IOC_GET_COMPRESS_OPTION_V2:
+ return f2fs_ioc_get_compress_option(filp, arg, F2FS_IOC_GET_COMPRESS_OPTION_V2);
case F2FS_IOC_SET_COMPRESS_OPTION:
return f2fs_ioc_set_compress_option(filp, arg, F2FS_IOC_SET_COMPRESS_OPTION);
case F2FS_IOC_SET_COMPRESS_OPTION_V2:
@@ -4902,6 +4912,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
case F2FS_IOC_RESERVE_COMPRESS_BLOCKS:
case F2FS_IOC_SEC_TRIM_FILE:
case F2FS_IOC_GET_COMPRESS_OPTION:
+ case F2FS_IOC_GET_COMPRESS_OPTION_V2:
case F2FS_IOC_SET_COMPRESS_OPTION:
case F2FS_IOC_SET_COMPRESS_OPTION_V2:
case F2FS_IOC_DECOMPRESS_FILE:
diff --git a/include/uapi/linux/f2fs.h b/include/uapi/linux/f2fs.h
index 640569444200..b82dc386e59e 100644
--- a/include/uapi/linux/f2fs.h
+++ b/include/uapi/linux/f2fs.h
@@ -45,6 +45,8 @@
#define F2FS_IOC_START_ATOMIC_REPLACE _IO(F2FS_IOCTL_MAGIC, 25)
#define F2FS_IOC_SET_COMPRESS_OPTION_V2 _IOW(F2FS_IOCTL_MAGIC, 26, \
struct f2fs_comp_option_v2)
+#define F2FS_IOC_GET_COMPRESS_OPTION_V2 _IOW(F2FS_IOCTL_MAGIC, 27, \
+ struct f2fs_comp_option_v2)
/*
* should be same as XFS_IOC_GOINGDOWN.
@@ -65,7 +67,7 @@
#define F2FS_TRIM_FILE_MASK 0x3
/*
- * Flags used by F2FS_IOC_SET_COMPRESS_OPTION_V2
+ * Flags used by F2FS_IOC_SET_COMPRESS_OPTION_V2 and F2FS_IOC_GET_COMPRESS_OPTION
*/
#define COMPRESS_CHKSUM 0x0 /* enable chksum for compress file */
#define COMPRESS_LEVEL_OFFSET 8
--
2.25.1
next prev parent reply other threads:[~2023-01-22 15:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-22 15:00 [PATCH v2 1/2] f2fs: add F2FS_IOC_SET_COMPRESS_OPTION_V2 ioctl Yangtao Li
2023-01-22 15:00 ` Yangtao Li [this message]
2023-01-22 15:36 ` Yangtao Li
2023-01-22 15:38 ` Yangtao Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230122150049.66607-2-frank.li@vivo.com \
--to=frank.li@vivo.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®