From 8c43a9adf7fd56d9212398c93433d68dfd6d683f Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Mon, 4 Oct 2010 15:41:10 -0400 Subject: [PATCH] Add btrfsck option to select the super block copy btrfsck -s 0 uses the defult 0, -s 1 uses copy #1 etc. Signed-off-by: Chris Mason --- btrfsck.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/btrfsck.c b/btrfsck.c index cd2cedd..63e44d1 100644 --- a/btrfsck.c +++ b/btrfsck.c @@ -20,6 +20,7 @@ #define _GNU_SOURCE 1 #include #include +#include #include #include #include "kerncompat.h" @@ -2819,23 +2820,43 @@ int main(int ac, char **av) { struct cache_tree root_cache; struct btrfs_root *root; + u64 bytenr = 0; int ret; + int num; - if (ac < 2) + while(1) { + int c; + c = getopt(ac, av, "s:"); + if (c < 0) + break; + switch(c) { + case 's': + num = atol(optarg); + bytenr = btrfs_sb_offset(num); + printf("using SB copy %d, bytenr %llu\n", num, + (unsigned long long)bytenr); + break; + default: + print_usage(); + } + } + ac = ac - optind; + + if (ac != 1) print_usage(); radix_tree_init(); cache_tree_init(&root_cache); - if((ret = check_mounted(av[1])) < 0) { + if((ret = check_mounted(av[optind])) < 0) { fprintf(stderr, "Could not check mount status: %s\n", strerror(ret)); return ret; } else if(ret) { - fprintf(stderr, "%s is currently mounted. Aborting.\n", av[1]); + fprintf(stderr, "%s is currently mounted. Aborting.\n", av[optind]); return -EBUSY; } - root = open_ctree(av[1], 0, 0); + root = open_ctree(av[optind], bytenr, 0); if (root == NULL) return 1; -- 2.11.4.GIT