public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
From: "zhangyi (F)" <yi.zhang@huawei.com>
To: linux-unionfs@vger.kernel.org, fstests@vger.kernel.org
Cc: miklos@szeredi.hu, amir73il@gmail.com, eguan@redhat.com,
	darrick.wong@oracle.com, yi.zhang@huawei.com, miaoxie@huawei.com
Subject: [PATCH v2 03/18] fsck.overlay: add -n -p and -y options
Date: Thu, 14 Dec 2017 14:47:32 +0800	[thread overview]
Message-ID: <20171214064747.20999-4-yi.zhang@huawei.com> (raw)
In-Reply-To: <20171214064747.20999-1-yi.zhang@huawei.com>

Add -n -p and -y options to make it official as fsck utilities.

Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
---
 fsck.c | 36 ++++++++++++++++++++++++++++++------
 lib.c  |  3 ++-
 lib.h  |  6 +++++-
 3 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/fsck.c b/fsck.c
index 7f704c8..f4c806b 100644
--- a/fsck.c
+++ b/fsck.c
@@ -49,13 +49,16 @@ static void ovl_clean_lowerdirs(void)
 static void usage(void)
 {
 	print_info(_("Usage:\n\t%s [-l lowerdir] [-u upperdir] [-w workdir] "
-		    "[-avhV]\n\n"), program_name);
+		    "[-pnyvhV]\n\n"), program_name);
 	print_info(_("Options:\n"
 		    "-l, --lowerdir=LOWERDIR   specify lower directories of overlayfs,\n"
-		    "                          multiple lower use ':' as separator\n"
+		    "                          multiple lower use ':' as separator,\n"
+		    "                          the leftmost one is the toppest\n"
 		    "-u, --upperdir=UPPERDIR   specify upper directory of overlayfs\n"
 		    "-w, --workdir=WORKDIR     specify work directory of overlayfs\n"
-		    "-a, --auto                repair automatically (no questions)\n"
+		    "-p,                       automatic repair (no questions)\n"
+		    "-n,                       make no changes to the filesystem\n"
+		    "-y,                       assume \"yes\" to all questions\n"
 		    "-v, --verbose             print more messages of overlayfs\n"
 		    "-h, --help                display this usage of overlayfs\n"
 		    "-V, --version             display version information\n"));
@@ -67,19 +70,19 @@ static void parse_options(int argc, char *argv[])
 	char *lowertemp;
 	int c;
 	int ret = 0;
+	bool opt_conflict = false;
 
 	struct option long_options[] = {
 		{"lowerdir", required_argument, NULL, 'l'},
 		{"upperdir", required_argument, NULL, 'u'},
 		{"workdir", required_argument, NULL, 'w'},
-		{"auto", no_argument, NULL, 'a'},
 		{"verbose", no_argument, NULL, 'v'},
 		{"version", no_argument, NULL, 'V'},
 		{"help", no_argument, NULL, 'h'},
 		{NULL, 0, NULL, 0}
 	};
 
-	while ((c = getopt_long(argc, argv, "l:u:w:avVh", long_options, NULL)) != -1) {
+	while ((c = getopt_long(argc, argv, "l:u:w:apnyvVh", long_options, NULL)) != -1) {
 		switch (c) {
 		case 'l':
 			lowertemp = strdup(optarg);
@@ -105,7 +108,23 @@ static void parse_options(int argc, char *argv[])
 			}
 			break;
 		case 'a':
-			flags |= FL_AUTO;
+		case 'p':
+			if (flags & (FL_OPT_YES | FL_OPT_NO))
+				opt_conflict = true;
+			else
+				flags |= FL_OPT_AUTO;
+			break;
+		case 'n':
+			if (flags & (FL_OPT_YES | FL_OPT_AUTO))
+				opt_conflict = true;
+			else
+				flags |= FL_OPT_NO;
+			break;
+		case 'y':
+			if (flags & (FL_OPT_NO | FL_OPT_AUTO))
+				opt_conflict = true;
+			else
+				flags |= FL_OPT_YES;
 			break;
 		case 'v':
 			flags |= FL_VERBOSE;
@@ -127,6 +146,11 @@ static void parse_options(int argc, char *argv[])
 		print_info(_("Please specify correct lowerdirs and upperdir\n"));
 		usage();
 	}
+
+	if (opt_conflict) {
+		print_info(_("Only one of the options -p/-a, -n or -y can be specified.\n"));
+		usage();
+	}
 }
 
 void fsck_status_check(int *val)
