All of lore.kernel.org
 help / color / mirror / Atom feed
From: Justin Maggard <jmaggard10@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Justin Maggard <jmaggard10@gmail.com>
Subject: [PATCH v2] btrfs-progs: add always option to restore's looping prompt
Date: Mon, 28 Jul 2014 18:55:09 -0700	[thread overview]
Message-ID: <1406598909-9658-1-git-send-email-jmaggard10@gmail.com> (raw)

If you are using btrfs restore to try to recover a very large or
fragmented file, you may encounter _lots_ of prompts requiring
you to press 'y' to continue because we are looping a lot.

Add the option to press 'a', to supress these prompts for the rest
of the file.

Signed-off-by: Justin Maggard <jmaggard10@gmail.com>
---
 cmds-restore.c |   31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/cmds-restore.c b/cmds-restore.c
index 3465f84..059194d 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -410,23 +410,31 @@ out:
 	return ret;
 }
 
-static int ask_to_continue(const char *file)
+enum loop_response {
+	LOOP_STOP,
+	LOOP_CONTINUE,
+	LOOP_DONTASK
+};
+
+static enum loop_response ask_to_continue(const char *file)
 {
 	char buf[2];
 	char *ret;
 
 	printf("We seem to be looping a lot on %s, do you want to keep going "
-	       "on ? (y/N): ", file);
+	       "on ? (y/N/a): ", file);
 again:
 	ret = fgets(buf, 2, stdin);
 	if (*ret == '\n' || tolower(*ret) == 'n')
-		return 1;
+		return LOOP_STOP;
+	if (tolower(*ret) == 'a')
+		return LOOP_DONTASK;
 	if (tolower(*ret) != 'y') {
-		printf("Please enter either 'y' or 'n': ");
+		printf("Please enter one of 'y', 'n', or 'a': ");
 		goto again;
 	}
 
-	return 0;
+	return LOOP_CONTINUE;
 }
 
 
@@ -594,11 +602,16 @@ static int copy_file(struct btrfs_root *root, int fd, struct btrfs_key *key,
 	}
 
 	while (1) {
-		if (loops++ >= 1024) {
-			ret = ask_to_continue(file);
-			if (ret)
+		if (loops >= 0 && loops++ >= 1024) {
+			enum loop_response resp;
+
+			resp = ask_to_continue(file);
+			if (resp == LOOP_STOP)
 				break;
-			loops = 0;
+			else if (resp == LOOP_CONTINUE)
+				loops = 0;
+			else if (resp == LOOP_DONTASK)
+				loops = -1;
 		}
 		if (path->slots[0] >= btrfs_header_nritems(leaf)) {
 			do {
-- 
1.7.10.4


             reply	other threads:[~2014-07-29  1:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-29  1:55 Justin Maggard [this message]
2014-07-29  2:11 ` [PATCH v2] btrfs-progs: add always option to restore's looping prompt Qu Wenruo

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=1406598909-9658-1-git-send-email-jmaggard10@gmail.com \
    --to=jmaggard10@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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 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.