linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: "Piotr Sokołowski" <piotrsok2@gmail.com>
To: linux-f2fs-devel@lists.sourceforge.net
Subject: [PATCH v2] f2fs-tools: fix displaing usage information
Date: Tue,  4 Jul 2017 14:44:27 +0200	[thread overview]
Message-ID: <1499172267-186-1-git-send-email-piotrsok2@gmail.com> (raw)

When commands that are symlinks to fsck.f2fs binary are invoked without 
any parameters, now they show their own usage communicate instead of 
fsck.f2fs help message in all cases.

---
 fsck/main.c | 477 +++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 250 insertions(+), 227 deletions(-)

diff --git a/fsck/main.c b/fsck/main.c
index 6c94a70..adc8675 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -108,6 +108,17 @@ void f2fs_parse_options(int argc, char *argv[])
 	char *prog = basename(argv[0]);
 	int err = NOERROR;
 
+	if (!strcmp("fsck.f2fs", prog))
+		c.func = FSCK;
+	else if (!strcmp("dump.f2fs", prog))
+		c.func = DUMP;
+	else if (!strcmp("defrag.f2fs", prog))
+		c.func = DEFRAG;
+	else if (!strcmp("resize.f2fs", prog))
+		c.func = RESIZE;
+	else if (!strcmp("sload.f2fs", prog))
+		c.func = SLOAD;
+
 	if (argc < 2) {
 		MSG(0, "\tError: Device not specified\n");
 		error_out();
@@ -115,261 +126,273 @@ void f2fs_parse_options(int argc, char *argv[])
 	c.devices[0].path = strdup(argv[argc - 1]);
 	argv[argc-- - 1] = 0;
 
-	if (!strcmp("fsck.f2fs", prog)) {
-		const char *option_string = ":ad:fp:t";
+	switch (c.func) {
+	case FSCK:
+		{
+			const char *option_string = ":ad:fp:t";
 
-		c.func = FSCK;
-		while ((option = getopt(argc, argv, option_string)) != EOF) {
-			switch (option) {
-			case 'a':
-				c.auto_fix = 1;
-				MSG(0, "Info: Fix the reported corruption.\n");
-				break;
-			case 'p':
-				/* preen mode has different levels:
-				 *  0: default level, the same as -a
-				 *  1: check meta
-				 */
-				if (optarg[0] == '-') {
-					c.preen_mode = PREEN_MODE_0;
-					optind--;
-					break;
-				} else if (!is_digits(optarg)) {
-					err = EWRONG_OPT;
-					break;
-				}
-				c.preen_mode = atoi(optarg);
-				if (c.preen_mode < 0)
-					c.preen_mode = PREEN_MODE_0;
-				else if (c.preen_mode >= PREEN_MODE_MAX)
-					c.preen_mode = PREEN_MODE_MAX - 1;
-				if (c.preen_mode == PREEN_MODE_0)
+			while ((option = getopt(argc, argv, option_string)) != EOF) {
+				switch (option) {
+				case 'a':
 					c.auto_fix = 1;
-				MSG(0, "Info: Fix the reported corruption in "
-					"preen mode %d\n", c.preen_mode);
-				break;
-			case 'd':
-				if (optarg[0] == '-') {
-					err = ENEED_ARG;
+					MSG(0, "Info: Fix the reported corruption.\n");
 					break;
-				} else if (!is_digits(optarg)) {
-					err = EWRONG_OPT;
+				case 'p':
+					/* preen mode has different levels:
+					*  0: default level, the same as -a
+					*  1: check meta
+					*/
+					if (optarg[0] == '-') {
+						c.preen_mode = PREEN_MODE_0;
+						optind--;
+						break;
+					} else if (!is_digits(optarg)) {
+						err = EWRONG_OPT;
+						break;
+					}
+					c.preen_mode = atoi(optarg);
+					if (c.preen_mode < 0)
+						c.preen_mode = PREEN_MODE_0;
+					else if (c.preen_mode >= PREEN_MODE_MAX)
+						c.preen_mode = PREEN_MODE_MAX - 1;
+					if (c.preen_mode == PREEN_MODE_0)
+						c.auto_fix = 1;
+					MSG(0, "Info: Fix the reported corruption in "
+						"preen mode %d\n", c.preen_mode);
+					break;
+				case 'd':
+					if (optarg[0] == '-') {
+						err = ENEED_ARG;
+						break;
+					} else if (!is_digits(optarg)) {
+						err = EWRONG_OPT;
+						break;
+					}
+					c.dbg_lv = atoi(optarg);
+					MSG(0, "Info: Debug level = %d\n", c.dbg_lv);
+					break;
+				case 'f':
+					c.fix_on = 1;
+					MSG(0, "Info: Force to fix corruption\n");
+					break;
+				case 't':
+					c.dbg_lv = -1;
 					break;
-				}
-				c.dbg_lv = atoi(optarg);
-				MSG(0, "Info: Debug level = %d\n", c.dbg_lv);
-				break;
-			case 'f':
-				c.fix_on = 1;
-				MSG(0, "Info: Force to fix corruption\n");
-				break;
-			case 't':
-				c.dbg_lv = -1;
-				break;
 
 
-			case ':':
-				if (optopt == 'p') {
-					MSG(0, "Info: Use default preen mode\n");
-					c.preen_mode = PREEN_MODE_0;
-					c.auto_fix = 1;
-				} else {
+				case ':':
+					if (optopt == 'p') {
+						MSG(0, "Info: Use default preen mode\n");
+						c.preen_mode = PREEN_MODE_0;
+						c.auto_fix = 1;
+					} else {
+						option = optopt;
+						err = ENEED_ARG;
+						break;
+					}
+					break;
+				case '?':
 					option = optopt;
-					err = ENEED_ARG;
+				default:
+					err = EUNKNOWN_OPT;
 					break;
 				}
-				break;
-			case '?':
-				option = optopt;
-			default:
-				err = EUNKNOWN_OPT;
-				break;
+				if (err != NOERROR)
+					break;
 			}
-			if (err != NOERROR)
-				break;
 		}
-	} else if (!strcmp("dump.f2fs", prog)) {
-		const char *option_string = "d:i:n:s:a:b:";
-		static struct dump_option dump_opt = {
-			.nid = 0,	/* default root ino */
-			.start_nat = -1,
-			.end_nat = -1,
-			.start_sit = -1,
-			.end_sit = -1,
-			.start_ssa = -1,
-			.end_ssa = -1,
-			.blk_addr = -1,
-		};
-
-		c.func = DUMP;
-		while ((option = getopt(argc, argv, option_string)) != EOF) {
-			int ret = 0;
-
-			switch (option) {
-			case 'd':
-				if (!is_digits(optarg)) {
-					err = EWRONG_OPT;
+		break;
+	case DUMP:
+		{
+			const char *option_string = "d:i:n:s:a:b:";
+			static struct dump_option dump_opt = {
+				.nid = 0,	/* default root ino */
+				.start_nat = -1,
+				.end_nat = -1,
+				.start_sit = -1,
+				.end_sit = -1,
+				.start_ssa = -1,
+				.end_ssa = -1,
+				.blk_addr = -1,
+			};
+
+			while ((option = getopt(argc, argv, option_string)) != EOF) {
+				int ret = 0;
+
+				switch (option) {
+				case 'd':
+					if (!is_digits(optarg)) {
+						err = EWRONG_OPT;
+						break;
+					}
+					c.dbg_lv = atoi(optarg);
+					MSG(0, "Info: Debug level = %d\n",
+								c.dbg_lv);
+					break;
+				case 'i':
+					if (strncmp(optarg, "0x", 2))
+						ret = sscanf(optarg, "%d",
+								&dump_opt.nid);
+					else
+						ret = sscanf(optarg, "%x",
+								&dump_opt.nid);
+					break;
+				case 'n':
+					ret = sscanf(optarg, "%d~%d",
+								&dump_opt.start_nat,
+								&dump_opt.end_nat);
+					break;
+				case 's':
+					ret = sscanf(optarg, "%d~%d",
+								&dump_opt.start_sit,
+								&dump_opt.end_sit);
+					break;
+				case 'a':
+					ret = sscanf(optarg, "%d~%d",
+								&dump_opt.start_ssa,
+								&dump_opt.end_ssa);
+					break;
+				case 'b':
+					if (strncmp(optarg, "0x", 2))
+						ret = sscanf(optarg, "%d",
+								&dump_opt.blk_addr);
+					else
+						ret = sscanf(optarg, "%x",
+								&dump_opt.blk_addr);
+					break;
+				default:
+					err = EUNKNOWN_OPT;
 					break;
 				}
-				c.dbg_lv = atoi(optarg);
-				MSG(0, "Info: Debug level = %d\n",
-							c.dbg_lv);
-				break;
-			case 'i':
-				if (strncmp(optarg, "0x", 2))
-					ret = sscanf(optarg, "%d",
-							&dump_opt.nid);
-				else
-					ret = sscanf(optarg, "%x",
-							&dump_opt.nid);
-				break;
-			case 'n':
-				ret = sscanf(optarg, "%d~%d",
-							&dump_opt.start_nat,
-							&dump_opt.end_nat);
-				break;
-			case 's':
-				ret = sscanf(optarg, "%d~%d",
-							&dump_opt.start_sit,
-							&dump_opt.end_sit);
-				break;
-			case 'a':
-				ret = sscanf(optarg, "%d~%d",
-							&dump_opt.start_ssa,
-							&dump_opt.end_ssa);
-				break;
-			case 'b':
-				if (strncmp(optarg, "0x", 2))
-					ret = sscanf(optarg, "%d",
-							&dump_opt.blk_addr);
-				else
-					ret = sscanf(optarg, "%x",
-							&dump_opt.blk_addr);
-				break;
-			default:
-				err = EUNKNOWN_OPT;
-				break;
+				ASSERT(ret >= 0);
+				if (err != NOERROR)
+					break;
 			}
-			ASSERT(ret >= 0);
-			if (err != NOERROR)
-				break;
-		}
-
-		c.private = &dump_opt;
-	} else if (!strcmp("defrag.f2fs", prog)) {
-		const char *option_string = "d:s:l:t:i";
 
-		c.func = DEFRAG;
-		while ((option = getopt(argc, argv, option_string)) != EOF) {
-			int ret = 0;
-
-			switch (option) {
-			case 'd':
-				if (!is_digits(optarg)) {
-					err = EWRONG_OPT;
+			c.private = &dump_opt;
+		}
+		break;
+	case DEFRAG:
+		{
+			const char *option_string = "d:s:l:t:i";
+
+			while ((option = getopt(argc, argv, option_string)) != EOF) {
+				int ret = 0;
+
+				switch (option) {
+				case 'd':
+					if (!is_digits(optarg)) {
+						err = EWRONG_OPT;
+						break;
+					}
+					c.dbg_lv = atoi(optarg);
+					MSG(0, "Info: Debug level = %d\n",
+								c.dbg_lv);
+					break;
+				case 's':
+					if (strncmp(optarg, "0x", 2))
+						ret = sscanf(optarg, "%"PRIu64"",
+								&c.defrag_start);
+					else
+						ret = sscanf(optarg, "%"PRIx64"",
+								&c.defrag_start);
+					break;
+				case 'l':
+					if (strncmp(optarg, "0x", 2))
+						ret = sscanf(optarg, "%"PRIu64"",
+								&c.defrag_len);
+					else
+						ret = sscanf(optarg, "%"PRIx64"",
+								&c.defrag_len);
+					break;
+				case 't':
+					if (strncmp(optarg, "0x", 2))
+						ret = sscanf(optarg, "%"PRIu64"",
+								&c.defrag_target);
+					else
+						ret = sscanf(optarg, "%"PRIx64"",
+								&c.defrag_target);
+					break;
+				case 'i':
+					c.defrag_shrink = 1;
+					break;
+				default:
+					err = EUNKNOWN_OPT;
 					break;
 				}
-				c.dbg_lv = atoi(optarg);
-				MSG(0, "Info: Debug level = %d\n",
-							c.dbg_lv);
-				break;
-			case 's':
-				if (strncmp(optarg, "0x", 2))
-					ret = sscanf(optarg, "%"PRIu64"",
-							&c.defrag_start);
-				else
-					ret = sscanf(optarg, "%"PRIx64"",
-							&c.defrag_start);
-				break;
-			case 'l':
-				if (strncmp(optarg, "0x", 2))
-					ret = sscanf(optarg, "%"PRIu64"",
-							&c.defrag_len);
-				else
-					ret = sscanf(optarg, "%"PRIx64"",
-							&c.defrag_len);
-				break;
-			case 't':
-				if (strncmp(optarg, "0x", 2))
-					ret = sscanf(optarg, "%"PRIu64"",
-							&c.defrag_target);
-				else
-					ret = sscanf(optarg, "%"PRIx64"",
-							&c.defrag_target);
-				break;
-			case 'i':
-				c.defrag_shrink = 1;
-				break;
-			default:
-				err = EUNKNOWN_OPT;
-				break;
+				ASSERT(ret >= 0);
+				if (err != NOERROR)
+					break;
 			}
-			ASSERT(ret >= 0);
-			if (err != NOERROR)
-				break;
 		}
-	} else if (!strcmp("resize.f2fs", prog)) {
-		const char *option_string = "d:t:";
-
-		c.func = RESIZE;
-		while ((option = getopt(argc, argv, option_string)) != EOF) {
-			int ret = 0;
-
-			switch (option) {
-			case 'd':
-				if (!is_digits(optarg)) {
-					err = EWRONG_OPT;
+		break;
+	case RESIZE:
+		{
+			const char *option_string = "d:t:";
+
+			while ((option = getopt(argc, argv, option_string)) != EOF) {
+				int ret = 0;
+
+				switch (option) {
+				case 'd':
+					if (!is_digits(optarg)) {
+						err = EWRONG_OPT;
+						break;
+					}
+					c.dbg_lv = atoi(optarg);
+					MSG(0, "Info: Debug level = %d\n",
+								c.dbg_lv);
+					break;
+				case 't':
+					if (strncmp(optarg, "0x", 2))
+						ret = sscanf(optarg, "%"PRIu64"",
+								&c.target_sectors);
+					else
+						ret = sscanf(optarg, "%"PRIx64"",
+								&c.target_sectors);
+					break;
+				default:
+					err = EUNKNOWN_OPT;
 					break;
 				}
-				c.dbg_lv = atoi(optarg);
-				MSG(0, "Info: Debug level = %d\n",
-							c.dbg_lv);
-				break;
-			case 't':
-				if (strncmp(optarg, "0x", 2))
-					ret = sscanf(optarg, "%"PRIu64"",
-							&c.target_sectors);
-				else
-					ret = sscanf(optarg, "%"PRIx64"",
-							&c.target_sectors);
-				break;
-			default:
-				err = EUNKNOWN_OPT;
-				break;
+				ASSERT(ret >= 0);
+				if (err != NOERROR)
+					break;
 			}
-			ASSERT(ret >= 0);
-			if (err != NOERROR)
-				break;
 		}
-	} else if (!strcmp("sload.f2fs", prog)) {
-		const char *option_string = "d:f:t:";
-
-		c.func = SLOAD;
-		while ((option = getopt(argc, argv, option_string)) != EOF) {
-			switch (option) {
-			case 'd':
-				if (!is_digits(optarg)) {
-					err = EWRONG_OPT;
+		break;
+	case SLOAD:
+		{
+			const char *option_string = "d:f:t:";
+
+			while ((option = getopt(argc, argv, option_string)) != EOF) {
+				switch (option) {
+				case 'd':
+					if (!is_digits(optarg)) {
+						err = EWRONG_OPT;
+						break;
+					}
+					c.dbg_lv = atoi(optarg);
+					MSG(0, "Info: Debug level = %d\n",
+							c.dbg_lv);
+					break;
+				case 'f':
+					c.from_dir = (char *)optarg;
+					break;
+				case 't':
+					c.mount_point = (char *)optarg;
+					break;
+				default:
+					err = EUNKNOWN_OPT;
 					break;
 				}
-				c.dbg_lv = atoi(optarg);
-				MSG(0, "Info: Debug level = %d\n",
-						c.dbg_lv);
-				break;
-			case 'f':
-				c.from_dir = (char *)optarg;
-				break;
-			case 't':
-				c.mount_point = (char *)optarg;
-				break;
-			default:
-				err = EUNKNOWN_OPT;
-				break;
+				if (err != NOERROR)
+					break;
 			}
-			if (err != NOERROR)
-				break;
 		}
+		break;
 	}
+
 	if (argc > optind) {
 		c.dbg_lv = 0;
 		err = EUNKNOWN_ARG;
-- 
1.9.1


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

             reply	other threads:[~2017-07-04 12:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-04 12:44 Piotr Sokołowski [this message]
2017-07-05  3:43 ` [PATCH v2] f2fs-tools: fix displaing usage information Jaegeuk Kim

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=1499172267-186-1-git-send-email-piotrsok2@gmail.com \
    --to=piotrsok2@gmail.com \
    --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).