diff --git a/lib.c b/lib.c
index a6832fe..7607517 100644
--- a/lib.c
+++ b/lib.c
@@ -46,7 +46,8 @@ static int ask_yn(const char *question, int def)
 /* Ask user */
 int ask_question(const char *question, int def)
 {
-	if (flags & FL_AUTO) {
+	if (flags & FL_OPT_MASK) {
+		def = (flags & FL_OPT_YES) ? 1 : (flags & FL_OPT_NO) ? 0 : def;
 		print_info(_("%s? %s\n"), question, def ? _("y") : _("n"));
 		return def;
 	}
diff --git a/lib.h b/lib.h
index 463b263..2956235 100644
--- a/lib.h
+++ b/lib.h
@@ -19,7 +19,11 @@
 #define FL_VERBOSE	(1 << 0)	/* verbose */
 #define FL_UPPER	(1 << 1)	/* specify upper directory */
 #define FL_WORK		(1 << 2)	/* specify work directory */
-#define FL_AUTO		(1 << 3)	/* automactically scan dirs and repair */
+#define FL_OPT_AUTO	(1 << 3)	/* automactically scan dirs and repair */
+#define FL_OPT_NO	(1 << 4)	/* no changes to the filesystem */
+#define FL_OPT_YES	(1 << 5)	/* yes to all questions */
+#define FL_OPT_MASK	(FL_OPT_AUTO|FL_OPT_NO|FL_OPT_YES)
+
 
 /* Scan path type */
 #define OVL_UPPER	0
-- 
2.9.5


  parent reply	other threads:[~2017-12-14  6:42 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-14  6:47 [PATCH v2 00/18] overlay: implement fsck.overlay utility zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 01/18] overlay: implement fsck utility zhangyi (F)
2017-12-14 14:13   ` Miklos Szeredi
2017-12-14 14:33     ` Amir Goldstein
2017-12-14 14:47       ` Miklos Szeredi
2017-12-14 15:03         ` Amir Goldstein
2017-12-14 15:10           ` Miklos Szeredi
2017-12-14 15:18             ` Amir Goldstein
2017-12-14 15:48               ` Miklos Szeredi
2017-12-14 16:03                 ` Vivek Goyal
2017-12-14 16:29                 ` Amir Goldstein
2017-12-15 14:18                   ` Miklos Szeredi
2017-12-15 14:44                     ` Amir Goldstein
2017-12-15 16:06                       ` Miklos Szeredi
2017-12-15 16:14                         ` Miklos Szeredi
2017-12-15 15:16                     ` Vivek Goyal
2017-12-15 16:17                       ` Miklos Szeredi
2017-12-14 15:21       ` Vivek Goyal
2017-12-14 15:43         ` Amir Goldstein
2017-12-14 16:12           ` Vivek Goyal
2017-12-15  4:18       ` zhangyi (F)
2017-12-15  3:35     ` zhangyi (F)
2017-12-15  7:45       ` Amir Goldstein
2017-12-15  9:13         ` zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 02/18] fsck.overlay: fix uninitialized variable zhangyi (F)
2017-12-14  9:15   ` Amir Goldstein
2017-12-14  6:47 ` zhangyi (F) [this message]
2017-12-14  6:47 ` [PATCH v2 04/18] fsck.overlay: add path package and split helper zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 05/18] fsck.overlay: convert path parse to use helper function zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 06/18] fsck.overlay: open lowerdirs in advance zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 07/18] fsck.overlay: check lowers use relative path zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 08/18] fsck.overlay: fix spelling mistakes zhangyi (F)
2017-12-14  9:13   ` Amir Goldstein
2017-12-14  6:47 ` [PATCH v2 09/18] fsck.overlay: add counter of checked objects zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 10/18] fsck.overlay: fix verbose flag zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 11/18] fsck.overlay: add ovl_ask_invalid helper zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 12/18] fsck.overlay: remove duplicate redirect xattr in yes mode zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 13/18] fsck.overlay: handle missing case of redirecte directory zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 14/18] fsck.overlay: correct copyright and License zhangyi (F)
2017-12-14  9:09   ` Amir Goldstein
2017-12-14  6:47 ` [PATCH v2 15/18] fsck.overlay: fix word mistake zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 16/18] fsck.overlay: remove test cases zhangyi (F)
2017-12-14  9:11   ` Amir Goldstein
2017-12-14  6:47 ` [PATCH v2 17/18] fsck.overlay: not enforce overlayfs is offline in 'no changes' mode zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 18/18] fsck.overlay: use relative path when checking lowers zhangyi (F)
2017-12-14  9:27 ` [PATCH v2 00/18] overlay: implement fsck.overlay utility Amir Goldstein
2017-12-14 10:43   ` zhangyi (F)

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=20171214064747.20999-4-yi.zhang@huawei.com \
    --to=yi.zhang@huawei.com \
    --cc=amir73il@gmail.com \
    --cc=darrick.wong@oracle.com \
    --cc=eguan@redhat.com \
    --cc=fstests@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miaoxie@huawei.com \
    --cc=miklos@szeredi.hu \
    /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