3 #include "libbcachefs/error.h"
4 #include "libbcachefs.h"
5 #include "libbcachefs/super.h"
6 #include "tools-util.h"
8 static void usage(void)
10 puts("bcachefs fsck - filesystem check and repair\n"
11 "Usage: bcachefs fsck [OPTION]... <devices>\n"
14 " -p Automatic repair (no questions)\n"
15 " -n Don't repair, only check for errors\n"
16 " -y Assume \"yes\" to all questions\n"
17 " -f Force checking even if filesystem is marked clean\n"
19 " --h Display this help and exit\n"
20 "Report bugs to <linux-bcache@vger.kernel.org>");
23 int cmd_fsck(int argc, char *argv[])
25 struct bch_opts opts = bch2_opts_empty();
29 opt_set(opts, degraded, true);
30 opt_set(opts, fix_errors, FSCK_OPT_ASK);
32 while ((opt = getopt(argc, argv, "apynfvh")) != -1)
34 case 'a': /* outdated alias for -p */
36 opt_set(opts, fix_errors, FSCK_OPT_YES);
39 opt_set(opts, fix_errors, FSCK_OPT_YES);
42 opt_set(opts, nochanges, true);
43 opt_set(opts, fix_errors, FSCK_OPT_NO);
46 /* force check, even if filesystem marked clean: */
49 opt_set(opts, verbose, true);
58 die("Please supply device(s) to check");
60 for (i = 0; i < argc; i++)
61 if (dev_mounted_rw(argv[i]))
62 die("%s is mounted read-write - aborting", argv[i]);
64 struct bch_fs *c = bch2_fs_open(argv, argc, opts);
66 die("error opening %s: %s", argv[0], strerror(-PTR_ERR(c)));
68 if (test_bit(BCH_FS_FSCK_FIXED_ERRORS, &c->flags))
70 if (test_bit(BCH_FS_FSCK_UNFIXED_ERRORS, &c->flags))