--- btrfs-progs-v0.19-118-gfdb6c04.orig/btrfs-image.c +++ btrfs-progs-v0.19-118-gfdb6c04/btrfs-image.c @@ -491,6 +491,11 @@ static int create_metadump(const char *i int ret; root = open_ctree(input, 0, 0); + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + exit(1); + } + BUG_ON(root->nodesize != root->leafsize); ret = metadump_init(&metadump, root, out, num_threads, --- btrfs-progs-v0.19-118-gfdb6c04.orig/btrfs-select-super.c +++ btrfs-progs-v0.19-118-gfdb6c04/btrfs-select-super.c @@ -100,8 +100,10 @@ int main(int ac, char **av) } root = open_ctree_fd(fp, av[optind], bytenr, 1, use_earliest_bdev); - if (root == NULL) + if (!root) { + fprintf(stderr, "Open ctree failed\n"); return 1; + } fprintf(stderr, "Found superblock with generation %llu.\n", root->fs_info->super_copy.generation); --- btrfs-progs-v0.19-118-gfdb6c04.orig/btrfslabel.c +++ btrfs-progs-v0.19-118-gfdb6c04/btrfslabel.c @@ -46,7 +46,7 @@ #define GET_LABEL 3 #define SET_LABEL 4 -static void change_label_unmounted(char *dev, char *nLabel) +static int change_label_unmounted(char *dev, char *nLabel) { struct btrfs_root *root; struct btrfs_trans_handle *trans; @@ -55,6 +55,10 @@ static void change_label_unmounted(char * and as read-write. */ root = open_ctree(dev, 0, 1); + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + return -1; + } trans = btrfs_start_transaction(root, 1); strncpy(root->fs_info->super_copy.label, nLabel, BTRFS_LABEL_SIZE); @@ -62,9 +66,10 @@ static void change_label_unmounted(char /* Now we close it since we are done. */ close_ctree(root); + return 0; } -static void get_label_unmounted(char *dev) +static int get_label_unmounted(char *dev) { struct btrfs_root *root; @@ -72,11 +77,16 @@ static void get_label_unmounted(char *de * and as read-only. */ root = open_ctree(dev, 0, 0); + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + return -1; + } fprintf(stdout, "%s\n", root->fs_info->super_copy.label); /* Now we close it since we are done. */ close_ctree(root); + return 0; } int get_label(char *btrfs_dev) @@ -95,8 +105,7 @@ int get_label(char *btrfs_dev) fprintf(stderr, "FATAL: the filesystem has to be unmounted\n"); return -2; } - get_label_unmounted(btrfs_dev); - return 0; + return get_label_unmounted(btrfs_dev); } @@ -116,6 +125,5 @@ int set_label(char *btrfs_dev, char *nLa fprintf(stderr, "FATAL: the filesystem has to be unmounted\n"); return -2; } - change_label_unmounted(btrfs_dev, nLabel); - return 0; + return change_label_unmounted(btrfs_dev, nLabel); } --- btrfs-progs-v0.19-118-gfdb6c04.orig/btrfstune.c +++ btrfs-progs-v0.19-118-gfdb6c04/btrfstune.c @@ -108,6 +108,11 @@ int main(int argc, char *argv[]) root = open_ctree(device, 0, 1); + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + return 1; + } + if (seeding_flag) { ret = update_seeding_flag(root, seeding_value); if (!ret) --- btrfs-progs-v0.19-118-gfdb6c04.orig/dir-test.c +++ btrfs-progs-v0.19-118-gfdb6c04/dir-test.c @@ -436,6 +436,12 @@ int main(int ac, char **av) radix_tree_init(); root = open_ctree(av[ac-1], &super, 0); + + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + return 1; + } + trans = btrfs_start_transaction(root, 1); dir_oid = btrfs_super_root_dir(&super); @@ -479,6 +485,11 @@ int main(int ac, char **av) btrfs_header_nritems(&root->node->node.header)); close_ctree(root, &super); root = open_ctree("dbfile", &super, 0); + + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + return 1; + } } while(count--) { ret = ops[op](trans, root, &radix); --- btrfs-progs-v0.19-118-gfdb6c04.orig/find-root.c +++ btrfs-progs-v0.19-118-gfdb6c04/find-root.c @@ -351,8 +351,11 @@ int main(int argc, char **argv) root = open_ctree_broken(dev_fd, argv[optind]); close(dev_fd); - if (!root) + + if (!root) { + fprintf(stderr, "Open ctree failed\n"); exit(1); + } csum_size = btrfs_super_csum_size(&root->fs_info->super_copy); ret = find_root(root); --- btrfs-progs-v0.19-118-gfdb6c04.orig/mkfs.c +++ btrfs-progs-v0.19-118-gfdb6c04/mkfs.c @@ -1362,8 +1362,9 @@ int main(int ac, char **av) root = open_ctree(file, 0, O_RDWR); if (!root) { - fprintf(stderr, "ctree init failed\n"); - return -1; + fprintf(stderr, "Open ctree failed\n"); + close (fd); + exit(1); } root->fs_info->alloc_start = alloc_start; --- btrfs-progs-v0.19-118-gfdb6c04.orig/quick-test.c +++ btrfs-progs-v0.19-118-gfdb6c04/quick-test.c @@ -52,6 +52,10 @@ int main(int ac, char **av) { radix_tree_init(); root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR); + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + exit(1); + } trans = btrfs_start_transaction(root, 1); srand(55); btrfs_set_key_type(&ins, BTRFS_STRING_ITEM_KEY); @@ -75,6 +79,10 @@ int main(int ac, char **av) { close_ctree(root); exit(1); root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR); + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + exit(1); + } printf("starting search\n"); srand(55); for (i = 0; i < run_size; i++) { @@ -94,6 +102,10 @@ int main(int ac, char **av) { close_ctree(root); root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR); + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + exit(1); + } printf("node %p level %d total ptrs %d free spc %lu\n", root->node, btrfs_header_level(root->node), btrfs_header_nritems(root->node), @@ -122,6 +134,10 @@ int main(int ac, char **av) { close_ctree(root); root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR); + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + exit(1); + } trans = btrfs_start_transaction(root, 1); srand(128); for (i = 0; i < run_size; i++) { @@ -138,6 +154,10 @@ int main(int ac, char **av) { close_ctree(root); root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR); + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + exit(1); + } srand(128); printf("starting search2\n"); for (i = 0; i < run_size; i++) { --- btrfs-progs-v0.19-118-gfdb6c04.orig/random-test.c +++ btrfs-progs-v0.19-118-gfdb6c04/random-test.c @@ -356,6 +356,10 @@ int main(int ac, char **av) struct btrfs_trans_handle *trans; radix_tree_init(); root = open_ctree("dbfile", &super); + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + exit(1); + } fill_radix(root, &radix); signal(SIGTERM, sigstopper); @@ -398,6 +402,10 @@ int main(int ac, char **av) btrfs_header_nritems(&root->node->node.header)); close_ctree(root, &super); root = open_ctree("dbfile", &super); + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + goto out; + } } while(count--) { ret = ops[op](trans, root, &radix);