From: Chao Yu <yuchao0@huawei.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>,
<linux-f2fs-devel@lists.sourceforge.net>
Cc: Jaegeuk Kim <jaegeuk@google.com>
Subject: Re: [f2fs-dev] [PATCH] f2fs_io: add get/setflags
Date: Mon, 12 Aug 2019 10:58:22 +0800 [thread overview]
Message-ID: <0177358e-f900-857d-d7e6-5e5335497913@huawei.com> (raw)
In-Reply-To: <20190809152328.94814-1-jaegeuk@kernel.org>
On 2019/8/9 23:23, Jaegeuk Kim wrote:
> From: Jaegeuk Kim <jaegeuk@google.com>
>
> Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
> ---
> tools/f2fs_io/f2fs_io.c | 91 +++++++++++++++++++++++++++++++++++++++++
> tools/f2fs_io/f2fs_io.h | 14 +++++++
> 2 files changed, 105 insertions(+)
>
> diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
> index 6b43778..b57c458 100644
> --- a/tools/f2fs_io/f2fs_io.c
> +++ b/tools/f2fs_io/f2fs_io.c
> @@ -45,6 +45,95 @@ struct cmd_desc {
> int cmd_flags;
> };
>
> +#define getflags_desc "getflags ioctl"
> +#define getflags_help \
> +"f2fs_io getflags [file]\n\n" \
> +"get a flag given the file\n" \
> +"flag can show \n" \
> +" casefold\n" \
> +" compression\n" \
> +" nocompression\n"
Could we support +/- flags?
> +
> +static void do_getflags(int argc, char **argv, const struct cmd_desc *cmd)
> +{
> + long flag;
> + int ret, fd;
> + int exist = 0;
> +
> + if (argc != 2) {
> + fputs("Excess arguments\n\n", stderr);
> + fputs(cmd->cmd_help, stderr);
> + exit(1);
> + }
> +
> + fd = open(argv[1], O_RDONLY);
> + if (fd == -1) {
> + fputs("Open failed\n\n", stderr);
> + fputs(cmd->cmd_help, stderr);
> + exit(1);
> + }
> + ret = ioctl(fd, F2FS_IOC_GETFLAGS, &flag);
> + printf("get a flag on %s ret=%d, flags=", argv[1], ret);
> + if (flag & FS_CASEFOLD_FL) {
> + printf("casefold");
> + exist = 1;
> + }
> + if (flag & FS_COMPR_FL) {
> + if (exist)
> + printf(",");
> + printf("compression");
> + exist = 1;
> + }
> + if (flag & FS_NOCOMP_FL) {
> + if (exist)
> + printf(",");
> + printf("nocompression");
> + exist = 1;
> + }
> + if (!exist)
> + printf("none");
> + printf("\n");
> + exit(0);
> +}
> +
> +#define setflags_desc "setflags ioctl"
> +#define setflags_help \
> +"f2fs_io setflags [flag] [file]\n\n" \
> +"set a flag given the file\n" \
> +"flag can be\n" \
> +" casefold\n" \
> +" compression\n" \
> +" nocompression\n"
> +
> +static void do_setflags(int argc, char **argv, const struct cmd_desc *cmd)
> +{
> + long flag;
> + int ret, fd;
> +
> + if (argc != 3) {
> + fputs("Excess arguments\n\n", stderr);
> + fputs(cmd->cmd_help, stderr);
> + exit(1);
> + }
> +
> + fd = open(argv[2], O_RDONLY);
> + if (fd == -1) {
> + fputs("Open failed\n\n", stderr);
> + fputs(cmd->cmd_help, stderr);
> + exit(1);
> + }
> + if (!strcmp(argv[1], "casefold"))
> + flag = FS_CASEFOLD_FL;
> + else if (!strcmp(argv[1], "compression"))
> + flag = FS_COMPR_FL;
> + else if (!strcmp(argv[1], "nocompression"))
> + flag = FS_NOCOMP_FL;
> +
> + ret = ioctl(fd, F2FS_IOC_SETFLAGS, &flag);
It will drop other existed flags, should be:
F2FS_IOC_GETFLAGS flag
flag +/- FS_*_FL
F2FS_IOC_SETFLAGS flag
Thanks,
> + printf("set a flag: %s ret=%d\n", argv[2], ret);
> + exit(0);
> +}
> +
> #define shutdown_desc "shutdown filesystem"
> #define shutdown_help \
> "f2fs_io shutdown [level] [dir]\n\n" \
> @@ -488,6 +577,8 @@ static void do_defrag_file(int argc, char **argv, const struct cmd_desc *cmd)
> static void do_help(int argc, char **argv, const struct cmd_desc *cmd);
> const struct cmd_desc cmd_list[] = {
> _CMD(help),
> + CMD(getflags),
> + CMD(setflags),
> CMD(shutdown),
> CMD(pinfile),
> CMD(fallocate),
> diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
> index 95fd5be..5768c1b 100644
> --- a/tools/f2fs_io/f2fs_io.h
> +++ b/tools/f2fs_io/f2fs_io.h
> @@ -41,9 +41,13 @@ typedef u32 __be32;
> #ifndef FS_IOC_GETFLAGS
> #define FS_IOC_GETFLAGS _IOR('f', 1, long)
> #endif
> +#ifndef FS_IOC_SETFLAGS
> +#define FS_IOC_SETFLAGS _IOW('f', 2, long)
> +#endif
>
> #define F2FS_IOCTL_MAGIC 0xf5
> #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
> +#define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
>
> #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
> #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
> @@ -98,6 +102,16 @@ typedef u32 __be32;
> #define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR
> #define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR
>
> +#ifndef FS_NOCOMP_FL
> +#define FS_NOCOMP_FL 0x00000400 /* Don't compress */
> +#endif
> +#ifndef FS_COMPR_FL
> +#define FS_COMPR_FL 0x00000004 /* Compress file */
> +#endif
> +#ifndef FS_CASEFOLD_FL
> +#define FS_CASEFOLD_FL 0x40000000 /* Folder is case insensitive */
> +#endif
> +
> struct f2fs_gc_range {
> u32 sync;
> u64 start;
>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2019-08-12 2:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-09 15:23 [f2fs-dev] [PATCH] f2fs_io: add get/setflags Jaegeuk Kim
2019-08-12 2:58 ` Chao Yu [this message]
2019-08-16 2:23 ` Jaegeuk Kim
2019-08-16 2:28 ` Jaegeuk Kim
2019-08-16 2:41 ` [f2fs-dev] [PATCH v2] " Jaegeuk Kim
2019-08-19 2:54 ` Chao Yu
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=0177358e-f900-857d-d7e6-5e5335497913@huawei.com \
--to=yuchao0@huawei.com \
--cc=jaegeuk@google.com \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/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;
as well as URLs for NNTP newsgroup(s).