summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Maggard <jmaggard10@gmail.com>2014-07-28 18:55:09 -0700
committerDavid Sterba <dsterba@suse.cz>2014-08-22 15:07:03 +0200
commit2ac5cdf79f5ffb4f9e6c50cd56ab0abca257a390 (patch)
tree87f1c32815ab098dc781eb1edd284f576bf2ddc9
parent84ebfa6d88fb9bfe10b26be03cf4982973b4fa17 (diff)
btrfs-progs: add always option to restore's looping prompt
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> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
-rw-r--r--cmds-restore.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/cmds-restore.c b/cmds-restore.c
index 33c0ba5a..e09acc42 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -411,23 +411,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;
}
@@ -595,11 +603,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 {