From 151fdb1aa090894eaa3dcef3194f7aaaeafb94cb Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Thu, 7 Mar 2024 14:29:13 +0800 Subject: f2fs_io: support get_advise command Support get_advise command to get i_advise field value and info in file. For example: f2fs_io get_advise /mnt/f2fs/foo.so i_advise=0x11, advise_type: cold keep_size Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- man/f2fs_io.8 | 3 +++ tools/f2fs_io/f2fs_io.c | 41 +++++++++++++++++++++++++++++++++++++++++ tools/f2fs_io/f2fs_io.h | 6 ++++++ 3 files changed, 50 insertions(+) diff --git a/man/f2fs_io.8 b/man/f2fs_io.8 index ecaab02..f097bde 100644 --- a/man/f2fs_io.8 +++ b/man/f2fs_io.8 @@ -171,6 +171,9 @@ Move a range of data blocks from source file to destination file .TP \fBgc_range\fR \fI[sync_mode] [start in 4kb] [length in 4kb] [file]\fR Trigger gc to move data blocks from specified address range +.TP +\fBget_advise\fR \fI[file]\fR +Get i_advise value and info in file .SH AUTHOR This version of .B f2fs_io diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c index 7059cbf..b8e4f02 100644 --- a/tools/f2fs_io/f2fs_io.c +++ b/tools/f2fs_io/f2fs_io.c @@ -1743,6 +1743,46 @@ static void do_lseek(int argc, char **argv, const struct cmd_desc *cmd) exit(0); } +#define get_advise_desc "get_advise" +#define get_advise_help "f2fs_io get_advise [file_path]\n\n" + +static void do_get_advise(int argc, char **argv, const struct cmd_desc *cmd) +{ + int ret; + unsigned char value; + + if (argc != 2) { + fputs("Excess arguments\n\n", stderr); + fputs(cmd->cmd_help, stderr); + exit(1); + } + + ret = getxattr(argv[1], F2FS_SYSTEM_ADVISE_NAME, &value, sizeof(value)); + if (ret != sizeof(value)) { + perror("getxattr"); + exit(1); + } + + printf("i_advise=0x%x, advise_type: ", value); + if (value & FADVISE_COLD_BIT) + printf("cold "); + if (value & FADVISE_LOST_PINO_BIT) + printf("lost_pino "); + if (value & FADVISE_ENCRYPT_BIT) + printf("encrypt "); + if (value & FADVISE_ENC_NAME_BIT) + printf("enc_name "); + if (value & FADVISE_KEEP_SIZE_BIT) + printf("keep_size "); + if (value & FADVISE_HOT_BIT) + printf("hot "); + if (value & FADVISE_VERITY_BIT) + printf("verity "); + if (value & FADVISE_TRUNC_BIT) + printf("trunc "); + printf("\n"); +} + #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 } @@ -1786,6 +1826,7 @@ const struct cmd_desc cmd_list[] = { CMD(setxattr), CMD(removexattr), CMD(lseek), + CMD(get_advise), { NULL, NULL, NULL, NULL, 0 } }; diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h index d2641cb..b5c82f5 100644 --- a/tools/f2fs_io/f2fs_io.h +++ b/tools/f2fs_io/f2fs_io.h @@ -169,7 +169,13 @@ struct fscrypt_get_policy_ex_arg { #define F2FS_SYSTEM_ADVISE_NAME "system.advise" #define FADVISE_COLD_BIT 0x01 +#define FADVISE_LOST_PINO_BIT 0x02 +#define FADVISE_ENCRYPT_BIT 0x04 +#define FADVISE_ENC_NAME_BIT 0x08 +#define FADVISE_KEEP_SIZE_BIT 0x10 #define FADVISE_HOT_BIT 0x20 +#define FADVISE_VERITY_BIT 0x40 +#define FADVISE_TRUNC_BIT 0x80 #ifndef FS_IMMUTABLE_FL #define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ -- cgit v1.2.3