f2fs_io: add get/set compression option
PATCH v2 1/1 f2fs_io: add get/set compression option
From: Daeho Jeong <[email protected]>
Added new commands, get_coption and set_coption, to support F2FS_IOC_GET_COMPRESS_OPTION and F2FS_IOC_SET_COMPRESS_OPTION.
Signed-off-by Daeho Jeong <[email protected]>
---
v2: changed the file open option of set_coption to write only.
--- tools/f2fs_io/f2fs_io.c | 61 +++++++++++++++++++++++++++++++++++++++++ tools/f2fs_io/f2fs_io.h | 9 ++++++ 2 files changed, 70 insertions(+)
tools/f2fs_io/f2fs_io.c +61 -0
@@ -905,6 +905,65 @@ static void do_reserve_cblocks(int argc, char **argv, const struct cmd_desc *cmdexit (0 ); } +#define get_coption_desc "get compression option of a compressed file" +#define get_coption_help \ +"f2fs_io get_coption [file]\n\n" \ +" algorithm : compression algorithm (0:lzo, 1: lz4, 2:zstd, 3:lzorle)\n" \ +" log_cluster_size : compression cluster log size (2 <= log_size <= 8)\n" + +static void do_get_coption (int argc,char **argv,const struct cmd_desc *cmd) +{ +struct f2fs_comp_option option; +int ret, fd; + +if (argc !=2 ) { +fputs ("Excess arguments\n\n" , stderr); +fputs (cmd->cmd_help, stderr); +exit (1 ); + } + + fd =xopen (argv[1 ],O_RDONLY ,0 ); + + ret =ioctl (fd,F2FS_IOC_GET_COMPRESS_OPTION , &option); +if (ret <0 ) +die_errno ("F2FS_IOC_GET_COMPRESS_OPTION failed" ); + +printf ("compression algorithm:%u\n" , option.algorithm); +printf ("compression cluster log size:%u\n" , option.log_cluster_size); + +exit (0 ); +} + +#define set_coption_desc "set compression option of a compressed file" +#define set_coption_help \ +"f2fs_io set_coption [algorithm] [log_cluster_size] [file_path]\n\n" \ +" algorithm : compression algorithm (0:lzo, 1: lz4, 2:zstd, 3:lzorle)\n" \ +" log_cluster_size : compression cluster log size (2 <= log_size <= 8)\n" + +static void do_set_coption (int argc,char **argv,const struct cmd_desc *cmd) +{ +struct f2fs_comp_option option; +int fd, ret; + +if (argc !=4 ) { +fputs ("Excess arguments\n\n" , stderr); +fputs (cmd->cmd_help, stderr); +exit (1 ); + } + + option.algorithm =atoi (argv[1 ]); + option.log_cluster_size =atoi (argv[2 ]); + + fd =xopen (argv[3 ],O_WRONLY ,0 ); + + ret =ioctl (fd,F2FS_IOC_SET_COMPRESS_OPTION , &option); +if (ret <0 ) +die_errno ("F2FS_IOC_SET_COMPRESS_OPTION failed" ); + +printf ("set compression option: algorithm=%u, log_cluster_size=%u\n" , + option.algorithm, option.log_cluster_size); +exit (0 ); +}#define CMD_HIDDEN 0x0001#define CMD (name) { #name, do_##name, name##_desc, name##_help, 0 }
@@ -930,6 +989,8 @@ const struct cmd_desc cmd_list[] = {CMD (get_cblocks),CMD (release_cblocks),CMD (reserve_cblocks), +CMD (get_coption), +CMD (set_coption), { NULL, NULL, NULL, NULL, 0 } };
tools/f2fs_io/f2fs_io.h +9 -0
@@ -84,6 +84,10 @@ typedef u32 __be32; _IOR(F2FS_IOCTL_MAGIC, 18, __u64)#define F2FS_IOC_RESERVE_COMPRESS_BLOCKS \ _IOR(F2FS_IOCTL_MAGIC, 19, __u64) +#define F2FS_IOC_GET_COMPRESS_OPTION _IOR(F2FS_IOCTL_MAGIC, 21, \ + struct f2fs_comp_option) +#define F2FS_IOC_SET_COMPRESS_OPTION _IOW(F2FS_IOCTL_MAGIC, 22, \ + struct f2fs_comp_option)#define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY#define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
@@ -164,3 +168,8 @@ struct f2fs_flush_device {u32 dev_num;/* device number to flush */ u32 segments;/* # of segments to flush */ }; + +struct f2fs_comp_option { +u8 algorithm; +u8 log_cluster_size; +};
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog