]> git.sesse.net Git - bcachefs-tools-debian/blob - cmd_fsck.c
5ca9b8254536d39f2cb7e405e42037f9a33b8f20
[bcachefs-tools-debian] / cmd_fsck.c
1
2 #include "cmds.h"
3 #include "error.h"
4 #include "libbcachefs.h"
5 #include "super.h"
6 #include "tools-util.h"
7
8 static void usage(void)
9 {
10         puts("bcachefs fsck - filesystem check and repair\n"
11              "Usage: bcachefs fsck [OPTION]... <devices>\n"
12              "\n"
13              "Options:\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"
18              "  -v     Be verbose\n"
19              " --h     Display this help and exit\n"
20              "Report bugs to <linux-bcache@vger.kernel.org>");
21 }
22
23 int cmd_fsck(int argc, char *argv[])
24 {
25         struct bch_opts opts = bch2_opts_empty();
26         struct bch_fs *c = NULL;
27         const char *err;
28         int opt;
29
30         opts.degraded = true;
31
32         while ((opt = getopt(argc, argv, "pynfvh")) != -1)
33                 switch (opt) {
34                 case 'p':
35                         opts.fix_errors = FSCK_ERR_YES;
36                         break;
37                 case 'y':
38                         opts.fix_errors = FSCK_ERR_YES;
39                         break;
40                 case 'n':
41                         opts.nochanges = true;
42                         opts.fix_errors = FSCK_ERR_NO;
43                         break;
44                 case 'f':
45                         /* force check, even if filesystem marked clean: */
46                         break;
47                 case 'v':
48                         opts.verbose_recovery = true;
49                         break;
50                 case 'h':
51                         usage();
52                         exit(EXIT_SUCCESS);
53                 }
54
55         if (optind >= argc)
56                 die("Please supply device(s) to check");
57
58         err = bch2_fs_open(argv + optind, argc - optind, opts, &c);
59         if (err)
60                 die("error opening %s: %s", argv[optind], err);
61
62         bch2_fs_stop(c);
63         return 0;
64 }