linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Junling Zheng <zhengjunling@huawei.com>
To: jaegeuk@kernel.org, chao@kernel.org, yuchao0@huawei.com
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [PATCH v2] mkfs.f2fs: support multiple features with one "-O"
Date: Tue, 3 Apr 2018 17:38:45 +0800	[thread overview]
Message-ID: <20180403093845.68535-1-zhengjunling@huawei.com> (raw)
In-Reply-To: <dd1b7eff-3b60-891b-48f4-0f029ef44507@huawei.com>

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

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
---
Changes from v1:
 - free buf to fix memory leak.
 mkfs/f2fs_format_main.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 741600e..278efff 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -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";
-- 
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

  parent reply	other threads:[~2018-04-03  9:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-02  4:19 [PATCH] mkfs.f2fs: support multiple features with one "-O" Junling Zheng
2018-04-02 13:35 ` Chao Yu
2018-04-03  2:15   ` Junling Zheng
2018-04-03  9:24     ` Chao Yu
2018-04-03  9:23       ` Junling Zheng
2018-04-03  9:38       ` Junling Zheng [this message]
2018-04-03 10:01         ` [PATCH v2] " Chao Yu
2018-04-08  4:09         ` [PATCH v3] " Junling Zheng

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=20180403093845.68535-1-zhengjunling@huawei.com \
    --to=zhengjunling@huawei.com \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=yuchao0@huawei.com \
    /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).