btrfs-progs: add option to disable backtrace usage
[platform/upstream/btrfs-progs.git] / btrfs-select-super.c
index 6a458b8..6231d42 100644 (file)
@@ -43,7 +43,7 @@ int main(int ac, char **av)
 {
        struct btrfs_root *root;
        int ret;
-       int num = 0;
+       u64 num = 0;
        u64 bytenr = 0;
 
        while(1) {
@@ -53,16 +53,23 @@ int main(int ac, char **av)
                        break;
                switch(c) {
                        case 's':
-                               num = atol(optarg);
-                               bytenr = btrfs_sb_offset(num);
+                               num = arg_strtou64(optarg);
+                               if (num >= BTRFS_SUPER_MIRROR_MAX) {
+                                       fprintf(stderr,
+                                               "ERROR: super mirror should be less than: %d\n",
+                                               BTRFS_SUPER_MIRROR_MAX);
+                                       exit(1);
+                               }
+                               bytenr = btrfs_sb_offset(((int)num));
                                break;
                        default:
                                print_usage();
                }
        }
+       set_argv0(av);
        ac = ac - optind;
 
-       if (ac != 1)
+       if (check_argc_exact(ac, 1))
                print_usage();
 
        if (bytenr == 0) {
@@ -94,8 +101,8 @@ int main(int ac, char **av)
        /* we don't close the ctree or anything, because we don't want a real
         * transaction commit.  We just want the super copy we pulled off the
         * disk to overwrite all the other copies
-        */ 
-       printf("using SB copy %d, bytenr %llu\n", num,
+        */
+       printf("using SB copy %llu, bytenr %llu\n", (unsigned long long)num,
               (unsigned long long)bytenr);
        return ret;
 }