Linux-f2fs-devel Archive on lore.kernel.org
 help / color / Atom feed
* [f2fs-dev] [PATCH] f2fs_io: add get/setflags
@ 2019-08-09 15:23 Jaegeuk Kim
  2019-08-12  2:58 ` Chao Yu
  2019-08-16  2:41 ` [f2fs-dev] [PATCH v2] " Jaegeuk Kim
  0 siblings, 2 replies; 6+ messages in thread
From: Jaegeuk Kim @ 2019-08-09 15:23 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: Jaegeuk Kim

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"
+
+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);
+	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;
-- 
2.19.0.605.g01d371f741-goog



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs_io: add get/setflags
  2019-08-09 15:23 [f2fs-dev] [PATCH] f2fs_io: add get/setflags Jaegeuk Kim
@ 2019-08-12  2:58 ` Chao Yu
  2019-08-16  2:23   ` Jaegeuk Kim
  2019-08-16  2:41 ` [f2fs-dev] [PATCH v2] " Jaegeuk Kim
  1 sibling, 1 reply; 6+ messages in thread
From: Chao Yu @ 2019-08-12  2:58 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-f2fs-devel; +Cc: Jaegeuk Kim

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs_io: add get/setflags
  2019-08-12  2:58 ` Chao Yu
@ 2019-08-16  2:23   ` Jaegeuk Kim
  2019-08-16  2:28     ` Jaegeuk Kim
  0 siblings, 1 reply; 6+ messages in thread
From: Jaegeuk Kim @ 2019-08-16  2:23 UTC (permalink / raw)
  To: Chao Yu; +Cc: Jaegeuk Kim, linux-f2fs-devel

On 08/12, Chao Yu wrote:
> 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:

Is it correct?

In f2fs_setflags_common,

	fi->i_flags = iflags | (fi->i_flags & ~mask);


> 
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs_io: add get/setflags
  2019-08-16  2:23   ` Jaegeuk Kim
@ 2019-08-16  2:28     ` Jaegeuk Kim
  0 siblings, 0 replies; 6+ messages in thread
From: Jaegeuk Kim @ 2019-08-16  2:28 UTC (permalink / raw)
  To: Chao Yu; +Cc: Jaegeuk Kim, linux-f2fs-devel

On 08/15, Jaegeuk Kim wrote:
> On 08/12, Chao Yu wrote:
> > 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:
> 
> Is it correct?
> 
> In f2fs_setflags_common,
> 
> 	fi->i_flags = iflags | (fi->i_flags & ~mask);

Hmm, it indeed drops the flags. :P

> 
> 
> > 
> > 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


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs_io: add get/setflags
  2019-08-09 15:23 [f2fs-dev] [PATCH] f2fs_io: add get/setflags Jaegeuk Kim
  2019-08-12  2:58 ` Chao Yu
@ 2019-08-16  2:41 ` " Jaegeuk Kim
  2019-08-19  2:54   ` Chao Yu
  1 sibling, 1 reply; 6+ messages in thread
From: Jaegeuk Kim @ 2019-08-16  2:41 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: Jaegeuk Kim

Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
---
- Add + flags for now

 tools/f2fs_io/f2fs_io.c | 98 +++++++++++++++++++++++++++++++++++++++++
 tools/f2fs_io/f2fs_io.h | 14 ++++++
 2 files changed, 112 insertions(+)

diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index a5a9836..add40c4 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -45,6 +45,102 @@ 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"
+
+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);
+	}
+
+	ret = ioctl(fd, F2FS_IOC_GETFLAGS, &flag);
+	printf("get a flag on %s ret=%d, flags=%lx\n", argv[1], ret, flag);
+	if (ret)
+		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);
+	printf("set a flag on %s ret=%d, flags=%s\n", argv[2], ret, argv[1]);
+	exit(0);
+}
+
 #define shutdown_desc "shutdown filesystem"
 #define shutdown_help					\
 "f2fs_io shutdown [level] [dir]\n\n"			\
@@ -488,6 +584,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;
-- 
2.19.0.605.g01d371f741-goog



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs_io: add get/setflags
  2019-08-16  2:41 ` [f2fs-dev] [PATCH v2] " Jaegeuk Kim
@ 2019-08-19  2:54   ` Chao Yu
  0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2019-08-19  2:54 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-f2fs-devel; +Cc: Jaegeuk Kim

On 2019/8/16 10:41, Jaegeuk Kim wrote:
> Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-09 15:23 [f2fs-dev] [PATCH] f2fs_io: add get/setflags Jaegeuk Kim
2019-08-12  2:58 ` Chao Yu
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

Linux-f2fs-devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-f2fs-devel/0 linux-f2fs-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-f2fs-devel linux-f2fs-devel/ https://lore.kernel.org/linux-f2fs-devel \
		linux-f2fs-devel@lists.sourceforge.net linux-f2fs-devel@archiver.kernel.org
	public-inbox-index linux-f2fs-devel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/net.sourceforge.lists.linux-f2fs-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox