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