f2fs_io: add compress/decompress commands

Added new commands, compress and decompress, to support
F2FS_IOC_COMPRESS_FILE and F2FS_IOC_DECOMPRESS_FILE.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Daeho Jeong 2020-12-08 10:19:10 +09:00 committed by Jaegeuk Kim
parent 457392a032
commit 7b63f7b399
2 changed files with 48 additions and 0 deletions

View File

@ -1052,6 +1052,50 @@ static void do_set_coption(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
#define decompress_desc "decompress an already compressed file"
#define decompress_help "f2fs_io decompress [file_path]\n\n"
static void do_decompress(int argc, char **argv, const struct cmd_desc *cmd)
{
int fd, ret;
if (argc != 2) {
fputs("Excess arguments\n\n", stderr);
fputs(cmd->cmd_help, stderr);
exit(1);
}
fd = xopen(argv[1], O_WRONLY, 0);
ret = ioctl(fd, F2FS_IOC_DECOMPRESS_FILE);
if (ret < 0)
die_errno("F2FS_IOC_DECOMPRESS_FILE failed");
exit(0);
}
#define compress_desc "compress a compression enabled file"
#define compress_help "f2fs_io compress [file_path]\n\n"
static void do_compress(int argc, char **argv, const struct cmd_desc *cmd)
{
int fd, ret;
if (argc != 2) {
fputs("Excess arguments\n\n", stderr);
fputs(cmd->cmd_help, stderr);
exit(1);
}
fd = xopen(argv[1], O_WRONLY, 0);
ret = ioctl(fd, F2FS_IOC_COMPRESS_FILE);
if (ret < 0)
die_errno("F2FS_IOC_COMPRESS_FILE failed");
exit(0);
}
#define CMD_HIDDEN 0x0001
#define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
#define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@ -1079,6 +1123,8 @@ const struct cmd_desc cmd_list[] = {
CMD(reserve_cblocks),
CMD(get_coption),
CMD(set_coption),
CMD(decompress),
CMD(compress),
{ NULL, NULL, NULL, NULL, 0 }
};

View File

@ -88,6 +88,8 @@ typedef u32 __be32;
struct f2fs_comp_option)
#define F2FS_IOC_SET_COMPRESS_OPTION _IOW(F2FS_IOCTL_MAGIC, 22, \
struct f2fs_comp_option)
#define F2FS_IOC_DECOMPRESS_FILE _IO(F2FS_IOCTL_MAGIC, 23)
#define F2FS_IOC_COMPRESS_FILE _IO(F2FS_IOCTL_MAGIC, 24)
#define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
#define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY