Skip to contentSkip to conversation

mkfs.f2fs: support multiple features with one "-O"

PATCH Superseded Junling Zheng 3 participants 8 messages Apr 2, 2018 – Apr 8, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.f2fs: support multiple features with one "-O"

Now one "-O" option can support multiple features separated by a comma or blank, such as:
feature1,feature2,... or "feature1 feature2 ..."

---
 mkfs/f2fs_format_main.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
mkfs/f2fs_format_main.c +27 -3
index 741600e..76ff296 100644
@@ -80,10 +80,8 @@ static void f2fs_show_info()
 	MSG(0, "Info: Trim is %s\n", c.trim ? "enabled": "disabled");
 }
 
-static void parse_feature(const char *features)
+static void set_feature_bits(char *features)
 {
-	while (*features == ' ')
-		features++;
 	if (!strcmp(features, "encrypt")) {
 		c.feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
 	} else if (!strcmp(features, "verity")) {
@@ -108,6 +106,32 @@ static void parse_feature(const char *features)
 	}
 }
 
+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);
+	}
+}
+
 static void f2fs_parse_options(int argc, char *argv[])
 {
 	static const char *option_string = "qa:c:d:e:E:il:mo:O:s:S:z:t:f";
Signature · 6 lines
2.16.2


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
#1 lore raw
Quoted 3 lines · Junling Zheng

Now one "-O" option can support multiple features separated by a comma or blank, such as:
feature1,feature2,... or "feature1 feature2 ..."

At a glance, can last sector number be parsed as feature name?

Thanks,

Quoted 46 lines
---
 mkfs/f2fs_format_main.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
mkfs/f2fs_format_main.c +20 -3
index 741600e..76ff296 100644
@@ -80,10 +80,8 @@ static void f2fs_show_info()
 	MSG(0, "Info: Trim is %s\n", c.trim ? "enabled": "disabled");
 }
 
-static void parse_feature(const char *features)
+static void set_feature_bits(char *features)
 {
-	while (*features == ' ')
-		features++;
 	if (!strcmp(features, "encrypt")) {
 		c.feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
 	} else if (!strcmp(features, "verity")) {
@@ -108,6 +106,32 @@ static void parse_feature(const char *features)
 	}
 }
 
+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;

mkfs/f2fs_format_main.c static void parse_feature(const char *features) · line 137

Quoted 10 lines
mkfs/f2fs_format_main.c +7 -0
+		else
+			*next = 0;
+
+		set_feature_bits(sub);
+	}
+}
+
 static void f2fs_parse_options(int argc, char *argv[])
 {
 	static const char *option_string = "qa:c:d:e:E:il:mo:O:s:S:z:t:f";

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

#2 lore raw

Hi, Chao

Quoted 7 lines · Chao Yu
Quoted 3 lines · Junling Zheng

Now one "-O" option can support multiple features separated by a comma or blank, such as:
feature1,feature2,... or "feature1 feature2 ..."

At a glance, can last sector number be parsed as feature name?

No, we should use quotation marks to wrap whole features while separating them with blanks.

Thanks,
Junling

Quoted 52 lines

Thanks,

Quoted 50 lines
---
 mkfs/f2fs_format_main.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
mkfs/f2fs_format_main.c +25 -3
index 741600e..76ff296 100644
@@ -80,10 +80,8 @@ static void f2fs_show_info()
 	MSG(0, "Info: Trim is %s\n", c.trim ? "enabled": "disabled");
 }
 
-static void parse_feature(const char *features)
+static void set_feature_bits(char *features)
 {
-	while (*features == ' ')
-		features++;
 	if (!strcmp(features, "encrypt")) {
 		c.feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
 	} else if (!strcmp(features, "verity")) {
@@ -108,6 +106,32 @@ static void parse_feature(const char *features)
 	}
 }
 
+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);
+	}
Quoted 9 lines

mkfs/f2fs_format_main.c static void parse_feature(const char *features) · line 137

