From 6a765fd0852e38d0dceebeceab8821ef0463ac11 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 18 May 2020 14:56:35 -0400 Subject: [PATCH] Add reconstruct_alloc option to fsck --- cmd_fsck.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/cmd_fsck.c b/cmd_fsck.c index e6792458..409b1585 100644 --- a/cmd_fsck.c +++ b/cmd_fsck.c @@ -1,4 +1,5 @@ +#include #include "cmds.h" #include "libbcachefs/error.h" #include "libbcachefs.h" @@ -11,17 +12,22 @@ static void usage(void) "Usage: bcachefs fsck [OPTION]... \n" "\n" "Options:\n" - " -p Automatic repair (no questions)\n" - " -n Don't repair, only check for errors\n" - " -y Assume \"yes\" to all questions\n" - " -f Force checking even if filesystem is marked clean\n" - " -v Be verbose\n" - " --h Display this help and exit\n" - "Report bugs to "); + " -p Automatic repair (no questions)\n" + " -n Don't repair, only check for errors\n" + " -y Assume \"yes\" to all questions\n" + " -f Force checking even if filesystem is marked clean\n" + " --reconstruct_alloc Reconstruct the alloc btree\n" + " -v Be verbose\n" + " --h Display this help and exit\n" + "Report bugs to "); } int cmd_fsck(int argc, char *argv[]) { + static const struct option longopts[] = { + { "reconstruct_alloc", no_argument, NULL, 'R' }, + { NULL } + }; struct bch_opts opts = bch2_opts_empty(); unsigned i; int opt, ret = 0; @@ -30,7 +36,9 @@ int cmd_fsck(int argc, char *argv[]) opt_set(opts, fsck, true); opt_set(opts, fix_errors, FSCK_OPT_ASK); - while ((opt = getopt(argc, argv, "apynfo:vh")) != -1) + while ((opt = getopt_long(argc, argv, + "apynfo:vh", + longopts, NULL)) != -1) switch (opt) { case 'a': /* outdated alias for -p */ case 'p': @@ -51,6 +59,9 @@ int cmd_fsck(int argc, char *argv[]) if (ret) return ret; break; + case 'R': + opt_set(opts, reconstruct_alloc, true); + break; case 'v': opt_set(opts, verbose, true); break;