summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2010-10-04 15:41:10 -0400
committerChris Mason <chris.mason@oracle.com>2010-10-04 15:41:10 -0400
commit8c43a9adf7fd56d9212398c93433d68dfd6d683f (patch)
tree4ef0cf316a06e32dc20216800d56ca4b16861901
parentc301fccdab6fa8126c3585c37227f988996492f8 (diff)
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 <chris.mason@oracle.com>
-rw-r--r--btrfsck.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/btrfsck.c b/btrfsck.c
index cd2cedd7..63e44d1d 100644
--- a/btrfsck.c
+++ b/btrfsck.c
@@ -20,6 +20,7 @@
#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#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;