Quoted 6 lines
mkfs/f2fs_format_main.c +2 -0
+}
+
 static void f2fs_parse_options(int argc, char *argv[])
 {
 	static const char *option_string = "qa:c:d:e:E:il:mo:O:s:S:z:t:f";

.

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

#3 lore raw

Hi Junling,

Quoted 4 lines · Junling Zheng

Hi, Chao

Quoted 1 line · Chao Yu

On 2018/4/2 12:19, Junling Zheng wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Now one "-O" option can support multiple features separated by a comma or blank, such as:
feature1,feature2,... or "feature1 feature2 ..."

At a glance, can last sector number be parsed as feature name?

No, we should use quotation marks to wrap whole features while separating them with blanks.

Sorry, that's right.

Quoted 48 lines

Thanks,
Junling

Quoted 44 lines

Thanks,

Quoted 42 lines
---
 mkfs/f2fs_format_main.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
mkfs/f2fs_format_main.c +17 -3
index 741600e..76ff296 100644
@@ -80,10 +80,8 @@ static void f2fs_show_info()
 	MSG(0, "Info: Trim is %s\n", c.trim ? "enabled": "disabled");
 }
 
-static void parse_feature(const char *features)
+static void set_feature_bits(char *features)
 {
-	while (*features == ' ')
-		features++;
 	if (!strcmp(features, "encrypt")) {
 		c.feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
 	} else if (!strcmp(features, "verity")) {
@@ -108,6 +106,32 @@ static void parse_feature(const char *features)
 	}
 }
 
+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++;
Quoted 8 lines
Quoted 8 lines

mkfs/f2fs_format_main.c static void parse_feature(const char *features) · line 132

Quoted 8 lines
mkfs/f2fs_format_main.c +8 -0
+
+		if (*next == 0)
+			next = NULL;
+		else
+			*next = 0;
+
+		set_feature_bits(sub);
+	}

free(buf);?

Thanks,

Quoted 12 lines
Quoted 9 lines

mkfs/f2fs_format_main.c static void parse_feature(const char *features) · line 137

Quoted 6 lines
mkfs/f2fs_format_main.c +2 -0
+}
+
 static void f2fs_parse_options(int argc, char *argv[])
 {
 	static const char *option_string = "qa:c:d:e:E:il:mo:O:s:S:z:t:f";

.

Quoted 2 lines

.

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

#4 lore raw
Quoted 68 lines · Chao Yu

Hi Junling,

Quoted 4 lines · Junling Zheng

Hi, Chao

Quoted 1 line · Chao Yu

On 2018/4/2 12:19, Junling Zheng wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Now one "-O" option can support multiple features separated by a comma or blank, such as:
feature1,feature2,... or "feature1 feature2 ..."

At a glance, can last sector number be parsed as feature name?

No, we should use quotation marks to wrap whole features while separating them with blanks.

Sorry, that's right.

Quoted 50 lines

Thanks,
Junling

Quoted 46 lines

Thanks,

Quoted 44 lines
---
 mkfs/f2fs_format_main.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
mkfs/f2fs_format_main.c +19 -3
index 741600e..76ff296 100644
@@ -80,10 +80,8 @@ static void f2fs_show_info()
 	MSG(0, "Info: Trim is %s\n", c.trim ? "enabled": "disabled");
 }
 
-static void parse_feature(const char *features)
+static void set_feature_bits(char *features)
 {
-	while (*features == ' ')
-		features++;
 	if (!strcmp(features, "encrypt")) {
 		c.feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
 	} else if (!strcmp(features, "verity")) {
@@ -108,6 +106,32 @@ static void parse_feature(const char *features)
 	}
 }
 
+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)
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

mkfs/f2fs_format_main.c static void parse_feature(const char *features) · line 132

Quoted 6 lines
mkfs/f2fs_format_main.c +6 -0
+			next = NULL;
+		else
+			*next = 0;
+
+		set_feature_bits(sub);
+	}

free(buf);?

