aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaeho Jeong <daehojeong@google.com>2020-12-08 10:19:10 +0900
committerJaegeuk Kim <jaegeuk@kernel.org>2020-12-10 05:51:08 -0800
commit7b63f7b399c02a4371ef1e49a94b382aaad9a006 (patch)
tree06a7ab6e43b9700b883cc48eb5383e085ce9fe27
parent457392a0325ab86808d8785269c9cc73745c9f8d (diff)
downloadf2fs-tools-7b63f7b399c02a4371ef1e49a94b382aaad9a006.tar.gz
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>
-rw-r--r--tools/f2fs_io/f2fs_io.c46
-rw-r--r--tools/f2fs_io/f2fs_io.h2
2 files changed, 48 insertions, 0 deletions
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index e53a397..033c256 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -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 }
};
diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
index cb56e8c..d53e576 100644
--- a/tools/f2fs_io/f2fs_io.h
+++ b/tools/f2fs_io/f2fs_io.h
@@ -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