All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mkfs.f2fs: factor out feature table from mkfs.f2fs
@ 2018-04-19 20:56 Jaegeuk Kim
  2018-04-23  3:56 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Jaegeuk Kim @ 2018-04-19 20:56 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: Jaegeuk Kim

This patch makes feature bit work be global in f2fs-tools.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 include/f2fs_fs.h       | 77 +++++++++++++++++++++++++++++++++++++++++
 mkfs/f2fs_format_main.c | 67 ++---------------------------------
 2 files changed, 80 insertions(+), 64 deletions(-)

diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 54ac1c8..a1274fd 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -40,6 +40,14 @@
 #include <linux/blkzoned.h>
 #endif
 
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
 #ifdef HAVE_LIBSELINUX
 #include <selinux/selinux.h>
 #include <selinux/label.h>
@@ -1307,4 +1315,73 @@ static inline void show_version(const char *prog)
 	MSG(0, "%s %s (%s)\n", prog, F2FS_TOOLS_VERSION, F2FS_TOOLS_DATE);
 }
 
+struct feature {
+	char *name;
+	u32  mask;
+};
+
+#define INIT_FEATURE_TABLE						\
+struct feature feature_table[] = {					\
+	{ "encrypt",			F2FS_FEATURE_ENCRYPT },		\
+	{ "extra_attr",			F2FS_FEATURE_EXTRA_ATTR },	\
+	{ "project_quota",		F2FS_FEATURE_PRJQUOTA },	\
+	{ "inode_checksum",		F2FS_FEATURE_INODE_CHKSUM },	\
+	{ "flexible_inline_xattr",	F2FS_FEATURE_FLEXIBLE_INLINE_XATTR },\
+	{ "quota",			F2FS_FEATURE_QUOTA_INO },	\
+	{ "inode_crtime",		F2FS_FEATURE_INODE_CRTIME },	\
+	{ "lost_found",			F2FS_FEATURE_LOST_FOUND },	\
+	{ "verity",			F2FS_FEATURE_VERITY },	/* reserved */ \
+	{ NULL,				0x0},				\
+};
+
+static inline u32 feature_map(struct feature *table, char *feature)
+{
+	struct feature *p;
+	for (p = table; p->name && strcmp(p->name, feature); p++)
+		;
+	return p->mask;
+}
+
+static inline int set_feature_bits(struct feature *table, char *features)
+{
+	u32 mask = feature_map(table, features);
+	if (mask) {
+		c.feature |= cpu_to_le32(mask);
+	} else {
+		MSG(0, "Error: Wrong features %s\n", features);
+		return -1;
+	}
+	return 0;
+}
+
+static inline int parse_feature(struct feature *table, const char *features)
+{
+	char *buf, *sub, *next;
+
+	buf = calloc(strlen(features) + 1, sizeof(char));
+	ASSERT(buf);
+	strncpy(buf, features, strlen(features) + 1);
+
+	for (sub = buf; sub && *sub; sub = next ? next + 1 : NULL) {
+		/* Skip the beginning blanks */
+		while (*sub && *sub == ' ')
+			sub++;
+		next = sub;
+		/* Skip a feature word */
+		while (*next && *next != ' ' && *next != ',')
+			next++;
+
+		if (*next == 0)
+			next = NULL;
+		else
+			*next = 0;
+
+		if (set_feature_bits(table, sub)) {
+			free(buf);
+			return -1;
+		}
+	}
+	free(buf);
+	return 0;
+}
 #endif	/*__F2FS_FS_H */
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 4e39fbd..8af70a2 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -37,23 +37,7 @@ extern struct sparse_file *f2fs_sparse_file;
 extern struct f2fs_configuration c;
 static int force_overwrite = 0;
 
-struct feature {
-	char *name;
-	u32  mask;
-};
-
-struct feature feature_table[] = {
-	{ "encrypt",			F2FS_FEATURE_ENCRYPT },
-	{ "extra_attr",			F2FS_FEATURE_EXTRA_ATTR },
-	{ "project_quota",		F2FS_FEATURE_PRJQUOTA },
-	{ "inode_checksum",		F2FS_FEATURE_INODE_CHKSUM },
-	{ "flexible_inline_xattr",	F2FS_FEATURE_FLEXIBLE_INLINE_XATTR },
-	{ "quota",			F2FS_FEATURE_QUOTA_INO },
-	{ "inode_crtime",		F2FS_FEATURE_INODE_CRTIME },
-	{ "lost_found",			F2FS_FEATURE_LOST_FOUND },
-	{ "verity",			F2FS_FEATURE_VERITY },	/* reserved */
-	{ NULL,				0x0},
-};
+INIT_FEATURE_TABLE;
 
 static void mkfs_usage()
 {
@@ -104,52 +88,6 @@ static void f2fs_show_info()
 		MSG(0, "Info: Set conf for android\n");
 }
 
-static inline u32 feature_map(char *feature)
-{
-	struct feature *p;
-	for (p = feature_table; p->name && strcmp(p->name, feature); p++)
-		;
-	return p->mask;
-}
-
-static void set_feature_bits(char *features)
-{
-	u32 mask = feature_map(features);
-	if (mask) {
-		c.feature |= cpu_to_le32(mask);
-	} else {
-		MSG(0, "Error: Wrong features %s\n", features);
-		mkfs_usage();
-	}
-}
-
-static void parse_feature(const char *features)
-{
-	char *buf, *sub, *next;
-
-	buf = calloc(strlen(features) + 1, sizeof(char));
-	ASSERT(buf);
-	strncpy(buf, features, strlen(features) + 1);
-
-	for (sub = buf; sub && *sub; sub = next ? next + 1 : NULL) {
-		/* Skip the beginning blanks */
-		while (*sub && *sub == ' ')
-			sub++;
-		next = sub;
-		/* Skip a feature word */
-		while (*next && *next != ' ' && *next != ',')
-			next++;
-
-		if (*next == 0)
-			next = NULL;
-		else
-			*next = 0;
-
-		set_feature_bits(sub);
-	}
-	free(buf);
-}
-
 static void add_default_options(void)
 {
 	switch (c.defset) {
@@ -221,7 +159,8 @@ static void f2fs_parse_options(int argc, char *argv[])
 			c.overprovision = atof(optarg);
 			break;
 		case 'O':
-			parse_feature(optarg);
+			if (parse_feature(feature_table, optarg))
+				mkfs_usage();
 			break;
 		case 's':
 			c.segs_per_sec = atoi(optarg);
-- 
2.17.0.484.g0c8726318c-goog


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] mkfs.f2fs: factor out feature table from mkfs.f2fs
  2018-04-19 20:56 [PATCH] mkfs.f2fs: factor out feature table from mkfs.f2fs Jaegeuk Kim
@ 2018-04-23  3:56 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2018-04-23  3:56 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-f2fs-devel

On 2018/4/20 4:56, Jaegeuk Kim wrote:
> This patch makes feature bit work be global in f2fs-tools.
> 
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

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

Thanks,



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

end of thread, other threads:[~2018-04-23  3:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-19 20:56 [PATCH] mkfs.f2fs: factor out feature table from mkfs.f2fs Jaegeuk Kim
2018-04-23  3:56 ` Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.