Sorry :(
I'll send patch v2...

Quoted 14 lines

Thanks,

Quoted 12 lines
Quoted 9 lines

mkfs/f2fs_format_main.c static void parse_feature(const char *features) · line 137

Quoted 6 lines
mkfs/f2fs_format_main.c +2 -0
+}
+
 static void f2fs_parse_options(int argc, char *argv[])
 {
 	static const char *option_string = "qa:c:d:e:E:il:mo:O:s:S:z:t:f";

.

Quoted 6 lines
Quoted 2 lines

.

.

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

#5 lore raw

PATCH v2 1/1 mkfs.f2fs: support multiple features with one "-O"

In reply to Chao Yu

Now one "-O" option can support multiple features separated by a comma or blank, such as:
feature1,feature2,... or "feature1 feature2 ..."

---
Changes from v1:
- free buf to fix memory leak.

 mkfs/f2fs_format_main.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)
mkfs/f2fs_format_main.c +28 -3
index 741600e..278efff 100644
@@ -80,10 +80,8 @@ static void f2fs_show_info()
 	MSG(0, "Info: Trim is %s\n", c.trim ? "enabled": "disabled");
 }
 
-static void parse_feature(const char *features)
+static void set_feature_bits(char *features)
 {
-	while (*features == ' ')
-		features++;
 	if (!strcmp(features, "encrypt")) {
 		c.feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
 	} else if (!strcmp(features, "verity")) {
@@ -108,6 +106,33 @@ static void parse_feature(const char *features)
 	}
 }
 
+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 f2fs_parse_options(int argc, char *argv[])
 {
 	static const char *option_string = "qa:c:d:e:E:il:mo:O:s:S:z:t:f";
Signature · 6 lines
2.16.2


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Reviewed-by on v2 1/1
#6 lore raw
Quoted 5 lines · Junling Zheng

Now one "-O" option can support multiple features separated by a comma or blank, such as:
feature1,feature2,... or "feature1 feature2 ..."

Thanks,

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

#7 lore raw

PATCH v3 1/1 mkfs.f2fs: support multiple features with one "-O"

In reply to Junling Zheng

Now one "-O" option can support multiple features separated by a comma or blank, such as:
feature1,feature2,... or "feature1 feature2 ..."

---
Changes from v1:
- free buf to fix memory leak.
Changes from v2:
- modify usage and man page to show this feature.

 man/mkfs.f2fs.8         |  3 ++-
 mkfs/f2fs_format_main.c | 33 +++++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 5 deletions(-)
man/mkfs.f2fs.8 +2 -1
index 442c0ea..29dd68f 100644
@@ -112,7 +112,8 @@ is hidden to users, and utilized by F2FS cleaner. If not specified, the best
 number will be assigned automatically accoring to the partition size.
 .TP
 .BI \-O " feature-list"
-Specify a feature list in order f2fs filesystem will supports.
+Specify a feature list like feature1[feature2,feature3,...] in order f2fs
+filesystem will supports.
 e.g "encrypt" and so on.
 .TP
 .BI \-q
mkfs/f2fs_format_main.c +29 -4
index 449a0ed..a6e4474 100644
@@ -51,7 +51,7 @@ static void mkfs_usage()
 	MSG(0, "  -l label\n");
 	MSG(0, "  -m support zoned block device [default:0]\n");
 	MSG(0, "  -o overprovision ratio [default:5]\n");
-	MSG(0, "  -O [feature list] e.g. \"encrypt\"\n");
+	MSG(0, "  -O feature1[feature2,feature3,...] e.g. \"encrypt\"\n");
 	MSG(0, "  -q quiet mode\n");
 	MSG(0, "  -s # of segments per section [default:1]\n");
 	MSG(0, "  -S sparse mode\n");
@@ -81,10 +81,8 @@ static void f2fs_show_info()
 	MSG(0, "Info: Trim is %s\n", c.trim ? "enabled": "disabled");
 }
 
-static void parse_feature(const char *features)
+static void set_feature_bits(char *features)
 {
-	while (*features == ' ')
-		features++;
 	if (!strcmp(features, "encrypt")) {
 		c.feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
 	} else if (!strcmp(features, "verity")) {
@@ -109,6 +107,33 @@ static void parse_feature(const char *features)
 	}
 }
 
+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 f2fs_parse_options(int argc, char *argv[])
 {
 	static const char *option_string = "qa:c:d:e:E:il:mo:O:s:S:z:t:fw:";
Signature · 6 lines
2.16.2


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